@shisho/plugin-types 0.0.19 → 0.0.21
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 +18 -13
- package/hooks.d.ts +11 -38
- package/metadata.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ The types provide autocompletion for:
|
|
|
15
15
|
- **`shisho.*`** - Host APIs (log, config, http, fs, archive, xml, ffmpeg)
|
|
16
16
|
- **`plugin`** - Hook structure (inputConverter, fileParser, metadataEnricher, outputGenerator)
|
|
17
17
|
- **Hook contexts** - Typed `context` parameters for each hook method
|
|
18
|
-
- **Return types** - `ParsedMetadata`, `ConvertResult`, `
|
|
18
|
+
- **Return types** - `ParsedMetadata`, `ConvertResult`, `SearchResponse`, etc.
|
|
19
19
|
|
|
20
20
|
### TypeScript
|
|
21
21
|
|
|
@@ -23,10 +23,10 @@ If you write your plugin in TypeScript (and compile to JavaScript for deployment
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
import type {
|
|
26
|
-
EnrichmentResult,
|
|
27
26
|
FileParserContext,
|
|
28
|
-
MetadataEnricherContext,
|
|
29
27
|
ParsedMetadata,
|
|
28
|
+
SearchContext,
|
|
29
|
+
SearchResponse,
|
|
30
30
|
ShishoPlugin,
|
|
31
31
|
} from "@shisho/plugin-types";
|
|
32
32
|
|
|
@@ -43,16 +43,20 @@ const plugin: ShishoPlugin = {
|
|
|
43
43
|
},
|
|
44
44
|
|
|
45
45
|
metadataEnricher: {
|
|
46
|
-
|
|
46
|
+
search(context: SearchContext): SearchResponse {
|
|
47
47
|
const apiKey = shisho.config.get("apiKey");
|
|
48
48
|
const resp = shisho.http.fetch(
|
|
49
|
-
`https://api.example.com/
|
|
49
|
+
`https://api.example.com/search?q=${context.query}`,
|
|
50
50
|
{ method: "GET" },
|
|
51
51
|
);
|
|
52
|
-
const data = resp.json() as {
|
|
52
|
+
const data = resp.json() as {
|
|
53
|
+
results: Array<{ title: string; description: string }>;
|
|
54
|
+
};
|
|
53
55
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
results: data.results.map((r) => ({
|
|
57
|
+
title: r.title,
|
|
58
|
+
description: r.description,
|
|
59
|
+
})),
|
|
56
60
|
};
|
|
57
61
|
},
|
|
58
62
|
},
|
|
@@ -80,17 +84,18 @@ var plugin = (function () {
|
|
|
80
84
|
},
|
|
81
85
|
|
|
82
86
|
metadataEnricher: {
|
|
83
|
-
/** @param {
|
|
84
|
-
|
|
87
|
+
/** @param {SearchContext} context @returns {SearchResponse} */
|
|
88
|
+
search: function (context) {
|
|
85
89
|
var apiKey = shisho.config.get("apiKey");
|
|
86
90
|
var resp = shisho.http.fetch(
|
|
87
|
-
"https://api.example.com/
|
|
91
|
+
"https://api.example.com/search?q=" + context.query,
|
|
88
92
|
{ method: "GET" },
|
|
89
93
|
);
|
|
90
94
|
var data = resp.json();
|
|
91
95
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
results: data.results.map(function (r) {
|
|
97
|
+
return { title: r.title, description: r.description };
|
|
98
|
+
}),
|
|
94
99
|
};
|
|
95
100
|
},
|
|
96
101
|
},
|
package/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedMetadata } from "./metadata";
|
|
1
|
+
import { ParsedAuthor, ParsedMetadata } from "./metadata";
|
|
2
2
|
|
|
3
3
|
/** Context passed to inputConverter.convert(). */
|
|
4
4
|
export interface InputConverterContext {
|
|
@@ -51,14 +51,21 @@ export interface SearchContext {
|
|
|
51
51
|
/** A single search result from metadataEnricher.search(). */
|
|
52
52
|
export interface SearchResult {
|
|
53
53
|
title: string;
|
|
54
|
-
authors?:
|
|
54
|
+
authors?: ParsedAuthor[];
|
|
55
55
|
description?: string;
|
|
56
56
|
imageUrl?: string;
|
|
57
57
|
releaseDate?: string;
|
|
58
58
|
publisher?: string;
|
|
59
|
+
imprint?: string;
|
|
60
|
+
url?: string;
|
|
61
|
+
coverUrl?: string;
|
|
62
|
+
subtitle?: string;
|
|
63
|
+
series?: string;
|
|
64
|
+
seriesNumber?: number;
|
|
65
|
+
genres?: string[];
|
|
66
|
+
tags?: string[];
|
|
67
|
+
narrators?: string[];
|
|
59
68
|
identifiers?: Array<{ type: string; value: string }>;
|
|
60
|
-
/** Opaque data passed back to enrich(). Use this to store internal IDs. */
|
|
61
|
-
providerData?: unknown;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
/** Result returned from metadataEnricher.search(). */
|
|
@@ -66,38 +73,6 @@ export interface SearchResponse {
|
|
|
66
73
|
results: SearchResult[];
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
/** Context passed to metadataEnricher.enrich(). */
|
|
70
|
-
export interface EnrichContext {
|
|
71
|
-
/** The selected search result's providerData. */
|
|
72
|
-
selectedResult: unknown;
|
|
73
|
-
/** Current book state from the database. */
|
|
74
|
-
book: {
|
|
75
|
-
id?: number;
|
|
76
|
-
title?: string;
|
|
77
|
-
subtitle?: string;
|
|
78
|
-
description?: string;
|
|
79
|
-
series?: Array<{ name: string; number?: number }>;
|
|
80
|
-
authors?: Array<{ name: string; role?: string }>;
|
|
81
|
-
genres?: string[];
|
|
82
|
-
tags?: string[];
|
|
83
|
-
identifiers?: Array<{ type: string; value: string }>;
|
|
84
|
-
publisher?: string;
|
|
85
|
-
};
|
|
86
|
-
/** File information. */
|
|
87
|
-
file: {
|
|
88
|
-
fileType?: string;
|
|
89
|
-
filePath?: string;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** Result returned from metadataEnricher.enrich(). */
|
|
94
|
-
export interface EnrichmentResult {
|
|
95
|
-
/** Whether metadata was modified. */
|
|
96
|
-
modified: boolean;
|
|
97
|
-
/** Updated metadata (only used if modified is true). */
|
|
98
|
-
metadata?: ParsedMetadata;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
76
|
/** Context passed to outputGenerator.generate(). */
|
|
102
77
|
export interface OutputGeneratorContext {
|
|
103
78
|
/** Path to the source book file. */
|
|
@@ -154,8 +129,6 @@ export interface FileParserHook {
|
|
|
154
129
|
export interface MetadataEnricherHook {
|
|
155
130
|
/** Search for candidate results from external sources. */
|
|
156
131
|
search(context: SearchContext): SearchResponse;
|
|
157
|
-
/** Enrich metadata from a selected search result. */
|
|
158
|
-
enrich(context: EnrichContext): EnrichmentResult;
|
|
159
132
|
}
|
|
160
133
|
|
|
161
134
|
/** Output generator hook. */
|
package/metadata.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface ParsedMetadata {
|
|
|
46
46
|
releaseDate?: string;
|
|
47
47
|
/** MIME type of cover image (e.g., "image/jpeg"). */
|
|
48
48
|
coverMimeType?: string;
|
|
49
|
+
/** Public URL for cover image. Server downloads at apply time. Lower precedence than coverData. Domain must be in httpAccess.domains. */
|
|
50
|
+
coverUrl?: string;
|
|
49
51
|
/** Cover image data as ArrayBuffer. */
|
|
50
52
|
coverData?: ArrayBuffer;
|
|
51
53
|
/** 0-indexed page number for CBZ cover. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shisho/plugin-types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "TypeScript type definitions for Shisho plugin development",
|
|
5
5
|
"homepage": "https://github.com/shishobooks/shisho/blob/master/packages/plugin-types/README.md",
|
|
6
6
|
"types": "index.d.ts",
|