Skip to content

Commit 67b9cd0

Browse files
committed
EmbeddedCollectionType --> EmbeddedCollectionMeta
1 parent 71859b6 commit 67b9cd0

File tree

6 files changed

+26
-40
lines changed

6 files changed

+26
-40
lines changed

src/EmbeddedCollection.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import LoadingStoreCollection from './LoadingStoreCollection'
2-
import { EmbeddedCollectionType } from './interfaces/Resource'
2+
import { EmbeddedCollectionMeta } from './interfaces/EmbeddedCollection'
33
import { Link } from './interfaces/StoreData'
44

55
/**
@@ -9,9 +9,9 @@ import { Link } from './interfaces/StoreData'
99
* URI, we need to reload the whole entity containing the embedded collection. Some extra info about the
1010
* containing entity must therefore be passed to the constrcutor.
1111
*/
12-
class EmbeddedCollection implements EmbeddedCollectionType {
12+
class EmbeddedCollection implements EmbeddedCollectionMeta {
1313
public _meta: {
14-
load: Promise<EmbeddedCollectionType>,
14+
load: Promise<EmbeddedCollectionMeta>,
1515
reload: {
1616
uri: string,
1717
property: string
@@ -30,7 +30,7 @@ class EmbeddedCollection implements EmbeddedCollectionType {
3030
* @param config dependency injection of config object
3131
* @param loadParent a promise that will resolve when the parent entity has finished (re-)loading
3232
*/
33-
constructor (items: Array<Link>, reloadUri: string, reloadProperty: string, loadCollection: Promise<EmbeddedCollectionType> | null = null) {
33+
constructor (items: Array<Link>, reloadUri: string, reloadProperty: string, loadCollection: Promise<EmbeddedCollectionMeta> | null = null) {
3434
this._storeData = {
3535
items
3636
}

src/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import ServerException from './ServerException'
99
import { ExternalConfig } from './interfaces/Config'
1010
import { Store } from 'vuex/types'
1111
import { AxiosInstance, AxiosError } from 'axios'
12-
import Resource, { EmbeddedCollectionType } from './interfaces/Resource'
12+
import Resource from './interfaces/Resource'
1313
import StoreData, { Link } from './interfaces/StoreData'
1414
import ApiActions from './interfaces/ApiActions'
15-
import EmbeddedCollection from './EmbeddedCollection'
16-
import EmbeddedCollectionInterface from './interfaces/EmbeddedCollection'
15+
import EmbeddedCollectionClass from './EmbeddedCollection'
16+
import EmbeddedCollection, { EmbeddedCollectionMeta } from './interfaces/EmbeddedCollection'
1717

1818
/**
1919
* Defines the API store methods available in all Vue components. The methods can be called as follows:
@@ -85,10 +85,10 @@ function HalJsonVuex (store: Store<Record<string, State>>, axios: AxiosInstance,
8585
* @returns Promise Resolves when the GET request has completed and the updated entity is available
8686
* in the Vuex store.
8787
*/
88-
async function reload (uriOrEntity: string | Resource | StoreData | EmbeddedCollectionType): Promise<Resource | EmbeddedCollectionInterface> {
89-
if (isEmbeddedCollectionType(uriOrEntity)) { // = type guard for Embedded Collection
88+
async function reload (uriOrEntity: string | Resource | StoreData | EmbeddedCollectionMeta): Promise<Resource | EmbeddedCollection> {
89+
if (isEmbeddedCollection(uriOrEntity)) { // = type guard for Embedded Collection
9090
return get(uriOrEntity._meta.reload.uri, true)._meta.load // load parent resource
91-
.then(parent => parent[uriOrEntity._meta.reload.property]() as EmbeddedCollectionInterface) // ... and unwrap reload property after loading has finished
91+
.then(parent => parent[uriOrEntity._meta.reload.property]() as EmbeddedCollection) // ... and unwrap reload property after loading has finished
9292
} else {
9393
return get(uriOrEntity, true)._meta.load
9494
}
@@ -141,18 +141,18 @@ function HalJsonVuex (store: Store<Record<string, State>>, axios: AxiosInstance,
141141
}
142142

143143
/**
144-
* Type guard for EmbeddedCollectionType
144+
* Type guard for EmbeddedCollectionMeta
145145
* @param uriOrEntity
146146
*/
147-
function isEmbeddedCollectionType (uriOrEntity: string | Resource | EmbeddedCollectionType | StoreData | null): uriOrEntity is EmbeddedCollectionType {
147+
function isEmbeddedCollection (uriOrEntity: string | Resource | EmbeddedCollectionMeta | StoreData | null): uriOrEntity is EmbeddedCollectionMeta {
148148
if (uriOrEntity === null) return false
149149

150150
if (typeof uriOrEntity === 'string') return false
151151

152152
// found an actual EmbeddedCollection instance
153-
if (uriOrEntity instanceof EmbeddedCollection) return true
153+
if (uriOrEntity instanceof EmbeddedCollectionClass) return true
154154

155-
// found an object that looks like an EmbeddedCollectionType
155+
// found an object that looks like an EmbeddedCollectionMeta
156156
return 'reload' in uriOrEntity._meta
157157
}
158158

src/interfaces/ApiActions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import EmbeddedCollection from './EmbeddedCollection'
2-
import Resource, { EmbeddedCollectionType } from './Resource'
2+
import Resource, { EmbeddedCollectionMeta } from './Resource'
33
import StoreData from './StoreData'
44

55
interface ApiActions {
66
get: (uriOrEntity: string | Resource | StoreData, forceReload?: boolean) => Resource
7-
reload: (uriOrEntity: string | Resource | StoreData | EmbeddedCollectionType) => Promise<Resource | EmbeddedCollection>
7+
reload: (uriOrEntity: string | Resource | StoreData | EmbeddedCollectionMeta) => Promise<Resource | EmbeddedCollection>
88
post: (uriOrEntity: string | Resource, data: unknown) =>Promise<Resource>
99
patch: (uriOrEntity: string | Resource, data: unknown) => Promise<Resource>
1010
del: (uriOrEntity: string | Resource) => Promise<string | void>

src/interfaces/EmbeddedCollection.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import Collection from './Collection'
22

3-
/**
4-
* Subtype for an embeddeed collection with no self link (no standalone store entry, exists only with its parent)
5-
*/
6-
type EmbeddedCollection = Collection & {
3+
type EmbeddedCollectionMeta = {
74
_meta: {
5+
load?: Promise<EmbeddedCollectionMeta>
86
reload: {
97
uri: string
108
property: string
119
}
1210
}
1311
}
1412

15-
export { EmbeddedCollection }
13+
/**
14+
* Subtype for an embedded collection with no self link (no standalone store entry, exists only with its parent)
15+
*/
16+
type EmbeddedCollection = Collection & EmbeddedCollectionMeta
17+
18+
export { EmbeddedCollection, EmbeddedCollectionMeta }
1619
export default EmbeddedCollection

src/interfaces/Resource.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,5 @@ type Resource = {
2020
$del: () => Promise<string | void>
2121
}
2222

23-
/**
24-
* Subtype for an embeddeed collection with no self link (no standalone store entry, exists only with its parent)
25-
*/
26-
type EmbeddedCollectionType = {
27-
_meta: {
28-
load?: Promise<EmbeddedCollectionType>
29-
reload: {
30-
uri: string
31-
property: string
32-
}
33-
}
34-
}
35-
36-
export { Resource, EmbeddedCollectionType }
23+
export { Resource }
3724
export default Resource

src/interfaces/StoreData.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ type StoreDataCollection = StoreDataMeta & {
3131

3232
type StoreData = StoreDataEntity | StoreDataCollection
3333

34-
type Collection = {
35-
items: Array<Link>
36-
}
37-
38-
export { StoreData, Link, TemplatedLink, Collection, StoreDataEntity, StoreDataCollection }
34+
export { StoreData, Link, TemplatedLink, StoreDataEntity, StoreDataCollection }
3935

4036
export default StoreData

0 commit comments

Comments
 (0)