Skip to content

fix(typescript): type a resource's 64-bit values as Long - #296

Closed
moetemp wants to merge 1 commit into
moe/up/python-proto-modulesfrom
moe/up/ts-long-resource-params
Closed

moetemp wants to merge 1 commit into
moe/up/python-proto-modulesfrom
moe/up/ts-long-resource-params

Conversation

@moetemp

@moetemp moetemp commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

This PR types each 64-bit integer of a TypeScript resource as Long, in its fields, method parameters and results, as a proto-backed model holds it.

A TypeScript resource's 64-bit value is now refused where it would cross a JSON model. A record without @nexus.proto holds a 64-bit integer as a number, but the resource holds it as a Long. The two types don't match, and a conversion to number loses the digits above 2^53. So nexgen refuses these cases, and names the record and the fix (@nexus.proto, or another type).

  • A resource field or method parameter with a 64-bit integer goes into a request record without @nexus.proto, also through a proto message inside that record.
  • An operation returns a resource with a 64-bit field with no proto wire message.

nexgen also refuses a 64-bit map key in any TypeScript resource, since a Long can't key a Record.

No sample has such a service. In the stream sample's TypeScript output, Stream.read takes fromOffset and maxBytes as Long, and the service type-checks.

Why?

The proto-backed request has a Long field, so resources.ts didn't type-check. A Long.fromNumber conversion fixes the types but not the values. A Brook offset is about 1.9e18, so a number loses its low bits.

How did you test it?

Link to a test plan if any -

  • Unit Tests
  • Staging
  • End to End Tests

A new TypeScript test reads from an offset above 2^53, then from the page's nextOffset. Rejection fixtures cover a parameter and a field that go into a plain request record, a parameter that goes into a proto message inside one, a resource result with no proto wire message, and the map key.

@moetemp
moetemp requested a review from a team as a code owner October 26, 2026 22:45
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch 2 times, most recently from 6a26022 to 713012f Compare October 27, 2026 09:08
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch 2 times, most recently from 1600a86 to d865755 Compare October 27, 2026 18:35
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch 2 times, most recently from db00f04 to 9e1d318 Compare October 28, 2026 16:37
@moetemp moetemp changed the title fix(typescript): convert 64-bit resource method values to Long for a proto request fix(typescript): type 64-bit resource values as Long for a proto request Oct 28, 2026
@moetemp
moetemp changed the base branch from main to moe/up/proto-unsigned-ints October 28, 2026 22:57
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from 9e1d318 to 566af30 Compare October 29, 2026 04:00
@moetemp
moetemp changed the base branch from moe/up/proto-unsigned-ints to moe/up/python-proto-modules October 29, 2026 04:00
@moetemp moetemp closed this Oct 29, 2026
@moetemp moetemp reopened this Oct 29, 2026
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from 566af30 to 8c475f3 Compare October 29, 2026 06:28
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 81fd8c7 to 36a8328 Compare October 29, 2026 06:28
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch 2 times, most recently from a649a98 to cbdf5c3 Compare October 29, 2026 07:35
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 2f28526 to 2497fc5 Compare October 29, 2026 07:35
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from cbdf5c3 to 770e53a Compare October 29, 2026 09:29
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 2497fc5 to 52b7104 Compare October 29, 2026 09:29
@moetemp moetemp changed the title fix(typescript): type 64-bit resource values as Long for a proto request fix(typescript): type a resource's 64-bit values as Long Oct 29, 2026
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from 770e53a to e1d283e Compare October 29, 2026 17:08
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 52b7104 to e00ebe2 Compare October 29, 2026 17:08
moetemp added a commit that referenced this pull request Oct 29, 2026
…#310)

### What changed?
This PR plans a protobuf `oneof` case that names a proto-bound WIT record as that record, as nexgen already does for a record field.

- Only oneof-bound variants get the new plan, and an `option` around the payload stays.
- A .NET case record names its payload's model in full. Else a case named like its record hides the model, and `record Superseded(Superseded Value)` doesn't compile. Brook's next WIT names a case like that.
- The first commit is the fix, and the stream sample's TypeScript output appears with it. The second commit generates the stream service for Python, with basedpyright off for it until #311. `tsc` skips the service until #296.

In the stream sample's .NET output, the read item now holds the records, not the proto classes.

It's based on #308.

### Why?
Brook's read item, `variant stream-item`, binds a `oneof` of three proto-bound records. Before the fix, Python and TypeScript generation panicked on it, and .NET typed each case as the proto class.

### How did you test it?
Link to a test plan if any -
- [x] Unit Tests
- [ ] Staging
- [ ] End to End Tests

New TypeScript and .NET tests round-trip the read item's cases, and the .NET test leaves out the data case. A unit test covers the full name of a case payload.


Co-authored-by: Tim Conley <timothy.conley@temporal.io>
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from e1d283e to eeab36c Compare October 29, 2026 17:18
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch 2 times, most recently from 25efbe1 to eb8425d Compare October 29, 2026 18:27
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from eeab36c to 2986e8f Compare October 29, 2026 18:27

public async read(
fromOffset?: number,
fromOffset?: Long,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the confusion between number and Long is likely a mistake, and not one we should compound with additional caveats and edge cases. If the overall goal is make these sepecific fields show up as longs, we could potentially just explicitly alias them in the wit.

A proto-backed request holds a 64-bit integer as a `Long`, but a resource method took a number,
which can't hold a Redis Store offset. A resource's 64-bit value is now always a `Long`. nexgen
refuses one that would go into a record without `@nexus.proto`, which holds it as a number, and a
64-bit map key in any resource. The stream service type-checks.
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 79f16e2 to 58790da Compare October 30, 2026 01:00
@moetemp
moetemp force-pushed the moe/up/ts-long-resource-params branch from c7b747b to 08816c8 Compare October 30, 2026 01:00
@moetemp

moetemp commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Closed in favour of #345

@moetemp moetemp closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants