@danmaku-anywhere/extension-protocol 0.1.0 → 0.2.0
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/src/kazumi.d.ts +97 -0
- package/dist/src/kazumi.js +44 -4
- package/dist/src/messages.d.ts +4 -1
- package/package.json +7 -7
package/dist/src/kazumi.d.ts
CHANGED
|
@@ -7,6 +7,62 @@ export declare const zKazumiManifest: z.ZodObject<{
|
|
|
7
7
|
lastUpdate: z.ZodNumber;
|
|
8
8
|
}, z.core.$strip>;
|
|
9
9
|
export type KazumiManifest = z.output<typeof zKazumiManifest>;
|
|
10
|
+
declare const zKazumiApiRequest: z.ZodObject<{
|
|
11
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
12
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
13
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
15
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
16
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
17
|
+
}, z.core.$loose>;
|
|
18
|
+
export type KazumiApiRequest = z.output<typeof zKazumiApiRequest>;
|
|
19
|
+
export declare const zKazumiSearchApiConfig: z.ZodObject<{
|
|
20
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
21
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
22
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
23
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
26
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
27
|
+
}, z.core.$loose>>;
|
|
28
|
+
listPath: z.ZodPrefault<z.ZodString>;
|
|
29
|
+
namePath: z.ZodPrefault<z.ZodString>;
|
|
30
|
+
sourcePath: z.ZodPrefault<z.ZodString>;
|
|
31
|
+
sourceTemplate: z.ZodPrefault<z.ZodString>;
|
|
32
|
+
}, z.core.$loose>;
|
|
33
|
+
export type KazumiSearchApiConfig = z.output<typeof zKazumiSearchApiConfig>;
|
|
34
|
+
export declare const zKazumiEpisodePage: z.ZodObject<{
|
|
35
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
36
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
37
|
+
}, z.core.$loose>;
|
|
38
|
+
export type KazumiEpisodePage = z.output<typeof zKazumiEpisodePage>;
|
|
39
|
+
export declare const zKazumiChapterApiConfig: z.ZodObject<{
|
|
40
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
41
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
42
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
43
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
46
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
47
|
+
}, z.core.$loose>>;
|
|
48
|
+
format: z.ZodPrefault<z.ZodString>;
|
|
49
|
+
roadsPath: z.ZodPrefault<z.ZodString>;
|
|
50
|
+
roadNamePath: z.ZodPrefault<z.ZodString>;
|
|
51
|
+
episodesPath: z.ZodPrefault<z.ZodString>;
|
|
52
|
+
episodeNamePath: z.ZodPrefault<z.ZodString>;
|
|
53
|
+
episodeUrlPath: z.ZodPrefault<z.ZodString>;
|
|
54
|
+
roadNamesPath: z.ZodPrefault<z.ZodString>;
|
|
55
|
+
roadEpisodesPath: z.ZodPrefault<z.ZodString>;
|
|
56
|
+
roadSeparator: z.ZodPrefault<z.ZodString>;
|
|
57
|
+
episodeSeparator: z.ZodPrefault<z.ZodString>;
|
|
58
|
+
fieldSeparator: z.ZodPrefault<z.ZodString>;
|
|
59
|
+
variables: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
60
|
+
episodePage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
61
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
62
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
63
|
+
}, z.core.$loose>>>;
|
|
64
|
+
}, z.core.$loose>;
|
|
65
|
+
export type KazumiChapterApiConfig = z.output<typeof zKazumiChapterApiConfig>;
|
|
10
66
|
export declare const zKazumiPolicy: z.ZodObject<{
|
|
11
67
|
api: z.ZodString;
|
|
12
68
|
type: z.ZodString;
|
|
@@ -34,6 +90,47 @@ export declare const zKazumiPolicy: z.ZodObject<{
|
|
|
34
90
|
chapterRoads: z.ZodPrefault<z.ZodString>;
|
|
35
91
|
chapterResult: z.ZodPrefault<z.ZodString>;
|
|
36
92
|
referer: z.ZodPrefault<z.ZodString>;
|
|
93
|
+
searchApiConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
94
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
95
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
96
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
97
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
100
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
101
|
+
}, z.core.$loose>>;
|
|
102
|
+
listPath: z.ZodPrefault<z.ZodString>;
|
|
103
|
+
namePath: z.ZodPrefault<z.ZodString>;
|
|
104
|
+
sourcePath: z.ZodPrefault<z.ZodString>;
|
|
105
|
+
sourceTemplate: z.ZodPrefault<z.ZodString>;
|
|
106
|
+
}, z.core.$loose>>>;
|
|
107
|
+
chapterApiConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
108
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
109
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
110
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
111
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
112
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
113
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
114
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
115
|
+
}, z.core.$loose>>;
|
|
116
|
+
format: z.ZodPrefault<z.ZodString>;
|
|
117
|
+
roadsPath: z.ZodPrefault<z.ZodString>;
|
|
118
|
+
roadNamePath: z.ZodPrefault<z.ZodString>;
|
|
119
|
+
episodesPath: z.ZodPrefault<z.ZodString>;
|
|
120
|
+
episodeNamePath: z.ZodPrefault<z.ZodString>;
|
|
121
|
+
episodeUrlPath: z.ZodPrefault<z.ZodString>;
|
|
122
|
+
roadNamesPath: z.ZodPrefault<z.ZodString>;
|
|
123
|
+
roadEpisodesPath: z.ZodPrefault<z.ZodString>;
|
|
124
|
+
roadSeparator: z.ZodPrefault<z.ZodString>;
|
|
125
|
+
episodeSeparator: z.ZodPrefault<z.ZodString>;
|
|
126
|
+
fieldSeparator: z.ZodPrefault<z.ZodString>;
|
|
127
|
+
variables: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
128
|
+
episodePage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
129
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
130
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
131
|
+
}, z.core.$loose>>>;
|
|
132
|
+
}, z.core.$loose>>>;
|
|
37
133
|
}, z.core.$strip>;
|
|
38
134
|
export type KazumiPolicy = z.output<typeof zKazumiPolicy>;
|
|
39
135
|
export declare function isXPathPolicy(policy: KazumiPolicy): boolean;
|
|
136
|
+
export {};
|
package/dist/src/kazumi.js
CHANGED
|
@@ -7,6 +7,45 @@ export const zKazumiManifest = z.object({
|
|
|
7
7
|
lastUpdate: z.number(),
|
|
8
8
|
});
|
|
9
9
|
const zKazumiRuleMode = z.enum(['xpath', 'api']).prefault('xpath');
|
|
10
|
+
// A rule that searches or lists chapters through an API describes the request
|
|
11
|
+
// as a template (values reference @keyword for search and @source for
|
|
12
|
+
// chapters) and reads the response with JSONPath expressions. Unknown fields
|
|
13
|
+
// are kept because Kazumi grows the format independently of this schema.
|
|
14
|
+
const zKazumiApiRequest = z.looseObject({
|
|
15
|
+
method: z.string().prefault('GET'),
|
|
16
|
+
url: z.string().prefault(''),
|
|
17
|
+
headers: z.record(z.string(), z.unknown()).prefault({}),
|
|
18
|
+
query: z.record(z.string(), z.unknown()).prefault({}),
|
|
19
|
+
bodyType: z.string().prefault('none'),
|
|
20
|
+
body: z.unknown().optional(),
|
|
21
|
+
});
|
|
22
|
+
export const zKazumiSearchApiConfig = z.looseObject({
|
|
23
|
+
request: zKazumiApiRequest.prefault({}),
|
|
24
|
+
listPath: z.string().prefault('$.data[*]'),
|
|
25
|
+
namePath: z.string().prefault('$.name'),
|
|
26
|
+
sourcePath: z.string().prefault('$.url'),
|
|
27
|
+
sourceTemplate: z.string().prefault(''),
|
|
28
|
+
});
|
|
29
|
+
export const zKazumiEpisodePage = z.looseObject({
|
|
30
|
+
url: z.string().prefault(''),
|
|
31
|
+
query: z.record(z.string(), z.unknown()).prefault({}),
|
|
32
|
+
});
|
|
33
|
+
export const zKazumiChapterApiConfig = z.looseObject({
|
|
34
|
+
request: zKazumiApiRequest.prefault({}),
|
|
35
|
+
format: z.string().prefault('nested'),
|
|
36
|
+
roadsPath: z.string().prefault('$.data.roads[*]'),
|
|
37
|
+
roadNamePath: z.string().prefault('$.name'),
|
|
38
|
+
episodesPath: z.string().prefault('$.episodes[*]'),
|
|
39
|
+
episodeNamePath: z.string().prefault('$.name'),
|
|
40
|
+
episodeUrlPath: z.string().prefault('$.url'),
|
|
41
|
+
roadNamesPath: z.string().prefault(''),
|
|
42
|
+
roadEpisodesPath: z.string().prefault(''),
|
|
43
|
+
roadSeparator: z.string().prefault('$$$'),
|
|
44
|
+
episodeSeparator: z.string().prefault('#'),
|
|
45
|
+
fieldSeparator: z.string().prefault('$'),
|
|
46
|
+
variables: z.record(z.string(), z.string()).prefault({}),
|
|
47
|
+
episodePage: zKazumiEpisodePage.nullish(),
|
|
48
|
+
});
|
|
10
49
|
const searchSelectors = [
|
|
11
50
|
'searchURL',
|
|
12
51
|
'searchList',
|
|
@@ -38,6 +77,8 @@ export const zKazumiPolicy = z
|
|
|
38
77
|
chapterRoads: z.string().prefault(''),
|
|
39
78
|
chapterResult: z.string().prefault(''),
|
|
40
79
|
referer: z.string().prefault(''),
|
|
80
|
+
searchApiConfig: zKazumiSearchApiConfig.nullish(),
|
|
81
|
+
chapterApiConfig: zKazumiChapterApiConfig.nullish(),
|
|
41
82
|
})
|
|
42
83
|
.superRefine((policy, ctx) => {
|
|
43
84
|
const required = [];
|
|
@@ -57,10 +98,9 @@ export const zKazumiPolicy = z
|
|
|
57
98
|
}
|
|
58
99
|
}
|
|
59
100
|
});
|
|
60
|
-
// Whether
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// are xpath rules.
|
|
101
|
+
// Whether every step of a rule opens a page and reads it with XPath, as
|
|
102
|
+
// opposed to a step that goes through an API. Rules stored before the mode
|
|
103
|
+
// fields existed have no mode at all, and are xpath rules.
|
|
64
104
|
export function isXPathPolicy(policy) {
|
|
65
105
|
return policy.searchMode !== 'api' && policy.chapterMode !== 'api';
|
|
66
106
|
}
|
package/dist/src/messages.d.ts
CHANGED
|
@@ -29,7 +29,10 @@ export type ExtAction = {
|
|
|
29
29
|
}, MediaInfo>;
|
|
30
30
|
episodeGetAll: ExtActionDef<void, GenericEpisodeLite[]>;
|
|
31
31
|
danmakuGet: ExtActionDef<GenericEpisodeLite, CommentEntity[]>;
|
|
32
|
-
setRequestHeaders: ExtActionDef<SetHeaderRule,
|
|
32
|
+
setRequestHeaders: ExtActionDef<SetHeaderRule, number | undefined>;
|
|
33
|
+
removeRequestHeaders: ExtActionDef<{
|
|
34
|
+
ruleId: number;
|
|
35
|
+
}, void>;
|
|
33
36
|
};
|
|
34
37
|
type ExtRequestBase<T extends ExtActionType> = {
|
|
35
38
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danmaku-anywhere/extension-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Messages exchanged between the Danmaku Anywhere extension and the pages it talks to",
|
|
5
5
|
"author": "Mr-Quin",
|
|
6
6
|
"repository": {
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"provenance": true
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@danmaku-anywhere/danmaku-model": "^0.2.
|
|
26
|
+
"@danmaku-anywhere/danmaku-model": "^0.2.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"zod": "^4.6.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"vitest": "^5.
|
|
33
|
-
"zod": "^4.6.
|
|
32
|
+
"vitest": "^5.1.2",
|
|
33
|
+
"zod": "^4.6.7"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"lint": "
|
|
38
|
-
"type-check": "
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"lint": "oxlint --fix && oxfmt",
|
|
38
|
+
"type-check": "tsc --noEmit",
|
|
39
39
|
"test": "vitest run"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|