@jeffusion/bungee-types 5.4.4 → 5.4.6

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
@@ -2,3 +2,4 @@ export * from './types.js';
2
2
  export * from './config-v2.js';
3
3
  export * from './rate-limit.js';
4
4
  export * from './daemon-control.js';
5
+ export * from './publication-policy.js';
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from './types.js';
2
2
  export * from './config-v2.js';
3
3
  export * from './rate-limit.js';
4
4
  export * from './daemon-control.js';
5
+ export * from './publication-policy.js';
@@ -0,0 +1,13 @@
1
+ export interface PublicationPolicy {
2
+ readonly drain_start_timeout_ms: number;
3
+ readonly drain_timeout_ms: number;
4
+ readonly worker_exit_timeout_ms: number;
5
+ }
6
+ export declare const DEFAULT_PUBLICATION_POLICY: Readonly<PublicationPolicy>;
7
+ export declare const MAX_PUBLICATION_TIMEOUT_MS = 2147483000;
8
+ export type PublicationPolicyValidationError = {
9
+ readonly field: keyof PublicationPolicy | 'publication';
10
+ readonly message: string;
11
+ };
12
+ export declare function validatePublicationPolicy(value: unknown): readonly PublicationPolicyValidationError[];
13
+ export declare function resolvePublicationPolicy(value?: PublicationPolicy): Readonly<PublicationPolicy>;
@@ -0,0 +1,51 @@
1
+ export const DEFAULT_PUBLICATION_POLICY = Object.freeze({
2
+ drain_start_timeout_ms: 5000,
3
+ drain_timeout_ms: 300000,
4
+ worker_exit_timeout_ms: 10000,
5
+ });
6
+ export const MAX_PUBLICATION_TIMEOUT_MS = 2147483000;
7
+ const PUBLICATION_FIELDS = [
8
+ 'drain_start_timeout_ms',
9
+ 'drain_timeout_ms',
10
+ 'worker_exit_timeout_ms',
11
+ ];
12
+ export function validatePublicationPolicy(value) {
13
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
14
+ return [{ field: 'publication', message: 'Expected an object' }];
15
+ }
16
+ const object = value;
17
+ const errors = [];
18
+ for (const key of Object.keys(object)) {
19
+ if (!PUBLICATION_FIELDS.includes(key)) {
20
+ errors.push({ field: 'publication', message: `Unknown field: ${key}` });
21
+ }
22
+ }
23
+ for (const field of PUBLICATION_FIELDS) {
24
+ if (!Object.prototype.hasOwnProperty.call(object, field)) {
25
+ errors.push({ field, message: 'Required field is missing' });
26
+ continue;
27
+ }
28
+ const timeout = object[field];
29
+ if (typeof timeout !== 'number' || !Number.isSafeInteger(timeout)) {
30
+ errors.push({ field, message: 'Expected a safe integer number of milliseconds' });
31
+ }
32
+ else if (timeout <= 0) {
33
+ errors.push({ field, message: 'Must be greater than zero' });
34
+ }
35
+ else if (timeout % 1000 !== 0) {
36
+ errors.push({ field, message: 'Must be a whole number of seconds' });
37
+ }
38
+ else if (timeout > MAX_PUBLICATION_TIMEOUT_MS) {
39
+ errors.push({ field, message: `Must not exceed ${MAX_PUBLICATION_TIMEOUT_MS} milliseconds` });
40
+ }
41
+ }
42
+ return errors;
43
+ }
44
+ export function resolvePublicationPolicy(value) {
45
+ if (value === undefined)
46
+ return DEFAULT_PUBLICATION_POLICY;
47
+ const errors = validatePublicationPolicy(value);
48
+ if (errors.length !== 0)
49
+ throw new TypeError(`Invalid publication policy: ${errors.map(({ field, message }) => `${field}: ${message}`).join('; ')}`);
50
+ return value;
51
+ }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { PublicationPolicy } from './publication-policy.js';
1
2
  /**
2
3
  * 插件配置值类型
3
4
  * 定义了插件配置中允许的值类型,比 `any` 更具体
@@ -283,6 +284,7 @@ export interface AppConfig {
283
284
  body_parser_limit?: string;
284
285
  auth?: AuthConfig;
285
286
  logging?: LoggingConfig;
287
+ publication?: PublicationPolicy;
286
288
  plugins?: Array<PluginConfig | string>;
287
289
  services?: Service[];
288
290
  routes: RouteConfig[];
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- // --- Type Definitions ---
2
1
  export { decodeDaemonMetadataV1, encodeDaemonMetadataV1, parseDaemonMetadataV1, validateDaemonMetadataV1, } from './daemon-control.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffusion/bungee-types",
3
- "version": "5.4.4",
3
+ "version": "5.4.6",
4
4
  "description": "TypeScript type definitions for Bungee",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",