zinfer 0.0.1 → 0.1.2
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 +477 -28
- package/bin/zinfer +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +486 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/brand-detector.d.ts +32 -0
- package/dist/core/brand-detector.d.ts.map +1 -0
- package/dist/core/brand-detector.js +121 -0
- package/dist/core/brand-detector.js.map +1 -0
- package/dist/core/config-loader.d.ts +87 -0
- package/dist/core/config-loader.d.ts.map +1 -0
- package/dist/core/config-loader.js +105 -0
- package/dist/core/config-loader.js.map +1 -0
- package/dist/core/description-extractor.d.ts +54 -0
- package/dist/core/description-extractor.d.ts.map +1 -0
- package/dist/core/description-extractor.js +180 -0
- package/dist/core/description-extractor.js.map +1 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +96 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/extractor.d.ts +121 -0
- package/dist/core/extractor.d.ts.map +1 -0
- package/dist/core/extractor.js +504 -0
- package/dist/core/extractor.js.map +1 -0
- package/dist/core/file-resolver.d.ts +41 -0
- package/dist/core/file-resolver.d.ts.map +1 -0
- package/dist/core/file-resolver.js +95 -0
- package/dist/core/file-resolver.js.map +1 -0
- package/dist/core/getter-resolver.d.ts +67 -0
- package/dist/core/getter-resolver.d.ts.map +1 -0
- package/dist/core/getter-resolver.js +234 -0
- package/dist/core/getter-resolver.js.map +1 -0
- package/dist/core/import-resolver.d.ts +51 -0
- package/dist/core/import-resolver.d.ts.map +1 -0
- package/dist/core/import-resolver.js +158 -0
- package/dist/core/import-resolver.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +20 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +36 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/name-mapper.d.ts +45 -0
- package/dist/core/name-mapper.d.ts.map +1 -0
- package/dist/core/name-mapper.js +82 -0
- package/dist/core/name-mapper.js.map +1 -0
- package/dist/core/normalizer.d.ts +24 -0
- package/dist/core/normalizer.d.ts.map +1 -0
- package/dist/core/normalizer.js +50 -0
- package/dist/core/normalizer.js.map +1 -0
- package/dist/core/schema-detector.d.ts +49 -0
- package/dist/core/schema-detector.d.ts.map +1 -0
- package/dist/core/schema-detector.js +272 -0
- package/dist/core/schema-detector.js.map +1 -0
- package/dist/core/schema-reference-analyzer.d.ts +77 -0
- package/dist/core/schema-reference-analyzer.d.ts.map +1 -0
- package/dist/core/schema-reference-analyzer.js +269 -0
- package/dist/core/schema-reference-analyzer.js.map +1 -0
- package/dist/core/test-generator.d.ts +97 -0
- package/dist/core/test-generator.d.ts.map +1 -0
- package/dist/core/test-generator.js +177 -0
- package/dist/core/test-generator.js.map +1 -0
- package/dist/core/type-printer.d.ts +46 -0
- package/dist/core/type-printer.d.ts.map +1 -0
- package/dist/core/type-printer.js +519 -0
- package/dist/core/type-printer.js.map +1 -0
- package/dist/core/types.d.ts +124 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -7
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates vitest type equality tests for zinfer.
|
|
3
|
+
*
|
|
4
|
+
* This module generates test files that verify zinfer-generated types
|
|
5
|
+
* match z.input<typeof Schema> and z.output<typeof Schema>.
|
|
6
|
+
*/
|
|
7
|
+
import type { MappedTypeName } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Information about a schema for test generation.
|
|
10
|
+
*/
|
|
11
|
+
export interface TestSchemaInfo {
|
|
12
|
+
/** Schema variable name (e.g., "UserSchema") */
|
|
13
|
+
schemaName: string;
|
|
14
|
+
/** Generated input type name (e.g., "UserInput") */
|
|
15
|
+
inputTypeName: string;
|
|
16
|
+
/** Generated output type name (e.g., "UserOutput") */
|
|
17
|
+
outputTypeName: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Information about a file for test generation.
|
|
21
|
+
*/
|
|
22
|
+
export interface TestFileInfo {
|
|
23
|
+
/** Path to the schema source file (for import) */
|
|
24
|
+
schemaFilePath: string;
|
|
25
|
+
/** Path to the generated types file (for import) */
|
|
26
|
+
typesFilePath: string;
|
|
27
|
+
/** Unique prefix for this file's imports (e.g., "Basic" for basic-schema.ts) */
|
|
28
|
+
importPrefix: string;
|
|
29
|
+
/** Schemas in this file */
|
|
30
|
+
schemas: TestSchemaInfo[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options for test generation.
|
|
34
|
+
*/
|
|
35
|
+
export interface TestGeneratorOptions {
|
|
36
|
+
/** Whether to include a file header comment */
|
|
37
|
+
includeHeader?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts a kebab-case or snake_case string to PascalCase.
|
|
41
|
+
*/
|
|
42
|
+
export declare function toPascalCase(str: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Generates a unique prefix from a file path.
|
|
45
|
+
*/
|
|
46
|
+
export declare function generateImportPrefix(filePath: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Creates TestSchemaInfo from schema name and mapped type names.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createTestSchemaInfo(schemaName: string, mappedNames: MappedTypeName): TestSchemaInfo;
|
|
51
|
+
/**
|
|
52
|
+
* Generates vitest type equality test file content.
|
|
53
|
+
*/
|
|
54
|
+
export declare class TestGenerator {
|
|
55
|
+
private options;
|
|
56
|
+
constructor(options?: TestGeneratorOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Generates the complete test file content.
|
|
59
|
+
*
|
|
60
|
+
* @param files - Array of file information for test generation
|
|
61
|
+
* @returns Generated test file content
|
|
62
|
+
*/
|
|
63
|
+
generate(files: TestFileInfo[]): string;
|
|
64
|
+
/**
|
|
65
|
+
* Generates the header comment.
|
|
66
|
+
*/
|
|
67
|
+
private generateHeader;
|
|
68
|
+
/**
|
|
69
|
+
* Generates core import statements.
|
|
70
|
+
*/
|
|
71
|
+
private generateCoreImports;
|
|
72
|
+
/**
|
|
73
|
+
* Generates import statements for a single file.
|
|
74
|
+
*/
|
|
75
|
+
private generateFileImports;
|
|
76
|
+
/**
|
|
77
|
+
* Generates the test suite with all describe blocks.
|
|
78
|
+
*/
|
|
79
|
+
private generateTestSuite;
|
|
80
|
+
/**
|
|
81
|
+
* Generates a describe block for a single file.
|
|
82
|
+
*/
|
|
83
|
+
private generateFileDescribe;
|
|
84
|
+
/**
|
|
85
|
+
* Generates test cases for a single schema.
|
|
86
|
+
*/
|
|
87
|
+
private generateSchemaTests;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Convenience function to generate test file content.
|
|
91
|
+
*
|
|
92
|
+
* @param files - Array of file information for test generation
|
|
93
|
+
* @param options - Generation options
|
|
94
|
+
* @returns Generated test file content
|
|
95
|
+
*/
|
|
96
|
+
export declare function generateTypeTests(files: TestFileInfo[], options?: TestGeneratorOptions): string;
|
|
97
|
+
//# sourceMappingURL=test-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-generator.d.ts","sourceRoot":"","sources":["../../src/core/test-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,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
|
4
|
+
* This module generates test files that verify zinfer-generated types
|
|
5
|
+
* match z.input<typeof Schema> and z.output<typeof Schema>.
|
|
6
|
+
*/
|
|
7
|
+
import { basename, extname } from "pathe";
|
|
8
|
+
/**
|
|
9
|
+
* Converts a kebab-case or snake_case string to PascalCase.
|
|
10
|
+
*/
|
|
11
|
+
export function toPascalCase(str) {
|
|
12
|
+
return str
|
|
13
|
+
.split(/[-_]/)
|
|
14
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
15
|
+
.join("");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Removes file extension from a path.
|
|
19
|
+
* Handles .ts, .js, .tsx, .jsx, .mts, .mjs, .cts, .cjs extensions.
|
|
20
|
+
*/
|
|
21
|
+
function removeExtension(filePath) {
|
|
22
|
+
const ext = extname(filePath);
|
|
23
|
+
const supportedExtensions = [".ts", ".js", ".tsx", ".jsx", ".mts", ".mjs", ".cts", ".cjs"];
|
|
24
|
+
if (supportedExtensions.includes(ext)) {
|
|
25
|
+
return filePath.slice(0, -ext.length);
|
|
26
|
+
}
|
|
27
|
+
return filePath;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generates a unique prefix from a file path.
|
|
31
|
+
*/
|
|
32
|
+
export function generateImportPrefix(filePath) {
|
|
33
|
+
const name = removeExtension(basename(filePath));
|
|
34
|
+
return toPascalCase(name);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates TestSchemaInfo from schema name and mapped type names.
|
|
38
|
+
*/
|
|
39
|
+
export function createTestSchemaInfo(schemaName, mappedNames) {
|
|
40
|
+
return {
|
|
41
|
+
schemaName,
|
|
42
|
+
inputTypeName: mappedNames.inputName,
|
|
43
|
+
outputTypeName: mappedNames.outputName,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generates vitest type equality test file content.
|
|
48
|
+
*/
|
|
49
|
+
export class TestGenerator {
|
|
50
|
+
options;
|
|
51
|
+
constructor(options = {}) {
|
|
52
|
+
this.options = {
|
|
53
|
+
includeHeader: options.includeHeader ?? true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates the complete test file content.
|
|
58
|
+
*
|
|
59
|
+
* @param files - Array of file information for test generation
|
|
60
|
+
* @returns Generated test file content
|
|
61
|
+
*/
|
|
62
|
+
generate(files) {
|
|
63
|
+
if (files.length === 0) {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
const parts = [];
|
|
67
|
+
// Header comment
|
|
68
|
+
if (this.options.includeHeader) {
|
|
69
|
+
parts.push(this.generateHeader());
|
|
70
|
+
parts.push("");
|
|
71
|
+
}
|
|
72
|
+
// Core imports
|
|
73
|
+
parts.push(this.generateCoreImports());
|
|
74
|
+
parts.push("");
|
|
75
|
+
// File-specific imports
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
parts.push(this.generateFileImports(file));
|
|
78
|
+
parts.push("");
|
|
79
|
+
}
|
|
80
|
+
// Test describe blocks
|
|
81
|
+
parts.push(this.generateTestSuite(files));
|
|
82
|
+
return parts.join("\n");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generates the header comment.
|
|
86
|
+
*/
|
|
87
|
+
generateHeader() {
|
|
88
|
+
return `// This file is auto-generated by zinfer --generate-tests
|
|
89
|
+
// Do not edit manually. Regenerate with: zinfer --generate-tests [schema-files] --types-dir [types-dir] --out [output]`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generates core import statements.
|
|
93
|
+
*/
|
|
94
|
+
generateCoreImports() {
|
|
95
|
+
return `import { describe, it, expectTypeOf } from "vitest";
|
|
96
|
+
import type { z } from "zod";`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generates import statements for a single file.
|
|
100
|
+
*/
|
|
101
|
+
generateFileImports(file) {
|
|
102
|
+
const lines = [];
|
|
103
|
+
const fileLabel = removeExtension(basename(file.schemaFilePath));
|
|
104
|
+
lines.push(`// --- ${fileLabel} ---`);
|
|
105
|
+
// Remove extension for imports (TypeScript/bundlers handle resolution)
|
|
106
|
+
const schemaPath = removeExtension(file.schemaFilePath);
|
|
107
|
+
const typesPath = removeExtension(file.typesFilePath);
|
|
108
|
+
// Schema imports (runtime values with aliases)
|
|
109
|
+
const schemaImports = file.schemas
|
|
110
|
+
.map((s) => `${s.schemaName} as ${file.importPrefix}${s.schemaName}`)
|
|
111
|
+
.join(", ");
|
|
112
|
+
lines.push(`import { ${schemaImports} } from "${schemaPath}";`);
|
|
113
|
+
// Type imports (with aliases)
|
|
114
|
+
const typeImports = file.schemas.flatMap((s) => [
|
|
115
|
+
`${s.inputTypeName} as ${file.importPrefix}${s.inputTypeName}`,
|
|
116
|
+
`${s.outputTypeName} as ${file.importPrefix}${s.outputTypeName}`,
|
|
117
|
+
]);
|
|
118
|
+
if (typeImports.length <= 2) {
|
|
119
|
+
lines.push(`import type { ${typeImports.join(", ")} } from "${typesPath}";`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
lines.push(`import type {`);
|
|
123
|
+
lines.push(` ${typeImports.join(",\n ")},`);
|
|
124
|
+
lines.push(`} from "${typesPath}";`);
|
|
125
|
+
}
|
|
126
|
+
return lines.join("\n");
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Generates the test suite with all describe blocks.
|
|
130
|
+
*/
|
|
131
|
+
generateTestSuite(files) {
|
|
132
|
+
const describes = files.map((file) => this.generateFileDescribe(file)).join("\n\n");
|
|
133
|
+
return `describe("Type equality tests", () => {
|
|
134
|
+
${describes}
|
|
135
|
+
});
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Generates a describe block for a single file.
|
|
140
|
+
*/
|
|
141
|
+
generateFileDescribe(file) {
|
|
142
|
+
const fileLabel = removeExtension(basename(file.schemaFilePath));
|
|
143
|
+
const tests = file.schemas
|
|
144
|
+
.map((s) => this.generateSchemaTests(file.importPrefix, s))
|
|
145
|
+
.join("\n\n");
|
|
146
|
+
return ` describe("${fileLabel}", () => {
|
|
147
|
+
${tests}
|
|
148
|
+
});`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generates test cases for a single schema.
|
|
152
|
+
*/
|
|
153
|
+
generateSchemaTests(prefix, schema) {
|
|
154
|
+
const prefixedSchema = `${prefix}${schema.schemaName}`;
|
|
155
|
+
const prefixedInput = `${prefix}${schema.inputTypeName}`;
|
|
156
|
+
const prefixedOutput = `${prefix}${schema.outputTypeName}`;
|
|
157
|
+
return ` it("${schema.schemaName} input matches z.input", () => {
|
|
158
|
+
expectTypeOf<${prefixedInput}>().toEqualTypeOf<z.input<typeof ${prefixedSchema}>>();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("${schema.schemaName} output matches z.output", () => {
|
|
162
|
+
expectTypeOf<${prefixedOutput}>().toEqualTypeOf<z.output<typeof ${prefixedSchema}>>();
|
|
163
|
+
});`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Convenience function to generate test file content.
|
|
168
|
+
*
|
|
169
|
+
* @param files - Array of file information for test generation
|
|
170
|
+
* @param options - Generation options
|
|
171
|
+
* @returns Generated test file content
|
|
172
|
+
*/
|
|
173
|
+
export function generateTypeTests(files, options) {
|
|
174
|
+
const generator = new TestGenerator(options);
|
|
175
|
+
return generator.generate(files);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=test-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-generator.js","sourceRoot":"","sources":["../../src/core/test-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAqC1C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG;SACP,KAAK,CAAC,MAAM,CAAC;SACb,GAAG,CA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* Options for formatting type output.
|
|
4
|
+
*/
|
|
5
|
+
export interface PrintOptions {
|
|
6
|
+
/** Indentation string (default: " ") */
|
|
7
|
+
indent?: string;
|
|
8
|
+
/** Whether to include the schema name in the output */
|
|
9
|
+
includeSchemaName?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Formats the extraction result for console output.
|
|
13
|
+
*
|
|
14
|
+
* @param result - The extraction result containing input and output types
|
|
15
|
+
* @param options - Formatting options
|
|
16
|
+
* @returns Formatted string ready for console output
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatResult(result: ExtractResult, options?: PrintOptions): string;
|
|
19
|
+
/**
|
|
20
|
+
* Formats the extraction result as input type only.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatInputOnly(result: ExtractResult, options?: PrintOptions): string;
|
|
23
|
+
/**
|
|
24
|
+
* Formats the extraction result as output type only.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatOutputOnly(result: ExtractResult, options?: PrintOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* Formats a single extraction result as TypeScript type declaration(s).
|
|
29
|
+
*
|
|
30
|
+
* @param result - The extraction result
|
|
31
|
+
* @param typeName - The mapped type names
|
|
32
|
+
* @param options - Declaration options
|
|
33
|
+
* @returns TypeScript type declaration string
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatAsDeclaration(result: ExtractResult, typeName: MappedTypeName, options?: DeclarationOptions): string;
|
|
36
|
+
export declare function formatMultipleAsDeclarations(results: ExtractResult[], mapName: (schemaName: string) => MappedTypeName, options?: DeclarationOptions): string;
|
|
37
|
+
/**
|
|
38
|
+
* Generates a complete TypeScript declaration file content.
|
|
39
|
+
*
|
|
40
|
+
* @param results - Array of extraction results
|
|
41
|
+
* @param mapName - Function to map schema name to type names
|
|
42
|
+
* @param options - Declaration options
|
|
43
|
+
* @returns Complete .d.ts or .ts file content
|
|
44
|
+
*/
|
|
45
|
+
export declare function generateDeclarationFile(results: ExtractResult[], mapName: (schemaName: string) => MappedTypeName, options?: DeclarationOptions): string;
|
|
46
|
+
//# sourceMappingURL=type-printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-printer.d.ts","sourceRoot":"","sources":["../../src/core/type-printer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAGnB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAgBtF;AA2PD;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAGzF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAG1F;AAyFD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAiDR;AAiBD,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa,EAAE,EACxB,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc,EAC/C,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAqIR;AASD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,aAAa,EAAE,EACxB,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc,EAC/C,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAkBR"}
|