@iamjulianacosta/mobx-data 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/CacheHandler-BTU_rYkv.js +208 -0
- package/dist/CacheHandler-BTU_rYkv.js.map +1 -0
- package/dist/CacheHandler-CXgY9IJo.cjs +2 -0
- package/dist/CacheHandler-CXgY9IJo.cjs.map +1 -0
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs +2 -0
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs.map +1 -0
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js +261 -0
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js.map +1 -0
- package/dist/JsonApiSerializer-CC5HXp4b.js +194 -0
- package/dist/JsonApiSerializer-CC5HXp4b.js.map +1 -0
- package/dist/JsonApiSerializer-CKB02AgP.cjs +2 -0
- package/dist/JsonApiSerializer-CKB02AgP.cjs.map +1 -0
- package/dist/MemoryAdapter-Bx1e7ndV.js +123 -0
- package/dist/MemoryAdapter-Bx1e7ndV.js.map +1 -0
- package/dist/MemoryAdapter-D1cTyydm.cjs +2 -0
- package/dist/MemoryAdapter-D1cTyydm.cjs.map +1 -0
- package/dist/ODataAdapter-C4IHK4BK.js +157 -0
- package/dist/ODataAdapter-C4IHK4BK.js.map +1 -0
- package/dist/ODataAdapter-DyyF1sdA.cjs +2 -0
- package/dist/ODataAdapter-DyyF1sdA.cjs.map +1 -0
- package/dist/RestAdapter-B4aRvs4m.js +355 -0
- package/dist/RestAdapter-B4aRvs4m.js.map +1 -0
- package/dist/RestAdapter-CJOwTsKK.cjs +2 -0
- package/dist/RestAdapter-CJOwTsKK.cjs.map +1 -0
- package/dist/SchemaService-DZwkFgZu.js +102 -0
- package/dist/SchemaService-DZwkFgZu.js.map +1 -0
- package/dist/SchemaService-Di_yjVzU.cjs +2 -0
- package/dist/SchemaService-Di_yjVzU.cjs.map +1 -0
- package/dist/Serializer-95gi5edy.cjs +2 -0
- package/dist/Serializer-95gi5edy.cjs.map +1 -0
- package/dist/Serializer-FxJbsZ50.js +139 -0
- package/dist/Serializer-FxJbsZ50.js.map +1 -0
- package/dist/Store-BdwMrbDi.cjs +2 -0
- package/dist/Store-BdwMrbDi.cjs.map +1 -0
- package/dist/Store-CZ7Z-Nme.js +912 -0
- package/dist/Store-CZ7Z-Nme.js.map +1 -0
- package/dist/adapter/Adapter.d.ts +146 -0
- package/dist/adapter/Adapter.d.ts.map +1 -0
- package/dist/adapter/MemoryAdapter.d.ts +44 -0
- package/dist/adapter/MemoryAdapter.d.ts.map +1 -0
- package/dist/adapter/RestAdapter.d.ts +57 -0
- package/dist/adapter/RestAdapter.d.ts.map +1 -0
- package/dist/adapter/index.cjs +2 -0
- package/dist/adapter/index.cjs.map +1 -0
- package/dist/adapter/index.d.ts +4 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +8 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/date-Bj4O2W1F.js +107 -0
- package/dist/date-Bj4O2W1F.js.map +1 -0
- package/dist/date-CRCe-9gf.cjs +2 -0
- package/dist/date-CRCe-9gf.cjs.map +1 -0
- package/dist/decorators-HQ1KnRdh.cjs +2 -0
- package/dist/decorators-HQ1KnRdh.cjs.map +1 -0
- package/dist/decorators-Zr35qr6A.js +50 -0
- package/dist/decorators-Zr35qr6A.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/json-api/JsonApiAdapter.d.ts +38 -0
- package/dist/json-api/JsonApiAdapter.d.ts.map +1 -0
- package/dist/json-api/JsonApiSerializer.d.ts +73 -0
- package/dist/json-api/JsonApiSerializer.d.ts.map +1 -0
- package/dist/json-api/index.cjs +2 -0
- package/dist/json-api/index.cjs.map +1 -0
- package/dist/json-api/index.d.ts +3 -0
- package/dist/json-api/index.d.ts.map +1 -0
- package/dist/json-api/index.js +6 -0
- package/dist/json-api/index.js.map +1 -0
- package/dist/model/Errors.d.ts +46 -0
- package/dist/model/Errors.d.ts.map +1 -0
- package/dist/model/Model.d.ts +226 -0
- package/dist/model/Model.d.ts.map +1 -0
- package/dist/model/Snapshot.d.ts +72 -0
- package/dist/model/Snapshot.d.ts.map +1 -0
- package/dist/model/StateMachine.d.ts +45 -0
- package/dist/model/StateMachine.d.ts.map +1 -0
- package/dist/model/index.cjs +2 -0
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +11 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/relationships.d.ts +182 -0
- package/dist/model/relationships.d.ts.map +1 -0
- package/dist/odata/ODataAdapter.d.ts +67 -0
- package/dist/odata/ODataAdapter.d.ts.map +1 -0
- package/dist/odata/index.cjs +2 -0
- package/dist/odata/index.cjs.map +1 -0
- package/dist/odata/index.d.ts +2 -0
- package/dist/odata/index.d.ts.map +1 -0
- package/dist/odata/index.js +5 -0
- package/dist/odata/index.js.map +1 -0
- package/dist/relationships-B55LBaCW.cjs +2 -0
- package/dist/relationships-B55LBaCW.cjs.map +1 -0
- package/dist/relationships-BEXANmWg.js +821 -0
- package/dist/relationships-BEXANmWg.js.map +1 -0
- package/dist/request/CacheHandler.d.ts +50 -0
- package/dist/request/CacheHandler.d.ts.map +1 -0
- package/dist/request/FetchHandler.d.ts +41 -0
- package/dist/request/FetchHandler.d.ts.map +1 -0
- package/dist/request/RequestManager.d.ts +52 -0
- package/dist/request/RequestManager.d.ts.map +1 -0
- package/dist/request/index.cjs +2 -0
- package/dist/request/index.cjs.map +1 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.d.ts.map +1 -0
- package/dist/request/index.js +7 -0
- package/dist/request/index.js.map +1 -0
- package/dist/request/types.d.ts +111 -0
- package/dist/request/types.d.ts.map +1 -0
- package/dist/schema/SchemaService.d.ts +58 -0
- package/dist/schema/SchemaService.d.ts.map +1 -0
- package/dist/schema/decorators.d.ts +50 -0
- package/dist/schema/decorators.d.ts.map +1 -0
- package/dist/schema/index.cjs +2 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +13 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +61 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/serializer/EmbeddedRecordsMixin.d.ts +80 -0
- package/dist/serializer/EmbeddedRecordsMixin.d.ts.map +1 -0
- package/dist/serializer/JsonSerializer.d.ts +52 -0
- package/dist/serializer/JsonSerializer.d.ts.map +1 -0
- package/dist/serializer/RestSerializer.d.ts +43 -0
- package/dist/serializer/RestSerializer.d.ts.map +1 -0
- package/dist/serializer/Serializer.d.ts +202 -0
- package/dist/serializer/Serializer.d.ts.map +1 -0
- package/dist/serializer/index.cjs +2 -0
- package/dist/serializer/index.cjs.map +1 -0
- package/dist/serializer/index.d.ts +5 -0
- package/dist/serializer/index.d.ts.map +1 -0
- package/dist/serializer/index.js +9 -0
- package/dist/serializer/index.js.map +1 -0
- package/dist/store/IdentityMap.d.ts +53 -0
- package/dist/store/IdentityMap.d.ts.map +1 -0
- package/dist/store/RecordArray.d.ts +114 -0
- package/dist/store/RecordArray.d.ts.map +1 -0
- package/dist/store/Store.d.ts +395 -0
- package/dist/store/Store.d.ts.map +1 -0
- package/dist/store/index.cjs +2 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.ts +5 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +8 -0
- package/dist/store/index.js.map +1 -0
- package/dist/transforms/Transform.d.ts +49 -0
- package/dist/transforms/Transform.d.ts.map +1 -0
- package/dist/transforms/boolean.d.ts +26 -0
- package/dist/transforms/boolean.d.ts.map +1 -0
- package/dist/transforms/date.d.ts +22 -0
- package/dist/transforms/date.d.ts.map +1 -0
- package/dist/transforms/index.cjs +2 -0
- package/dist/transforms/index.cjs.map +1 -0
- package/dist/transforms/index.d.ts +6 -0
- package/dist/transforms/index.d.ts.map +1 -0
- package/dist/transforms/index.js +9 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/number.d.ts +17 -0
- package/dist/transforms/number.d.ts.map +1 -0
- package/dist/transforms/string.d.ts +18 -0
- package/dist/transforms/string.d.ts.map +1 -0
- package/dist/types-C9NB2gRj.js +7 -0
- package/dist/types-C9NB2gRj.js.map +1 -0
- package/dist/types-uWOXMPWW.cjs +2 -0
- package/dist/types-uWOXMPWW.cjs.map +1 -0
- package/package.json +140 -0
- package/src/adapter/Adapter.ts +320 -0
- package/src/adapter/MemoryAdapter.ts +216 -0
- package/src/adapter/RestAdapter.ts +248 -0
- package/src/adapter/index.ts +7 -0
- package/src/index.ts +17 -0
- package/src/json-api/JsonApiAdapter.ts +93 -0
- package/src/json-api/JsonApiSerializer.ts +245 -0
- package/src/json-api/index.ts +2 -0
- package/src/model/Errors.ts +100 -0
- package/src/model/Model.ts +683 -0
- package/src/model/Snapshot.ts +162 -0
- package/src/model/StateMachine.ts +149 -0
- package/src/model/index.ts +20 -0
- package/src/model/relationships.ts +484 -0
- package/src/odata/ODataAdapter.ts +245 -0
- package/src/odata/index.ts +1 -0
- package/src/request/CacheHandler.ts +125 -0
- package/src/request/FetchHandler.ts +119 -0
- package/src/request/RequestManager.ts +112 -0
- package/src/request/index.ts +4 -0
- package/src/request/types.ts +139 -0
- package/src/schema/SchemaService.ts +161 -0
- package/src/schema/decorators.ts +162 -0
- package/src/schema/index.ts +3 -0
- package/src/schema/types.ts +66 -0
- package/src/serializer/EmbeddedRecordsMixin.ts +257 -0
- package/src/serializer/JsonSerializer.ts +173 -0
- package/src/serializer/RestSerializer.ts +138 -0
- package/src/serializer/Serializer.ts +397 -0
- package/src/serializer/index.ts +15 -0
- package/src/store/IdentityMap.ts +110 -0
- package/src/store/RecordArray.ts +210 -0
- package/src/store/Store.ts +1391 -0
- package/src/store/index.ts +11 -0
- package/src/transforms/Transform.ts +52 -0
- package/src/transforms/boolean.ts +57 -0
- package/src/transforms/date.ts +48 -0
- package/src/transforms/index.ts +5 -0
- package/src/transforms/number.ts +42 -0
- package/src/transforms/string.ts +35 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform that converts between ISO 8601 strings (or numeric timestamps)
|
|
3
|
+
* and JavaScript `Date` objects.
|
|
4
|
+
*
|
|
5
|
+
* Deserialization:
|
|
6
|
+
* - `null` / `undefined` / `''` → `null`
|
|
7
|
+
* - `Date` instance → returned as-is (or `null` when invalid)
|
|
8
|
+
* - `number` (Unix ms) or `string` (ISO 8601) → parsed via `new Date(value)`,
|
|
9
|
+
* returns `null` when parsing yields `NaN`
|
|
10
|
+
* - anything else → `null`
|
|
11
|
+
*
|
|
12
|
+
* Serialization:
|
|
13
|
+
* - `null` / `undefined` → `null`
|
|
14
|
+
* - `Date` instance → ISO 8601 string via `.toISOString()` (or `null` when invalid)
|
|
15
|
+
* - anything else → `null`
|
|
16
|
+
*/
|
|
17
|
+
import { BaseTransform } from './Transform.js';
|
|
18
|
+
export declare class DateTransform extends BaseTransform<unknown, Date | null> {
|
|
19
|
+
deserialize(serialized: unknown): Date | null;
|
|
20
|
+
serialize(deserialized: Date | null): unknown;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/transforms/date.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBACa,aAAc,SAAQ,aAAa,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;IACpE,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI;IAc7C,SAAS,CAAC,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO;CAW9C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../date-CRCe-9gf.cjs");exports.BaseTransform=e.BaseTransform;Object.defineProperty(exports,"BooleanTransform",{enumerable:!0,get:()=>e.BooleanTransform});Object.defineProperty(exports,"DateTransform",{enumerable:!0,get:()=>e.DateTransform});Object.defineProperty(exports,"NumberTransform",{enumerable:!0,get:()=>e.NumberTransform});Object.defineProperty(exports,"StringTransform",{enumerable:!0,get:()=>e.StringTransform});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseTransform, type Transform } from './Transform.js';
|
|
2
|
+
export { StringTransform } from './string.js';
|
|
3
|
+
export { NumberTransform } from './number.js';
|
|
4
|
+
export { BooleanTransform } from './boolean.js';
|
|
5
|
+
export { DateTransform } from './date.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform that converts between arbitrary wire values and numbers.
|
|
3
|
+
*
|
|
4
|
+
* Deserialization / serialization coercions (identical in both directions):
|
|
5
|
+
* - `null` / `undefined` / `''` → `null`
|
|
6
|
+
* - finite `number` → passed through
|
|
7
|
+
* - non-finite `number` (NaN, Infinity) → `null`
|
|
8
|
+
* - `string` → trimmed and parsed; `null` when the result is not finite
|
|
9
|
+
* - anything else → `null`
|
|
10
|
+
*/
|
|
11
|
+
import { BaseTransform } from './Transform.js';
|
|
12
|
+
export declare class NumberTransform extends BaseTransform<unknown, number | null> {
|
|
13
|
+
static coerce(value: unknown): number | null;
|
|
14
|
+
deserialize(serialized: unknown): number | null;
|
|
15
|
+
serialize(deserialized: number | null): unknown;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/transforms/number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBACa,eAAgB,SAAQ,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAkB5C,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAI/C,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;CAGhD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform that converts between arbitrary wire values and strings.
|
|
3
|
+
*
|
|
4
|
+
* Deserialization:
|
|
5
|
+
* - `null` / `undefined` → `null`
|
|
6
|
+
* - `string` → passed through
|
|
7
|
+
* - anything else → `String(value)`
|
|
8
|
+
*
|
|
9
|
+
* Serialization:
|
|
10
|
+
* - `null` / `undefined` → `null`
|
|
11
|
+
* - anything else → `String(value)`
|
|
12
|
+
*/
|
|
13
|
+
import { BaseTransform } from './Transform.js';
|
|
14
|
+
export declare class StringTransform extends BaseTransform<unknown, string | null> {
|
|
15
|
+
deserialize(serialized: unknown): string | null;
|
|
16
|
+
serialize(deserialized: string | null): unknown;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/transforms/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBACa,eAAgB,SAAQ,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAU/C,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;CAMhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-C9NB2gRj.js","sources":["../src/schema/types.ts"],"sourcesContent":["/** Shape of a single `@attr` decoration on a model class property. */\nexport interface AttributeDef {\n /** Property name on the model class. */\n name: string;\n /** Registered transform type (e.g. `'string'`, `'number'`), or `null` for pass-through. */\n type: string | null;\n /** Extra options passed by the decorator (default value, etc.). */\n options: AttributeOptions;\n /** Discriminant – always `true`; used to narrow union types. */\n isAttribute: true;\n}\n\n/** Options accepted by the `@attr` decorator. */\nexport interface AttributeOptions {\n /** Static value or factory function called when the attribute has no server value. */\n defaultValue?: unknown | (() => unknown);\n /** Arbitrary custom options forwarded to the transform. */\n [key: string]: unknown;\n}\n\n/** Identifies the direction of a relationship from the owning model's perspective. */\nexport type RelationshipKind = 'belongsTo' | 'hasMany';\n\n/** Shape of a single `@belongsTo` / `@hasMany` decoration on a model class property. */\nexport interface RelationshipDef {\n /** Property name on the model class. */\n name: string;\n /** Direction from the owning model's perspective. */\n kind: RelationshipKind;\n /** `modelName` of the related model. */\n type: string;\n /** Normalised options (async, inverse, polymorphic, …). */\n options: RelationshipOptions;\n /** Discriminant – always `true`; used to narrow union types. */\n isRelationship: true;\n}\n\n/** Options accepted by `@belongsTo` and `@hasMany` decorators. */\nexport interface RelationshipOptions {\n /**\n * When `true` the relationship proxy returns an `AsyncBelongsTo` / `AsyncHasMany`\n * that must be awaited before the related record(s) are available.\n */\n async?: boolean;\n /**\n * Name of the inverse property on the related model.\n * Set to `null` to explicitly opt out of inverse tracking.\n */\n inverse?: string | null;\n /** When `true` the relationship can point to records of multiple model types. */\n polymorphic?: boolean;\n /** Arbitrary custom options. */\n [key: string]: unknown;\n}\n\n/** Attribute definitions keyed by property name. */\nexport type AttributeDefinitionsMap = Map<string, AttributeDef>;\n/** Relationship definitions keyed by property name. */\nexport type RelationshipDefinitionsMap = Map<string, RelationshipDef>;\n\n/** Reflect-metadata key used to store attribute definitions on a prototype. */\nexport const ATTRIBUTES_META_KEY = Symbol('mobx-data:attributes');\n/** Reflect-metadata key used to store relationship definitions on a prototype. */\nexport const RELATIONSHIPS_META_KEY = Symbol('mobx-data:relationships');\n/** Reflect-metadata key used to store the registered model name on a class. */\nexport const MODEL_NAME_META_KEY = Symbol('mobx-data:modelName');\n"],"names":["ATTRIBUTES_META_KEY","RELATIONSHIPS_META_KEY","MODEL_NAME_META_KEY"],"mappings":"AA6DO,MAAMA,IAAsB,OAAO,sBAAsB,GAEnDC,IAAyB,OAAO,yBAAyB,GAEzDC,IAAsB,OAAO,qBAAqB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-uWOXMPWW.cjs","sources":["../src/schema/types.ts"],"sourcesContent":["/** Shape of a single `@attr` decoration on a model class property. */\nexport interface AttributeDef {\n /** Property name on the model class. */\n name: string;\n /** Registered transform type (e.g. `'string'`, `'number'`), or `null` for pass-through. */\n type: string | null;\n /** Extra options passed by the decorator (default value, etc.). */\n options: AttributeOptions;\n /** Discriminant – always `true`; used to narrow union types. */\n isAttribute: true;\n}\n\n/** Options accepted by the `@attr` decorator. */\nexport interface AttributeOptions {\n /** Static value or factory function called when the attribute has no server value. */\n defaultValue?: unknown | (() => unknown);\n /** Arbitrary custom options forwarded to the transform. */\n [key: string]: unknown;\n}\n\n/** Identifies the direction of a relationship from the owning model's perspective. */\nexport type RelationshipKind = 'belongsTo' | 'hasMany';\n\n/** Shape of a single `@belongsTo` / `@hasMany` decoration on a model class property. */\nexport interface RelationshipDef {\n /** Property name on the model class. */\n name: string;\n /** Direction from the owning model's perspective. */\n kind: RelationshipKind;\n /** `modelName` of the related model. */\n type: string;\n /** Normalised options (async, inverse, polymorphic, …). */\n options: RelationshipOptions;\n /** Discriminant – always `true`; used to narrow union types. */\n isRelationship: true;\n}\n\n/** Options accepted by `@belongsTo` and `@hasMany` decorators. */\nexport interface RelationshipOptions {\n /**\n * When `true` the relationship proxy returns an `AsyncBelongsTo` / `AsyncHasMany`\n * that must be awaited before the related record(s) are available.\n */\n async?: boolean;\n /**\n * Name of the inverse property on the related model.\n * Set to `null` to explicitly opt out of inverse tracking.\n */\n inverse?: string | null;\n /** When `true` the relationship can point to records of multiple model types. */\n polymorphic?: boolean;\n /** Arbitrary custom options. */\n [key: string]: unknown;\n}\n\n/** Attribute definitions keyed by property name. */\nexport type AttributeDefinitionsMap = Map<string, AttributeDef>;\n/** Relationship definitions keyed by property name. */\nexport type RelationshipDefinitionsMap = Map<string, RelationshipDef>;\n\n/** Reflect-metadata key used to store attribute definitions on a prototype. */\nexport const ATTRIBUTES_META_KEY = Symbol('mobx-data:attributes');\n/** Reflect-metadata key used to store relationship definitions on a prototype. */\nexport const RELATIONSHIPS_META_KEY = Symbol('mobx-data:relationships');\n/** Reflect-metadata key used to store the registered model name on a class. */\nexport const MODEL_NAME_META_KEY = Symbol('mobx-data:modelName');\n"],"names":["ATTRIBUTES_META_KEY","RELATIONSHIPS_META_KEY","MODEL_NAME_META_KEY"],"mappings":"aA6DO,MAAMA,EAAsB,OAAO,sBAAsB,EAEnDC,EAAyB,OAAO,yBAAyB,EAEzDC,EAAsB,OAAO,qBAAqB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iamjulianacosta/mobx-data",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Ember Data feature-complete clone for MobX",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./adapter": {
|
|
16
|
+
"types": "./dist/adapter/index.d.ts",
|
|
17
|
+
"import": "./dist/adapter/index.js",
|
|
18
|
+
"require": "./dist/adapter/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./model": {
|
|
21
|
+
"types": "./dist/model/index.d.ts",
|
|
22
|
+
"import": "./dist/model/index.js",
|
|
23
|
+
"require": "./dist/model/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./store": {
|
|
26
|
+
"types": "./dist/store/index.d.ts",
|
|
27
|
+
"import": "./dist/store/index.js",
|
|
28
|
+
"require": "./dist/store/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./schema": {
|
|
31
|
+
"types": "./dist/schema/index.d.ts",
|
|
32
|
+
"import": "./dist/schema/index.js",
|
|
33
|
+
"require": "./dist/schema/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./serializer": {
|
|
36
|
+
"types": "./dist/serializer/index.d.ts",
|
|
37
|
+
"import": "./dist/serializer/index.js",
|
|
38
|
+
"require": "./dist/serializer/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./transforms": {
|
|
41
|
+
"types": "./dist/transforms/index.d.ts",
|
|
42
|
+
"import": "./dist/transforms/index.js",
|
|
43
|
+
"require": "./dist/transforms/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./request": {
|
|
46
|
+
"types": "./dist/request/index.d.ts",
|
|
47
|
+
"import": "./dist/request/index.js",
|
|
48
|
+
"require": "./dist/request/index.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./json-api": {
|
|
51
|
+
"types": "./dist/json-api/index.d.ts",
|
|
52
|
+
"import": "./dist/json-api/index.js",
|
|
53
|
+
"require": "./dist/json-api/index.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./odata": {
|
|
56
|
+
"types": "./dist/odata/index.d.ts",
|
|
57
|
+
"import": "./dist/odata/index.js",
|
|
58
|
+
"require": "./dist/odata/index.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"files": [
|
|
62
|
+
"dist",
|
|
63
|
+
"src",
|
|
64
|
+
"README.md",
|
|
65
|
+
"LICENSE"
|
|
66
|
+
],
|
|
67
|
+
"scripts": {
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"test:e2e": "playwright test",
|
|
71
|
+
"test:e2e:coverage": "playwright test && nyc report --temp-dir=coverage/playwright --report-dir=coverage/playwright-report --reporter=text",
|
|
72
|
+
"test:all": "vitest run --coverage && playwright test",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
75
|
+
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
76
|
+
"build": "vite build --config vite.config.build.ts && tsc -p tsconfig.build.json",
|
|
77
|
+
"docs:dev": "vitepress dev docs",
|
|
78
|
+
"docs:build": "typedoc && vitepress build docs",
|
|
79
|
+
"docs:preview": "vitepress preview docs",
|
|
80
|
+
"prepublishOnly": "npm run build"
|
|
81
|
+
},
|
|
82
|
+
"keywords": [
|
|
83
|
+
"mobx",
|
|
84
|
+
"data",
|
|
85
|
+
"orm",
|
|
86
|
+
"ember-data",
|
|
87
|
+
"identity-map",
|
|
88
|
+
"adapter",
|
|
89
|
+
"serializer",
|
|
90
|
+
"json-api",
|
|
91
|
+
"odata",
|
|
92
|
+
"state-management"
|
|
93
|
+
],
|
|
94
|
+
"author": "Julián Acosta <iam@julianacosta.me>",
|
|
95
|
+
"license": "MIT",
|
|
96
|
+
"homepage": "https://iamjulianacosta.github.io/mobx-data/",
|
|
97
|
+
"repository": {
|
|
98
|
+
"type": "git",
|
|
99
|
+
"url": "https://github.com/IAmJulianAcosta/mobx-data.git"
|
|
100
|
+
},
|
|
101
|
+
"sideEffects": false,
|
|
102
|
+
"engines": {
|
|
103
|
+
"node": ">=18"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"mobx": "^6.0.0",
|
|
107
|
+
"reflect-metadata": "^0.2.0"
|
|
108
|
+
},
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"change-case": "^5.4.4",
|
|
111
|
+
"pluralize": "^8.0.0",
|
|
112
|
+
"tsyringe": "^4.8.0"
|
|
113
|
+
},
|
|
114
|
+
"devDependencies": {
|
|
115
|
+
"@playwright/test": "^1.60.0",
|
|
116
|
+
"@types/node": "^22.10.0",
|
|
117
|
+
"@types/pluralize": "^0.0.33",
|
|
118
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
119
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
120
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
121
|
+
"eslint": "^8.57.0",
|
|
122
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
123
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
124
|
+
"eslint-import-resolver-typescript": "^3.7.0",
|
|
125
|
+
"eslint-plugin-import": "^2.31.0",
|
|
126
|
+
"mobx": "^6.13.5",
|
|
127
|
+
"nyc": "^18.0.0",
|
|
128
|
+
"reflect-metadata": "^0.2.2",
|
|
129
|
+
"simple-odata-server": "^1.2.2",
|
|
130
|
+
"typedoc": "^0.28.19",
|
|
131
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
132
|
+
"typescript": "^5.7.2",
|
|
133
|
+
"vite": "^6.0.3",
|
|
134
|
+
"vite-plugin-dts": "^4.3.0",
|
|
135
|
+
"vite-plugin-istanbul": "^9.0.0",
|
|
136
|
+
"vitepress": "^1.6.4",
|
|
137
|
+
"vitest": "^2.1.8"
|
|
138
|
+
},
|
|
139
|
+
"packageManager": "pnpm@9.14.4"
|
|
140
|
+
}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all adapters.
|
|
3
|
+
*
|
|
4
|
+
* An adapter translates store operations (findRecord, createRecord, …) into
|
|
5
|
+
* concrete network requests and returns raw payloads that the serializer layer
|
|
6
|
+
* then normalises. Concrete subclasses (`RestAdapter`, `ODataAdapter`, …)
|
|
7
|
+
* override the abstract CRUD methods and may also override the URL-building
|
|
8
|
+
* helpers to produce protocol-specific URLs.
|
|
9
|
+
*
|
|
10
|
+
* URL construction follows an Ember Data–style pipeline:
|
|
11
|
+
* `buildURL` → `urlForFindRecord` / `urlForQuery` / … → `_composeURL`
|
|
12
|
+
*
|
|
13
|
+
* Configuration surface:
|
|
14
|
+
* - `host` – base URL prefix (e.g. `https://api.example.com`)
|
|
15
|
+
* - `namespace` – path segment appended after the host (e.g. `v2`)
|
|
16
|
+
* - `headers` – headers merged into every request
|
|
17
|
+
* - `coalesceFindRequests` – when `true` the store batches separate
|
|
18
|
+
* `findRecord` calls into a single `findMany` call
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import pluralize from 'pluralize';
|
|
22
|
+
import { kebabCase } from 'change-case';
|
|
23
|
+
|
|
24
|
+
/** Union of all operation names the store can issue to an adapter. */
|
|
25
|
+
export type AdapterRequestType =
|
|
26
|
+
| 'findRecord'
|
|
27
|
+
| 'findAll'
|
|
28
|
+
| 'findMany'
|
|
29
|
+
| 'query'
|
|
30
|
+
| 'queryRecord'
|
|
31
|
+
| 'createRecord'
|
|
32
|
+
| 'updateRecord'
|
|
33
|
+
| 'deleteRecord';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A frozen view of a model record passed to the adapter.
|
|
37
|
+
* Adapters read but do not mutate snapshots.
|
|
38
|
+
*/
|
|
39
|
+
export interface AdapterSnapshot {
|
|
40
|
+
/** The record's server-assigned id, or `null` for new records. */
|
|
41
|
+
id: string | null;
|
|
42
|
+
/** The model's registered `modelName`. */
|
|
43
|
+
modelName: string;
|
|
44
|
+
/** Returns the current value for an attribute key. */
|
|
45
|
+
attr(key: string): unknown;
|
|
46
|
+
/** Returns the `belongsTo` relationship value (or just its id when `{ id: true }`). */
|
|
47
|
+
belongsTo(key: string, options?: { id: boolean }): unknown;
|
|
48
|
+
/** Returns the `hasMany` relationship values (or just ids when `{ ids: true }`). */
|
|
49
|
+
hasMany(key: string, options?: { ids: boolean }): unknown;
|
|
50
|
+
/** Returns `{ [key]: [oldValue, newValue] }` for attributes that differ from the server state. */
|
|
51
|
+
changedAttributes(): Record<string, [unknown, unknown]>;
|
|
52
|
+
/** Reference to the live record instance. */
|
|
53
|
+
record: unknown;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export abstract class Adapter {
|
|
57
|
+
/** Base URL prepended to every generated URL. Empty string = relative URLs. */
|
|
58
|
+
namespace: string = '';
|
|
59
|
+
/** Host prefix, e.g. `https://api.example.com`. */
|
|
60
|
+
host: string = '';
|
|
61
|
+
/** Extra headers merged into every request via `defaultHeaders()`. */
|
|
62
|
+
headers: Record<string, string> = {};
|
|
63
|
+
/**
|
|
64
|
+
* When `true` the store will coalesce multiple `findRecord` calls for the
|
|
65
|
+
* same model type into a single `findMany` network request.
|
|
66
|
+
*/
|
|
67
|
+
coalesceFindRequests: boolean = false;
|
|
68
|
+
|
|
69
|
+
/** Fetches a single record by id. */
|
|
70
|
+
abstract findRecord(
|
|
71
|
+
store: unknown,
|
|
72
|
+
modelName: string,
|
|
73
|
+
id: string,
|
|
74
|
+
snapshot: AdapterSnapshot,
|
|
75
|
+
options?: { include?: string },
|
|
76
|
+
): Promise<unknown>;
|
|
77
|
+
|
|
78
|
+
/** Fetches all records of a given model type. */
|
|
79
|
+
abstract findAll(
|
|
80
|
+
store: unknown,
|
|
81
|
+
modelName: string,
|
|
82
|
+
sinceToken: string | null,
|
|
83
|
+
snapshotArray: AdapterSnapshot[],
|
|
84
|
+
options?: { include?: string },
|
|
85
|
+
): Promise<unknown>;
|
|
86
|
+
|
|
87
|
+
/** Fetches multiple records by id in a single request. */
|
|
88
|
+
abstract findMany(
|
|
89
|
+
store: unknown,
|
|
90
|
+
modelName: string,
|
|
91
|
+
ids: string[],
|
|
92
|
+
snapshots: AdapterSnapshot[],
|
|
93
|
+
): Promise<unknown>;
|
|
94
|
+
|
|
95
|
+
/** Executes an arbitrary server-side query, returning an array of records. */
|
|
96
|
+
abstract query(
|
|
97
|
+
store: unknown,
|
|
98
|
+
modelName: string,
|
|
99
|
+
query: Record<string, unknown>,
|
|
100
|
+
): Promise<unknown>;
|
|
101
|
+
|
|
102
|
+
/** Like `query` but returns at most one record. */
|
|
103
|
+
abstract queryRecord(
|
|
104
|
+
store: unknown,
|
|
105
|
+
modelName: string,
|
|
106
|
+
query: Record<string, unknown>,
|
|
107
|
+
): Promise<unknown>;
|
|
108
|
+
|
|
109
|
+
/** Persists a new record to the server (POST). */
|
|
110
|
+
abstract createRecord(
|
|
111
|
+
store: unknown,
|
|
112
|
+
modelName: string,
|
|
113
|
+
snapshot: AdapterSnapshot,
|
|
114
|
+
): Promise<unknown>;
|
|
115
|
+
|
|
116
|
+
/** Persists all attributes of an existing record (PUT). */
|
|
117
|
+
abstract updateRecord(
|
|
118
|
+
store: unknown,
|
|
119
|
+
modelName: string,
|
|
120
|
+
snapshot: AdapterSnapshot,
|
|
121
|
+
): Promise<unknown>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Persists only the changed attributes of an existing record (PATCH).
|
|
125
|
+
* Default implementation delegates to `updateRecord`.
|
|
126
|
+
* Override in subclasses to send a partial payload via HTTP PATCH.
|
|
127
|
+
*/
|
|
128
|
+
patchRecord(
|
|
129
|
+
store: unknown,
|
|
130
|
+
modelName: string,
|
|
131
|
+
snapshot: AdapterSnapshot,
|
|
132
|
+
): Promise<unknown> {
|
|
133
|
+
return this.updateRecord(store, modelName, snapshot);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Removes a record from the server (DELETE). */
|
|
137
|
+
abstract deleteRecord(
|
|
138
|
+
store: unknown,
|
|
139
|
+
modelName: string,
|
|
140
|
+
snapshot: AdapterSnapshot,
|
|
141
|
+
): Promise<unknown>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns the URL path segment for a given model name.
|
|
145
|
+
* Default: dasherized, pluralized form — e.g. `userPost` → `user-posts`.
|
|
146
|
+
*/
|
|
147
|
+
pathForType(modelName: string): string {
|
|
148
|
+
return pluralize.plural(kebabCase(modelName));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Assembles a full URL from `host`, `namespace`, and the supplied `path`.
|
|
153
|
+
* Returns an absolute URL when `host` is set, otherwise a root-relative path.
|
|
154
|
+
*/
|
|
155
|
+
protected _composeURL(path: string): string {
|
|
156
|
+
const ns = this.namespace.replace(/^\/+|\/+$/g, '');
|
|
157
|
+
const hostPrefix = this.host ? this.host.replace(/\/+$/, '') : '';
|
|
158
|
+
const parts: string[] = [];
|
|
159
|
+
if (hostPrefix) {
|
|
160
|
+
parts.push(hostPrefix);
|
|
161
|
+
}
|
|
162
|
+
if (ns) {
|
|
163
|
+
parts.push(ns);
|
|
164
|
+
}
|
|
165
|
+
parts.push(path);
|
|
166
|
+
if (hostPrefix) {
|
|
167
|
+
return parts.join('/');
|
|
168
|
+
}
|
|
169
|
+
return `/${parts.filter(Boolean).join('/')}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Dispatches to the appropriate `urlFor*` method based on `requestType`.
|
|
174
|
+
*
|
|
175
|
+
* @param modelName - Registered model name.
|
|
176
|
+
* @param id - Record id(s), or `null` for collection requests.
|
|
177
|
+
* @param snapshot - Snapshot(s) for the request.
|
|
178
|
+
* @param requestType - Operation being performed.
|
|
179
|
+
* @param query - Query parameters (used for `query` / `queryRecord`).
|
|
180
|
+
*/
|
|
181
|
+
buildURL(
|
|
182
|
+
modelName: string,
|
|
183
|
+
id: string | string[] | null,
|
|
184
|
+
snapshot: AdapterSnapshot | AdapterSnapshot[] | null,
|
|
185
|
+
requestType: AdapterRequestType,
|
|
186
|
+
query: Record<string, unknown> = {},
|
|
187
|
+
): string {
|
|
188
|
+
switch (requestType) {
|
|
189
|
+
case 'findRecord':
|
|
190
|
+
return this.urlForFindRecord(id as string, modelName, snapshot as AdapterSnapshot);
|
|
191
|
+
case 'findAll':
|
|
192
|
+
return this.urlForFindAll(modelName, (snapshot as AdapterSnapshot[]) ?? []);
|
|
193
|
+
case 'findMany':
|
|
194
|
+
return this.urlForFindMany(
|
|
195
|
+
(id as string[]) ?? [],
|
|
196
|
+
modelName,
|
|
197
|
+
(snapshot as AdapterSnapshot[]) ?? [],
|
|
198
|
+
);
|
|
199
|
+
case 'query':
|
|
200
|
+
return this.urlForQuery(query, modelName);
|
|
201
|
+
case 'queryRecord':
|
|
202
|
+
return this.urlForQueryRecord(query, modelName);
|
|
203
|
+
case 'createRecord':
|
|
204
|
+
return this.urlForCreateRecord(modelName, snapshot as AdapterSnapshot);
|
|
205
|
+
case 'updateRecord':
|
|
206
|
+
return this.urlForUpdateRecord(
|
|
207
|
+
id as string,
|
|
208
|
+
modelName,
|
|
209
|
+
snapshot as AdapterSnapshot,
|
|
210
|
+
);
|
|
211
|
+
case 'deleteRecord':
|
|
212
|
+
return this.urlForDeleteRecord(
|
|
213
|
+
id as string,
|
|
214
|
+
modelName,
|
|
215
|
+
snapshot as AdapterSnapshot,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** URL for a `findRecord` request. Default: `<collection>/<id>`. */
|
|
221
|
+
urlForFindRecord(id: string, modelName: string, _snapshot: AdapterSnapshot): string {
|
|
222
|
+
return this._composeURL(`${this.pathForType(modelName)}/${encodeURIComponent(id)}`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** URL for a `findAll` request. Default: `<collection>`. */
|
|
226
|
+
urlForFindAll(modelName: string, _snapshots: AdapterSnapshot[]): string {
|
|
227
|
+
return this._composeURL(this.pathForType(modelName));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** URL for a `findMany` request. Default: `<collection>` (ids appended by the adapter). */
|
|
231
|
+
urlForFindMany(
|
|
232
|
+
_ids: string[],
|
|
233
|
+
modelName: string,
|
|
234
|
+
_snapshots: AdapterSnapshot[],
|
|
235
|
+
): string {
|
|
236
|
+
return this._composeURL(this.pathForType(modelName));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** URL for a `query` request. Default: `<collection>`. */
|
|
240
|
+
urlForQuery(_query: Record<string, unknown>, modelName: string): string {
|
|
241
|
+
return this._composeURL(this.pathForType(modelName));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** URL for a `queryRecord` request. Default: `<collection>`. */
|
|
245
|
+
urlForQueryRecord(_query: Record<string, unknown>, modelName: string): string {
|
|
246
|
+
return this._composeURL(this.pathForType(modelName));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** URL for a `createRecord` request. Default: `<collection>`. */
|
|
250
|
+
urlForCreateRecord(modelName: string, _snapshot: AdapterSnapshot): string {
|
|
251
|
+
return this._composeURL(this.pathForType(modelName));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** URL for an `updateRecord` request. Default: `<collection>/<id>`. */
|
|
255
|
+
urlForUpdateRecord(
|
|
256
|
+
id: string,
|
|
257
|
+
modelName: string,
|
|
258
|
+
_snapshot: AdapterSnapshot,
|
|
259
|
+
): string {
|
|
260
|
+
return this._composeURL(`${this.pathForType(modelName)}/${encodeURIComponent(id)}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** URL for a `deleteRecord` request. Default: `<collection>/<id>`. */
|
|
264
|
+
urlForDeleteRecord(
|
|
265
|
+
id: string,
|
|
266
|
+
modelName: string,
|
|
267
|
+
_snapshot: AdapterSnapshot,
|
|
268
|
+
): string {
|
|
269
|
+
return this._composeURL(`${this.pathForType(modelName)}/${encodeURIComponent(id)}`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Groups snapshots into batches for `findMany`.
|
|
274
|
+
* Default implementation puts all snapshots in a single batch.
|
|
275
|
+
*/
|
|
276
|
+
groupRecordsForFindMany(
|
|
277
|
+
_store: unknown,
|
|
278
|
+
snapshots: AdapterSnapshot[],
|
|
279
|
+
): AdapterSnapshot[][] {
|
|
280
|
+
return [snapshots];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Returns `true` when the store should bypass the cache and reload this
|
|
285
|
+
* record immediately. Default: always `false`.
|
|
286
|
+
*/
|
|
287
|
+
shouldReloadRecord(_store: unknown, _snapshot: AdapterSnapshot): boolean {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Returns `true` when the store should schedule a background reload for
|
|
293
|
+
* this record after returning the cached version. Default: always `true`.
|
|
294
|
+
*/
|
|
295
|
+
shouldBackgroundReloadRecord(
|
|
296
|
+
_store: unknown,
|
|
297
|
+
_snapshot: AdapterSnapshot,
|
|
298
|
+
): boolean {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Returns `true` when the store should reload the full collection on every
|
|
304
|
+
* `findAll` call. Default: always `false`.
|
|
305
|
+
*/
|
|
306
|
+
shouldReloadAll(_store: unknown, _snapshotRecordArray: AdapterSnapshot[]): boolean {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Returns `true` when the store should schedule a background reload after
|
|
312
|
+
* returning a cached collection. Default: always `true`.
|
|
313
|
+
*/
|
|
314
|
+
shouldBackgroundReloadAll(
|
|
315
|
+
_store: unknown,
|
|
316
|
+
_snapshotRecordArray: AdapterSnapshot[],
|
|
317
|
+
): boolean {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
}
|