@internetarchive/metadata-service 1.0.1 → 1.0.3

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/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export { MetadataResponse } from './src/responses/metadata-response';
2
+ export { File } from './src/models/file';
3
+ export { Review } from './src/models/review';
4
+ export { SpeechMusicASREntry } from './src/models/speech-music-asr-entry';
2
5
  export { DefaultMetadataBackend } from './src/backend/default-metadata-backend';
3
6
  export { MetadataService } from './src/metadata-service';
4
7
  export { MetadataServiceError } from './src/metadata-service-error';
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { MetadataResponse } from './src/responses/metadata-response';
2
+ export { File } from './src/models/file';
3
+ export { Review } from './src/models/review';
2
4
  export { DefaultMetadataBackend } from './src/backend/default-metadata-backend';
3
5
  export { MetadataService } from './src/metadata-service';
4
6
  export { MetadataServiceError } from './src/metadata-service-error';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["export { MetadataResponse } from './src/responses/metadata-response';\n\nexport { DefaultMetadataBackend } from './src/backend/default-metadata-backend';\nexport { MetadataService } from './src/metadata-service';\nexport { MetadataServiceError } from './src/metadata-service-error';\nexport { MetadataServiceInterface } from './src/metadata-service-interface';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["export { MetadataResponse } from './src/responses/metadata-response';\n\nexport { File } from './src/models/file';\nexport { Review } from './src/models/review';\nexport { SpeechMusicASREntry } from './src/models/speech-music-asr-entry';\n\nexport { DefaultMetadataBackend } from './src/backend/default-metadata-backend';\nexport { MetadataService } from './src/metadata-service';\nexport { MetadataServiceError } from './src/metadata-service-error';\nexport { MetadataServiceInterface } from './src/metadata-service-interface';\n"]}
@@ -0,0 +1,29 @@
1
+ import { Byte, Duration } from '@internetarchive/field-parsers';
2
+ /**
3
+ * This represents an Internet Archive File
4
+ *
5
+ * @export
6
+ * @class File
7
+ */
8
+ export declare class File {
9
+ readonly rawValue: Readonly<Record<string, any>>;
10
+ get name(): string;
11
+ get source(): string;
12
+ get btih(): string;
13
+ get md5(): string;
14
+ get format(): string;
15
+ get mtime(): string;
16
+ get crc32(): string;
17
+ get sha1(): string;
18
+ get original(): string | undefined;
19
+ get size(): Byte | undefined;
20
+ get title(): string | undefined;
21
+ get length(): Duration | undefined;
22
+ get height(): number | undefined;
23
+ get width(): number | undefined;
24
+ get track(): number | undefined;
25
+ get external_identifier(): string | string[] | undefined;
26
+ get creator(): string | undefined;
27
+ get album(): string | undefined;
28
+ constructor(json?: Record<string, any>);
29
+ }
@@ -0,0 +1,95 @@
1
+ import { __decorate } from "tslib";
2
+ import { Memoize } from 'typescript-memoize';
3
+ import { ByteParser, DurationParser, NumberParser, } from '@internetarchive/field-parsers';
4
+ /**
5
+ * This represents an Internet Archive File
6
+ *
7
+ * @export
8
+ * @class File
9
+ */
10
+ export class File {
11
+ get name() {
12
+ return this.rawValue.name;
13
+ }
14
+ get source() {
15
+ return this.rawValue.source;
16
+ }
17
+ get btih() {
18
+ return this.rawValue.btih;
19
+ }
20
+ get md5() {
21
+ return this.rawValue.md5;
22
+ }
23
+ get format() {
24
+ return this.rawValue.format;
25
+ }
26
+ get mtime() {
27
+ return this.rawValue.mtime;
28
+ }
29
+ get crc32() {
30
+ return this.rawValue.crc32;
31
+ }
32
+ get sha1() {
33
+ return this.rawValue.sha1;
34
+ }
35
+ get original() {
36
+ return this.rawValue.original;
37
+ }
38
+ get size() {
39
+ return this.rawValue.size != null
40
+ ? ByteParser.shared.parseValue(this.rawValue.size)
41
+ : undefined;
42
+ }
43
+ get title() {
44
+ return this.rawValue.title;
45
+ }
46
+ get length() {
47
+ return this.rawValue.length != null
48
+ ? DurationParser.shared.parseValue(this.rawValue.length)
49
+ : undefined;
50
+ }
51
+ get height() {
52
+ return this.rawValue.height != null
53
+ ? NumberParser.shared.parseValue(this.rawValue.height)
54
+ : undefined;
55
+ }
56
+ get width() {
57
+ return this.rawValue.width != null
58
+ ? NumberParser.shared.parseValue(this.rawValue.width)
59
+ : undefined;
60
+ }
61
+ get track() {
62
+ return this.rawValue.track != null
63
+ ? NumberParser.shared.parseValue(this.rawValue.track)
64
+ : undefined;
65
+ }
66
+ get external_identifier() {
67
+ return this.rawValue.external_identifier;
68
+ }
69
+ get creator() {
70
+ return this.rawValue.creator;
71
+ }
72
+ get album() {
73
+ return this.rawValue.album;
74
+ }
75
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
76
+ constructor(json = {}) {
77
+ this.rawValue = json;
78
+ }
79
+ }
80
+ __decorate([
81
+ Memoize()
82
+ ], File.prototype, "size", null);
83
+ __decorate([
84
+ Memoize()
85
+ ], File.prototype, "length", null);
86
+ __decorate([
87
+ Memoize()
88
+ ], File.prototype, "height", null);
89
+ __decorate([
90
+ Memoize()
91
+ ], File.prototype, "width", null);
92
+ __decorate([
93
+ Memoize()
94
+ ], File.prototype, "track", null);
95
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 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AAV,OAAO,EAAE;kCAIT;AAEU;IAAV,OAAO,EAAE;iCAIT;AAEU;IAAV,OAAO,EAAE;iCAIT","sourcesContent":["import { Memoize } from 'typescript-memoize';\nimport {\n Byte,\n ByteParser,\n Duration,\n DurationParser,\n NumberParser,\n} from '@internetarchive/field-parsers';\n\n/**\n * This represents an Internet Archive File\n *\n * @export\n * @class File\n */\nexport class File {\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n readonly rawValue: Readonly<Record<string, any>>;\n\n get name(): string {\n return this.rawValue.name;\n }\n\n get source(): string {\n return this.rawValue.source;\n }\n\n get btih(): string {\n return this.rawValue.btih;\n }\n\n get md5(): string {\n return this.rawValue.md5;\n }\n\n get format(): string {\n return this.rawValue.format;\n }\n\n get mtime(): string {\n return this.rawValue.mtime;\n }\n\n get crc32(): string {\n return this.rawValue.crc32;\n }\n\n get sha1(): string {\n return this.rawValue.sha1;\n }\n\n get original(): string | undefined {\n return this.rawValue.original;\n }\n\n @Memoize() get size(): Byte | undefined {\n return this.rawValue.size != null\n ? ByteParser.shared.parseValue(this.rawValue.size)\n : undefined;\n }\n\n get title(): string | undefined {\n return this.rawValue.title;\n }\n\n @Memoize() get length(): Duration | undefined {\n return this.rawValue.length != null\n ? DurationParser.shared.parseValue(this.rawValue.length)\n : undefined;\n }\n\n @Memoize() get height(): number | undefined {\n return this.rawValue.height != null\n ? NumberParser.shared.parseValue(this.rawValue.height)\n : undefined;\n }\n\n @Memoize() get width(): number | undefined {\n return this.rawValue.width != null\n ? NumberParser.shared.parseValue(this.rawValue.width)\n : undefined;\n }\n\n @Memoize() get track(): number | undefined {\n return this.rawValue.track != null\n ? NumberParser.shared.parseValue(this.rawValue.track)\n : undefined;\n }\n\n get external_identifier(): string | string[] | undefined {\n return this.rawValue.external_identifier;\n }\n\n get creator(): string | undefined {\n return this.rawValue.creator;\n }\n\n get album(): string | undefined {\n return this.rawValue.album;\n }\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n constructor(json: Record<string, any> = {}) {\n this.rawValue = json;\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export declare class Review {
2
+ readonly rawValue: Readonly<Record<string, any>>;
3
+ get reviewbody(): string | undefined;
4
+ get reviewtitle(): string | undefined;
5
+ get reviewer(): string | undefined;
6
+ get reviewdate(): Date | undefined;
7
+ get createdate(): Date | undefined;
8
+ get stars(): number | undefined;
9
+ constructor(json?: Record<string, any>);
10
+ }
@@ -0,0 +1,43 @@
1
+ import { __decorate } from "tslib";
2
+ import { Memoize } from 'typescript-memoize';
3
+ import { DateParser, NumberParser } from '@internetarchive/field-parsers';
4
+ export class Review {
5
+ get reviewbody() {
6
+ return this.rawValue.reviewbody;
7
+ }
8
+ get reviewtitle() {
9
+ return this.rawValue.reviewtitle;
10
+ }
11
+ get reviewer() {
12
+ return this.rawValue.reviewer;
13
+ }
14
+ get reviewdate() {
15
+ return this.rawValue.reviewdate != null
16
+ ? DateParser.shared.parseValue(this.rawValue.reviewdate)
17
+ : undefined;
18
+ }
19
+ get createdate() {
20
+ return this.rawValue.createdate != null
21
+ ? DateParser.shared.parseValue(this.rawValue.createdate)
22
+ : undefined;
23
+ }
24
+ get stars() {
25
+ return this.rawValue.stars != null
26
+ ? NumberParser.shared.parseValue(this.rawValue.stars)
27
+ : undefined;
28
+ }
29
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
30
+ constructor(json = {}) {
31
+ this.rawValue = json;
32
+ }
33
+ }
34
+ __decorate([
35
+ Memoize()
36
+ ], Review.prototype, "reviewdate", null);
37
+ __decorate([
38
+ Memoize()
39
+ ], Review.prototype, "createdate", null);
40
+ __decorate([
41
+ Memoize()
42
+ ], Review.prototype, "stars", null);
43
+ //# sourceMappingURL=review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.js","sourceRoot":"","sources":["../../../src/models/review.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE1E,MAAM,OAAO,MAAM;IAIjB,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;IAClC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACnC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEU,IAAI,UAAU;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,IAAI;YACrC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;YACxD,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAEU,IAAI,UAAU;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,IAAI;YACrC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;YACxD,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAEU,IAAI,KAAK;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI;YAChC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YACrD,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAED,iEAAiE;IACjE,YAAY,OAA4B,EAAE;QACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AAtBY;IAAV,OAAO,EAAE;wCAIT;AAEU;IAAV,OAAO,EAAE;wCAIT;AAEU;IAAV,OAAO,EAAE;mCAIT","sourcesContent":["import { Memoize } from 'typescript-memoize';\nimport { DateParser, NumberParser } from '@internetarchive/field-parsers';\n\nexport class Review {\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n readonly rawValue: Readonly<Record<string, any>>;\n\n get reviewbody(): string | undefined {\n return this.rawValue.reviewbody;\n }\n\n get reviewtitle(): string | undefined {\n return this.rawValue.reviewtitle;\n }\n\n get reviewer(): string | undefined {\n return this.rawValue.reviewer;\n }\n\n @Memoize() get reviewdate(): Date | undefined {\n return this.rawValue.reviewdate != null\n ? DateParser.shared.parseValue(this.rawValue.reviewdate)\n : undefined;\n }\n\n @Memoize() get createdate(): Date | undefined {\n return this.rawValue.createdate != null\n ? DateParser.shared.parseValue(this.rawValue.createdate)\n : undefined;\n }\n\n @Memoize() get stars(): number | undefined {\n return this.rawValue.stars != null\n ? NumberParser.shared.parseValue(this.rawValue.stars)\n : undefined;\n }\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n constructor(json: Record<string, any> = {}) {\n this.rawValue = json;\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This is the format used for radio transcripts
3
+ */
4
+ export type SpeechMusicASREntry = {
5
+ readonly end: number;
6
+ readonly id: number;
7
+ readonly is_music: boolean;
8
+ readonly start: number;
9
+ readonly text: string;
10
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=speech-music-asr-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speech-music-asr-entry.js","sourceRoot":"","sources":["../../../src/models/speech-music-asr-entry.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * This is the format used for radio transcripts\n */\nexport type SpeechMusicASREntry = {\n readonly end: number;\n readonly id: number;\n readonly is_music: boolean;\n readonly start: number;\n readonly text: string;\n};\n"]}
@@ -1,4 +1,7 @@
1
- import { File, Metadata, Review, SpeechMusicASREntry } from '@internetarchive/iaux-item-metadata';
1
+ import { Metadata } from '@internetarchive/iaux-item-metadata';
2
+ import { File } from '../models/file';
3
+ import { Review } from '../models/review';
4
+ import { SpeechMusicASREntry } from '../models/speech-music-asr-entry';
2
5
  /**
3
6
  * The main top-level reponse when fetching Metadata
4
7
  *
@@ -1,4 +1,6 @@
1
- import { File, Metadata, Review, } from '@internetarchive/iaux-item-metadata';
1
+ import { Metadata } from '@internetarchive/iaux-item-metadata';
2
+ import { File } from '../models/file';
3
+ import { Review } from '../models/review';
2
4
  /**
3
5
  * The main top-level reponse when fetching Metadata
4
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"metadata-response.js","sourceRoot":"","sources":["../../../src/responses/metadata-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,GAEP,MAAM,qCAAqC,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAgC3B,iEAAiE;IACjE,YAAY,IAAyB;;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,iEAAiE;QACjE,IAAI,CAAC,KAAK,GAAG,MAAA,IAAI,CAAC,KAAK,0CAAE,GAAG,CAAC,CAAC,IAAyB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,MAAA,IAAI,CAAC,OAAO,0CAAE,GAAG;QAC9B,iEAAiE;QACjE,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAClD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n File,\n Metadata,\n Review,\n SpeechMusicASREntry,\n} from '@internetarchive/iaux-item-metadata';\n\n/**\n * The main top-level reponse when fetching Metadata\n *\n * @export\n * @class MetadataResponse\n */\nexport class MetadataResponse {\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n readonly rawResponse: Readonly<Record<string, any>>;\n\n readonly created: number;\n\n readonly d1: string;\n\n readonly d2: string;\n\n readonly dir: string;\n\n readonly files: File[];\n\n readonly files_count: number;\n\n readonly item_last_updated: number;\n\n readonly item_size: number;\n\n readonly metadata: Metadata;\n\n readonly server: string;\n\n readonly uniq: number;\n\n readonly workable_servers: string[];\n\n readonly speech_vs_music_asr?: SpeechMusicASREntry[];\n\n readonly reviews?: Review[];\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n constructor(json: Record<string, any>) {\n this.rawResponse = json;\n this.created = json.created;\n this.d1 = json.d1;\n this.d2 = json.d2;\n this.dir = json.dir;\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n this.files = json.files?.map((file: Record<string, any>) => new File(file));\n this.files_count = json.files_count;\n this.item_last_updated = json.item_last_updated;\n this.item_size = json.item_size;\n this.metadata = new Metadata(json.metadata);\n this.server = json.server;\n this.uniq = json.uniq;\n this.workable_servers = json.workable_servers;\n this.speech_vs_music_asr = json.speech_vs_music_asr;\n this.reviews = json.reviews?.map(\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n (entry: Record<string, any>) => new Review(entry),\n );\n }\n}\n"]}
1
+ {"version":3,"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AA,IAAI,CAAC,OAAO,0CAAE,GAAG;QAC9B,iEAAiE;QACjE,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAClD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Metadata } from '@internetarchive/iaux-item-metadata';\nimport { File } from '../models/file';\nimport { Review } from '../models/review';\nimport { SpeechMusicASREntry } from '../models/speech-music-asr-entry';\n\n/**\n * The main top-level reponse when fetching Metadata\n *\n * @export\n * @class MetadataResponse\n */\nexport class MetadataResponse {\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n readonly rawResponse: Readonly<Record<string, any>>;\n\n readonly created: number;\n\n readonly d1: string;\n\n readonly d2: string;\n\n readonly dir: string;\n\n readonly files: File[];\n\n readonly files_count: number;\n\n readonly item_last_updated: number;\n\n readonly item_size: number;\n\n readonly metadata: Metadata;\n\n readonly server: string;\n\n readonly uniq: number;\n\n readonly workable_servers: string[];\n\n readonly speech_vs_music_asr?: SpeechMusicASREntry[];\n\n readonly reviews?: Review[];\n\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n constructor(json: Record<string, any>) {\n this.rawResponse = json;\n this.created = json.created;\n this.d1 = json.d1;\n this.d2 = json.d2;\n this.dir = json.dir;\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n this.files = json.files?.map((file: Record<string, any>) => new File(file));\n this.files_count = json.files_count;\n this.item_last_updated = json.item_last_updated;\n this.item_size = json.item_size;\n this.metadata = new Metadata(json.metadata);\n this.server = json.server;\n this.uniq = json.uniq;\n this.workable_servers = json.workable_servers;\n this.speech_vs_music_asr = json.speech_vs_music_asr;\n this.reviews = json.reviews?.map(\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n (entry: Record<string, any>) => new Review(entry),\n );\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { File } from '../../src/models/file';
3
+ describe('File', () => {
4
+ it('can be instantiated with an object', async () => {
5
+ const file = new File({ name: 'foo.jpg' });
6
+ expect(file.name).to.equal('foo.jpg');
7
+ });
8
+ // some fields like size and length get converted to their proper types
9
+ it('properly instantiates modeled fields', async () => {
10
+ const file = new File({
11
+ name: 'foo.jpg',
12
+ size: '1234',
13
+ length: '1:23',
14
+ height: '1080',
15
+ width: '1920',
16
+ track: '1',
17
+ });
18
+ expect(file.size).to.equal(1234);
19
+ expect(file.length).to.equal(83);
20
+ expect(file.height).to.equal(1080);
21
+ expect(file.width).to.equal(1920);
22
+ expect(file.track).to.equal(1);
23
+ });
24
+ it('external_identifier can be a single value', async () => {
25
+ const file = new File({ name: 'foo.jpg', external_identifier: 'bar' });
26
+ expect(file.external_identifier).to.equal('bar');
27
+ });
28
+ it('external_identifier can be an array', async () => {
29
+ const file = new File({
30
+ name: 'foo.jpg',
31
+ external_identifier: ['foo', 'bar'],
32
+ });
33
+ expect(file.external_identifier).to.deep.equal(['foo', 'bar']);
34
+ });
35
+ it('handles falsy values properly', async () => {
36
+ const file = new File({
37
+ name: 'foo.jpg',
38
+ size: 0,
39
+ track: 0,
40
+ });
41
+ expect(file.size).to.not.be.undefined;
42
+ expect(file.size).to.equal(0);
43
+ expect(file.track).to.not.be.undefined;
44
+ expect(file.track).to.equal(0);
45
+ });
46
+ });
47
+ //# sourceMappingURL=file.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.test.js","sourceRoot":"","sources":["../../../test/models/file.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3C,MAAM,CA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YACf,mBAAmB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;SACpC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC;YACpB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from '@open-wc/testing';\n\nimport { File } from '../../src/models/file';\n\ndescribe('File', () => {\n it('can be instantiated with an object', async () => {\n const file = new File({ name: 'foo.jpg' });\n expect(file.name).to.equal('foo.jpg');\n });\n\n // some fields like size and length get converted to their proper types\n it('properly instantiates modeled fields', async () => {\n const file = new File({\n name: 'foo.jpg',\n size: '1234',\n length: '1:23',\n height: '1080',\n width: '1920',\n track: '1',\n });\n expect(file.size).to.equal(1234);\n expect(file.length).to.equal(83);\n expect(file.height).to.equal(1080);\n expect(file.width).to.equal(1920);\n expect(file.track).to.equal(1);\n });\n\n it('external_identifier can be a single value', async () => {\n const file = new File({ name: 'foo.jpg', external_identifier: 'bar' });\n expect(file.external_identifier).to.equal('bar');\n });\n\n it('external_identifier can be an array', async () => {\n const file = new File({\n name: 'foo.jpg',\n external_identifier: ['foo', 'bar'],\n });\n expect(file.external_identifier).to.deep.equal(['foo', 'bar']);\n });\n\n it('handles falsy values properly', async () => {\n const file = new File({\n name: 'foo.jpg',\n size: 0,\n track: 0,\n });\n expect(file.size).to.not.be.undefined;\n expect(file.size).to.equal(0);\n expect(file.track).to.not.be.undefined;\n expect(file.track).to.equal(0);\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { Review } from '../../src/models/review';
3
+ describe('Review', () => {
4
+ it('can be instantiated with a title', async () => {
5
+ const review = new Review({
6
+ reviewtitle: 'It was awesome!',
7
+ });
8
+ expect(review.reviewtitle).to.equal('It was awesome!');
9
+ });
10
+ it('stars get converted to a number', async () => {
11
+ const review = new Review({
12
+ stars: '5',
13
+ });
14
+ expect(review.stars).to.equal(5);
15
+ });
16
+ it('reviewdate get converted to a date', async () => {
17
+ var _a;
18
+ const review = new Review({
19
+ reviewdate: '2014-05-09 09:47:15',
20
+ });
21
+ const expected = new Date();
22
+ expected.setHours(9);
23
+ expected.setMinutes(47);
24
+ expected.setSeconds(15);
25
+ expected.setMilliseconds(0);
26
+ expected.setMonth(4);
27
+ expected.setDate(9);
28
+ expected.setFullYear(2014);
29
+ expect((_a = review.reviewdate) === null || _a === void 0 ? void 0 : _a.getTime()).to.equal(expected.getTime());
30
+ });
31
+ it('handles falsy values properly', async () => {
32
+ var _a;
33
+ const review = new Review({
34
+ reviewtitle: 'yay',
35
+ reviewdate: '0',
36
+ stars: 0,
37
+ });
38
+ const expected = new Date();
39
+ expected.setHours(0);
40
+ expected.setMinutes(0);
41
+ expected.setSeconds(0);
42
+ expected.setMilliseconds(0);
43
+ expected.setMonth(0);
44
+ expected.setDate(1);
45
+ expected.setFullYear(2000);
46
+ expect(review.reviewtitle).to.equal('yay');
47
+ expect(review.reviewdate).to.not.be.undefined;
48
+ expect((_a = review.reviewdate) === null || _a === void 0 ? void 0 : _a.getTime()).to.equal(expected.getTime());
49
+ expect(review.stars).to.not.be.undefined;
50
+ expect(review.stars).to.equal(0);
51
+ });
52
+ });
53
+ //# sourceMappingURL=review.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.test.js","sourceRoot":"","sources":["../../../test/models/review.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAChD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACxB,WAAW,EAAE,iBAAiB;SAC/B,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACxB,KAAK,EAAE,GAAG;SACX,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;;QAClD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;YACxB,UAAU,EAAE,qBAAqB;SAClC,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,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AAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;QACzC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from '@open-wc/testing';\n\nimport { Review } from '../../src/models/review';\n\ndescribe('Review', () => {\n it('can be instantiated with a title', async () => {\n const review = new Review({\n reviewtitle: 'It was awesome!',\n });\n expect(review.reviewtitle).to.equal('It was awesome!');\n });\n\n it('stars get converted to a number', async () => {\n const review = new Review({\n stars: '5',\n });\n expect(review.stars).to.equal(5);\n });\n\n it('reviewdate get converted to a date', async () => {\n const review = new Review({\n reviewdate: '2014-05-09 09:47:15',\n });\n\n const expected = new Date();\n expected.setHours(9);\n expected.setMinutes(47);\n expected.setSeconds(15);\n expected.setMilliseconds(0);\n expected.setMonth(4);\n expected.setDate(9);\n expected.setFullYear(2014);\n\n expect(review.reviewdate?.getTime()).to.equal(expected.getTime());\n });\n\n it('handles falsy values properly', async () => {\n const review = new Review({\n reviewtitle: 'yay',\n reviewdate: '0',\n stars: 0,\n });\n\n const expected = new Date();\n expected.setHours(0);\n expected.setMinutes(0);\n expected.setSeconds(0);\n expected.setMilliseconds(0);\n expected.setMonth(0);\n expected.setDate(1);\n expected.setFullYear(2000);\n\n expect(review.reviewtitle).to.equal('yay');\n expect(review.reviewdate).to.not.be.undefined;\n expect(review.reviewdate?.getTime()).to.equal(expected.getTime());\n expect(review.stars).to.not.be.undefined;\n expect(review.stars).to.equal(0);\n });\n});\n"]}
package/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export { MetadataResponse } from './src/responses/metadata-response';
2
2
 
3
+ export { File } from './src/models/file';
4
+ export { Review } from './src/models/review';
5
+ export { SpeechMusicASREntry } from './src/models/speech-music-asr-entry';
6
+
3
7
  export { DefaultMetadataBackend } from './src/backend/default-metadata-backend';
4
8
  export { MetadataService } from './src/metadata-service';
5
9
  export { MetadataServiceError } from './src/metadata-service-error';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/metadata-service",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A service for fetching metadata about items in the Internet Archive",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "dist/index.js",
@@ -26,8 +26,10 @@
26
26
  "codecov": "npx codecov"
27
27
  },
28
28
  "dependencies": {
29
- "@internetarchive/iaux-item-metadata": "^1.0.3",
30
- "@internetarchive/result-type": "^0.0.1"
29
+ "@internetarchive/field-parsers": "^0.1.4",
30
+ "@internetarchive/iaux-item-metadata": "^1.0.4",
31
+ "@internetarchive/result-type": "^0.0.1",
32
+ "typescript-memoize": "^1.1.1"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@open-wc/eslint-config": "^12.0.3",
@@ -0,0 +1,106 @@
1
+ import { Memoize } from 'typescript-memoize';
2
+ import {
3
+ Byte,
4
+ ByteParser,
5
+ Duration,
6
+ DurationParser,
7
+ NumberParser,
8
+ } from '@internetarchive/field-parsers';
9
+
10
+ /**
11
+ * This represents an Internet Archive File
12
+ *
13
+ * @export
14
+ * @class File
15
+ */
16
+ export class File {
17
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
18
+ readonly rawValue: Readonly<Record<string, any>>;
19
+
20
+ get name(): string {
21
+ return this.rawValue.name;
22
+ }
23
+
24
+ get source(): string {
25
+ return this.rawValue.source;
26
+ }
27
+
28
+ get btih(): string {
29
+ return this.rawValue.btih;
30
+ }
31
+
32
+ get md5(): string {
33
+ return this.rawValue.md5;
34
+ }
35
+
36
+ get format(): string {
37
+ return this.rawValue.format;
38
+ }
39
+
40
+ get mtime(): string {
41
+ return this.rawValue.mtime;
42
+ }
43
+
44
+ get crc32(): string {
45
+ return this.rawValue.crc32;
46
+ }
47
+
48
+ get sha1(): string {
49
+ return this.rawValue.sha1;
50
+ }
51
+
52
+ get original(): string | undefined {
53
+ return this.rawValue.original;
54
+ }
55
+
56
+ @Memoize() get size(): Byte | undefined {
57
+ return this.rawValue.size != null
58
+ ? ByteParser.shared.parseValue(this.rawValue.size)
59
+ : undefined;
60
+ }
61
+
62
+ get title(): string | undefined {
63
+ return this.rawValue.title;
64
+ }
65
+
66
+ @Memoize() get length(): Duration | undefined {
67
+ return this.rawValue.length != null
68
+ ? DurationParser.shared.parseValue(this.rawValue.length)
69
+ : undefined;
70
+ }
71
+
72
+ @Memoize() get height(): number | undefined {
73
+ return this.rawValue.height != null
74
+ ? NumberParser.shared.parseValue(this.rawValue.height)
75
+ : undefined;
76
+ }
77
+
78
+ @Memoize() get width(): number | undefined {
79
+ return this.rawValue.width != null
80
+ ? NumberParser.shared.parseValue(this.rawValue.width)
81
+ : undefined;
82
+ }
83
+
84
+ @Memoize() get track(): number | undefined {
85
+ return this.rawValue.track != null
86
+ ? NumberParser.shared.parseValue(this.rawValue.track)
87
+ : undefined;
88
+ }
89
+
90
+ get external_identifier(): string | string[] | undefined {
91
+ return this.rawValue.external_identifier;
92
+ }
93
+
94
+ get creator(): string | undefined {
95
+ return this.rawValue.creator;
96
+ }
97
+
98
+ get album(): string | undefined {
99
+ return this.rawValue.album;
100
+ }
101
+
102
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
103
+ constructor(json: Record<string, any> = {}) {
104
+ this.rawValue = json;
105
+ }
106
+ }
@@ -0,0 +1,42 @@
1
+ import { Memoize } from 'typescript-memoize';
2
+ import { DateParser, NumberParser } from '@internetarchive/field-parsers';
3
+
4
+ export class Review {
5
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
6
+ readonly rawValue: Readonly<Record<string, any>>;
7
+
8
+ get reviewbody(): string | undefined {
9
+ return this.rawValue.reviewbody;
10
+ }
11
+
12
+ get reviewtitle(): string | undefined {
13
+ return this.rawValue.reviewtitle;
14
+ }
15
+
16
+ get reviewer(): string | undefined {
17
+ return this.rawValue.reviewer;
18
+ }
19
+
20
+ @Memoize() get reviewdate(): Date | undefined {
21
+ return this.rawValue.reviewdate != null
22
+ ? DateParser.shared.parseValue(this.rawValue.reviewdate)
23
+ : undefined;
24
+ }
25
+
26
+ @Memoize() get createdate(): Date | undefined {
27
+ return this.rawValue.createdate != null
28
+ ? DateParser.shared.parseValue(this.rawValue.createdate)
29
+ : undefined;
30
+ }
31
+
32
+ @Memoize() get stars(): number | undefined {
33
+ return this.rawValue.stars != null
34
+ ? NumberParser.shared.parseValue(this.rawValue.stars)
35
+ : undefined;
36
+ }
37
+
38
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
39
+ constructor(json: Record<string, any> = {}) {
40
+ this.rawValue = json;
41
+ }
42
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This is the format used for radio transcripts
3
+ */
4
+ export type SpeechMusicASREntry = {
5
+ readonly end: number;
6
+ readonly id: number;
7
+ readonly is_music: boolean;
8
+ readonly start: number;
9
+ readonly text: string;
10
+ };
@@ -1,9 +1,7 @@
1
- import {
2
- File,
3
- Metadata,
4
- Review,
5
- SpeechMusicASREntry,
6
- } from '@internetarchive/iaux-item-metadata';
1
+ import { Metadata } from '@internetarchive/iaux-item-metadata';
2
+ import { File } from '../models/file';
3
+ import { Review } from '../models/review';
4
+ import { SpeechMusicASREntry } from '../models/speech-music-asr-entry';
7
5
 
8
6
  /**
9
7
  * The main top-level reponse when fetching Metadata
@@ -0,0 +1,52 @@
1
+ import { expect } from '@open-wc/testing';
2
+
3
+ import { File } from '../../src/models/file';
4
+
5
+ describe('File', () => {
6
+ it('can be instantiated with an object', async () => {
7
+ const file = new File({ name: 'foo.jpg' });
8
+ expect(file.name).to.equal('foo.jpg');
9
+ });
10
+
11
+ // some fields like size and length get converted to their proper types
12
+ it('properly instantiates modeled fields', async () => {
13
+ const file = new File({
14
+ name: 'foo.jpg',
15
+ size: '1234',
16
+ length: '1:23',
17
+ height: '1080',
18
+ width: '1920',
19
+ track: '1',
20
+ });
21
+ expect(file.size).to.equal(1234);
22
+ expect(file.length).to.equal(83);
23
+ expect(file.height).to.equal(1080);
24
+ expect(file.width).to.equal(1920);
25
+ expect(file.track).to.equal(1);
26
+ });
27
+
28
+ it('external_identifier can be a single value', async () => {
29
+ const file = new File({ name: 'foo.jpg', external_identifier: 'bar' });
30
+ expect(file.external_identifier).to.equal('bar');
31
+ });
32
+
33
+ it('external_identifier can be an array', async () => {
34
+ const file = new File({
35
+ name: 'foo.jpg',
36
+ external_identifier: ['foo', 'bar'],
37
+ });
38
+ expect(file.external_identifier).to.deep.equal(['foo', 'bar']);
39
+ });
40
+
41
+ it('handles falsy values properly', async () => {
42
+ const file = new File({
43
+ name: 'foo.jpg',
44
+ size: 0,
45
+ track: 0,
46
+ });
47
+ expect(file.size).to.not.be.undefined;
48
+ expect(file.size).to.equal(0);
49
+ expect(file.track).to.not.be.undefined;
50
+ expect(file.track).to.equal(0);
51
+ });
52
+ });
@@ -0,0 +1,59 @@
1
+ import { expect } from '@open-wc/testing';
2
+
3
+ import { Review } from '../../src/models/review';
4
+
5
+ describe('Review', () => {
6
+ it('can be instantiated with a title', async () => {
7
+ const review = new Review({
8
+ reviewtitle: 'It was awesome!',
9
+ });
10
+ expect(review.reviewtitle).to.equal('It was awesome!');
11
+ });
12
+
13
+ it('stars get converted to a number', async () => {
14
+ const review = new Review({
15
+ stars: '5',
16
+ });
17
+ expect(review.stars).to.equal(5);
18
+ });
19
+
20
+ it('reviewdate get converted to a date', async () => {
21
+ const review = new Review({
22
+ reviewdate: '2014-05-09 09:47:15',
23
+ });
24
+
25
+ const expected = new Date();
26
+ expected.setHours(9);
27
+ expected.setMinutes(47);
28
+ expected.setSeconds(15);
29
+ expected.setMilliseconds(0);
30
+ expected.setMonth(4);
31
+ expected.setDate(9);
32
+ expected.setFullYear(2014);
33
+
34
+ expect(review.reviewdate?.getTime()).to.equal(expected.getTime());
35
+ });
36
+
37
+ it('handles falsy values properly', async () => {
38
+ const review = new Review({
39
+ reviewtitle: 'yay',
40
+ reviewdate: '0',
41
+ stars: 0,
42
+ });
43
+
44
+ const expected = new Date();
45
+ expected.setHours(0);
46
+ expected.setMinutes(0);
47
+ expected.setSeconds(0);
48
+ expected.setMilliseconds(0);
49
+ expected.setMonth(0);
50
+ expected.setDate(1);
51
+ expected.setFullYear(2000);
52
+
53
+ expect(review.reviewtitle).to.equal('yay');
54
+ expect(review.reviewdate).to.not.be.undefined;
55
+ expect(review.reviewdate?.getTime()).to.equal(expected.getTime());
56
+ expect(review.stars).to.not.be.undefined;
57
+ expect(review.stars).to.equal(0);
58
+ });
59
+ });