@natlibfi/ekirjasto-opds-feed-parser 0.0.0-post.147
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/.github/CODEOWNERS +4 -0
- package/.github/pull_request_template.md +12 -0
- package/.github/workflows/release.yml +102 -0
- package/.github/workflows/test.yml +23 -0
- package/CHANGELOG +17 -0
- package/LICENSE +201 -0
- package/README.md +57 -0
- package/lib/src/acquisition_feed.d.ts +3 -0
- package/lib/src/acquisition_feed.js +26 -0
- package/lib/src/alternate_link.d.ts +5 -0
- package/lib/src/alternate_link.js +30 -0
- package/lib/src/availability_parser.d.ts +5 -0
- package/lib/src/availability_parser.js +34 -0
- package/lib/src/category.d.ts +8 -0
- package/lib/src/category.js +9 -0
- package/lib/src/category_parser.d.ts +5 -0
- package/lib/src/category_parser.js +33 -0
- package/lib/src/complete_entry_link.d.ts +6 -0
- package/lib/src/complete_entry_link.js +30 -0
- package/lib/src/contributor.d.ts +8 -0
- package/lib/src/contributor.js +9 -0
- package/lib/src/contributor_parser.d.ts +5 -0
- package/lib/src/contributor_parser.js +35 -0
- package/lib/src/copies_parser.d.ts +5 -0
- package/lib/src/copies_parser.js +33 -0
- package/lib/src/entry_parser.d.ts +5 -0
- package/lib/src/entry_parser.js +106 -0
- package/lib/src/feed_parser.d.ts +5 -0
- package/lib/src/feed_parser.js +61 -0
- package/lib/src/holds_parser.d.ts +5 -0
- package/lib/src/holds_parser.js +33 -0
- package/lib/src/index.d.ts +25 -0
- package/lib/src/index.js +45 -0
- package/lib/src/indirect_acquisition_parser.d.ts +5 -0
- package/lib/src/indirect_acquisition_parser.js +37 -0
- package/lib/src/link_parser.d.ts +7 -0
- package/lib/src/link_parser.js +110 -0
- package/lib/src/namespace_parser.d.ts +13 -0
- package/lib/src/namespace_parser.js +44 -0
- package/lib/src/navigation_feed.d.ts +3 -0
- package/lib/src/navigation_feed.js +26 -0
- package/lib/src/opds_acquisition_link.d.ts +29 -0
- package/lib/src/opds_acquisition_link.js +41 -0
- package/lib/src/opds_artwork_link.d.ts +7 -0
- package/lib/src/opds_artwork_link.js +33 -0
- package/lib/src/opds_availability.d.ts +6 -0
- package/lib/src/opds_availability.js +2 -0
- package/lib/src/opds_catalog_root_link.d.ts +5 -0
- package/lib/src/opds_catalog_root_link.js +30 -0
- package/lib/src/opds_collection_link.d.ts +5 -0
- package/lib/src/opds_collection_link.js +30 -0
- package/lib/src/opds_copies.d.ts +5 -0
- package/lib/src/opds_copies.js +2 -0
- package/lib/src/opds_crawlable_link.d.ts +5 -0
- package/lib/src/opds_crawlable_link.js +30 -0
- package/lib/src/opds_entry.d.ts +27 -0
- package/lib/src/opds_entry.js +9 -0
- package/lib/src/opds_facet_link.d.ts +13 -0
- package/lib/src/opds_facet_link.js +30 -0
- package/lib/src/opds_feed.d.ts +19 -0
- package/lib/src/opds_feed.js +9 -0
- package/lib/src/opds_holds.d.ts +5 -0
- package/lib/src/opds_holds.js +2 -0
- package/lib/src/opds_indirect_acquisition.d.ts +5 -0
- package/lib/src/opds_indirect_acquisition.js +2 -0
- package/lib/src/opds_link.d.ts +15 -0
- package/lib/src/opds_link.js +9 -0
- package/lib/src/opds_parser.d.ts +5 -0
- package/lib/src/opds_parser.js +40 -0
- package/lib/src/opds_price.d.ts +5 -0
- package/lib/src/opds_price.js +2 -0
- package/lib/src/opds_shelf_link.d.ts +5 -0
- package/lib/src/opds_shelf_link.js +30 -0
- package/lib/src/partial_opds_entry.d.ts +3 -0
- package/lib/src/partial_opds_entry.js +26 -0
- package/lib/src/prefix_map.d.ts +4 -0
- package/lib/src/prefix_map.js +2 -0
- package/lib/src/price_parser.d.ts +5 -0
- package/lib/src/price_parser.js +31 -0
- package/lib/src/search_link.d.ts +5 -0
- package/lib/src/search_link.js +30 -0
- package/lib/src/series.d.ts +7 -0
- package/lib/src/series.js +9 -0
- package/lib/src/series_parser.d.ts +5 -0
- package/lib/src/series_parser.js +34 -0
- package/lib/src/summary.d.ts +7 -0
- package/lib/src/summary.js +9 -0
- package/lib/src/xml2js_output_parser.d.ts +11 -0
- package/lib/src/xml2js_output_parser.js +48 -0
- package/lib/src/xml_interface.d.ts +9 -0
- package/lib/src/xml_interface.js +2 -0
- package/package.json +45 -0
- package/requirements-ci.txt +1 -0
- package/test/availability_parser_test.ts +32 -0
- package/test/category_parser_test.ts +30 -0
- package/test/contributor_parser_test.ts +44 -0
- package/test/copies_parser_test.ts +30 -0
- package/test/entry_parser_test.ts +272 -0
- package/test/feed_parser_test.ts +244 -0
- package/test/files/acquisition.xml +416 -0
- package/test/files/entry.xml +33 -0
- package/test/files/navigation.xml +56 -0
- package/test/holds_parser_test.ts +30 -0
- package/test/indirect_acquisition_parser_test.ts +46 -0
- package/test/link_parser_test.ts +324 -0
- package/test/namespace_parser_test.ts +41 -0
- package/test/opds_parser_test.ts +147 -0
- package/test/price_parser_test.ts +30 -0
- package/test/series_parser_test.ts +30 -0
- package/tsconfig.json +15 -0
- package/tslint.json +54 -0
- package/typings.json +8 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import PrefixMap from "../src/prefix_map";
|
|
2
|
+
import FeedParser from "../src/feed_parser";
|
|
3
|
+
import AcquisitionFeed from "../src/acquisition_feed";
|
|
4
|
+
import NavigationFeed from "../src/navigation_feed";
|
|
5
|
+
import NamespaceParser from "../src/namespace_parser";
|
|
6
|
+
import OPDSAcquisitionLink from "../src/opds_acquisition_link";
|
|
7
|
+
import chai = require("chai");
|
|
8
|
+
let expect = chai.expect;
|
|
9
|
+
|
|
10
|
+
describe("FeedParser", () => {
|
|
11
|
+
let parser: FeedParser;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
let prefixes: PrefixMap = {};
|
|
15
|
+
prefixes[NamespaceParser.ATOM_URI] = "atom:";
|
|
16
|
+
prefixes[NamespaceParser.OPEN_SEARCH_URI] = "opensearch:";
|
|
17
|
+
prefixes[NamespaceParser.FH_URI] = "fh:";
|
|
18
|
+
parser = new FeedParser(prefixes);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("#parse", () => {
|
|
22
|
+
it("extracts entries", () => {
|
|
23
|
+
let entries = [{
|
|
24
|
+
"atom:id": [{"_": "test id"}],
|
|
25
|
+
"atom:title": [{"_": "test title"}]
|
|
26
|
+
}];
|
|
27
|
+
|
|
28
|
+
let feed = {
|
|
29
|
+
"$": {
|
|
30
|
+
"xmlns:atom": {
|
|
31
|
+
"value": NamespaceParser.ATOM_URI,
|
|
32
|
+
"local": "atom"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"atom:entry": entries
|
|
36
|
+
};
|
|
37
|
+
let parsedFeed = parser.parse(feed);
|
|
38
|
+
expect(parsedFeed.entries.length).to.equals(1);
|
|
39
|
+
let parsedEntry = parsedFeed.entries[0];
|
|
40
|
+
expect(parsedEntry.title).to.equals("test title");
|
|
41
|
+
expect(parsedEntry.id).to.equals("test id");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("extracts links", () => {
|
|
45
|
+
let links = [{
|
|
46
|
+
"$": {
|
|
47
|
+
"href": {"value": "test href"},
|
|
48
|
+
"rel": {"value": "test rel"}
|
|
49
|
+
}
|
|
50
|
+
}];
|
|
51
|
+
let feed = {
|
|
52
|
+
"$": {
|
|
53
|
+
"xmlns:atom": {
|
|
54
|
+
"value": NamespaceParser.ATOM_URI,
|
|
55
|
+
"local": "atom"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"atom:link": links
|
|
59
|
+
};
|
|
60
|
+
let parsedFeed = parser.parse(feed);
|
|
61
|
+
expect(parsedFeed.links.length).to.equals(1);
|
|
62
|
+
let parsedLink = parsedFeed.links[0];
|
|
63
|
+
expect(parsedLink.href).to.equals("test href");
|
|
64
|
+
expect(parsedLink.rel).to.equals("test rel");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("extracts id", () => {
|
|
68
|
+
let id = {
|
|
69
|
+
"_": "test id"
|
|
70
|
+
};
|
|
71
|
+
let feed = {
|
|
72
|
+
"$": {
|
|
73
|
+
"xmlns:atom": {
|
|
74
|
+
"value": NamespaceParser.ATOM_URI,
|
|
75
|
+
"local": "atom"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"atom:id": [id]
|
|
79
|
+
};
|
|
80
|
+
let parsedFeed = parser.parse(feed);
|
|
81
|
+
expect(parsedFeed.id).to.equals("test id");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("extracts title", () => {
|
|
85
|
+
let title = {
|
|
86
|
+
"_": "test title"
|
|
87
|
+
};
|
|
88
|
+
let feed = {
|
|
89
|
+
"$": {
|
|
90
|
+
"xmlns:atom": {
|
|
91
|
+
"value": NamespaceParser.ATOM_URI,
|
|
92
|
+
"local": "atom"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"atom:title": [title]
|
|
96
|
+
};
|
|
97
|
+
let parsedFeed = parser.parse(feed);
|
|
98
|
+
expect(parsedFeed.title).to.equals("test title");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("extracts updated date", () => {
|
|
102
|
+
let updated = {
|
|
103
|
+
"_": "2016-02-01T18:30:59Z"
|
|
104
|
+
};
|
|
105
|
+
let feed = {
|
|
106
|
+
"$": {
|
|
107
|
+
"xmlns:atom": {
|
|
108
|
+
"value": NamespaceParser.ATOM_URI,
|
|
109
|
+
"local": "atom"
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"atom:updated": [updated]
|
|
113
|
+
};
|
|
114
|
+
let parsedFeed = parser.parse(feed);
|
|
115
|
+
expect(parsedFeed.updated).to.equals(updated["_"]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("extracts fh:complete if present", () => {
|
|
119
|
+
let complete = {};
|
|
120
|
+
let feed = {
|
|
121
|
+
"$": {
|
|
122
|
+
"xmlns:fh": {
|
|
123
|
+
"value": NamespaceParser.FH_URI,
|
|
124
|
+
"local": "fh"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"fh:complete": [complete]
|
|
128
|
+
};
|
|
129
|
+
let parsedFeed = parser.parse(feed);
|
|
130
|
+
expect(parsedFeed.complete).to.be.true;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("does not extract fh:complete if not present", () => {
|
|
134
|
+
let feed = {
|
|
135
|
+
"$": {
|
|
136
|
+
"xmlns:fh": {
|
|
137
|
+
"value": NamespaceParser.FH_URI,
|
|
138
|
+
"local": "fh"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
let parsedFeed = parser.parse(feed);
|
|
143
|
+
expect(parsedFeed.complete).to.be.false;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("extracts search info", () => {
|
|
147
|
+
let totalResults = {
|
|
148
|
+
"_": "22"
|
|
149
|
+
};
|
|
150
|
+
let startIndex = {
|
|
151
|
+
"_": "5"
|
|
152
|
+
};
|
|
153
|
+
let itemsPerPage = {
|
|
154
|
+
"_": "12"
|
|
155
|
+
};
|
|
156
|
+
let feed = {
|
|
157
|
+
"$": {
|
|
158
|
+
"xmlns:atom": {
|
|
159
|
+
"value": NamespaceParser.ATOM_URI,
|
|
160
|
+
"local": "atom"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"opensearch:totalResults": [totalResults],
|
|
164
|
+
"opensearch:startIndex": [startIndex],
|
|
165
|
+
"opensearch:itemsPerPage": [itemsPerPage]
|
|
166
|
+
};
|
|
167
|
+
let parsedFeed = parser.parse(feed);
|
|
168
|
+
expect(parsedFeed.search.totalResults).to.equals(22);
|
|
169
|
+
expect(parsedFeed.search.startIndex).to.equals(5);
|
|
170
|
+
expect(parsedFeed.search.itemsPerPage).to.equals(12);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("recognizes navigation feed", () => {
|
|
174
|
+
let links = [{
|
|
175
|
+
"$": {
|
|
176
|
+
"href": {"value": "test href"},
|
|
177
|
+
"rel": {"value": "test rel"}
|
|
178
|
+
}
|
|
179
|
+
}];
|
|
180
|
+
let entry = {
|
|
181
|
+
"atom:link": links
|
|
182
|
+
};
|
|
183
|
+
let feed = {
|
|
184
|
+
"$": {
|
|
185
|
+
"xmlns:atom": {
|
|
186
|
+
"value": NamespaceParser.ATOM_URI,
|
|
187
|
+
"local": "atom"
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"atom:entry": [entry],
|
|
191
|
+
};
|
|
192
|
+
let parsedFeed = parser.parse(feed);
|
|
193
|
+
expect(parsedFeed).to.be.an.instanceof(NavigationFeed);
|
|
194
|
+
expect(parsedFeed).not.to.be.an.instanceof(AcquisitionFeed);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("recognizes acquisition feed", () => {
|
|
198
|
+
let links = [{
|
|
199
|
+
"$": {
|
|
200
|
+
"href": {"value": "test href"},
|
|
201
|
+
"rel": {"value": OPDSAcquisitionLink.GENERIC_REL}
|
|
202
|
+
}
|
|
203
|
+
}];
|
|
204
|
+
let entry = {
|
|
205
|
+
"atom:link": links
|
|
206
|
+
};
|
|
207
|
+
let feed = {
|
|
208
|
+
"$": {
|
|
209
|
+
"xmlns:atom": {
|
|
210
|
+
"value": NamespaceParser.ATOM_URI,
|
|
211
|
+
"local": "atom"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
"atom:entry": [entry],
|
|
215
|
+
};
|
|
216
|
+
let parsedFeed = parser.parse(feed);
|
|
217
|
+
expect(parsedFeed).to.be.an.instanceof(AcquisitionFeed);
|
|
218
|
+
expect(parsedFeed).not.to.be.an.instanceof(NavigationFeed);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("keeps unparsed data", () => {
|
|
222
|
+
let links = [{
|
|
223
|
+
"$": {
|
|
224
|
+
"href": {"value": "test href"},
|
|
225
|
+
"rel": {"value": OPDSAcquisitionLink.GENERIC_REL}
|
|
226
|
+
}
|
|
227
|
+
}];
|
|
228
|
+
let entry = {
|
|
229
|
+
"atom:link": links
|
|
230
|
+
};
|
|
231
|
+
let feed = {
|
|
232
|
+
"$": {
|
|
233
|
+
"xmlns:atom": {
|
|
234
|
+
"value": NamespaceParser.ATOM_URI,
|
|
235
|
+
"local": "atom"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"atom:entry": [entry],
|
|
239
|
+
};
|
|
240
|
+
let parsedFeed = parser.parse(feed);
|
|
241
|
+
expect(parsedFeed.unparsed).to.eql(feed);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|