SnowLuma v2.4.2 source snapshot
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
This commit is contained in:
commit
fa9c73363d
1367 files changed
+355735
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import ts from 'typescript';
|
||||
import { SourceContext } from '../../src/source/context';
|
||||
import { SchemaResolver } from '../../src/schema/resolver';
|
||||
import { generateCode } from '../../src/codegen/generator';
|
||||
|
||||
export function schemaCodecs<T>(code: string, name = 'Msg') {
|
||||
const generated = generateCode(schemaRegistry(code));
|
||||
return new Function(
|
||||
`${generated}\nreturn { encode: protobuf_encode_${name}, decode: protobuf_decode_${name} };`,
|
||||
)() as {
|
||||
encode(value: T): Uint8Array;
|
||||
decode(bytes: Uint8Array): T;
|
||||
};
|
||||
}
|
||||
|
||||
export function schemaRegistry(code: string, file = 'schema.ts') {
|
||||
const context = new SourceContext();
|
||||
const source = context.source(file, code);
|
||||
const resolver = new SchemaResolver(context);
|
||||
const roots: string[] = [];
|
||||
|
||||
for (const statement of source.statements) {
|
||||
if (ts.isInterfaceDeclaration(statement) && !statement.typeParameters?.length) {
|
||||
roots.push(statement.name.text);
|
||||
}
|
||||
}
|
||||
|
||||
const expanded = context.source(
|
||||
file,
|
||||
code + roots.map((name, i) => `\ntype __TestRoot${i} = ${name};`).join(''),
|
||||
);
|
||||
|
||||
for (const statement of expanded.statements) {
|
||||
if (ts.isTypeAliasDeclaration(statement) && statement.name.text.startsWith('__TestRoot')) {
|
||||
resolver.message(resolver.type(statement.type), statement);
|
||||
}
|
||||
}
|
||||
|
||||
return resolver.registry;
|
||||
}
|
||||
Reference in new issue
Block a user