@sphereon/ssi-sdk.data-store 0.34.1-feature.disable.test.8 → 0.34.1-next.29

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.
@@ -1,41 +1,70 @@
1
- import { IOAuthStatusListEntity, IStatusList2021Entity, IStatusListEntity } from '../../types'
2
- import { OAuthStatusListEntity, StatusList2021Entity, StatusListEntity } from '../../entities/statusList/StatusListEntities'
1
+ import { IBitstringStatusListEntity, IOAuthStatusListEntity, IStatusList2021Entity, IStatusListEntity } from '../../types'
2
+ import {
3
+ BitstringStatusListEntity,
4
+ OAuthStatusListEntity,
5
+ StatusList2021Entity,
6
+ StatusListEntity,
7
+ } from '../../entities/statusList/StatusListEntities'
3
8
  import { StatusListType } from '@sphereon/ssi-types'
4
9
  import { replaceNullWithUndefined } from '../FormattingUtils'
5
10
 
6
11
  export const statusListEntityFrom = (args: IStatusListEntity): StatusListEntity => {
7
- if (args.type === StatusListType.StatusList2021) {
8
- const entity = new StatusList2021Entity()
9
- const sl2021 = args as IStatusList2021Entity
10
- entity.indexingDirection = sl2021.indexingDirection
11
- entity.statusPurpose = sl2021.statusPurpose
12
- setBaseFields(entity, args)
13
- Object.defineProperty(entity, 'type', {
14
- value: StatusListType.StatusList2021,
15
- enumerable: true,
16
- configurable: true,
17
- })
18
- return entity
19
- }
12
+ switch (args.type) {
13
+ case StatusListType.StatusList2021: {
14
+ const entity = new StatusList2021Entity()
15
+ const sl2021 = args as IStatusList2021Entity
16
+ entity.indexingDirection = sl2021.indexingDirection
17
+ entity.statusPurpose = sl2021.statusPurpose
18
+ setBaseFields(entity, args)
19
+ Object.defineProperty(entity, 'type', {
20
+ value: StatusListType.StatusList2021,
21
+ enumerable: true,
22
+ configurable: true,
23
+ })
24
+ return entity
25
+ }
20
26
 
21
- if (args.type === StatusListType.OAuthStatusList) {
22
- const entity = new OAuthStatusListEntity()
23
- const oauthSl = args as IOAuthStatusListEntity
24
- entity.bitsPerStatus = oauthSl.bitsPerStatus
25
- entity.expiresAt = oauthSl.expiresAt
26
- setBaseFields(entity, args)
27
- Object.defineProperty(entity, 'type', {
28
- value: StatusListType.OAuthStatusList,
29
- enumerable: true,
30
- configurable: true,
31
- })
32
- return entity
33
- }
27
+ case StatusListType.OAuthStatusList: {
28
+ const entity = new OAuthStatusListEntity()
29
+ const oauthSl = args as IOAuthStatusListEntity
30
+ entity.bitsPerStatus = oauthSl.bitsPerStatus
31
+ entity.expiresAt = oauthSl.expiresAt
32
+ setBaseFields(entity, args)
33
+ Object.defineProperty(entity, 'type', {
34
+ value: StatusListType.OAuthStatusList,
35
+ enumerable: true,
36
+ configurable: true,
37
+ })
38
+ return entity
39
+ }
40
+
41
+ case StatusListType.BitstringStatusList: {
42
+ const entity = new BitstringStatusListEntity()
43
+ const bitstringsl = args as IBitstringStatusListEntity
44
+ if (!bitstringsl.bitsPerStatus) {
45
+ throw Error('bitsPerStatus must be set for BitstringStatusList')
46
+ }
47
+
48
+ entity.statusPurpose = bitstringsl.statusPurpose
49
+ entity.bitsPerStatus = bitstringsl.bitsPerStatus
50
+ entity.validFrom = bitstringsl.validFrom
51
+ entity.validUntil = bitstringsl.validUntil
52
+ entity.ttl = bitstringsl.ttl
53
+ setBaseFields(entity, args)
54
+ Object.defineProperty(entity, 'type', {
55
+ value: StatusListType.BitstringStatusList,
56
+ enumerable: true,
57
+ configurable: true,
58
+ })
59
+ return entity
60
+ }
34
61
 
35
- throw new Error(`Invalid status list type ${args.type}`)
62
+ default:
63
+ throw new Error(`Invalid status list type ${args.type}`)
64
+ }
36
65
  }
37
66
 
38
- export const statusListFrom = (entity: StatusListEntity): IStatusListEntity => {
67
+ export const statusListFrom = (entity: StatusListEntity): IStatusListEntity | IBitstringStatusListEntity => {
39
68
  if (entity instanceof StatusList2021Entity) {
40
69
  const result: IStatusList2021Entity = {
41
70
  ...getBaseFields(entity),
@@ -56,6 +85,18 @@ export const statusListFrom = (entity: StatusListEntity): IStatusListEntity => {
56
85
  return replaceNullWithUndefined(result)
57
86
  }
58
87
 
88
+ if (entity instanceof BitstringStatusListEntity) {
89
+ const result: IBitstringStatusListEntity = {
90
+ ...getBaseFields(entity),
91
+ type: StatusListType.BitstringStatusList,
92
+ statusPurpose: entity.statusPurpose,
93
+ bitsPerStatus: entity.bitsPerStatus,
94
+ validFrom: entity.validFrom,
95
+ validUntil: entity.validUntil,
96
+ ttl: entity.ttl,
97
+ }
98
+ return replaceNullWithUndefined(result)
99
+ }
59
100
  throw new Error(`Invalid status list type ${typeof entity}`)
60
101
  }
61
102