@warp-drive/core 5.7.0-alpha.14 → 5.7.0-alpha.16

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 (69) hide show
  1. package/declarations/graph/-private/-diff.d.ts +8 -8
  2. package/declarations/graph/-private/-edge-definition.d.ts +2 -2
  3. package/declarations/graph/-private/-state.d.ts +2 -2
  4. package/declarations/graph/-private/-utils.d.ts +5 -5
  5. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
  6. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  7. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  8. package/declarations/graph/-private/edges/resource.d.ts +5 -5
  9. package/declarations/graph/-private/graph.d.ts +15 -15
  10. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
  11. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
  12. package/declarations/index.d.ts +1 -1
  13. package/declarations/reactive/-private/default-mode.d.ts +2 -2
  14. package/declarations/reactive/-private/document.d.ts +6 -16
  15. package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
  16. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  17. package/declarations/reactive/-private/hooks.d.ts +2 -2
  18. package/declarations/reactive/-private/record.d.ts +44 -5
  19. package/declarations/reactive/-private/schema.d.ts +12 -12
  20. package/declarations/reactive/-private/symbols.d.ts +1 -0
  21. package/declarations/reactive.d.ts +277 -1
  22. package/declarations/request/-private/context.d.ts +2 -2
  23. package/declarations/request/-private/manager.d.ts +2 -2
  24. package/declarations/request/-private/types.d.ts +4 -4
  25. package/declarations/store/-private/cache-handler/types.d.ts +9 -9
  26. package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
  27. package/declarations/store/-private/caches/instance-cache.d.ts +18 -18
  28. package/declarations/store/-private/default-cache-policy.d.ts +25 -38
  29. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +13 -11
  30. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +21 -19
  31. package/declarations/store/-private/managers/cache-manager.d.ts +46 -94
  32. package/declarations/store/-private/managers/notification-manager.d.ts +21 -22
  33. package/declarations/store/-private/managers/record-array-manager.d.ts +15 -15
  34. package/declarations/store/-private/network/request-cache.d.ts +11 -11
  35. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  36. package/declarations/store/-private/new-core-tmp/request-state.d.ts +1 -1
  37. package/declarations/store/-private/record-arrays/-utils.d.ts +3 -3
  38. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +2 -2
  39. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +2 -2
  40. package/declarations/store/-private/record-arrays/resource-array.d.ts +9 -9
  41. package/declarations/store/-private/store-service.d.ts +19 -16
  42. package/declarations/store/-private.d.ts +1 -1
  43. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  44. package/declarations/store/-types/q/identifier.d.ts +9 -6
  45. package/declarations/store/-types/q/schema-service.d.ts +9 -9
  46. package/declarations/store/deprecated/-private.d.ts +5 -5
  47. package/declarations/types/-private.d.ts +1 -1
  48. package/declarations/types/cache/aliases.d.ts +2 -2
  49. package/declarations/types/cache/change.d.ts +2 -2
  50. package/declarations/types/cache/mutations.d.ts +13 -13
  51. package/declarations/types/cache/operations.d.ts +20 -20
  52. package/declarations/types/cache/relationship.d.ts +4 -4
  53. package/declarations/types/cache.d.ts +51 -113
  54. package/declarations/types/graph.d.ts +12 -12
  55. package/declarations/types/identifier.d.ts +60 -76
  56. package/declarations/types/request.d.ts +6 -6
  57. package/declarations/types/schema/concepts.d.ts +2 -2
  58. package/declarations/types/spec/document.d.ts +6 -6
  59. package/dist/graph/-private.js +125 -125
  60. package/dist/index.js +2 -2
  61. package/dist/reactive/-private.js +1 -1
  62. package/dist/reactive.js +126 -4
  63. package/dist/{request-state-CCrTjb0Z.js → request-state-CQ0Q6d1V.js} +3493 -3483
  64. package/dist/store/-private.js +1 -1
  65. package/dist/store.js +30 -43
  66. package/dist/{symbols-C5p2hcy9.js → symbols-sql1_mdx.js} +2 -1
  67. package/dist/types/-private.js +1 -1
  68. package/dist/types/identifier.js +19 -45
  69. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@ import { a as cloneResponseProperties, I as IS_CACHE_HANDLER, b as assertValidRe
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
4
  import { w as waitFor } from "./configure-B48bFHOl.js";
5
5
  import { peekUniversalTransient, setUniversalTransient } from './types/-private.js';
6
- export { C as CacheHandler, S as Store, r as recordIdentifierFor, K as setIdentifierForgetMethod, I as setIdentifierGenerationMethod, L as setIdentifierResetMethod, J as setIdentifierUpdateMethod, M as setKeyInfoForResource, s as storeFor } from "./request-state-CCrTjb0Z.js";
6
+ export { C as CacheHandler, S as Store, r as recordIdentifierFor, M as setIdentifierForgetMethod, K as setIdentifierGenerationMethod, N as setIdentifierResetMethod, L as setIdentifierUpdateMethod, O as setKeyInfoForResource, s as storeFor } from "./request-state-CQ0Q6d1V.js";
7
7
  import '@ember/debug';
8
8
  import './utils/string.js';
9
- import "./symbols-C5p2hcy9.js";
9
+ import "./symbols-sql1_mdx.js";
10
10
 
11
11
  // Lazily close over fetch to avoid breaking Mirage
12
12
  const _fetch = typeof fetch !== 'undefined' ? (...args) => fetch(...args) : typeof FastBoot !== 'undefined' ? (...args) => FastBoot.require('node-fetch')(...args) : () => {
@@ -1 +1 @@
1
- export { C as Context } from "../symbols-C5p2hcy9.js";
1
+ export { C as Context } from "../symbols-sql1_mdx.js";
package/dist/reactive.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { F as ReactiveResource, G as isNonIdentityCacheableField, H as getFieldCacheKeyStrict, r as recordIdentifierFor, z as withSignalStore } from "./request-state-CQ0Q6d1V.js";
2
+ export { I as checkout, J as commit } from "./request-state-CQ0Q6d1V.js";
1
3
  import { isResourceSchema } from './types/schema/fields.js';
2
- import { F as ReactiveResource, G as isNonIdentityCacheableField, H as getFieldCacheKeyStrict, r as recordIdentifierFor, z as withSignalStore } from "./request-state-CCrTjb0Z.js";
3
- import { D as Destroy, C as Context } from "./symbols-C5p2hcy9.js";
4
- export { a as Checkout } from "./symbols-C5p2hcy9.js";
4
+ import { D as Destroy, C as Context } from "./symbols-sql1_mdx.js";
5
+ export { a as Checkout } from "./symbols-sql1_mdx.js";
5
6
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
7
  import { warn, deprecate } from '@ember/debug';
7
8
  import './index.js';
@@ -772,4 +773,125 @@ function mergeMap(base, toApply) {
772
773
  base.set(key, value);
773
774
  }
774
775
  }
775
- export { SchemaService, fromIdentity, instantiateRecord, registerDerivations, teardownRecord, withDefaults };
776
+ const Subscriptions = new WeakMap();
777
+
778
+ /**
779
+ * `ExpensiveSubscription` is a mechanism for non-reactive
780
+ * frameworks such as `react` to integrate with WarpDrive.
781
+ *
782
+ * This mechanism should never be used by frameworks or libraries
783
+ * that support fine-grained reactivity.
784
+ *
785
+ * ExpensiveSubscription is expensive *because* it doubles the number
786
+ * of notification callbacks required for each resource contained in
787
+ * the request being subscribed to. The more requests in-use, the more
788
+ * this cost adds up.
789
+ */
790
+ class ExpensiveSubscription {
791
+ constructor(store, request) {
792
+ this._store = store;
793
+ this._request = request;
794
+ this._callbacks = new Set();
795
+ this._resources = new Map();
796
+ this._subscription = store.notifications.subscribe(request, this._notifyRequestChange);
797
+ this._updateResourceCallbacks();
798
+ }
799
+ _updateResourceCallbacks() {
800
+ const request = this._request;
801
+ const store = this._store;
802
+ const {
803
+ notifications
804
+ } = store;
805
+ const req = store.cache.peek(request);
806
+ const resources = this._resources;
807
+ const isInitialSubscription = resources.size === 0;
808
+ if (req && 'data' in req) {
809
+ if (Array.isArray(req.data)) {
810
+ for (const resourceKey of req.data) {
811
+ if (isInitialSubscription || !resources.has(resourceKey)) {
812
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
813
+ }
814
+ }
815
+ } else if (req.data) {
816
+ if (isInitialSubscription || !resources.has(req.data)) {
817
+ resources.set(req.data, notifications.subscribe(req.data, this._scheduleNotify));
818
+ }
819
+ }
820
+ }
821
+ if (req && 'included' in req && Array.isArray(req.included)) {
822
+ for (const resourceKey of req.included) {
823
+ if (isInitialSubscription || !resources.has(resourceKey)) {
824
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
825
+ }
826
+ }
827
+ }
828
+ }
829
+ _notifyRequestChange = () => {
830
+ this._updateResourceCallbacks();
831
+ this._scheduleNotify();
832
+ };
833
+ _scheduleNotify = () => {
834
+ this._notify = this._notify || Promise.resolve().then(() => {
835
+ for (const callback of this._callbacks) {
836
+ callback();
837
+ }
838
+ this._notify = null;
839
+ });
840
+ };
841
+ addWatcher(callback) {
842
+ this._callbacks.add(callback);
843
+ }
844
+ removeWatcher(callback) {
845
+ this._callbacks.delete(callback);
846
+ if (this._callbacks.size === 0) {
847
+ this.destroy();
848
+ }
849
+ }
850
+ destroy() {
851
+ Subscriptions.delete(this._request);
852
+ const {
853
+ notifications
854
+ } = this._store;
855
+ if (this._subscription) {
856
+ notifications.unsubscribe(this._subscription);
857
+ }
858
+ for (const token of this._resources.values()) {
859
+ notifications.unsubscribe(token);
860
+ }
861
+ this._callbacks.clear();
862
+ this._resources.clear();
863
+ }
864
+ }
865
+
866
+ /**
867
+ * Creates an {@link ExpensiveSubscription} for the {@link RequestKey}
868
+ * if one does not already exist and adds a watcher to it.
869
+ *
870
+ * Returns a cleanup function. This should be called on-mount by a component
871
+ * that wants to subscribe to a request and cleanup should be called on dismount.
872
+ *
873
+ * ::: warning ⚠️ Avoid Using If Your App Supports Fine-grained Reactivity
874
+ * This mechanism should never be used by frameworks or libraries
875
+ * that support fine-grained reactivity.
876
+ * :::
877
+ *
878
+ * `ExpensiveSubscription` is a mechanism for non-reactive
879
+ * frameworks such as `react` to integrate with WarpDrive, for instance
880
+ * by treating a request as an [external store](https://react.dev/reference/react/useSyncExternalStore)
881
+ *
882
+ * `ExpensiveSubscription` is expensive *because* it doubles the number
883
+ * of notification callbacks required for each resource contained in
884
+ * the request being subscribed to. The more requests in-use, the more
885
+ * this cost adds up.
886
+ */
887
+ function getExpensiveRequestSubscription(store, requestKey, callback) {
888
+ let subscription = Subscriptions.get(requestKey);
889
+ if (!subscription) {
890
+ subscription = new ExpensiveSubscription(store, requestKey);
891
+ }
892
+ subscription.addWatcher(callback);
893
+ return () => {
894
+ subscription.removeWatcher(callback);
895
+ };
896
+ }
897
+ export { SchemaService, fromIdentity, getExpensiveRequestSubscription, instantiateRecord, registerDerivations, teardownRecord, withDefaults };