types-mediawiki-response 1.1.0 → 1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # types-mediawiki-response
2
2
 
3
- English | [简体中文](https://github.com/BearBin1215/types-mediawiki-response/blob/main/README.zh.md) | [Document](https://bearbin1215.github.io/types-mediawiki-response/)
3
+ English | [简体中文](https://github.com/BearBin1215/types-mediawiki-response/blob/main/README.zh.md) | [Document](https://types-mediawiki-response.pages.dev/)
4
4
 
5
5
  Reusable typings for MediaWiki Action API responses.
6
6
 
@@ -30,9 +30,9 @@ const res = (await api.get({
30
30
  })) as ApiQueryResponse;
31
31
  ```
32
32
 
33
- Wrap with `ApiResponseWith<T>` to get the full error response type — see the [envelope and error handling guide](https://bearbin1215.github.io/types-mediawiki-response/guide/errors.html).
33
+ Wrap with `ApiResponseWith<T>` to get the full error response type — see the [envelope and error handling guide](https://types-mediawiki-response.pages.dev/guide/errors).
34
34
 
35
- When using `ApiQueryResponse`, `query.pages[]` in the response is the union of every covered `prop=` field; project it with `QueryPage<K>` to scope a page to the props you requested — see the [query responses guide](https://bearbin1215.github.io/types-mediawiki-response/guide/query.html).
35
+ When using `ApiQueryResponse`, `query.pages[]` in the response is the union of every covered `prop=` field; project it with `QueryPage<K>` to scope a page to the props you requested — see the [query responses guide](https://types-mediawiki-response.pages.dev/guide/query).
36
36
 
37
37
  ## Extensions
38
38
 
@@ -54,4 +54,4 @@ import type { ApiThankResponse } from "types-mediawiki-response/ext/thanks";
54
54
  const res = (await api.post({ action: "thank", rev })) as ApiThankResponse;
55
55
  ```
56
56
 
57
- Bundled packs are listed in the [extension packs guide](https://bearbin1215.github.io/types-mediawiki-response/guide/ext-packs.html). Extensions this package does not cover can be augmented the same way with a hand-written `declare module 'types-mediawiki-response' { … }`.
57
+ Bundled packs are listed in the [extension packs guide](https://types-mediawiki-response.pages.dev/guide/ext-packs). Extensions this package does not cover can be augmented the same way with a hand-written `declare module 'types-mediawiki-response' { … }`.
package/README.zh.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # types-mediawiki-response
2
2
 
3
- [English](https://github.com/BearBin1215/types-mediawiki-response/blob/main/README.md) | 简体中文 | [在线文档](https://bearbin1215.github.io/types-mediawiki-response/zh/)
3
+ [English](https://github.com/BearBin1215/types-mediawiki-response/blob/main/README.md) | 简体中文 | [在线文档](https://types-mediawiki-response.pages.dev/zh/)
4
4
 
5
5
  为 MediaWiki Action API 响应提供可复用类型。
6
6
 
@@ -30,9 +30,9 @@ const res = (await api.get({
30
30
  })) as ApiQueryResponse;
31
31
  ```
32
32
 
33
- 可用 `ApiResponseWith<T>` 包装以获得含错误结果的响应类型,见文档[信封与错误处理指南](https://bearbin1215.github.io/types-mediawiki-response/zh/guide/errors.html)。
33
+ 可用 `ApiResponseWith<T>` 包装以获得含错误结果的响应类型,见文档[信封与错误处理指南](https://types-mediawiki-response.pages.dev/zh/guide/errors)。
34
34
 
35
- 使用 `ApiQueryResponse` 的情况下,响应里的 `query.pages[]` 类型是所有已覆盖 `prop=` 字段的并集,可用 `QueryPage<K>` 收窄到本次请求的 prop,见文档[query 响应指南](https://bearbin1215.github.io/types-mediawiki-response/zh/guide/query.html)。
35
+ 使用 `ApiQueryResponse` 的情况下,响应里的 `query.pages[]` 类型是所有已覆盖 `prop=` 字段的并集,可用 `QueryPage<K>` 收窄到本次请求的 prop,见文档[query 响应指南](https://types-mediawiki-response.pages.dev/zh/guide/query)。
36
36
 
37
37
  ## 扩展
38
38
 
@@ -54,4 +54,4 @@ import type { ApiThankResponse } from "types-mediawiki-response/ext/thanks";
54
54
  const res = (await api.post({ action: "thank", rev })) as ApiThankResponse;
55
55
  ```
56
56
 
57
- 内置包清单见文档站的[扩展包指南](https://bearbin1215.github.io/types-mediawiki-response/zh/guide/ext-packs.html)。本包未覆盖的扩展,手写 `declare module 'types-mediawiki-response' { … }` 走同一接缝增广。
57
+ 内置包清单见文档站的[扩展包指南](https://types-mediawiki-response.pages.dev/zh/guide/ext-packs)。本包未覆盖的扩展,手写 `declare module 'types-mediawiki-response' { … }` 走同一接缝增广。
@@ -448,6 +448,7 @@ export interface ApiQueryResponse extends ApiEnvelope {
448
448
  "query-noncontinue"?: Record<string, Record<string, string | number>>;
449
449
  }
450
450
  export * from "./shared";
451
+ export * from "./logparams";
451
452
  export * from "./info";
452
453
  export * from "./categories";
453
454
  export * from "./revisions";
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { Flag, NamespaceIndex, Timestamp } from "../../common";
11
11
  import type { ApiHiddenFlags } from "./shared";
12
+ import type { ApiLogEventParams } from "./logparams";
12
13
  /** One log event. `leprop` controls which fields appear. */
13
14
  export interface ApiLogEvent extends ApiHiddenFlags {
14
15
  /** Log record id. `leprop=ids`. */
@@ -31,8 +32,11 @@ export interface ApiLogEvent extends ApiHiddenFlags {
31
32
  type?: string;
32
33
  /** Log action, e.g. `create`, `delete`. `leprop=type`. */
33
34
  action?: string;
34
- /** Structured log details; shape varies by `type`/`action`. `leprop=details`. */
35
- params?: Record<string, unknown>;
35
+ /**
36
+ * Structured log details; shape varies by `type`/`action` — see
37
+ * {@link ApiLogEventParams}. `leprop=details`.
38
+ */
39
+ params?: ApiLogEventParams;
36
40
  /** Performing user name (or IP). `leprop=user`. */
37
41
  user?: string;
38
42
  /** Performing user id. `leprop=userid`. */
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Structured details of log events, shared by `logevents.params`,
3
+ * `recentchanges.logparams` and `watchlist.logparams`.
4
+ */
5
+ import type { ContentModel, Expiry, Timestamp } from "../../common";
6
+ /**
7
+ * Structured log details — the `params` object of a log event (`leprop=details`
8
+ * on `list=logevents`, `logparams` under the log-info fields of
9
+ * `list=recentchanges` / `list=watchlist`).
10
+ *
11
+ * Each log action writes its own key set, which the server normalizes for the
12
+ * API. The keys below are the ones MediaWiki core itself writes; which of
13
+ * them a row carries depends on its `type`/`action`.
14
+ *
15
+ * The key space is open: extensions and site configuration can register
16
+ * further log actions, and rows written by older MediaWiki versions keep
17
+ * their historical key forms. Unknown keys therefore fall back to `unknown`
18
+ * instead of erroring. Consumers targeting one specific log action — or a
19
+ * site-custom one — can add its keys through interface merging:
20
+ *
21
+ * @example
22
+ * declare module "types-mediawiki-response" {
23
+ * interface ApiLogEventParams {
24
+ * // a site-custom log action, or a legacy key form still in the data
25
+ * "4::target"?: string;
26
+ * }
27
+ * }
28
+ */
29
+ export interface ApiLogEventParams {
30
+ /**
31
+ * Block duration as configured: `'infinity'` or the raw specifier
32
+ * (`'2 weeks'`, …), on `block/block`, `block/reblock`, `suppress/block` and
33
+ * `suppress/reblock` rows. Older rows without one are normalized to
34
+ * `'infinity'`.
35
+ */
36
+ duration?: string;
37
+ /**
38
+ * Options in force on the block. Rows written by very old MediaWiki
39
+ * versions may carry the legacy values `autoblock` or `angry-autoblock`
40
+ * instead of the current flag set. An array (`[]` when none).
41
+ */
42
+ flags?: Array<"anononly" | "nocreate" | "noautoblock" | "noemail" | "nousertalk" | "hiddenname" | "autoblock" | "angry-autoblock">;
43
+ /**
44
+ * Absolute expiry of the block (ISO 8601), on rows with a finite duration.
45
+ */
46
+ expiry?: Timestamp;
47
+ /** Whether the block covers the whole site (`false` for a partial block). */
48
+ sitewide?: boolean;
49
+ /** Scope of a partial block; absent for sitewide blocks. */
50
+ restrictions?: ApiLogBlockRestrictions;
51
+ /**
52
+ * Id of the block the row created or changed.
53
+ *
54
+ * @since MediaWiki 1.44
55
+ */
56
+ blockId?: number;
57
+ /**
58
+ * Localized duration text (e.g. `'14 days'`, `'infinite'`), in the
59
+ * requesting user's language.
60
+ *
61
+ * @since MediaWiki 1.44
62
+ */
63
+ "duration-l10n"?: string;
64
+ /** Namespace of the move destination (on `move/move` and `move/move_redir` rows). */
65
+ target_ns?: number;
66
+ /** Title of the move destination. */
67
+ target_title?: string;
68
+ /** Whether the move left no redirect behind. */
69
+ suppressredirect?: boolean;
70
+ /**
71
+ * Content-language protection summary (e.g. `'[edit=autoconfirmed]
72
+ * (indefinite)'`), aimed at machine feeds; the structured data lives in
73
+ * {@link details}.
74
+ */
75
+ description?: string;
76
+ /** Whether cascading protection was requested. */
77
+ cascade?: boolean;
78
+ /** Protection restrictions in force. */
79
+ details?: ApiLogProtectDetail[];
80
+ /** Namespace of the title the protection moved away from. */
81
+ oldtitle_ns?: number;
82
+ /** Title the protection moved away from. */
83
+ oldtitle_title?: string;
84
+ /**
85
+ * How many revisions and archived file versions the undeletion restored
86
+ * (`delete/restore`), how many revisions an import created
87
+ * (`import/upload`, `import/interwiki`), or how many uses a managed tag
88
+ * had (`managetags/activate|deactivate|delete`).
89
+ */
90
+ count?: {
91
+ revisions: number;
92
+ files: number;
93
+ } | number;
94
+ /**
95
+ * What the visibility change targeted: `'revision'`, `'archive'`,
96
+ * `'oldimage'` or `'filearchive'` on `…/revision` rows; `'logging'` on
97
+ * `…/event` rows.
98
+ */
99
+ type?: "revision" | "archive" | "oldimage" | "filearchive" | "logging";
100
+ /**
101
+ * Ids of the targeted revisions, file versions or log entries — numbers on
102
+ * current rows, strings on legacy ones.
103
+ */
104
+ ids?: Array<number | string>;
105
+ /** Visibility state before the change. */
106
+ old?: ApiLogRevDelVisibility;
107
+ /** Visibility state after the change. */
108
+ new?: ApiLogRevDelVisibility;
109
+ /**
110
+ * Id of the account the row reports (on `newusers/create`, `newusers/create2`
111
+ * and `newusers/autocreate` rows).
112
+ */
113
+ userid?: number;
114
+ /**
115
+ * Groups the target user belonged to before the change (on `rights/rights`
116
+ * and `rights/autopromote` rows).
117
+ */
118
+ oldgroups?: string[];
119
+ /** Groups after the change. */
120
+ newgroups?: string[];
121
+ /**
122
+ * Per-group membership expiry, parallel to {@link oldgroups}; `[]` when the
123
+ * memberships were all permanent. Absent on `rights/autopromote` rows.
124
+ */
125
+ oldmetadata?: ApiLogGroupMetadata[];
126
+ /**
127
+ * Per-group membership expiry, parallel to {@link newgroups}; `[]` when
128
+ * permanent. Absent on `rights/autopromote` rows.
129
+ */
130
+ newmetadata?: ApiLogGroupMetadata[];
131
+ /**
132
+ * Content model before the change (on `contentmodel/change` and
133
+ * `contentmodel/new` rows).
134
+ */
135
+ oldmodel?: ContentModel;
136
+ /** Content model after the change. */
137
+ newmodel?: ContentModel;
138
+ /** Namespace of the page the history was merged into. */
139
+ dest_ns?: number;
140
+ /** Title of the page the history was merged into. */
141
+ dest_title?: string;
142
+ /**
143
+ * Namespace of the page whose history was merged in (`merge/merge-into` row
144
+ * filed on the destination page).
145
+ *
146
+ * @since MediaWiki 1.45
147
+ */
148
+ src_ns?: number;
149
+ /**
150
+ * Title of the page whose history was merged in (`merge/merge-into`).
151
+ *
152
+ * @since MediaWiki 1.45
153
+ */
154
+ src_title?: string;
155
+ /**
156
+ * Revision the histories were interleaved at (ISO 8601), on `merge/merge`
157
+ * and `merge/merge-into` rows.
158
+ */
159
+ mergepoint?: Timestamp;
160
+ /**
161
+ * Boundary revision id the merge stopped at; stored raw, so it appears as
162
+ * a number or its decimal string.
163
+ *
164
+ * @since MediaWiki 1.42
165
+ */
166
+ mergerevid?: number | string;
167
+ /**
168
+ * Timestamp of the first revision kept out of the merge, when a start
169
+ * boundary was used (ISO 8601); the id of that revision is
170
+ * {@link mergestartid}. Only `merge/merge` rows carry it — `merge/merge-into`
171
+ * rows do not report the start boundary at all.
172
+ *
173
+ * @since MediaWiki 1.45
174
+ */
175
+ mergestart?: Timestamp;
176
+ /**
177
+ * First revision id kept out of the merge; stored raw like
178
+ * {@link mergerevid}.
179
+ *
180
+ * @since MediaWiki 1.45
181
+ */
182
+ mergestartid?: number | string;
183
+ /** Namespace of the source page on the foreign wiki (`import/interwiki`). */
184
+ interwiki_ns?: number;
185
+ /** Source page on the foreign wiki, with its interwiki prefix (`import/interwiki`). */
186
+ interwiki_title?: string;
187
+ /**
188
+ * SHA-1 of the uploaded file (base36), on `upload/upload`, `upload/overwrite`
189
+ * and `upload/revert` rows.
190
+ */
191
+ img_sha1?: string;
192
+ /** File timestamp (ISO 8601), which can differ from the row's timestamp. */
193
+ img_timestamp?: Timestamp;
194
+ /** Revision id that was marked patrolled, on `patrol/patrol` rows. */
195
+ curid?: number;
196
+ /** Revision id the patrolled one followed. */
197
+ previd?: number;
198
+ /** Always `false`: automatic patrols are not logged. */
199
+ auto?: boolean;
200
+ /**
201
+ * Revision the tags were applied to (`tag/update` rows); a raw value from
202
+ * the tagging caller, so forms vary (a number, its decimal string, or
203
+ * `false` when the update targeted a log entry).
204
+ */
205
+ revid?: number | string | false;
206
+ /**
207
+ * Log entry the tags were applied to, on rows that targeted one; a raw
208
+ * value like {@link revid} — `false` when the update targeted a revision.
209
+ */
210
+ logid?: number | string | false;
211
+ /** Tags the update added. */
212
+ tagsAdded?: string[];
213
+ /** How many tags {@link tagsAdded} holds. */
214
+ tagsAddedCount?: number;
215
+ /** Tags the update removed. */
216
+ tagsRemoved?: string[];
217
+ /** How many tags {@link tagsRemoved} holds. */
218
+ tagsRemovedCount?: number;
219
+ /** Tags the target carried before the update. */
220
+ initialTags?: string[];
221
+ /** Name of the managed tag (`managetags/create|activate|deactivate|delete`). */
222
+ tag?: string;
223
+ /**
224
+ * Page language before the change, on `pagelang/pagelang` rows; the wiki's
225
+ * default language carries a `[def]` suffix (e.g. `'en[def]'`).
226
+ */
227
+ oldlanguage?: string;
228
+ /** Page language after the change; also `[def]`-suffixed when set to default. */
229
+ newlanguage?: string;
230
+ /**
231
+ * Any other parameter a log action attaches — a log action registered by an
232
+ * extension or site configuration, or a legacy key form on rows written by
233
+ * an older MediaWiki version.
234
+ */
235
+ [key: string]: unknown;
236
+ }
237
+ /** One page a partial block is restricted to (`restrictions.pages` entry). */
238
+ export interface ApiLogPageRef {
239
+ /** Namespace index. */
240
+ page_ns: number;
241
+ /** Full page title. */
242
+ page_title: string;
243
+ }
244
+ /** Scope of a partial block (`restrictions`). */
245
+ export interface ApiLogBlockRestrictions {
246
+ /** Pages the block is restricted to. */
247
+ pages?: ApiLogPageRef[];
248
+ /** Namespace indexes the block is restricted to. */
249
+ namespaces?: number[];
250
+ /** Action names the block is restricted to (e.g. `'edit'`). */
251
+ actions?: string[];
252
+ }
253
+ /** One protection restriction (`details` entry on `protect/protect`, `protect/modify`). */
254
+ export interface ApiLogProtectDetail {
255
+ /** Action being restricted (e.g. `'edit'`); `'create'` for title protection. */
256
+ type: string;
257
+ /** Protection level (e.g. `'autoconfirmed'`, `'sysop'`). */
258
+ level: string;
259
+ /** When the protection lapses (ISO 8601), or `'infinite'`. */
260
+ expiry: Timestamp | "infinite";
261
+ /** Whether this restriction cascades; absent on `'create'` entries. */
262
+ cascade?: boolean;
263
+ }
264
+ /** One visibility state (`old`/`new` on a RevisionDelete row). */
265
+ export interface ApiLogRevDelVisibility {
266
+ /** Raw visibility bitfield. */
267
+ bitmask: number;
268
+ /** Whether the content is hidden. */
269
+ content: boolean;
270
+ /** Whether the edit summary is hidden. */
271
+ comment: boolean;
272
+ /** Whether the performer is hidden. */
273
+ user: boolean;
274
+ /** Whether only suppressors can unhide. */
275
+ restricted: boolean;
276
+ }
277
+ /** One group-membership change with its expiry (`oldmetadata`/`newmetadata` entry). */
278
+ export interface ApiLogGroupMetadata {
279
+ /** Group name. */
280
+ group: string;
281
+ /** When the membership lapses. */
282
+ expiry: Expiry;
283
+ }
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { Flag, NamespaceIndex, Timestamp } from "../../common";
11
11
  import type { ApiHiddenFlags } from "./shared";
12
+ import type { ApiLogEventParams } from "./logparams";
12
13
  /** Change type (`rctype`). Open union for forward compatibility. */
13
14
  export type RecentChangeType = "edit" | "new" | "log" | "categorize" | "external" | (string & {});
14
15
  /** One recent-changes entry. `rcprop` controls which fields appear. */
@@ -83,8 +84,11 @@ export interface ApiRecentChange extends ApiHiddenFlags {
83
84
  logtype?: string;
84
85
  /** Log action, e.g. `create`. `rcprop=loginfo`. */
85
86
  logaction?: string;
86
- /** Structured log parameters. `rcprop=loginfo`. */
87
- logparams?: Record<string, unknown>;
87
+ /**
88
+ * Structured log details — see {@link ApiLogEventParams}. `rcprop=loginfo`
89
+ * (only for `type=log`).
90
+ */
91
+ logparams?: ApiLogEventParams;
88
92
  }
89
93
  declare module "./index" {
90
94
  interface ApiQueryResult {
@@ -13,6 +13,7 @@
13
13
  import type { ApiWatchlistLabel, Flag, NamespaceIndex, Timestamp } from "../../common";
14
14
  import type { ApiHiddenFlags } from "./shared";
15
15
  import type { RecentChangeType } from "./recentchanges";
16
+ import type { ApiLogEventParams } from "./logparams";
16
17
  /** One watchlist entry. `wlprop` controls which fields appear. */
17
18
  export interface ApiWatchlistEntry extends ApiHiddenFlags {
18
19
  /** Change type. */
@@ -33,8 +34,11 @@ export interface ApiWatchlistEntry extends ApiHiddenFlags {
33
34
  logtype?: string;
34
35
  /** Log action. `wlprop=loginfo` (only for `type=log`). */
35
36
  logaction?: string;
36
- /** Structured log parameters. `wlprop=loginfo` (only for `type=log`). */
37
- logparams?: Record<string, unknown>;
37
+ /**
38
+ * Structured log details — see {@link ApiLogEventParams}. `wlprop=loginfo`
39
+ * (only for `type=log`).
40
+ */
41
+ logparams?: ApiLogEventParams;
38
42
  /**
39
43
  * Localized log action text, e.g. `changed protection settings`.
40
44
  * `wlprop=loginfo` (only for `type=log`).
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Opt-in extension pack: **BetaFeatures** (`list=betafeatures`).
3
+ *
4
+ * Not in the default export: importing anything from this file — even just the
5
+ * field-group type you are about to use — activates the augmentation shipped at
6
+ * the bottom, which merges the field groups into the root package automatically
7
+ * (no manual `declare module`):
8
+ *
9
+ * ```ts
10
+ * import type {} from 'types-mediawiki-response/ext/betafeatures';
11
+ * ```
12
+ *
13
+ * The result is a flat map keyed by feature id — one entry per feature
14
+ * registered through `$wgBetaFeatures` or the
15
+ * `GetBetaFeaturePreferences` hook, so the key set is site-configured and open.
16
+ * A wiki with no beta features omits the whole `betafeatures` bucket.
17
+ *
18
+ * @see https://www.mediawiki.org/wiki/Extension:BetaFeatures
19
+ */
20
+ /**
21
+ * One `list=betafeatures` entry: a feature id with its user count.
22
+ */
23
+ export interface ApiBetaFeature {
24
+ /** The feature id, e.g. `mw-vector-2022-default-title`. */
25
+ name: string;
26
+ /**
27
+ * Number of users who enabled the feature; `0` unless `bfcounts` was
28
+ * requested.
29
+ */
30
+ count: number;
31
+ }
32
+ declare module "types-mediawiki-response" {
33
+ interface ApiQueryResult {
34
+ /**
35
+ * Beta features registered on this wiki, keyed by feature id
36
+ * (`list=betafeatures`). Absent when no features are registered.
37
+ */
38
+ betafeatures?: Record<string, ApiBetaFeature>;
39
+ }
40
+ }