-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[typescript-fetch] Add Temporal support #24714
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
base: master
Are you sure you want to change the base?
Changes from all commits
782f8eb
7d0da5f
22b94ca
0870de1
0686a0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl | |
| <li>ReturnType</li> | ||
| <li>Set</li> | ||
| <li>String</li> | ||
| <li>Temporal.Instant</li> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This doc covers the base Prompt for AI agents |
||
| <li>Temporal.PlainDate</li> | ||
| <li>ThisParameterType</li> | ||
| <li>ThisType</li> | ||
| <li>Uncapitalize</li> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,10 @@ | ||||||
| {{! Assign query parameters based on their type }} | ||||||
| {{#isDateTimeType}} | ||||||
| queryParameters['{{baseName}}'] = (requestParameters['{{paramName}}'] as any).toISOString(); | ||||||
| queryParameters['{{baseName}}'] = {{#temporal}}(requestParameters['{{paramName}}'] as any).toString(){{/temporal}}{{^temporal}}(requestParameters['{{paramName}}'] as any).toISOString(){{/temporal}}; | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth noting that Temporal.Instant's toString() method gives something like this (based on my experiments):
So in Node, the precision is up to nanoseconds. Also, the specification says that the number of places after the decimal point may differ because trailing zeroes are removed. We could also fix the number of fractional seconds (the method has a parameter for that). |
||||||
| {{/isDateTimeType}} | ||||||
| {{^isDateTimeType}} | ||||||
| {{#isDateType}} | ||||||
| queryParameters['{{baseName}}'] = (requestParameters['{{paramName}}'] as any).toISOString().substring(0,10); | ||||||
| queryParameters['{{baseName}}'] = {{#temporal}}(requestParameters['{{paramName}}'] as any).toString(){{/temporal}}{{^temporal}}(requestParameters['{{paramName}}'] as any).toISOString().substring(0,10){{/temporal}}; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When a caller supplies a non-ISO-calendar Prompt for AI agents
Suggested change
|
||||||
| {{/isDateType}} | ||||||
| {{^isDateType}} | ||||||
| queryParameters['{{baseName}}'] = requestParameters['{{paramName}}']; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,10 +98,10 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole | |
| {{/isArray}} | ||
| {{^isArray}} | ||
| {{#isDateType}} | ||
| '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? json['{{baseName}}'] : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), | ||
| '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? json['{{baseName}}'] : {{/isNullable}}{{/required}}{{#temporal}}Temporal.PlainDate.from(json['{{baseName}}']){{/temporal}}{{^temporal}}new Date(json['{{baseName}}']){{/temporal}}), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: For array properties with date or date-time items, this scalar-only branch is skipped and Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: When consumers provide Temporal through the usual polyfill module import without assigning Prompt for AI agents |
||
| {{/isDateType}} | ||
| {{#isDateTimeType}} | ||
| '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? json['{{baseName}}'] : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), | ||
| '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? json['{{baseName}}'] : {{/isNullable}}{{/required}}{{#temporal}}Temporal.Instant.from(json['{{baseName}}']){{/temporal}}{{^temporal}}new Date(json['{{baseName}}']){{/temporal}}), | ||
| {{/isDateTimeType}} | ||
| {{^isDateType}} | ||
| {{^isDateTimeType}} | ||
|
|
@@ -173,10 +173,10 @@ export function {{classname}}ToJSONTyped(value?: {{#hasReadOnly}}Omit<{{classnam | |
| {{^isReadOnly}} | ||
| {{#isPrimitiveType}} | ||
| {{#isDateType}} | ||
| '{{baseName}}': value['{{name}}'] == null ? value['{{name}}'] : value['{{name}}'].toISOString().substring(0,10), | ||
| '{{baseName}}': value['{{name}}'] == null ? value['{{name}}'] : {{#temporal}}value['{{name}}'].toString(){{/temporal}}{{^temporal}}value['{{name}}'].toISOString().substring(0,10){{/temporal}}, | ||
| {{/isDateType}} | ||
| {{#isDateTimeType}} | ||
| '{{baseName}}': value['{{name}}'] == null ? value['{{name}}'] : value['{{name}}'].toISOString(), | ||
| '{{baseName}}': value['{{name}}'] == null ? value['{{name}}'] : {{#temporal}}value['{{name}}'].toString(){{/temporal}}{{^temporal}}value['{{name}}'].toISOString(){{/temporal}}, | ||
| {{/isDateTimeType}} | ||
| {{#isArray}} | ||
| '{{baseName}}': {{#uniqueItems}}{{^required}}value['{{name}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}value['{{name}}'] == null ? null : {{/isNullable}}{{/required}}Array.from(value['{{name}}'] as Set<any>){{/uniqueItems}}{{^uniqueItems}}value['{{name}}']{{/uniqueItems}}, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The temporal option description does not mention that generated code emits bare
Temporal.Instant/Temporal.PlainDatereferences with no import, so consumers enablingtemporal: truemust provide a Temporal runtime/polyfill plus typings or the generated code will not compile. Add the runtime/import requirement to the option documentation (via the CliOption comment it is generated from) so users know what to install.Prompt for AI agents