feat
This commit is contained in:
1 parent
8e28bca775
commit
1172a6bd3d
100 files changed
+8305
-6025
No files matched your search
@@ -1,21 +0,0 @@
|
||||
// Aliased import of the pb / pb_repeated markers.
|
||||
//
|
||||
// `parsePbTypeRef` compared the literal type-ref identifier text against
|
||||
// the constants `'pb'` / `'pb_repeated'`. With `import { pb as P }` the
|
||||
// identifier text becomes `'P'`, so the field was silently dropped from
|
||||
// the message — interfaces ended up looking empty.
|
||||
//
|
||||
// Fix: resolve the marker name through the imported-name resolver before
|
||||
// comparing.
|
||||
|
||||
import type { pb as P, pb_repeated as PR, uint_32 } from '@snowluma/proton';
|
||||
|
||||
interface Aliased {
|
||||
id: P<1, uint_32>;
|
||||
tags: PR<2, string>;
|
||||
}
|
||||
|
||||
const data = protobuf_encode<Aliased>({ id: 1, tags: ['a', 'b'] });
|
||||
const decoded = protobuf_decode<Aliased>(data);
|
||||
|
||||
export { };
|
||||
@@ -1,7 +0,0 @@
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
import type { UserMsg as AliasMsg } from './types';
|
||||
|
||||
const buf = protobuf_encode<AliasMsg>({ id: 42, name: 'alice' });
|
||||
const decoded = protobuf_decode<AliasMsg>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { UserMsg } from './types';
|
||||
|
||||
const buf = protobuf_encode<UserMsg>({ id: 42, name: 'alice' });
|
||||
const decoded = protobuf_decode<UserMsg>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,5 +0,0 @@
|
||||
interface Deep {
|
||||
val: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export type { Deep };
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
|
||||
const buf = protobuf_encode<Wrapper<string>>({ value: 'hello' });
|
||||
const decoded = protobuf_decode<Wrapper<string>>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,5 +0,0 @@
|
||||
interface Wrapper<T> {
|
||||
value: pb<1, T>;
|
||||
}
|
||||
|
||||
export type { Wrapper };
|
||||
@@ -1,5 +0,0 @@
|
||||
interface Inner {
|
||||
value: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export type { Inner };
|
||||
@@ -1,11 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
|
||||
function localEncode<T>(value: T): Uint8Array {
|
||||
return protobuf_encode<T>(value);
|
||||
}
|
||||
|
||||
const buf = localEncode<Wrapper<string>>({ value: 'local' });
|
||||
const decoded = protobuf_decode<Wrapper<string>>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Deep } from './deep';
|
||||
|
||||
interface Mid {
|
||||
inner: pb<1, Deep>;
|
||||
}
|
||||
|
||||
export type { Mid };
|
||||
@@ -1,10 +0,0 @@
|
||||
import type { Inner } from './inner';
|
||||
|
||||
interface Outer {
|
||||
inner: pb<1, Inner>;
|
||||
}
|
||||
|
||||
const buf = protobuf_encode<Outer>({ inner: { value: 42 } });
|
||||
const decoded = protobuf_decode<Outer>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,5 +0,0 @@
|
||||
interface SimpleMessage {
|
||||
id: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
export { SimpleMessage };
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
import type { Mid } from './mid';
|
||||
|
||||
interface Top {
|
||||
nested: pb<1, Mid>;
|
||||
}
|
||||
|
||||
const buf = protobuf_encode<Top>({ nested: { inner: { val: 99 } } });
|
||||
const decoded = protobuf_decode<Top>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,6 +0,0 @@
|
||||
interface UserMsg {
|
||||
id: pb<1, uint_32>;
|
||||
name: pb<2, string>;
|
||||
}
|
||||
|
||||
export type { UserMsg };
|
||||
@@ -1,7 +0,0 @@
|
||||
import { SimpleMessage } from './protobuf';
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
|
||||
const bytes = protobuf_encode<SimpleMessage>({ id: 42 });
|
||||
const decoded = protobuf_decode<SimpleMessage>(bytes);
|
||||
|
||||
export { };
|
||||
@@ -1,49 +0,0 @@
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
|
||||
export function encodeViaWrapper<T>(value: T): Uint8Array {
|
||||
return protobuf_encode<T>(value);
|
||||
}
|
||||
|
||||
export function decodeViaWrapper<T>(data: Uint8Array): T {
|
||||
return protobuf_decode<T>(data);
|
||||
}
|
||||
|
||||
export const encodeArrowWrapper = <T>(value: T): Uint8Array => protobuf_encode<T>(value);
|
||||
|
||||
export const decodeArrowWrapper = <T>(data: Uint8Array): T => protobuf_decode<T>(data);
|
||||
|
||||
export function encodeSecondGeneric<Ignored, T>(_ignored: Ignored, value: T): Uint8Array {
|
||||
return protobuf_encode<T>(value);
|
||||
}
|
||||
|
||||
export function passthroughOnly<T>(value: T): T {
|
||||
return value;
|
||||
}
|
||||
|
||||
export const wrapperObject = {
|
||||
encode<T>(value: T): Uint8Array {
|
||||
return protobuf_encode<T>(value);
|
||||
},
|
||||
decode<T>(data: Uint8Array): T {
|
||||
return protobuf_decode<T>(data);
|
||||
},
|
||||
encodeArrow: <T>(value: T): Uint8Array => protobuf_encode<T>(value),
|
||||
};
|
||||
|
||||
export function encodeWithBranch<T>(value: T, enabled: boolean): Uint8Array {
|
||||
if (enabled) {
|
||||
return protobuf_encode<T>(value);
|
||||
}
|
||||
return protobuf_encode<T>(value);
|
||||
}
|
||||
|
||||
export function encodeWithNestedHelper<T>(value: T): Uint8Array {
|
||||
function inner(payload: T): Uint8Array {
|
||||
return protobuf_encode<T>(payload);
|
||||
}
|
||||
return inner(value);
|
||||
}
|
||||
|
||||
export function encodeChained<T>(value: T): Uint8Array {
|
||||
return encodeViaWrapper<T>(value);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import {
|
||||
wrapperObject,
|
||||
encodeWithBranch,
|
||||
encodeWithNestedHelper,
|
||||
encodeChained,
|
||||
} from './wrapper-api';
|
||||
|
||||
const objectBuf = wrapperObject.encode<Wrapper<string>>({ value: 'object' });
|
||||
const objectDecoded = wrapperObject.decode<Wrapper<string>>(objectBuf);
|
||||
|
||||
const arrowMemberBuf = wrapperObject.encodeArrow<Wrapper<Wrapper<string>>>({ value: { value: 'member' } });
|
||||
|
||||
const { encodeArrow } = wrapperObject;
|
||||
const destructuredBuf = encodeArrow<Wrapper<string>>({ value: 'destructured' });
|
||||
|
||||
const branchBuf = encodeWithBranch<Wrapper<string>>({ value: 'branch' }, true);
|
||||
const nestedHelperBuf = encodeWithNestedHelper<Wrapper<string>>({ value: 'nested-helper' });
|
||||
const chainedBuf = encodeChained<Wrapper<string>>({ value: 'chained' });
|
||||
|
||||
export { };
|
||||
@@ -1,7 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import { encodeViaWrapper, decodeViaWrapper } from './wrapper-api';
|
||||
|
||||
const buf = encodeViaWrapper<Wrapper<string>>({ value: 'hello' });
|
||||
const decoded = decodeViaWrapper<Wrapper<string>>(buf);
|
||||
|
||||
export { };
|
||||
@@ -1,21 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import {
|
||||
encodeViaWrapper as encAlias,
|
||||
decodeViaWrapper as decAlias,
|
||||
encodeArrowWrapper,
|
||||
decodeArrowWrapper,
|
||||
encodeSecondGeneric,
|
||||
passthroughOnly,
|
||||
} from './wrapper-api';
|
||||
|
||||
const aliasBuf = encAlias<Wrapper<string>>({ value: 'alias' });
|
||||
const aliasDecoded = decAlias<Wrapper<string>>(aliasBuf);
|
||||
|
||||
const arrowBuf = encodeArrowWrapper<Wrapper<Wrapper<string>>>({ value: { value: 'nested' } });
|
||||
const arrowDecoded = decodeArrowWrapper<Wrapper<Wrapper<string>>>(arrowBuf);
|
||||
|
||||
const secondBuf = encodeSecondGeneric<number, Wrapper<string>>(1, { value: 'second' });
|
||||
|
||||
const passthrough = passthroughOnly<Wrapper<string>>({ value: 'ignored' });
|
||||
|
||||
export { };
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
|
||||
export function encodeBoxed<T>(value: Wrapper<T>): Uint8Array {
|
||||
return protobuf_encode<Wrapper<T>>(value);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import {
|
||||
encodeBoxed,
|
||||
decodeBoxed,
|
||||
encodeAliasBoxed,
|
||||
encodeNestedBoxed,
|
||||
encodeBoxedChain,
|
||||
} from './wrapper-type-source';
|
||||
|
||||
const boxedBuf = encodeBoxed<string>({ value: 'boxed' });
|
||||
const boxedDecoded = decodeBoxed<string>(boxedBuf);
|
||||
const aliasBuf = encodeAliasBoxed<string>({ value: 'alias' });
|
||||
const nestedBuf = encodeNestedBoxed<string>({ value: { value: 'nested' } });
|
||||
const chainedBuf = encodeBoxedChain<string>({ value: 'chain' });
|
||||
|
||||
export { };
|
||||
@@ -1,25 +0,0 @@
|
||||
import type { Wrapper } from './generic-types';
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
import { encodeBoxed as encodeBoxedBase } from './wrapper-type-source-base';
|
||||
|
||||
export type AliasWrapper<T> = Wrapper<T>;
|
||||
|
||||
export function encodeBoxed<T>(value: Wrapper<T>): Uint8Array {
|
||||
return protobuf_encode<Wrapper<T>>(value);
|
||||
}
|
||||
|
||||
export function decodeBoxed<T>(data: Uint8Array): Wrapper<T> {
|
||||
return protobuf_decode<Wrapper<T>>(data);
|
||||
}
|
||||
|
||||
export function encodeAliasBoxed<T>(value: AliasWrapper<T>): Uint8Array {
|
||||
return protobuf_encode<Wrapper<T>>(value);
|
||||
}
|
||||
|
||||
export function encodeNestedBoxed<T>(value: Wrapper<Wrapper<T>>): Uint8Array {
|
||||
return protobuf_encode<Wrapper<Wrapper<T>>>(value);
|
||||
}
|
||||
|
||||
export function encodeBoxedChain<T>(value: Wrapper<T>): Uint8Array {
|
||||
return encodeBoxedBase<T>(value);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
interface TestProtobufAny<T> {
|
||||
name?: pb<1, T>;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
interface TestProtobufAny<T> {
|
||||
name?: pb<1, T>;
|
||||
}
|
||||
|
||||
const dataT = protobuf_encode<TestProtobufAny<TestProtobufAny<string>>>({ name: { name: "test" } });
|
||||
const decodedT = protobuf_decode<TestProtobufAny<TestProtobufAny<string>>>(dataT);
|
||||
|
||||
export { };
|
||||
@@ -1,24 +0,0 @@
|
||||
// Generic template with a generic-instantiated message field.
|
||||
//
|
||||
// The outer template's type param (`U`) shows up *inside* an inner generic
|
||||
// instantiation (`Wrapper<U>`). When the outer is monomorphized at the call
|
||||
// site (`Outer<uint_32>`), the inner instantiation must be re-instantiated
|
||||
// with the substitution (becoming `Wrapper<uint_32>`) and put into the
|
||||
// registry under its mangled name `Wrapper__uint_32`.
|
||||
//
|
||||
// Without the fix, the field's `rawTypeName` was `'Wrapper__U'` and the
|
||||
// substituted-mono never produced `Wrapper__uint_32`, leaving the field's
|
||||
// wire-type unresolved.
|
||||
|
||||
interface Wrapper<T> {
|
||||
value: pb<1, T>;
|
||||
}
|
||||
|
||||
interface Outer<U> {
|
||||
wrapped: pb<5, Wrapper<U>>;
|
||||
}
|
||||
|
||||
const data = protobuf_encode<Outer<uint_32>>({ wrapped: { value: 42 } });
|
||||
const decoded = protobuf_decode<Outer<uint_32>>(data);
|
||||
|
||||
export { };
|
||||
@@ -1,5 +0,0 @@
|
||||
interface UserProfile {
|
||||
id: pb<1, uint_32>;
|
||||
username: pb<2, string>;
|
||||
active: pb<3, bool>;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Concrete interface with a generic-instantiated message field.
|
||||
//
|
||||
// The call site only references the concrete outer type (`Container`), so
|
||||
// the analyzer must independently:
|
||||
// 1) resolve the field's typeName to the *mangled* form (`Wrapper__uint_32`)
|
||||
// so it matches what monomorphization produces,
|
||||
// 2) enqueue `Wrapper<uint_32>` for monomorphization itself, since the
|
||||
// call-site-driven queue only sees `Container`.
|
||||
//
|
||||
// Without both, wire-type resolution silently leaves the field at the
|
||||
// `WireType.Varint` placeholder and codegen emits a wrong wire format.
|
||||
|
||||
interface Wrapper<T> {
|
||||
value: pb<1, T>;
|
||||
}
|
||||
|
||||
interface Container {
|
||||
wrapped: pb<5, Wrapper<uint_32>>;
|
||||
}
|
||||
|
||||
const data = protobuf_encode<Container>({ wrapped: { value: 42 } });
|
||||
const decoded = protobuf_decode<Container>(data);
|
||||
|
||||
export { };
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
interface Foo {
|
||||
bar: string;
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
interface TestProtobuf {
|
||||
name: pb<1, uint_32>;
|
||||
}
|
||||
|
||||
interface TestProtobufOutput {
|
||||
name: pb<1, TestProtobuf>;
|
||||
}
|
||||
|
||||
const data = protobuf_encode<TestProtobuf>({ name: 123 });
|
||||
const decoded = protobuf_decode<TestProtobufOutput>(data);
|
||||
|
||||
export { };
|
||||
Reference in new issue
Block a user