MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / StructRule

Class StructRule

src/common/rule.ts:232–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231// 结构体规则, 必须和 predefined 类型相同, 且每个字段都必须存在
232class StructRule<T extends { [key: string]: any }> implements Rule {
233 predefined: T;
234 check: CheckFuction;
235 metadata?: FieldMetadataMap;
236 notice?: string;
237 docUrl?: string;
238 constructor(
239 predefined: T,
240 check?: CheckFuction,
241 metadata?: FieldMetadataMap,
242 notice?: string,
243 docUrl?: string
244 ) {
245 this.predefined = predefined;
246 this.metadata = metadata;
247 this.notice = notice;
248 this.docUrl = docUrl;
249 if (check) {
250 this.check = check;
251 } else {
252 this.check = function (value: T) {
253 for (const key of Object.keys(predefined)) {
254 if (
255 value[key] == undefined ||
256 typeof value[key] !== typeof predefined[key]
257 ) {
258 return false;
259 }
260 }
261 return true;
262 };
263 }
264 }
265}
266
267export {
268 Rule,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected