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,80 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
4
+ /**
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ *
10
+ * @flow strict-local
11
+ * @format
12
+ */
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ var RelayModernRecord_1 = require("./RelayModernRecord");
17
+ /**
18
+ * @internal
19
+ *
20
+ * Wrapper API that is an amalgam of the `RelayModernRecord` API and
21
+ * `MutableRecordSource` interface, implementing copy-on-write semantics for records
22
+ * in a record source.
23
+ *
24
+ * Modifications are applied to fresh copies of records:
25
+ * - Records in `base` are never modified.
26
+ * - Modifications cause a fresh version of a record to be created in `sink`.
27
+ * These sink records contain only modified fields.
28
+ */
29
+ var RelayRecordSourceMutator = /** @class */function () {
30
+ function RelayRecordSourceMutator(base, sink) {
31
+ this.__sources = [sink, base];
32
+ this._base = base;
33
+ this._sink = sink;
34
+ }
35
+ RelayRecordSourceMutator.prototype._getSinkRecord = function (dataID) {
36
+ var sinkRecord = this._sink.get(dataID);
37
+ if (!sinkRecord) {
38
+ sinkRecord = RelayModernRecord_1.RelayModernRecord.create(dataID);
39
+ this._sink.set(dataID, sinkRecord);
40
+ }
41
+ return sinkRecord;
42
+ };
43
+ RelayRecordSourceMutator.prototype.create = function (dataID) {
44
+ var record = RelayModernRecord_1.RelayModernRecord.create(dataID);
45
+ this._sink.set(dataID, record);
46
+ };
47
+ RelayRecordSourceMutator.prototype.delete = function (dataID) {
48
+ this._sink.delete(dataID);
49
+ };
50
+ RelayRecordSourceMutator.prototype.getStatus = function (dataID) {
51
+ return this._sink.has(dataID) ? this._sink.getStatus(dataID) : this._base.getStatus(dataID);
52
+ };
53
+ RelayRecordSourceMutator.prototype.setValue = function (dataID, storageKey, value) {
54
+ var sinkRecord = this._getSinkRecord(dataID);
55
+ RelayModernRecord_1.RelayModernRecord.setValue(sinkRecord, storageKey, value);
56
+ };
57
+ RelayRecordSourceMutator.prototype.setLinkedRecordID = function (dataID, storageKey, linkedID) {
58
+ var sinkRecord = this._getSinkRecord(dataID);
59
+ RelayModernRecord_1.RelayModernRecord.setLinkedRecordID(sinkRecord, storageKey, linkedID);
60
+ };
61
+ RelayRecordSourceMutator.prototype.getLinkedRecordIDs = function (dataID, storageKey) {
62
+ for (var ii = 0; ii < this.__sources.length; ii++) {
63
+ var record = this.__sources[ii].get(dataID);
64
+ if (record) {
65
+ var linkedIDs = RelayModernRecord_1.RelayModernRecord.getLinkedRecordIDs(record, storageKey);
66
+ if (linkedIDs !== undefined) {
67
+ return linkedIDs;
68
+ }
69
+ } else if (record === null) {
70
+ return null;
71
+ }
72
+ }
73
+ };
74
+ RelayRecordSourceMutator.prototype.setLinkedRecordIDs = function (dataID, storageKey, linkedIDs) {
75
+ var sinkRecord = this._getSinkRecord(dataID);
76
+ RelayModernRecord_1.RelayModernRecord.setLinkedRecordIDs(sinkRecord, storageKey, linkedIDs);
77
+ };
78
+ return RelayRecordSourceMutator;
79
+ }();
80
+ exports.RelayRecordSourceMutator = 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,57 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
4
+ /**
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ *
10
+ * @flow
11
+ * @format
12
+ */
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ var RelayRecordProxy_1 = require("./RelayRecordProxy");
17
+ var RelayStoreUtils_1 = require("./RelayStoreUtils");
18
+ /**
19
+ * @internal
20
+ *
21
+ * A helper for manipulating a `RecordSource` via an imperative/OO-style API.
22
+ */
23
+ var RelayRecordSourceProxy = /** @class */function () {
24
+ function RelayRecordSourceProxy(mutator) {
25
+ this.__mutator = mutator;
26
+ this._proxies = {};
27
+ }
28
+ RelayRecordSourceProxy.prototype.create = function (dataID) {
29
+ this.__mutator.create(dataID);
30
+ delete this._proxies[dataID];
31
+ return this.get(dataID);
32
+ };
33
+ RelayRecordSourceProxy.prototype.delete = function (dataID) {
34
+ delete this._proxies[dataID];
35
+ this.__mutator.delete(dataID);
36
+ };
37
+ RelayRecordSourceProxy.prototype.get = function (dataID) {
38
+ if (!this._proxies.hasOwnProperty(dataID)) {
39
+ var status_1 = this.__mutator.getStatus(dataID);
40
+ if (status_1 === RelayStoreUtils_1.RelayRecordState.EXISTENT) {
41
+ this._proxies[dataID] = new RelayRecordProxy_1.RelayRecordProxy(this, this.__mutator, dataID);
42
+ } else {
43
+ this._proxies[dataID] = status_1 === RelayStoreUtils_1.RelayRecordState.NONEXISTENT ? null : undefined;
44
+ }
45
+ }
46
+ return this._proxies[dataID];
47
+ };
48
+ RelayRecordSourceProxy.prototype.getRoot = function () {
49
+ var root = this.get(RelayStoreUtils_1.RelayStoreUtils.ROOT_ID);
50
+ if (!root) {
51
+ root = this.create(RelayStoreUtils_1.RelayStoreUtils.ROOT_ID);
52
+ }
53
+ return root;
54
+ };
55
+ return RelayRecordSourceProxy;
56
+ }();
57
+ exports.RelayRecordSourceProxy = 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,60 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Copyright (c) Facebook, Inc. and its affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @flow strict-local
10
+ * @format
11
+ */
12
+ Object.defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ var RelayModernRecord_1 = require("./RelayModernRecord");
16
+ var RelayStoreUtils_1 = require("./RelayStoreUtils");
17
+ function mark(recordSource, selector, references) {
18
+ var dataID = selector.dataID,
19
+ node = selector.node;
20
+ var marker = new RelayReferenceMarker(recordSource, references);
21
+ marker.mark(node, dataID);
22
+ }
23
+ exports.mark = mark;
24
+ /**
25
+ * @private
26
+ */
27
+ var RelayReferenceMarker = /** @class */function () {
28
+ function RelayReferenceMarker(recordSource, references) {
29
+ this._recordSource = recordSource;
30
+ this._references = references;
31
+ }
32
+ RelayReferenceMarker.prototype.mark = function (node, dataID) {
33
+ this._traverse(node, dataID);
34
+ };
35
+ RelayReferenceMarker.prototype._traverse = function (node, dataID) {
36
+ if (dataID != null) {
37
+ this._references.add(dataID);
38
+ var record = this._recordSource.get(dataID);
39
+ record != null && this._traverseSelections(node.selections, record);
40
+ }
41
+ };
42
+ RelayReferenceMarker.prototype._traverseSelections = function (selections, record) {
43
+ var _this = this;
44
+ selections.forEach(function (selection) {
45
+ var name = selection.name;
46
+ if (selection.kind == RelayStoreUtils_1.LINKED_FIELD) {
47
+ if (selection.plural) {
48
+ var linkedIDs = RelayModernRecord_1.RelayModernRecord.getLinkedRecordIDs(record, name) || [];
49
+ linkedIDs.forEach(function (linkedID) {
50
+ _this._traverse(selection, linkedID);
51
+ });
52
+ } else {
53
+ var linkedID = RelayModernRecord_1.RelayModernRecord.getLinkedRecordID(record, name);
54
+ _this._traverse(selection, linkedID);
55
+ }
56
+ }
57
+ });
58
+ };
59
+ return RelayReferenceMarker;
60
+ }();
@@ -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,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var React = require("react");
7
+ var ReactRelayContext = React.createContext(null);
8
+ exports.StoreProvider = function (props) {
9
+ var context = React.useMemo(function () {
10
+ return {
11
+ store: props.store
12
+ };
13
+ }, [props.store]);
14
+ return React.createElement(ReactRelayContext.Provider, {
15
+ value: context
16
+ }, props.children);
17
+ };
18
+ function useStore() {
19
+ var store = React.useContext(ReactRelayContext).store;
20
+ return store;
21
+ }
22
+ exports.useStore = useStore;
@@ -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;
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
7
+ /**
8
+ * Copyright (c) Facebook, Inc. and its affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ *
13
+ * @flow
14
+ * @format
15
+ */
16
+ function isPromise(p) {
17
+ return !!p && typeof p.then === 'function';
18
+ }
19
+ exports.isPromise = isPromise;
20
+ 'use strict';
21
+ /**
22
+ * Copyright (c) 2013-present, Facebook, Inc.
23
+ *
24
+ * This source code is licensed under the MIT license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ *
27
+ *
28
+ */
29
+ var aStackPool = [];
30
+ var bStackPool = [];
31
+ /**
32
+ * Checks if two values are equal. Values may be primitives, arrays, or objects.
33
+ * Returns true if both arguments have the same keys and values.
34
+ *
35
+ * @see http://underscorejs.org
36
+ * @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
37
+ * @license MIT
38
+ */
39
+ function areEqual(a, b) {
40
+ var aStack = aStackPool.length ? aStackPool.pop() : [];
41
+ var bStack = bStackPool.length ? bStackPool.pop() : [];
42
+ var result = eq(a, b, aStack, bStack);
43
+ aStack.length = 0;
44
+ bStack.length = 0;
45
+ aStackPool.push(aStack);
46
+ bStackPool.push(bStack);
47
+ return result;
48
+ }
49
+ exports.areEqual = areEqual;
50
+ function eq(a, b, aStack, bStack) {
51
+ if (a === b) {
52
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
53
+ return a !== 0 || 1 / a == 1 / b;
54
+ }
55
+ if (a == null || b == null) {
56
+ // a or b can be `null` or `undefined`
57
+ return false;
58
+ }
59
+ if (typeof a != 'object' || typeof b != 'object') {
60
+ return false;
61
+ }
62
+ var objToStr = Object.prototype.toString;
63
+ var className = objToStr.call(a);
64
+ if (className != objToStr.call(b)) {
65
+ return false;
66
+ }
67
+ switch (className) {
68
+ case '[object String]':
69
+ return a == String(b);
70
+ case '[object Number]':
71
+ return isNaN(a) || isNaN(b) ? false : a == Number(b);
72
+ case '[object Date]':
73
+ case '[object Boolean]':
74
+ return +a == +b;
75
+ case '[object RegExp]':
76
+ return a.source == b.source && a.global == b.global && a.multiline == b.multiline && a.ignoreCase == b.ignoreCase;
77
+ } // Assume equality for cyclic structures.
78
+ var length = aStack.length;
79
+ // eslint-disable-next-line no-plusplus
80
+ while (length--) {
81
+ if (aStack[length] == a) {
82
+ return bStack[length] == b;
83
+ }
84
+ }
85
+ aStack.push(a);
86
+ bStack.push(b);
87
+ var size = 0; // Recursively compare objects and arrays.
88
+ if (className === '[object Array]') {
89
+ size = a.length;
90
+ if (size !== b.length) {
91
+ return false;
92
+ } // Deep compare the contents, ignoring non-numeric properties.
93
+ // eslint-disable-next-line no-plusplus
94
+ while (size--) {
95
+ if (!eq(a[size], b[size], aStack, bStack)) {
96
+ return false;
97
+ }
98
+ }
99
+ } else {
100
+ if (a.constructor !== b.constructor) {
101
+ return false;
102
+ }
103
+ if (a.hasOwnProperty('valueOf') && b.hasOwnProperty('valueOf')) {
104
+ return a.valueOf() == b.valueOf();
105
+ }
106
+ var keys = Object.keys(a);
107
+ if (keys.length != Object.keys(b).length) {
108
+ return false;
109
+ }
110
+ for (var i = 0; i < keys.length; i++) {
111
+ if (!eq(a[keys[i]], b[keys[i]], aStack, bStack)) {
112
+ return false;
113
+ }
114
+ }
115
+ }
116
+ aStack.pop();
117
+ bStack.pop();
118
+ return true;
119
+ }
120
+ /**
121
+ * Constants shared by all implementations of RecordSource/MutableRecordSource/etc.
122
+ */
123
+ exports.RelayStoreUtils = {
124
+ ID_KEY: '__id',
125
+ REF_KEY: '__ref',
126
+ REFS_KEY: '__refs',
127
+ ROOT_ID: 'client:root'
128
+ };
129
+ var RelayRecordState;
130
+ (function (RelayRecordState) {
131
+ /**
132
+ * Record exists (either fetched from the server or produced by a local,
133
+ * optimistic update).
134
+ */
135
+ RelayRecordState["EXISTENT"] = "EXISTENT";
136
+ /**
137
+ * Record is known not to exist (either as the result of a mutation, or
138
+ * because the server returned `null` when queried for the record).
139
+ */
140
+ RelayRecordState["NONEXISTENT"] = "NONEXISTENT";
141
+ /**
142
+ * Record State is unknown because it has not yet been fetched from the
143
+ * server.
144
+ */
145
+ RelayRecordState["UNKNOWN"] = "UNKNOWN";
146
+ })(RelayRecordState = exports.RelayRecordState || (exports.RelayRecordState = {}));
147
+ exports.LINKED_FIELD = 'LinkedField';
148
+ //const hasWeakSetDefined = typeof WeakSet !== 'undefined';
149
+ //const hasWeakMapDefined = typeof WeakMap !== 'undefined';
150
+ function checkRecycleData(data) {
151
+ return typeof data !== 'object' || data instanceof Set || data instanceof Map ||
152
+ //(hasWeakSetDefined && nextData instanceof WeakSet) ||
153
+ //(hasWeakMapDefined && nextData instanceof WeakMap) ||
154
+ !data;
155
+ }
156
+ /**
157
+ * Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
158
+ */
159
+ function recycleNodesInto(prevData, nextData) {
160
+ if (prevData === nextData || checkRecycleData(prevData) || checkRecycleData(nextData)) {
161
+ return nextData;
162
+ }
163
+ var canRecycle = false;
164
+ // Assign local variables to preserve Flow type refinement.
165
+ var prevArray = Array.isArray(prevData) ? prevData : null;
166
+ var nextArray = Array.isArray(nextData) ? nextData : null;
167
+ if (prevArray && nextArray) {
168
+ canRecycle = nextArray.reduce(function (wasEqual, nextItem, ii) {
169
+ var prevValue = prevArray[ii];
170
+ var nextValue = recycleNodesInto(prevValue, nextItem);
171
+ if (nextValue !== nextArray[ii]) {
172
+ nextArray[ii] = nextValue;
173
+ }
174
+ return wasEqual && nextValue === prevArray[ii];
175
+ }, true) && prevArray.length === nextArray.length;
176
+ } else if (!prevArray && !nextArray) {
177
+ // Assign local variables to preserve Flow type refinement.
178
+ var prevObject_1 = prevData;
179
+ var nextObject_1 = nextData;
180
+ var prevKeys = Object.keys(prevObject_1);
181
+ var nextKeys = Object.keys(nextObject_1);
182
+ canRecycle = nextKeys.reduce(function (wasEqual, key) {
183
+ var prevValue = prevObject_1[key];
184
+ var nextValue = recycleNodesInto(prevValue, nextObject_1[key]);
185
+ if (nextValue !== nextObject_1[key]) {
186
+ nextObject_1[key] = nextValue;
187
+ }
188
+ return wasEqual && nextValue === prevObject_1[key];
189
+ }, true) && prevKeys.length === nextKeys.length;
190
+ }
191
+ return canRecycle ? prevData : nextData;
192
+ }
193
+ exports.recycleNodesInto = recycleNodesInto;
194
+ var ITERATOR_KEY = Symbol.iterator;
195
+ function hasOverlappingIDs(seenRecords, updatedRecordIDs) {
196
+ // $FlowFixMe: Set is an iterable type, accessing its iterator is allowed.
197
+ var iterator = seenRecords[ITERATOR_KEY]();
198
+ var next = iterator.next();
199
+ while (!next.done) {
200
+ var key = next.value;
201
+ if (updatedRecordIDs.has(key)) {
202
+ return true;
203
+ }
204
+ next = iterator.next();
205
+ }
206
+ return false;
207
+ }
208
+ exports.hasOverlappingIDs = hasOverlappingIDs;
@@ -0,0 +1,92 @@
1
+ import { RelayRecordState } from './RelayStoreUtils';
2
+ export declare type Disposable = {
3
+ dispose(): void;
4
+ };
5
+ export interface RecordProxy {
6
+ getDataID(): string;
7
+ getLinkedRecords(name: string): Array<RecordProxy | null | undefined> | null | undefined;
8
+ setLinkedRecord(record: RecordProxy, name: string): RecordProxy;
9
+ setLinkedRecords(records: Array<RecordProxy>, name: string): RecordProxy;
10
+ setValue(value: any, name: string): RecordProxy;
11
+ }
12
+ export interface RecordSourceProxy {
13
+ create(string: string): RecordProxy;
14
+ delete(string: string): void;
15
+ get(string: string): RecordProxy | null | undefined;
16
+ getRoot(): RecordProxy;
17
+ }
18
+ export declare type StoreUpdater = (store: RecordSourceProxy) => void;
19
+ export declare type Record = {
20
+ [key: string]: any;
21
+ };
22
+ export declare type SelectorData = {
23
+ [key: string]: any;
24
+ };
25
+ export declare type RecordState = keyof typeof RelayRecordState;
26
+ export interface RecordSource {
27
+ get(dataID: string): Record | null | undefined;
28
+ getRecordIDs(): Array<string>;
29
+ getStatus(dataID: string): RecordState;
30
+ has(dataID: string): boolean;
31
+ size(): number;
32
+ toJSON(): {
33
+ [key: string]: Record | null | undefined;
34
+ };
35
+ }
36
+ export declare type Snapshot = {
37
+ data: SelectorData | null | undefined;
38
+ seenRecords: Set<string>;
39
+ selector: any;
40
+ };
41
+ export declare type OperationDescriptor = {
42
+ fragment: any;
43
+ request: any;
44
+ root: any;
45
+ };
46
+ export interface Store {
47
+ /**
48
+ * Commit an updater to the environment. This mutation cannot be reverted and
49
+ * should therefore not be used for optimistic updates. This is mainly
50
+ * intended for updating fields from client schema extensions.
51
+ */
52
+ commitUpdate(updater: StoreUpdater): void;
53
+ /**
54
+ * Get a read-only view of the store's internal RecordSource.
55
+ */
56
+ getSource(): RecordSource;
57
+ /**
58
+ * Read the results of a selector from in-memory records in the store.
59
+ */
60
+ lookup(selector: any): Snapshot;
61
+ /**
62
+ * Notify subscribers (see `subscribe`) of any data that was published
63
+ * (`publish()`) since the last time `notify` was called.
64
+ * Optionally provide an OperationDescriptor indicating the source operation
65
+ * that was being processed to produce this run.
66
+ */
67
+ notify(sourceOperation?: OperationDescriptor, invalidateStore?: boolean): any;
68
+ /**
69
+ * Publish new information (e.g. from the network) to the store, updating its
70
+ * internal record source. Subscribers are not immediately notified - this
71
+ * occurs when `notify()` is called.
72
+ */
73
+ publish(source: RecordSource): void;
74
+ /**
75
+ * Ensure that all the records necessary to fulfill the given selector are
76
+ * retained in memory. The records will not be eligible for garbage collection
77
+ * until the returned reference is disposed.
78
+ */
79
+ retain(operation: OperationDescriptor): Disposable;
80
+ /**
81
+ * Subscribe to changes to the results of a selector. The callback is called
82
+ * when `notify()` is called *and* records have been published that affect the
83
+ * selector results relative to the last `notify()`.
84
+ */
85
+ subscribe(snapshot: Snapshot, callback: (snapshot: Snapshot) => void): Disposable;
86
+ }
87
+ export interface MutableRecordSource extends RecordSource {
88
+ clear(): void;
89
+ delete(dataID: string): void;
90
+ remove(dataID: string): void;
91
+ set(dataID: string, record: Record): void;
92
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });