-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts-proto 2.x ideas #647
Comments
allowed import common from a common ? generate a common for type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in Exclude<keyof T, '$type'>]?: DeepPartial<T[K]> }
: Partial<T>;
function toTimestamp(date: Date): Timestamp {
const seconds = numberToLong(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { $type: 'google.protobuf.Timestamp', seconds, nanos };
}
function fromTimestamp(t: Timestamp): Date {
let millis = t.seconds.toNumber() * 1_000;
millis += t.nanos / 1_000_000;
return new Date(millis);
}
function fromJsonTimestamp(o: any): Date {
if (o instanceof Date) {
return o;
} else if (typeof o === 'string') {
return new Date(o);
} else {
return fromTimestamp(Timestamp.fromJSON(o));
}
}
function numberToLong(number: number) {
return Long.fromNumber(number);
}
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
} |
I'm using the common import here: https://github.com/aperturerobotics/protobuf-project/blob/main/example/other/other.pb.ts#L2 |
Allowed toJSON to omit empty ? // sequelize
const model = await ResourceModel.create(User.toJSON(item), {
returning: true,
}); without toJSON to omit default value, the create may fail, e.g. |
Generate with a generated header comment // Code generated by protoc-gen-ts-proto v1.2.3. DO NOT EDIT. this can hint some other program, e.g. ignore count code lines |
But still has the common functions, only a wkt used an external import. |
Are you planing to migrate to BigInt`s?
Do you want your own encoder/decoder? Great lib, thanks for your work! |
Hey @Sermelyan ; yeah, I think For the encoder/decoder, no I think that's probably out-of-scope for ts-proto and I'd poke around at using like the grpc encoders or something like that. Buf ended up writing their own ESM-based encoders, so that would likely be a good candidate. Full disclaimer I'm not actively planning on working on these personally, as I don't need them for anything I'm working on at the moment, but if others wanted to pick them up, that'd be great. |
Moving from the custom UTF8 encoding/decoding done in protobufjs to the standardised |
Hopefully 2023 would be the year that bigints make it to protobufjs. |
env
to benode_browser
instead ofboth
useOptionals
all
to bescalar_messages
The text was updated successfully, but these errors were encountered: