@ember-data/store 5.4.0-alpha.3 → 5.4.0-alpha.31

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 (76) hide show
  1. package/README.md +8 -4
  2. package/addon/-private.js +1 -1
  3. package/addon/{store-service-0a03d2a4.js → cache-handler-oB00-31L.js} +1165 -1014
  4. package/addon/cache-handler-oB00-31L.js.map +1 -0
  5. package/addon/index.js +1 -1
  6. package/addon/index.js.map +1 -1
  7. package/package.json +62 -41
  8. package/unstable-preview-types/-private/cache-handler.d.ts +99 -0
  9. package/unstable-preview-types/-private/cache-handler.d.ts.map +1 -0
  10. package/unstable-preview-types/-private/caches/cache-utils.d.ts +9 -0
  11. package/unstable-preview-types/-private/caches/cache-utils.d.ts.map +1 -0
  12. package/unstable-preview-types/-private/caches/identifier-cache.d.ts +180 -0
  13. package/unstable-preview-types/-private/caches/identifier-cache.d.ts.map +1 -0
  14. package/unstable-preview-types/-private/caches/instance-cache.d.ts +61 -0
  15. package/unstable-preview-types/-private/caches/instance-cache.d.ts.map +1 -0
  16. package/unstable-preview-types/-private/caches/resource-utils.d.ts +10 -0
  17. package/unstable-preview-types/-private/caches/resource-utils.d.ts.map +1 -0
  18. package/unstable-preview-types/-private/document.d.ts +144 -0
  19. package/unstable-preview-types/-private/document.d.ts.map +1 -0
  20. package/unstable-preview-types/-private/index.d.ts +16 -0
  21. package/unstable-preview-types/-private/index.d.ts.map +1 -0
  22. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts +177 -0
  23. package/unstable-preview-types/-private/legacy-model-support/record-reference.d.ts.map +1 -0
  24. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts +17 -0
  25. package/unstable-preview-types/-private/legacy-model-support/shim-model-class.d.ts.map +1 -0
  26. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts +27 -0
  27. package/unstable-preview-types/-private/managers/cache-capabilities-manager.d.ts.map +1 -0
  28. package/unstable-preview-types/-private/managers/cache-manager.d.ts +440 -0
  29. package/unstable-preview-types/-private/managers/cache-manager.d.ts.map +1 -0
  30. package/unstable-preview-types/-private/managers/notification-manager.d.ts +96 -0
  31. package/unstable-preview-types/-private/managers/notification-manager.d.ts.map +1 -0
  32. package/unstable-preview-types/-private/managers/record-array-manager.d.ts +95 -0
  33. package/unstable-preview-types/-private/managers/record-array-manager.d.ts.map +1 -0
  34. package/unstable-preview-types/-private/network/request-cache.d.ts +107 -0
  35. package/unstable-preview-types/-private/network/request-cache.d.ts.map +1 -0
  36. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts +135 -0
  37. package/unstable-preview-types/-private/record-arrays/identifier-array.d.ts.map +1 -0
  38. package/unstable-preview-types/-private/store-service.d.ts +1552 -0
  39. package/unstable-preview-types/-private/store-service.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/utils/coerce-id.d.ts +8 -0
  41. package/unstable-preview-types/-private/utils/coerce-id.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/utils/construct-resource.d.ts +8 -0
  43. package/unstable-preview-types/-private/utils/construct-resource.d.ts.map +1 -0
  44. package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts +5 -0
  45. package/unstable-preview-types/-private/utils/identifier-debug-consts.d.ts.map +1 -0
  46. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts +2 -0
  47. package/unstable-preview-types/-private/utils/is-non-empty-string.d.ts.map +1 -0
  48. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts +2 -0
  49. package/unstable-preview-types/-private/utils/normalize-model-name.d.ts.map +1 -0
  50. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts +2 -0
  51. package/unstable-preview-types/-private/utils/uuid-polyfill.d.ts.map +1 -0
  52. package/unstable-preview-types/-private.d.ts +2 -0
  53. package/unstable-preview-types/-private.d.ts.map +1 -0
  54. package/unstable-preview-types/-types/overview.d.ts +19 -0
  55. package/unstable-preview-types/-types/overview.d.ts.map +1 -0
  56. package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts +105 -0
  57. package/unstable-preview-types/-types/q/cache-store-wrapper.d.ts.map +1 -0
  58. package/unstable-preview-types/-types/q/cache.d.ts +45 -0
  59. package/unstable-preview-types/-types/q/cache.d.ts.map +1 -0
  60. package/unstable-preview-types/-types/q/ds-model.d.ts +13 -0
  61. package/unstable-preview-types/-types/q/ds-model.d.ts.map +1 -0
  62. package/unstable-preview-types/-types/q/identifier.d.ts +169 -0
  63. package/unstable-preview-types/-types/q/identifier.d.ts.map +1 -0
  64. package/unstable-preview-types/-types/q/promise-proxies.d.ts +2 -0
  65. package/unstable-preview-types/-types/q/promise-proxies.d.ts.map +1 -0
  66. package/unstable-preview-types/-types/q/record-data-json-api.d.ts +34 -0
  67. package/unstable-preview-types/-types/q/record-data-json-api.d.ts.map +1 -0
  68. package/unstable-preview-types/-types/q/record-instance.d.ts +27 -0
  69. package/unstable-preview-types/-types/q/record-instance.d.ts.map +1 -0
  70. package/unstable-preview-types/-types/q/schema-service.d.ts +212 -0
  71. package/unstable-preview-types/-types/q/schema-service.d.ts.map +1 -0
  72. package/unstable-preview-types/-types/q/store.d.ts +15 -0
  73. package/unstable-preview-types/-types/q/store.d.ts.map +1 -0
  74. package/unstable-preview-types/index.d.ts +185 -0
  75. package/unstable-preview-types/index.d.ts.map +1 -0
  76. package/addon/store-service-0a03d2a4.js.map +0 -1
package/addon/index.js CHANGED
@@ -1 +1 @@
1
- export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./store-service-0a03d2a4";
1
+ export { C as CacheHandler, S as default, r as recordIdentifierFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./cache-handler-oB00-31L";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ember-data/store",
3
- "version": "5.4.0-alpha.3",
3
+ "version": "5.4.0-alpha.31",
4
4
  "description": "The core of EmberData. Provides the Store service which coordinates the cache with the network and presentation layers.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -11,70 +11,91 @@
11
11
  "directory": "packages/store"
12
12
  },
13
13
  "license": "MIT",
14
- "author": "",
15
- "directories": {},
16
- "ember-addon": {
17
- "main": "addon-main.js",
18
- "type": "addon",
19
- "version": 1
20
- },
14
+ "author": "Chris Thoburn <runspired@users.noreply.github.com>",
21
15
  "files": [
16
+ "unstable-preview-types",
22
17
  "addon-main.js",
23
18
  "addon",
24
19
  "README.md",
25
20
  "LICENSE.md",
26
21
  "ember-data-logo-dark.svg",
27
- "ember-data-logo-light.svg",
28
- "ember-data-logo-dark.svg",
29
22
  "ember-data-logo-light.svg"
30
23
  ],
31
- "peerDependencies": {
32
- "@ember-data/tracking": "5.4.0-alpha.3",
33
- "@ember/string": "^3.1.1",
34
- "@glimmer/tracking": "^1.1.2"
24
+ "dependencies": {
25
+ "@ember-data/private-build-infra": "5.4.0-alpha.31",
26
+ "@embroider/macros": "^1.13.5",
27
+ "ember-cli-babel": "^8.2.0",
28
+ "pnpm-sync-dependencies-meta-injected": "0.0.10"
35
29
  },
36
30
  "dependenciesMeta": {
37
31
  "@ember-data/private-build-infra": {
38
32
  "injected": true
33
+ },
34
+ "@ember-data/tracking": {
35
+ "injected": true
36
+ },
37
+ "@ember-data/request": {
38
+ "injected": true
39
+ },
40
+ "@warp-drive/core-types": {
41
+ "injected": true
42
+ },
43
+ "@ember/string": {
44
+ "injected": true
39
45
  }
40
46
  },
41
- "dependencies": {
42
- "@ember-data/private-build-infra": "5.4.0-alpha.3",
43
- "@embroider/macros": "^1.13.1",
44
- "ember-cached-decorator-polyfill": "^1.0.2",
45
- "ember-cli-babel": "^7.26.11"
47
+ "peerDependencies": {
48
+ "@ember-data/request": "5.4.0-alpha.31",
49
+ "@ember-data/tracking": "5.4.0-alpha.31",
50
+ "@ember/string": "^3.1.1",
51
+ "@warp-drive/core-types": "0.0.0-alpha.17"
46
52
  },
47
53
  "devDependencies": {
48
- "@babel/cli": "^7.22.10",
49
- "@babel/core": "^7.22.10",
50
- "@babel/plugin-proposal-decorators": "^7.22.10",
51
- "@babel/plugin-transform-class-properties": "^7.22.5",
52
- "@babel/plugin-transform-private-methods": "^7.22.5",
53
- "@babel/plugin-transform-runtime": "^7.22.10",
54
- "@babel/plugin-transform-typescript": "^7.22.10",
55
- "@babel/preset-env": "^7.22.10",
56
- "@babel/preset-typescript": "^7.22.5",
57
- "@babel/runtime": "^7.22.10",
58
- "@embroider/addon-dev": "^4.1.0",
54
+ "@babel/cli": "^7.23.9",
55
+ "@babel/core": "^7.23.9",
56
+ "@babel/plugin-proposal-decorators": "^7.23.9",
57
+ "@babel/plugin-transform-class-properties": "^7.23.3",
58
+ "@babel/plugin-transform-private-methods": "^7.23.3",
59
+ "@babel/plugin-transform-runtime": "^7.23.9",
60
+ "@babel/plugin-transform-typescript": "^7.23.6",
61
+ "@babel/preset-env": "^7.23.9",
62
+ "@babel/preset-typescript": "^7.23.3",
63
+ "@babel/runtime": "^7.23.9",
64
+ "@ember-data/request": "5.4.0-alpha.31",
65
+ "@ember-data/tracking": "5.4.0-alpha.31",
66
+ "@ember/string": "^3.1.1",
67
+ "@embroider/addon-dev": "^4.1.2",
59
68
  "@glimmer/component": "^1.1.2",
60
- "@rollup/plugin-babel": "^6.0.3",
61
- "@rollup/plugin-node-resolve": "^15.2.0",
62
- "ember-source": "~5.2.0",
63
- "rollup": "^3.28.0",
64
- "tslib": "^2.6.1",
65
- "typescript": "^5.1.6",
69
+ "@rollup/plugin-babel": "^6.0.4",
70
+ "@rollup/plugin-node-resolve": "^15.2.3",
71
+ "@warp-drive/core-types": "0.0.0-alpha.17",
72
+ "@warp-drive/internal-config": "5.4.0-alpha.31",
73
+ "ember-source": "~5.6.0",
74
+ "rollup": "^4.9.6",
75
+ "typescript": "^5.3.3",
66
76
  "walk-sync": "^3.0.0",
67
- "webpack": "^5.88.2"
77
+ "webpack": "^5.89.0"
68
78
  },
69
79
  "engines": {
70
- "node": "16.* || >= 18.*"
80
+ "node": ">= 18.19.1"
71
81
  },
72
82
  "volta": {
73
83
  "extends": "../../package.json"
74
84
  },
75
- "packageManager": "pnpm@8.6.12",
85
+ "packageManager": "pnpm@8.6.0",
86
+ "ember-addon": {
87
+ "main": "addon-main.js",
88
+ "type": "addon",
89
+ "version": 1
90
+ },
91
+ "ember": {
92
+ "edition": "octane"
93
+ },
76
94
  "scripts": {
77
- "build": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
78
- "start": "rollup --config --watch"
95
+ "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives",
96
+ "build:runtime": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
97
+ "build:types": "tsc --build",
98
+ "_build": "bun run build:runtime && bun run build:types",
99
+ "_syncPnpm": "bun run sync-dependencies-meta-injected"
79
100
  }
80
101
  }
@@ -0,0 +1,99 @@
1
+ import type { Handler } from '@ember-data/request/-private/types';
2
+ import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier';
3
+ import type { ImmutableRequestInfo, RequestContext, ResponseInfo } from '@warp-drive/core-types/request';
4
+ import { EnableHydration } from '@warp-drive/core-types/request';
5
+ import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
6
+ import type Store from './store-service';
7
+ /**
8
+ * A service which an application may provide to the store via
9
+ * the store's `lifetimes` property to configure the behavior
10
+ * of the CacheHandler.
11
+ *
12
+ * The default behavior for request lifetimes is to never expire
13
+ * unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
14
+ *
15
+ * Implementing this service allows you to programatically define
16
+ * when a request should be considered expired.
17
+ *
18
+ * @class <Interface> LifetimesService
19
+ * @public
20
+ */
21
+ export interface LifetimesService {
22
+ /**
23
+ * Invoked to determine if the request may be fulfilled from cache
24
+ * if possible.
25
+ *
26
+ * Note, this is only invoked if the request has a cache-key.
27
+ *
28
+ * If no cache entry is found or the entry is hard expired,
29
+ * the request will be fulfilled from the configured request handlers
30
+ * and the cache will be updated before returning the response.
31
+ *
32
+ * @method isHardExpired
33
+ * @public
34
+ * @param {StableDocumentIdentifier} identifier
35
+ * @param {Store} store
36
+ * @return {boolean} true if the request is considered hard expired
37
+ */
38
+ isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
39
+ /**
40
+ * Invoked if `isHardExpired` is false to determine if the request
41
+ * should be update behind the scenes if cache data is already available.
42
+ *
43
+ * Note, this is only invoked if the request has a cache-key.
44
+ *
45
+ * If true, the request will be fulfilled from cache while a backgrounded
46
+ * request is made to update the cache via the configured request handlers.
47
+ *
48
+ * @method isSoftExpired
49
+ * @public
50
+ * @param {StableDocumentIdentifier} identifier
51
+ * @param {Store} store
52
+ * @return {boolean} true if the request is considered soft expired
53
+ */
54
+ isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
55
+ /**
56
+ * Invoked when a request will be sent to the configured request handlers.
57
+ * This is invoked for both foreground and background requests.
58
+ *
59
+ * Note, this is invoked regardless of whether the request has a cache-key.
60
+ *
61
+ * @method willRequest [Optional]
62
+ * @public
63
+ * @param {ImmutableRequestInfo} request
64
+ * @param {StableDocumentIdentifier | null} identifier
65
+ * @param {Store} store
66
+ * @return {void}
67
+ */
68
+ willRequest?(request: ImmutableRequestInfo, identifier: StableDocumentIdentifier | null, store: Store): void;
69
+ /**
70
+ * Invoked when a request has been fulfilled from the configured request handlers.
71
+ * This is invoked for both foreground and background requests once the cache has
72
+ * been updated.
73
+ *
74
+ * Note, this is invoked regardless of whether the request has a cache-key.
75
+ *
76
+ * @method didRequest [Optional]
77
+ * @public
78
+ * @param {ImmutableRequestInfo} request
79
+ * @param {ImmutableResponse} response
80
+ * @param {StableDocumentIdentifier | null} identifier
81
+ * @param {Store} store
82
+ * @return {void}
83
+ */
84
+ didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
85
+ }
86
+ export type StoreRequestInfo = ImmutableRequestInfo;
87
+ export type LooseStoreRequestInfo = Omit<StoreRequestInfo, 'records' | 'headers'> & {
88
+ records?: ResourceIdentifierObject[];
89
+ headers?: Headers;
90
+ };
91
+ export type StoreRequestInput = StoreRequestInfo | LooseStoreRequestInfo;
92
+ export interface StoreRequestContext extends RequestContext {
93
+ request: StoreRequestInfo & {
94
+ store: Store;
95
+ [EnableHydration]?: boolean;
96
+ };
97
+ }
98
+ export declare const CacheHandler: Handler;
99
+ //# sourceMappingURL=cache-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-handler.d.ts","sourceRoot":"","sources":["../../src/-private/cache-handler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAU,OAAO,EAAU,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EAGV,oBAAoB,EAEpB,cAAc,EACd,YAAY,EAGb,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAa,MAAM,gCAAgC,CAAC;AAO5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAIhF,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAC3E;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,UAAU,EAAE,wBAAwB,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IAE3E;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE7G;;;;;;;;;;;;;;OAcG;IACH,UAAU,CAAC,CACT,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI,EACxC,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAC3C,KAAK,EAAE,KAAK,GACX,IAAI,CAAC;CACT;AAED,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AACpD,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG;IAClF,OAAO,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,qBAAqB,CAAC;AAEzE,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,OAAO,EAAE,gBAAgB,GAAG;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,CAAC,eAAe,CAAC,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3E;AA+RD,eAAO,MAAM,YAAY,EAAE,OAoD1B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { StableRecordIdentifier } from '@warp-drive/core-types/identifier';
2
+ import type { Cache } from '../../-types/q/cache';
3
+ import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
4
+ export declare const CacheForIdentifierCache: Map<unknown, Cache>;
5
+ export declare function setCacheFor(identifier: StableRecordIdentifier | OpaqueRecordInstance, cache: Cache): void;
6
+ export declare function removeRecordDataFor(identifier: StableRecordIdentifier | OpaqueRecordInstance): void;
7
+ export default function peekCache(instance: StableRecordIdentifier): Cache | null;
8
+ export default function peekCache(instance: OpaqueRecordInstance): Cache;
9
+ //# sourceMappingURL=cache-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-utils.d.ts","sourceRoot":"","sources":["../../../src/-private/caches/cache-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAO3E,eAAO,MAAM,uBAAuB,qBAAkE,CAAC;AAEvG,wBAAgB,WAAW,CAAC,UAAU,EAAE,sBAAsB,GAAG,oBAAoB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAMzG;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,sBAAsB,GAAG,oBAAoB,GAAG,IAAI,CAEnG;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,sBAAsB,GAAG,KAAK,GAAG,IAAI,CAAC;AAClF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,180 @@
1
+ import { type Identifier, type RecordIdentifier, type StableDocumentIdentifier, type StableRecordIdentifier } from '@warp-drive/core-types/identifier';
2
+ import type { ImmutableRequestInfo } from '@warp-drive/core-types/request';
3
+ import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
4
+ import type { ForgetMethod, GenerationMethod, ResetMethod, UpdateMethod } from '../../-types/q/identifier';
5
+ export declare function isStableIdentifier(identifier: unknown): identifier is StableRecordIdentifier;
6
+ export declare function isDocumentIdentifier(identifier: unknown): identifier is StableDocumentIdentifier;
7
+ interface KeyOptions {
8
+ lid: IdentifierMap;
9
+ id: IdentifierMap;
10
+ }
11
+ type TypeMap = {
12
+ [key: string]: KeyOptions;
13
+ };
14
+ type IdentifierMap = Map<string, StableRecordIdentifier>;
15
+ type KeyInfo = {
16
+ id: string | null;
17
+ type: string;
18
+ };
19
+ type StableCache = {
20
+ resources: IdentifierMap;
21
+ documents: Map<string, StableDocumentIdentifier>;
22
+ resourcesByType: TypeMap;
23
+ polymorphicLidBackMap: Map<string, string[]>;
24
+ };
25
+ export type KeyInfoMethod = (resource: unknown, known: StableRecordIdentifier | null) => KeyInfo;
26
+ export type MergeMethod = (targetIdentifier: StableRecordIdentifier, matchedIdentifier: StableRecordIdentifier, resourceData: unknown) => StableRecordIdentifier;
27
+ export declare function setIdentifierGenerationMethod(method: GenerationMethod | null): void;
28
+ export declare function setIdentifierUpdateMethod(method: UpdateMethod | null): void;
29
+ export declare function setIdentifierForgetMethod(method: ForgetMethod | null): void;
30
+ export declare function setIdentifierResetMethod(method: ResetMethod | null): void;
31
+ export declare function setKeyInfoForResource(method: KeyInfoMethod | null): void;
32
+ /**
33
+ * Each instance of {Store} receives a unique instance of a IdentifierCache.
34
+ *
35
+ * This cache is responsible for assigning or retrieving the unique identify
36
+ * for arbitrary resource data encountered by the store. Data representing
37
+ * a unique resource or record should always be represented by the same
38
+ * identifier.
39
+ *
40
+ * It can be configured by consuming applications.
41
+ *
42
+ * @class IdentifierCache
43
+ @public
44
+ */
45
+ export declare class IdentifierCache {
46
+ _cache: StableCache;
47
+ _generate: GenerationMethod;
48
+ _update: UpdateMethod;
49
+ _forget: ForgetMethod;
50
+ _reset: ResetMethod;
51
+ _merge: MergeMethod;
52
+ _keyInfoForResource: KeyInfoMethod;
53
+ _isDefaultConfig: boolean;
54
+ _id: number;
55
+ constructor();
56
+ /**
57
+ * Internal hook to allow management of merge conflicts with identifiers.
58
+ *
59
+ * we allow late binding of this private internal merge so that
60
+ * the cache can insert itself here to handle elimination of duplicates
61
+ *
62
+ * @method __configureMerge
63
+ * @private
64
+ */
65
+ __configureMerge(method: MergeMethod | null): void;
66
+ upgradeIdentifier(resource: {
67
+ type: string;
68
+ id: string | null;
69
+ lid?: string;
70
+ }): StableRecordIdentifier;
71
+ /**
72
+ * @method _getRecordIdentifier
73
+ * @private
74
+ */
75
+ _getRecordIdentifier(resource: {
76
+ type: string;
77
+ id: string | null;
78
+ lid?: string;
79
+ }, shouldGenerate: 2): StableRecordIdentifier;
80
+ _getRecordIdentifier(resource: unknown, shouldGenerate: 1): StableRecordIdentifier;
81
+ _getRecordIdentifier(resource: unknown, shouldGenerate: 0): StableRecordIdentifier | undefined;
82
+ /**
83
+ * allows us to peek without generating when needed
84
+ * useful for the "create" case when we need to see if
85
+ * we are accidentally overwritting something
86
+ *
87
+ * @method peekRecordIdentifier
88
+ * @param resource
89
+ * @return {StableRecordIdentifier | undefined}
90
+ * @private
91
+ */
92
+ peekRecordIdentifier(resource: ResourceIdentifierObject | Identifier): StableRecordIdentifier | undefined;
93
+ /**
94
+ Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
95
+ Returns `null` if the request does not have a `cacheKey` or `url`.
96
+
97
+ @method getOrCreateDocumentIdentifier
98
+ @param request
99
+ @return {StableDocumentIdentifier | null}
100
+ @public
101
+ */
102
+ getOrCreateDocumentIdentifier(request: ImmutableRequestInfo): StableDocumentIdentifier | null;
103
+ /**
104
+ Returns the Identifier for the given Resource, creates one if it does not yet exist.
105
+
106
+ Specifically this means that we:
107
+
108
+ - validate the `id` `type` and `lid` combo against known identifiers
109
+ - return an object with an `lid` that is stable (repeated calls with the same
110
+ `id` + `type` or `lid` will return the same `lid` value)
111
+ - this referential stability of the object itself is guaranteed
112
+
113
+ @method getOrCreateRecordIdentifier
114
+ @param resource
115
+ @return {StableRecordIdentifier}
116
+ @public
117
+ */
118
+ getOrCreateRecordIdentifier(resource: unknown): StableRecordIdentifier;
119
+ /**
120
+ Returns a new Identifier for the supplied data. Call this method to generate
121
+ an identifier when a new resource is being created local to the client and
122
+ potentially does not have an `id`.
123
+
124
+ Delegates generation to the user supplied `GenerateMethod` if one has been provided
125
+ with the signature `generateMethod({ type }, 'record')`.
126
+
127
+ @method createIdentifierForNewRecord
128
+ @param data
129
+ @return {StableRecordIdentifier}
130
+ @public
131
+ */
132
+ createIdentifierForNewRecord(data: {
133
+ type: string;
134
+ id?: string | null;
135
+ }): StableRecordIdentifier;
136
+ /**
137
+ Provides the opportunity to update secondary lookup tables for existing identifiers
138
+ Called after an identifier created with `createIdentifierForNewRecord` has been
139
+ committed.
140
+
141
+ Assigned `id` to an `Identifier` if `id` has not previously existed; however,
142
+ attempting to change the `id` or calling update without providing an `id` when
143
+ one is missing will throw an error.
144
+
145
+ - sets `id` (if `id` was previously `null`)
146
+ - `lid` and `type` MUST NOT be altered post creation
147
+
148
+ If a merge occurs, it is possible the returned identifier does not match the originally
149
+ provided identifier. In this case the abandoned identifier will go through the usual
150
+ `forgetRecordIdentifier` codepaths.
151
+
152
+ @method updateRecordIdentifier
153
+ @param identifierObject
154
+ @param data
155
+ @return {StableRecordIdentifier}
156
+ @public
157
+ */
158
+ updateRecordIdentifier(identifierObject: RecordIdentifier, data: unknown): StableRecordIdentifier;
159
+ /**
160
+ * @method _mergeRecordIdentifiers
161
+ * @private
162
+ */
163
+ _mergeRecordIdentifiers(keyInfo: KeyInfo, identifier: StableRecordIdentifier, existingIdentifier: StableRecordIdentifier, data: unknown): StableRecordIdentifier;
164
+ /**
165
+ Provides the opportunity to eliminate an identifier from secondary lookup tables
166
+ as well as eliminates it from ember-data's own lookup tables and book keeping.
167
+
168
+ Useful when a record has been deleted and the deletion has been persisted and
169
+ we do not care about the record anymore. Especially useful when an `id` of a
170
+ deleted record might be reused later for a new record.
171
+
172
+ @method forgetRecordIdentifier
173
+ @param identifierObject
174
+ @public
175
+ */
176
+ forgetRecordIdentifier(identifierObject: RecordIdentifier): void;
177
+ destroy(): void;
178
+ }
179
+ export {};
180
+ //# sourceMappingURL=identifier-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifier-cache.d.ts","sourceRoot":"","sources":["../../../src/-private/caches/identifier-cache.ts"],"names":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sBAAsB;IACzB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,GAAG,sBAAsB;IAClF,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,GAAG,sBAAsB,GAAG,SAAS;IAsE9F;;;;;;;;;OASG;IACH,oBAAoB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,UAAU,GAAG,sBAAsB,GAAG,SAAS;IAIzG;;;;;;;;MAQE;IACF,6BAA6B,CAAC,OAAO,EAAE,oBAAoB,GAAG,wBAAwB,GAAG,IAAI;IAyB7F;;;;;;;;;;;;;;MAcE;IACF,2BAA2B,CAAC,QAAQ,EAAE,OAAO,GAAG,sBAAsB;IAItE;;;;;;;;;;;;MAYE;IACF,4BAA4B,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,sBAAsB;IAyBhG;;;;;;;;;;;;;;;;;;;;;MAqBE;IACF,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,GAAG,sBAAsB;IAoEjG;;;OAGG;IACH,uBAAuB,CACrB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,sBAAsB,EAClC,kBAAkB,EAAE,sBAAsB,EAC1C,IAAI,EAAE,OAAO,GACZ,sBAAsB;IAoCzB;;;;;;;;;;;MAWE;IACF,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI;IA+BhE,OAAO;CAOR"}
@@ -0,0 +1,61 @@
1
+ import type { RecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier';
2
+ import type { Value } from '@warp-drive/core-types/json/raw';
3
+ import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
4
+ import type { Cache } from '../../-types/q/cache';
5
+ import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
6
+ import RecordReference from '../legacy-model-support/record-reference';
7
+ import { CacheCapabilitiesManager } from '../managers/cache-capabilities-manager';
8
+ import type { CacheManager } from '../managers/cache-manager';
9
+ import type { CreateRecordProperties } from '../store-service';
10
+ import type Store from '../store-service';
11
+ export declare function peekRecordIdentifier(record: OpaqueRecordInstance): StableRecordIdentifier | undefined;
12
+ /**
13
+ Retrieves the unique referentially-stable [RecordIdentifier](/ember-data/release/classes/StableRecordIdentifier)
14
+ assigned to the given record instance.
15
+ ```js
16
+ import { recordIdentifierFor } from "@ember-data/store";
17
+ // ... gain access to a record, for instance with peekRecord or findRecord
18
+ const record = store.peekRecord("user", "1");
19
+ // get the identifier for the record (see docs for StableRecordIdentifier)
20
+ const identifier = recordIdentifierFor(record);
21
+ // access the identifier's properties.
22
+ const { id, type, lid } = identifier;
23
+ ```
24
+ @method recordIdentifierFor
25
+ @public
26
+ @static
27
+ @for @ember-data/store
28
+ @param {Object} record a record instance previously obstained from the store.
29
+ @return {StableRecordIdentifier}
30
+ */
31
+ export declare function recordIdentifierFor<T extends TypedRecordInstance>(record: T): StableRecordIdentifier<TypeFromInstance<T>>;
32
+ export declare function recordIdentifierFor(record: OpaqueRecordInstance): StableRecordIdentifier;
33
+ export declare function setRecordIdentifier(record: OpaqueRecordInstance, identifier: StableRecordIdentifier): void;
34
+ export declare const StoreMap: Map<unknown, Store>;
35
+ export declare function storeFor(record: OpaqueRecordInstance): Store | undefined;
36
+ type Caches = {
37
+ record: Map<StableRecordIdentifier, OpaqueRecordInstance>;
38
+ reference: WeakMap<StableRecordIdentifier, RecordReference>;
39
+ };
40
+ export declare class InstanceCache {
41
+ store: Store;
42
+ cache: Cache;
43
+ _storeWrapper: CacheCapabilitiesManager;
44
+ __cacheFor: (resource: RecordIdentifier) => Cache;
45
+ __cacheManager: CacheManager;
46
+ __instances: Caches;
47
+ constructor(store: Store);
48
+ peek(identifier: StableRecordIdentifier): Cache | OpaqueRecordInstance | undefined;
49
+ getRecord(identifier: StableRecordIdentifier, properties?: CreateRecordProperties): OpaqueRecordInstance;
50
+ getReference(identifier: StableRecordIdentifier): RecordReference;
51
+ recordIsLoaded(identifier: StableRecordIdentifier, filterDeleted?: boolean): boolean;
52
+ disconnect(identifier: StableRecordIdentifier): void;
53
+ unloadRecord(identifier: StableRecordIdentifier): void;
54
+ clear(type?: string): void;
55
+ setRecordId(identifier: StableRecordIdentifier, id: string): void;
56
+ }
57
+ export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
58
+ export declare function preloadData(store: Store, identifier: StableRecordIdentifier, preload: Record<string, Value>): void;
59
+ export declare function _clearCaches(): void;
60
+ export {};
61
+ //# sourceMappingURL=instance-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-cache.d.ts","sourceRoot":"","sources":["../../../src/-private/caches/instance-cache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAClG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAA4B,MAAM,+BAA+B,CAAC;AAIrH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,eAAe,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAoB1C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,sBAAsB,GAAG,SAAS,CAErG;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB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AAW,CAAC,UAAU,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM;CA+C3D;AAMD,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,sBAAsB,GAAG,OAAO,CAGhH;AAcD,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,QAwB3G;AAiCD,wBAAgB,YAAY,SAI3B"}
@@ -0,0 +1,10 @@
1
+ export declare function hasLid(resource: unknown): resource is {
2
+ lid: string;
3
+ };
4
+ export declare function hasId(resource: unknown): resource is {
5
+ id: string;
6
+ };
7
+ export declare function hasType(resource: unknown): resource is {
8
+ type: string;
9
+ };
10
+ //# sourceMappingURL=resource-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-utils.d.ts","sourceRoot":"","sources":["../../../src/-private/caches/resource-utils.ts"],"names":[],"mappings":"AAUA,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAErE;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAInE;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAEvE"}