Skip to content

Commit 1bc2a59

Browse files
committed
Update Nexus system API generation
1 parent a30396b commit 1bc2a59

18 files changed

Lines changed: 1328 additions & 1539 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ exclude = [
172172
[tool.pydocstyle]
173173
convention = "google"
174174
# https://github.com/PyCQA/pydocstyle/issues/363#issuecomment-625563088
175-
match_dir = "^(?!(docs|scripts|tests|api|proto|_system|\\.)).*"
175+
match_dir = "^(?!(docs|scripts|tests|api|proto|system|\\.)).*"
176176
add_ignore = [
177177
# We like to wrap at a certain number of chars, even long summary sentences.
178178
# https://github.com/PyCQA/pydocstyle/issues/184
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/// @nexus.support
2+
/// python="python/model_overrides.py"
3+
/// typescript="typescript/model_overrides.ts"
4+
package nexus:temporal-types@1.0.0;
5+
6+
interface model {
7+
/// String-shaped placeholder for semantic types that generators reinterpret.
8+
type placeholder = string;
9+
10+
/// @nexus.proto "temporal.api.common.v1.Payload" typescript-package="@temporalio/proto"
11+
/// @nexus.type python="typing.Any" typescript="common.Payload" typescript-package="@temporalio/common"
12+
type payload = placeholder;
13+
14+
/// @nexus.proto "temporal.api.common.v1.Payloads"
15+
/// typescript-package="@temporalio/proto"
16+
type payloads = list<payload>;
17+
18+
/// Callable result annotation for workflow functions.
19+
/// @nexus.type
20+
/// python="collections.abc.Awaitable[WorkflowResult]"
21+
/// typescript="Promise<any>"
22+
type workflow-result = placeholder;
23+
24+
/// Receiver/context argument for workflow callable method forms.
25+
/// @nexus.type python="typing.Any" typescript="any"
26+
type callable-prefix = placeholder;
27+
28+
/// @nexus.function-args
29+
/// varargs=true
30+
/// param="args"
31+
/// typescript-drop-prefix=true
32+
workflow-call: async func(callable-prefix: callable-prefix, args: payloads) -> workflow-result;
33+
34+
/// Callable result annotation for signal functions.
35+
/// @nexus.type python="None | collections.abc.Awaitable[None]" typescript="void"
36+
type signal-result = placeholder;
37+
38+
/// @nexus.function-args
39+
/// varargs=true
40+
/// param="signal-args"
41+
/// typescript-drop-prefix=true
42+
signal-call: func(callable-prefix: callable-prefix, signal-args: payloads) -> signal-result;
43+
44+
/// @nexus.proto "temporal.api.common.v1.WorkflowType" typescript-package="@temporalio/proto"
45+
/// @nexus.type python="str" typescript="string"
46+
type workflow-type = placeholder;
47+
48+
/// @nexus.function
49+
/// primary=true
50+
/// signature="workflow-call"
51+
/// args-field="input"
52+
/// result-type-parameter="WorkflowResult"
53+
/// alternate-type="workflow-type"
54+
/// @nexus.add-rpc-compatible-with "workflow-type"
55+
type workflow-function = placeholder;
56+
57+
/// @nexus.function
58+
/// signature="signal-call"
59+
/// args-field="signal-input"
60+
/// alternate-type="string"
61+
/// python-converter="signal_function_to_proto"
62+
/// typescript-converter="signalFunctionToProto"
63+
/// @nexus.add-rpc-compatible-with "string"
64+
/// @nexus.typescript-with-arguments
65+
/// signature="signal-call"
66+
/// args-field="signal-input"
67+
/// alternate-type="string"
68+
/// value-type="workflow.SignalDefinition<any[]>"
69+
/// args-type="Value extends workflow.SignalDefinition<infer Args, any> ? Args : never"
70+
/// name-expr="value.name"
71+
/// typescript-package="@temporalio/workflow"
72+
type signal-function = placeholder;
73+
74+
/// @nexus.proto "temporal.api.common.v1.RetryPolicy" typescript-package="@temporalio/proto"
75+
/// @nexus.type
76+
/// python="temporalio.common.RetryPolicy"
77+
/// typescript="common.RetryPolicy"
78+
/// typescript-package="@temporalio/common"
79+
type retry-policy = placeholder;
80+
81+
/// @nexus.proto "temporal.api.taskqueue.v1.TaskQueue" typescript-package="@temporalio/proto"
82+
/// @nexus.type python="str" typescript="string"
83+
type task-queue = placeholder;
84+
85+
/// @nexus.proto "temporal.api.common.v1.Memo" typescript-package="@temporalio/proto"
86+
/// @nexus.type python="collections.abc.Mapping[str, typing.Any]" typescript="Record<string, unknown>"
87+
type memo = placeholder;
88+
89+
/// @nexus.proto "temporal.api.common.v1.SearchAttributes" typescript-package="@temporalio/proto"
90+
/// @nexus.type
91+
/// python="temporalio.common.TypedSearchAttributes"
92+
/// typescript="common.TypedSearchAttributes"
93+
/// typescript-package="@temporalio/common"
94+
type search-attributes = placeholder;
95+
96+
/// @nexus.proto "temporal.api.common.v1.Priority" typescript-package="@temporalio/proto"
97+
/// @nexus.type
98+
/// python="temporalio.common.Priority"
99+
/// typescript="common.Priority"
100+
/// typescript-package="@temporalio/common"
101+
type priority = placeholder;
102+
103+
/// @nexus.proto "temporal.api.workflow.v1.VersioningOverride" typescript-package="@temporalio/proto"
104+
/// @nexus.type
105+
/// python="temporalio.common.VersioningOverride"
106+
/// typescript="common.VersioningOverride"
107+
/// typescript-package="@temporalio/common"
108+
type versioning-override = placeholder;
109+
110+
/// @nexus.proto "google.protobuf.Duration" typescript-package="@temporalio/proto"
111+
/// @nexus.type
112+
/// python="datetime.timedelta"
113+
/// typescript="common.Duration"
114+
/// typescript-package="@temporalio/common"
115+
type duration = placeholder;
116+
117+
/// @nexus.proto "temporal.api.enums.v1.WorkflowIdReusePolicy" typescript-package="@temporalio/proto"
118+
/// @nexus.type
119+
/// python="temporalio.common.WorkflowIDReusePolicy"
120+
/// typescript="common.WorkflowIdReusePolicy"
121+
/// typescript-package="@temporalio/common"
122+
enum workflow-id-reuse-policy {
123+
allow-duplicate,
124+
allow-duplicate-failed-only,
125+
reject-duplicate,
126+
terminate-if-running,
127+
}
128+
129+
/// @nexus.proto "temporal.api.enums.v1.WorkflowIdConflictPolicy" typescript-package="@temporalio/proto"
130+
/// @nexus.type
131+
/// python="temporalio.common.WorkflowIDConflictPolicy"
132+
/// typescript="common.WorkflowIdConflictPolicy"
133+
/// typescript-package="@temporalio/common"
134+
enum workflow-id-conflict-policy {
135+
fail,
136+
use-existing,
137+
terminate-existing,
138+
}
139+
140+
/// @nexus.proto "temporal.api.sdk.v1.UserMetadata" typescript-package="@temporalio/proto"
141+
/// @nexus.flatten-in-api
142+
record user-metadata {
143+
/// @nexus.doc "Single-line fixed summary for the workflow execution that may appear in UI and CLI. This can be in single-line Temporal Markdown format."
144+
/// @nexus.proto-field "summary"
145+
/// @nexus.flattened-type python="str" typescript="string"
146+
static-summary: option<payload>,
147+
/// @nexus.doc "General fixed details for the workflow execution that may appear in UI and CLI. This can be in Temporal Markdown format and can span multiple lines. This value is fixed on the workflow execution and cannot be updated."
148+
/// @nexus.proto-field "details"
149+
/// @nexus.flattened-type python="str" typescript="string"
150+
static-details: option<payload>,
151+
}
152+
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# pyright: reportAny=false, reportExplicitAny=false
2+
3+
import collections.abc
4+
from datetime import timedelta
5+
import typing
6+
7+
import google.protobuf.duration_pb2
8+
import temporalio.api.common.v1.message_pb2 as common_pb2
9+
import temporalio.api.enums.v1.workflow_pb2 as workflow_enums_pb2
10+
import temporalio.api.taskqueue.v1.message_pb2 as taskqueue_pb2
11+
import temporalio.api.workflow.v1
12+
import temporalio.converter
13+
import temporalio.common
14+
import temporalio.workflow
15+
16+
17+
def retry_policy_from_proto(
18+
proto: common_pb2.RetryPolicy,
19+
) -> temporalio.common.RetryPolicy:
20+
return temporalio.common.RetryPolicy.from_proto(proto)
21+
22+
23+
def retry_policy_to_proto(
24+
retry_policy: temporalio.common.RetryPolicy,
25+
) -> common_pb2.RetryPolicy:
26+
proto = common_pb2.RetryPolicy()
27+
retry_policy.apply_to_proto(proto)
28+
return proto
29+
30+
31+
def workflow_function_name(
32+
value: str | collections.abc.Callable[..., collections.abc.Awaitable[object]],
33+
) -> str:
34+
name, _result_type = temporalio.workflow._Definition.get_name_and_result_type(value) # pyright: ignore[reportPrivateUsage]
35+
return name
36+
37+
38+
def signal_function_to_proto(
39+
value: str | collections.abc.Callable[..., typing.Any],
40+
) -> str:
41+
return temporalio.workflow._SignalDefinition.must_name_from_fn_or_str(value) # pyright: ignore[reportPrivateUsage, reportUnknownMemberType]
42+
43+
44+
def workflow_type_to_proto(
45+
workflow_type: str
46+
| collections.abc.Callable[..., collections.abc.Awaitable[object]],
47+
) -> common_pb2.WorkflowType:
48+
return common_pb2.WorkflowType(name=workflow_function_name(workflow_type))
49+
50+
51+
def task_queue_from_proto(
52+
proto: taskqueue_pb2.TaskQueue,
53+
) -> str:
54+
return proto.name
55+
56+
57+
def task_queue_to_proto(
58+
task_queue: str,
59+
) -> taskqueue_pb2.TaskQueue:
60+
return taskqueue_pb2.TaskQueue(name=task_queue)
61+
62+
63+
def workflow_namespace() -> str:
64+
return temporalio.workflow.info().namespace
65+
66+
67+
def payloads_to_proto(
68+
values: collections.abc.Sequence[typing.Any],
69+
) -> common_pb2.Payloads:
70+
return temporalio.workflow.payload_converter().to_payloads_wrapper(values)
71+
72+
73+
def _clone_payload(payload: common_pb2.Payload) -> common_pb2.Payload:
74+
clone = common_pb2.Payload()
75+
clone.CopyFrom(payload)
76+
return clone
77+
78+
79+
def _value_to_payload(value: object | common_pb2.Payload) -> common_pb2.Payload:
80+
if isinstance(value, common_pb2.Payload):
81+
return _clone_payload(value)
82+
payloads = temporalio.workflow.payload_converter().to_payloads_wrapper([value])
83+
return _clone_payload(payloads.payloads[0])
84+
85+
86+
def _payload_to_value(payload: common_pb2.Payload) -> object:
87+
wrapper = common_pb2.Payloads()
88+
wrapper.payloads.add().CopyFrom(payload)
89+
return typing.cast(
90+
object,
91+
temporalio.workflow.payload_converter().from_payloads_wrapper(wrapper)[0],
92+
)
93+
94+
95+
def payload_from_proto(
96+
proto: common_pb2.Payload,
97+
) -> object:
98+
return _payload_to_value(proto)
99+
100+
101+
def payload_to_proto(
102+
payload: object,
103+
) -> common_pb2.Payload:
104+
return _value_to_payload(payload)
105+
106+
107+
def memo_from_proto(
108+
proto: common_pb2.Memo,
109+
) -> collections.abc.Mapping[str, object]:
110+
return {key: _payload_to_value(value) for key, value in proto.fields.items()}
111+
112+
113+
def memo_to_proto(
114+
memo: collections.abc.Mapping[str, object],
115+
) -> common_pb2.Memo:
116+
message = common_pb2.Memo()
117+
for key, value in memo.items():
118+
message.fields[key].CopyFrom(_value_to_payload(value))
119+
return message
120+
121+
122+
def duration_from_proto(proto: google.protobuf.duration_pb2.Duration) -> timedelta:
123+
return proto.ToTimedelta()
124+
125+
126+
def duration_to_proto(
127+
duration: timedelta,
128+
) -> google.protobuf.duration_pb2.Duration:
129+
proto = google.protobuf.duration_pb2.Duration()
130+
proto.FromTimedelta(duration)
131+
return proto
132+
133+
134+
def workflow_id_reuse_policy_from_proto(
135+
policy: workflow_enums_pb2.WorkflowIdReusePolicy.ValueType,
136+
) -> temporalio.common.WorkflowIDReusePolicy:
137+
return temporalio.common.WorkflowIDReusePolicy(int(policy))
138+
139+
140+
def workflow_id_reuse_policy_to_proto(
141+
policy: temporalio.common.WorkflowIDReusePolicy,
142+
) -> workflow_enums_pb2.WorkflowIdReusePolicy.ValueType:
143+
return typing.cast(workflow_enums_pb2.WorkflowIdReusePolicy.ValueType, int(policy))
144+
145+
146+
def workflow_id_conflict_policy_from_proto(
147+
policy: workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType,
148+
) -> temporalio.common.WorkflowIDConflictPolicy:
149+
return temporalio.common.WorkflowIDConflictPolicy(int(policy))
150+
151+
152+
def workflow_id_conflict_policy_to_proto(
153+
policy: temporalio.common.WorkflowIDConflictPolicy,
154+
) -> workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType:
155+
return typing.cast(workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType, int(policy))
156+
157+
158+
def search_attributes_to_proto(
159+
search_attributes: temporalio.common.TypedSearchAttributes,
160+
) -> common_pb2.SearchAttributes:
161+
proto = common_pb2.SearchAttributes()
162+
temporalio.converter.encode_search_attributes(search_attributes, proto)
163+
return proto
164+
165+
166+
def priority_from_proto(
167+
proto: common_pb2.Priority,
168+
) -> temporalio.common.Priority:
169+
return temporalio.common.Priority._from_proto(proto) # pyright: ignore[reportPrivateUsage]
170+
171+
172+
def priority_to_proto(
173+
priority: temporalio.common.Priority,
174+
) -> common_pb2.Priority:
175+
return priority._to_proto() # pyright: ignore[reportPrivateUsage]
176+
177+
178+
def versioning_override_to_proto(
179+
versioning_override: temporalio.common.VersioningOverride,
180+
) -> temporalio.api.workflow.v1.VersioningOverride:
181+
return versioning_override._to_proto() # pyright: ignore[reportPrivateUsage]

0 commit comments

Comments
 (0)