Skip to content
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

fix: Support using messages called String/Boolean/Number/Array #934

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions integration/angular/simple-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SimpleMessage = {
},

fromJSON(object: any): SimpleMessage {
return { numberField: isSet(object.numberField) ? Number(object.numberField) : 0 };
return { numberField: isSet(object.numberField) ? globalThis.Number(object.numberField) : 0 };
},

toJSON(message: SimpleMessage): unknown {
Expand All @@ -67,7 +67,8 @@ export const SimpleMessage = {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
5 changes: 3 additions & 2 deletions integration/async-iterable-services-abort-signal/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const EchoMsg = {
},

fromJSON(object: any): EchoMsg {
return { body: isSet(object.body) ? String(object.body) : "" };
return { body: isSet(object.body) ? globalThis.String(object.body) : "" };
},

toJSON(message: EchoMsg): unknown {
Expand Down Expand Up @@ -176,7 +176,8 @@ interface Rpc {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
5 changes: 3 additions & 2 deletions integration/async-iterable-services/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const EchoMsg = {
},

fromJSON(object: any): EchoMsg {
return { body: isSet(object.body) ? String(object.body) : "" };
return { body: isSet(object.body) ? globalThis.String(object.body) : "" };
},

toJSON(message: EchoMsg): unknown {
Expand Down Expand Up @@ -160,7 +160,8 @@ interface Rpc {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
7 changes: 4 additions & 3 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const Simple = {

fromJSON(object: any): Simple {
return {
name: isSet(object.name) ? String(object.name) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
otherSimple: isSet(object.otherSimple) ? Simple3.fromJSON(object.otherSimple) : undefined,
};
},
Expand Down Expand Up @@ -197,7 +197,7 @@ export const DifferentSimple = {

fromJSON(object: any): DifferentSimple {
return {
name: isSet(object.name) ? String(object.name) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
otherOptionalSimple2: isSet(object.otherOptionalSimple2)
? Simple3.fromJSON(object.otherOptionalSimple2)
: undefined,
Expand Down Expand Up @@ -443,7 +443,8 @@ interface Rpc {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
8 changes: 6 additions & 2 deletions integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export const Simple = {
},

fromJSON(object: any): Simple {
return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 };
return {
name: isSet(object.name) ? globalThis.String(object.name) : "",
age: isSet(object.age) ? globalThis.Number(object.age) : 0,
};
},

toJSON(message: Simple): unknown {
Expand Down Expand Up @@ -160,7 +163,8 @@ export const Simple = {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
8 changes: 6 additions & 2 deletions integration/barrel-imports/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const Bar = {
},

fromJSON(object: any): Bar {
return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 };
return {
name: isSet(object.name) ? globalThis.String(object.name) : "",
age: isSet(object.age) ? globalThis.Number(object.age) : 0,
};
},

toJSON(message: Bar): unknown {
Expand Down Expand Up @@ -80,7 +83,8 @@ export const Bar = {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
5 changes: 3 additions & 2 deletions integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Foo = {

fromJSON(object: any): Foo {
return {
name: isSet(object.name) ? String(object.name) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined,
};
},
Expand Down Expand Up @@ -84,7 +84,8 @@ export const Foo = {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
18 changes: 11 additions & 7 deletions integration/batching-with-context-esModuleInterop/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const BatchQueryRequest = {
},

fromJSON(object: any): BatchQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchQueryRequest): unknown {
Expand Down Expand Up @@ -198,7 +198,7 @@ export const BatchMapQueryRequest = {
},

fromJSON(object: any): BatchMapQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchMapQueryRequest): unknown {
Expand Down Expand Up @@ -344,7 +344,7 @@ export const BatchMapQueryResponse_EntitiesEntry = {

fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry {
return {
key: isSet(object.key) ? String(object.key) : "",
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined,
};
},
Expand Down Expand Up @@ -413,7 +413,7 @@ export const GetOnlyMethodRequest = {
},

fromJSON(object: any): GetOnlyMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: GetOnlyMethodRequest): unknown {
Expand Down Expand Up @@ -529,7 +529,7 @@ export const WriteMethodRequest = {
},

fromJSON(object: any): WriteMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: WriteMethodRequest): unknown {
Expand Down Expand Up @@ -639,7 +639,10 @@ export const Entity = {
},

fromJSON(object: any): Entity {
return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" };
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
};
},

toJSON(message: Entity): unknown {
Expand Down Expand Up @@ -758,7 +761,8 @@ export interface DataLoaders {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
18 changes: 11 additions & 7 deletions integration/batching-with-context/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const BatchQueryRequest = {
},

fromJSON(object: any): BatchQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchQueryRequest): unknown {
Expand Down Expand Up @@ -198,7 +198,7 @@ export const BatchMapQueryRequest = {
},

fromJSON(object: any): BatchMapQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchMapQueryRequest): unknown {
Expand Down Expand Up @@ -344,7 +344,7 @@ export const BatchMapQueryResponse_EntitiesEntry = {

fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry {
return {
key: isSet(object.key) ? String(object.key) : "",
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined,
};
},
Expand Down Expand Up @@ -413,7 +413,7 @@ export const GetOnlyMethodRequest = {
},

fromJSON(object: any): GetOnlyMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: GetOnlyMethodRequest): unknown {
Expand Down Expand Up @@ -529,7 +529,7 @@ export const WriteMethodRequest = {
},

fromJSON(object: any): WriteMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: WriteMethodRequest): unknown {
Expand Down Expand Up @@ -639,7 +639,10 @@ export const Entity = {
},

fromJSON(object: any): Entity {
return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" };
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
};
},

toJSON(message: Entity): unknown {
Expand Down Expand Up @@ -758,7 +761,8 @@ export interface DataLoaders {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
18 changes: 11 additions & 7 deletions integration/batching/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const BatchQueryRequest = {
},

fromJSON(object: any): BatchQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchQueryRequest): unknown {
Expand Down Expand Up @@ -196,7 +196,7 @@ export const BatchMapQueryRequest = {
},

fromJSON(object: any): BatchMapQueryRequest {
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] };
return { ids: globalThis.Array.isArray(object?.ids) ? object.ids.map((e: any) => globalThis.String(e)) : [] };
},

toJSON(message: BatchMapQueryRequest): unknown {
Expand Down Expand Up @@ -342,7 +342,7 @@ export const BatchMapQueryResponse_EntitiesEntry = {

fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry {
return {
key: isSet(object.key) ? String(object.key) : "",
key: isSet(object.key) ? globalThis.String(object.key) : "",
value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined,
};
},
Expand Down Expand Up @@ -411,7 +411,7 @@ export const GetOnlyMethodRequest = {
},

fromJSON(object: any): GetOnlyMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: GetOnlyMethodRequest): unknown {
Expand Down Expand Up @@ -527,7 +527,7 @@ export const WriteMethodRequest = {
},

fromJSON(object: any): WriteMethodRequest {
return { id: isSet(object.id) ? String(object.id) : "" };
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},

toJSON(message: WriteMethodRequest): unknown {
Expand Down Expand Up @@ -637,7 +637,10 @@ export const Entity = {
},

fromJSON(object: any): Entity {
return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" };
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
name: isSet(object.name) ? globalThis.String(object.name) : "",
};
},

toJSON(message: Entity): unknown {
Expand Down Expand Up @@ -715,7 +718,8 @@ interface Rpc {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
3 changes: 2 additions & 1 deletion integration/bytes-as-base64/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function base64FromBytes(arr: Uint8Array): string {
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Expand Down
Loading
Loading