ddex-json-codec 0.1.0 → 0.1.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/README.md +38 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# ddex-json-codec
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bidirectional XML/JSON codec for the DDEX ERN (Electronic Release Notification) standard, written in TypeScript.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
- ERN XML
|
|
8
|
-
- ERN 3.8
|
|
9
|
-
-
|
|
10
|
-
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser)
|
|
7
|
+
- Convert ERN XML to typed TypeScript objects and back
|
|
8
|
+
- Supports ERN 3.8.x (3.8 - 3.8.3) and ERN 4.x (4.1 - 4.3.2)
|
|
9
|
+
- Automatic version detection from namespace URI
|
|
10
|
+
- Built on [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser)
|
|
11
11
|
- Node.js >= 20
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install ddex-json-codec
|
|
@@ -18,66 +18,66 @@ npm install ddex-json-codec
|
|
|
18
18
|
pnpm add ddex-json-codec
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Usage
|
|
22
22
|
|
|
23
|
-
### XML
|
|
23
|
+
### XML to JSON
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { xmlToJson } from 'ddex-json-codec';
|
|
27
27
|
|
|
28
28
|
const message = xmlToJson(xmlString);
|
|
29
|
-
console.log(message.ernVersion); // "3.8.
|
|
29
|
+
console.log(message.ernVersion); // "3.8.2"
|
|
30
30
|
console.log(message.resourceList); // SoundRecording[]
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
### JSON
|
|
33
|
+
### JSON to XML
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
36
|
import { jsonToXml } from 'ddex-json-codec';
|
|
37
37
|
|
|
38
38
|
const xml = jsonToXml(message);
|
|
39
|
-
//
|
|
39
|
+
// Optionally specify a target version
|
|
40
40
|
const xml382 = jsonToXml(message, '3.8.2');
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
###
|
|
43
|
+
### Version Detection
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
46
|
import { detectVersion } from 'ddex-json-codec';
|
|
47
47
|
|
|
48
|
-
const version = detectVersion(xmlString); // "3
|
|
48
|
+
const version = detectVersion(xmlString); // "4.3"
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
##
|
|
51
|
+
## Supported Versions
|
|
52
52
|
|
|
53
|
-
| ERN
|
|
53
|
+
| ERN Version | Status |
|
|
54
54
|
|---|---|
|
|
55
|
-
| 3.8 |
|
|
56
|
-
| 3.8.1 |
|
|
57
|
-
| 3.8.2 |
|
|
58
|
-
| 3.8.3 |
|
|
59
|
-
| 4.1 |
|
|
60
|
-
| 4.1.1 |
|
|
61
|
-
| 4.2 |
|
|
62
|
-
| 4.3 |
|
|
63
|
-
| 4.3.1 |
|
|
64
|
-
| 4.3.2 |
|
|
65
|
-
|
|
66
|
-
## API
|
|
55
|
+
| 3.8 | Supported |
|
|
56
|
+
| 3.8.1 | Supported |
|
|
57
|
+
| 3.8.2 | Supported |
|
|
58
|
+
| 3.8.3 | Supported |
|
|
59
|
+
| 4.1 | Supported |
|
|
60
|
+
| 4.1.1 | Supported |
|
|
61
|
+
| 4.2 | Supported |
|
|
62
|
+
| 4.3 | Supported |
|
|
63
|
+
| 4.3.1 | Supported |
|
|
64
|
+
| 4.3.2 | Supported |
|
|
65
|
+
|
|
66
|
+
## API
|
|
67
67
|
|
|
68
68
|
### `xmlToJson(xml: string): DdexMessage`
|
|
69
69
|
|
|
70
|
-
ERN XML
|
|
70
|
+
Parse an ERN XML string into a typed object. Version is auto-detected.
|
|
71
71
|
|
|
72
72
|
### `jsonToXml(message: DdexMessage, version?: ErnVersion): string`
|
|
73
73
|
|
|
74
|
-
`DdexMessage`
|
|
74
|
+
Convert a `DdexMessage` back to an ERN XML string. Falls back to `message.ernVersion` when `version` is omitted.
|
|
75
75
|
|
|
76
76
|
### `detectVersion(xml: string): ErnVersion`
|
|
77
77
|
|
|
78
|
-
ERN
|
|
78
|
+
Detect the ERN version from namespace URI or `MessageSchemaVersionId` attribute.
|
|
79
79
|
|
|
80
|
-
###
|
|
80
|
+
### Types
|
|
81
81
|
|
|
82
82
|
```typescript
|
|
83
83
|
interface DdexMessage {
|
|
@@ -87,19 +87,19 @@ interface DdexMessage {
|
|
|
87
87
|
resourceList: SoundRecording[];
|
|
88
88
|
releaseList: Release[];
|
|
89
89
|
dealList: ReleaseDeal[];
|
|
90
|
-
partyList?: Party[]; // 4
|
|
91
|
-
trackReleaseList?: TrackRelease[]; // 4
|
|
90
|
+
partyList?: Party[]; // ERN 4.x only
|
|
91
|
+
trackReleaseList?: TrackRelease[]; // ERN 4.x only
|
|
92
92
|
}
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
Exported types:
|
|
96
96
|
|
|
97
97
|
`DdexMessage`, `ErnVersion`, `ErnMajorVersion`, `MessageHeader`, `MessageParty`,
|
|
98
98
|
`SoundRecording`, `Release`, `TrackRelease`, `ResourceGroup`, `ReleaseResourceReference`,
|
|
99
99
|
`ReleaseDeal`, `Deal`, `DealTerms`, `Usage`,
|
|
100
|
-
`Party`, `Artist`, `DisplayArtist`, `ResourceContributor`, `IndirectResourceContributor`,
|
|
101
|
-
`TextWithAttribute`, `Genre`, `PLine`, `CLine`, `Title`
|
|
100
|
+
`Party`, `Artist`, `DisplayArtist`, `ResourceContributor`, `IndirectResourceContributor`, `Contributor`,
|
|
101
|
+
`TextWithAttribute`, `Genre`, `PLine`, `CLine`, `Title`, `DisplayTitle`
|
|
102
102
|
|
|
103
|
-
##
|
|
103
|
+
## License
|
|
104
104
|
|
|
105
105
|
[MIT](./LICENSE.md)
|