@zhin.js/schema 1.1.3 → 1.1.4

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.
@@ -1,4 +1,10 @@
1
1
  import type { Schema } from './schema.js';
2
+ /** Optional display metadata; translated labels never change stored values. */
3
+ export type ConfigFieldI18n = Readonly<Partial<Record<'zh-CN' | 'en', Readonly<{
4
+ title?: string;
5
+ description?: string;
6
+ enumLabels?: Readonly<Record<string, string>>;
7
+ }>>>>;
2
8
  /** Form annotations on the same JSON Schema used for configuration validation. */
3
9
  export interface ConfigFieldMetadata {
4
10
  readonly secret?: boolean;
@@ -69,6 +69,8 @@ export function toJsonSchema(schema) {
69
69
  }
70
70
  if (meta.description !== undefined)
71
71
  result.description = meta.description;
72
+ if (meta.i18n !== undefined)
73
+ result['x-i18n'] = structuredClone(meta.i18n);
72
74
  if (meta.default !== undefined) {
73
75
  assertJsonValue(meta.default);
74
76
  assertPublicDefault(schema, meta.default);
package/lib/schema.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { safeParseSchema, type SchemaSafeParseResult } from './validate.js';
2
- import { type ConfigFieldMetadata } from './json-schema.js';
2
+ import { type ConfigFieldMetadata, type ConfigFieldI18n } from './json-schema.js';
3
3
  export { SchemaValidationError, type SchemaSafeParseResult, type SchemaValidationIssue } from './validate.js';
4
4
  export { safeParseSchema };
5
5
  declare const configPresent: unique symbol;
@@ -23,6 +23,8 @@ export declare class Schema<S = any, T = S> {
23
23
  hidden(): this;
24
24
  /** 设置描述 */
25
25
  description(description: string): this;
26
+ /** Translate form labels without changing validation, defaults or values. */
27
+ i18n(translations: ConfigFieldI18n): this;
26
28
  /** 设置默认值 */
27
29
  default(defaultValue: T): this & Schema.Present;
28
30
  /** Secret values remain environment references in application configuration. */
@@ -114,6 +116,7 @@ export declare namespace Schema {
114
116
  multiple?: boolean;
115
117
  key?: string;
116
118
  description?: string;
119
+ i18n?: ConfigFieldI18n;
117
120
  component?: string;
118
121
  min?: number;
119
122
  max?: number;
package/lib/schema.js CHANGED
@@ -75,6 +75,11 @@ export class Schema {
75
75
  this.meta.description = description;
76
76
  return this;
77
77
  }
78
+ /** Translate form labels without changing validation, defaults or values. */
79
+ i18n(translations) {
80
+ this.meta.i18n = structuredClone(translations);
81
+ return this;
82
+ }
78
83
  /** 设置默认值 */
79
84
  default(defaultValue) {
80
85
  this.meta.default = defaultValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/schema",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Configuration validation and schema system for Zhin.js",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",