Skip to content
Draft
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: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ format = [
{ cmd = "cargo fmt", cwd = "temporalio/bridge" },
]
gen-docs = "uv run scripts/gen_docs.py"
gen-nexus-system-api = "uv run scripts/gen_nexus_system_api.py"
gen-protos = [
{ cmd = "uv run scripts/gen_protos.py" },
{ ref = "gen-nexus-system-api" },
{ cmd = "uv run scripts/gen_payload_visitor.py" },
{ cmd = "uv run scripts/gen_bridge_client.py" },
{ ref = "format" },
]
gen-protos-docker = [
{ cmd = "uv run scripts/gen_protos_docker.py" },
{ ref = "gen-nexus-system-api" },
{ cmd = "uv run scripts/gen_payload_visitor.py" },
{ cmd = "uv run scripts/gen_bridge_client.py" },
{ ref = "format" },
Expand Down Expand Up @@ -169,7 +172,7 @@ exclude = [
[tool.pydocstyle]
convention = "google"
# https://github.com/PyCQA/pydocstyle/issues/363#issuecomment-625563088
match_dir = "^(?!(docs|scripts|tests|api|proto|\\.)).*"
match_dir = "^(?!(docs|scripts|tests|api|proto|system|\\.)).*"
add_ignore = [
# We like to wrap at a certain number of chars, even long summary sentences.
# https://github.com/PyCQA/pydocstyle/issues/184
Expand Down
152 changes: 152 additions & 0 deletions scripts/_nexus/deps/nexus-temporal-types/model.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/// @nexus.support
/// python="python/temporal_model_converters.py"
/// typescript="typescript/temporal_model_converters.ts"
package nexus:temporal-types@1.0.0;

interface model {
/// String-shaped placeholder for semantic types that generators reinterpret.
type placeholder = string;

/// @nexus.proto "temporal.api.common.v1.Payload" typescript-package="@temporalio/proto"
/// @nexus.type python="typing.Any" typescript="common.Payload" typescript-package="@temporalio/common"
type payload = placeholder;

/// @nexus.proto "temporal.api.common.v1.Payloads"
/// typescript-package="@temporalio/proto"
type payloads = list<payload>;

/// Callable result annotation for workflow functions.
/// @nexus.type
/// python="collections.abc.Awaitable[WorkflowResult]"
/// typescript="Promise<any>"
type workflow-result = placeholder;

/// Receiver/context argument for workflow callable method forms.
/// @nexus.type python="typing.Any" typescript="any"
type callable-prefix = placeholder;

/// @nexus.function-args
/// varargs=true
/// param="args"
/// typescript-drop-prefix=true
workflow-call: async func(callable-prefix: callable-prefix, args: payloads) -> workflow-result;

/// Callable result annotation for signal functions.
/// @nexus.type python="None | collections.abc.Awaitable[None]" typescript="void"
type signal-result = placeholder;

/// @nexus.function-args
/// varargs=true
/// param="signal-args"
/// typescript-drop-prefix=true
signal-call: func(callable-prefix: callable-prefix, signal-args: payloads) -> signal-result;

/// @nexus.proto "temporal.api.common.v1.WorkflowType" typescript-package="@temporalio/proto"
/// @nexus.type python="str" typescript="string"
type workflow-type = placeholder;

/// @nexus.function
/// primary=true
/// signature="workflow-call"
/// args-field="input"
/// result-type-parameter="WorkflowResult"
/// alternate-type="workflow-type"
/// @nexus.add-rpc-compatible-with "workflow-type"
type workflow-function = placeholder;

/// @nexus.function
/// signature="signal-call"
/// args-field="signal-input"
/// alternate-type="string"
/// python-converter="signal_function_to_proto"
/// typescript-converter="signalFunctionToProto"
/// @nexus.add-rpc-compatible-with "string"
/// @nexus.typescript-with-arguments
/// signature="signal-call"
/// args-field="signal-input"
/// alternate-type="string"
/// value-type="workflow.SignalDefinition<any[]>"
/// args-type="Value extends workflow.SignalDefinition<infer Args, any> ? Args : never"
/// name-expr="value.name"
/// typescript-package="@temporalio/workflow"
type signal-function = placeholder;

/// @nexus.proto "temporal.api.common.v1.RetryPolicy" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.RetryPolicy"
/// typescript="common.RetryPolicy"
/// typescript-package="@temporalio/common"
type retry-policy = placeholder;

/// @nexus.proto "temporal.api.taskqueue.v1.TaskQueue" typescript-package="@temporalio/proto"
/// @nexus.type python="str" typescript="string"
type task-queue = placeholder;

/// @nexus.proto "temporal.api.common.v1.Memo" typescript-package="@temporalio/proto"
/// @nexus.type python="collections.abc.Mapping[str, typing.Any]" typescript="Record<string, unknown>"
type memo = placeholder;

/// @nexus.proto "temporal.api.common.v1.SearchAttributes" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.TypedSearchAttributes"
/// typescript="common.TypedSearchAttributes"
/// typescript-package="@temporalio/common"
type search-attributes = placeholder;

/// @nexus.proto "temporal.api.common.v1.Priority" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.Priority"
/// typescript="common.Priority"
/// typescript-package="@temporalio/common"
type priority = placeholder;

/// @nexus.proto "temporal.api.workflow.v1.VersioningOverride" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.VersioningOverride"
/// typescript="common.VersioningOverride"
/// typescript-package="@temporalio/common"
type versioning-override = placeholder;

/// @nexus.proto "google.protobuf.Duration" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="datetime.timedelta"
/// typescript="common.Duration"
/// typescript-package="@temporalio/common"
type duration = placeholder;

/// @nexus.proto "temporal.api.enums.v1.WorkflowIdReusePolicy" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.WorkflowIDReusePolicy"
/// typescript="common.WorkflowIdReusePolicy"
/// typescript-package="@temporalio/common"
enum workflow-id-reuse-policy {
allow-duplicate,
allow-duplicate-failed-only,
reject-duplicate,
terminate-if-running,
}

/// @nexus.proto "temporal.api.enums.v1.WorkflowIdConflictPolicy" typescript-package="@temporalio/proto"
/// @nexus.type
/// python="temporalio.common.WorkflowIDConflictPolicy"
/// typescript="common.WorkflowIdConflictPolicy"
/// typescript-package="@temporalio/common"
enum workflow-id-conflict-policy {
fail,
use-existing,
terminate-existing,
}

/// @nexus.proto "temporal.api.sdk.v1.UserMetadata" typescript-package="@temporalio/proto"
/// @nexus.flatten-in-api
record user-metadata {
/// @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."
/// @nexus.proto-field "summary"
/// @nexus.flattened-type python="str" typescript="string"
static-summary: option<payload>,
/// @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."
/// @nexus.proto-field "details"
/// @nexus.flattened-type python="str" typescript="string"
static-details: option<payload>,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# pyright: reportAny=false, reportExplicitAny=false

import collections.abc
import typing
from datetime import timedelta

import google.protobuf.duration_pb2

import temporalio.api.common.v1.message_pb2 as common_pb2
import temporalio.api.enums.v1.workflow_pb2 as workflow_enums_pb2
import temporalio.api.taskqueue.v1.message_pb2 as taskqueue_pb2
import temporalio.api.workflow.v1
import temporalio.common
import temporalio.converter


def retry_policy_from_proto(
proto: common_pb2.RetryPolicy,
) -> temporalio.common.RetryPolicy:
return temporalio.common.RetryPolicy.from_proto(proto)


def retry_policy_to_proto(
retry_policy: temporalio.common.RetryPolicy,
) -> common_pb2.RetryPolicy:
proto = common_pb2.RetryPolicy()
retry_policy.apply_to_proto(proto)
return proto


def workflow_function_name(
value: str | collections.abc.Callable[..., collections.abc.Awaitable[object]],
) -> str:
from temporalio.workflow import _Definition # pyright: ignore[reportPrivateUsage]

name, _result_type = _Definition.get_name_and_result_type(value)
return name


def signal_function_to_proto(
value: str | collections.abc.Callable[..., typing.Any],
) -> str:
from temporalio.workflow import (
_SignalDefinition, # pyright: ignore[reportPrivateUsage]
)

return _SignalDefinition.must_name_from_fn_or_str(value) # pyright: ignore[reportUnknownMemberType]


def workflow_type_to_proto(
workflow_type: str
| collections.abc.Callable[..., collections.abc.Awaitable[object]],
) -> common_pb2.WorkflowType:
return common_pb2.WorkflowType(name=workflow_function_name(workflow_type))


def task_queue_from_proto(
proto: taskqueue_pb2.TaskQueue,
) -> str:
return proto.name


def task_queue_to_proto(
task_queue: str,
) -> taskqueue_pb2.TaskQueue:
return taskqueue_pb2.TaskQueue(name=task_queue)


def workflow_namespace() -> str:
from temporalio.workflow import info

return info().namespace


def payloads_to_proto(
values: collections.abc.Sequence[typing.Any],
) -> common_pb2.Payloads:
from temporalio.workflow import payload_converter

return payload_converter().to_payloads_wrapper(values)


def _clone_payload(payload: common_pb2.Payload) -> common_pb2.Payload:
clone = common_pb2.Payload()
clone.CopyFrom(payload)
return clone


def _value_to_payload(value: object | common_pb2.Payload) -> common_pb2.Payload:
if isinstance(value, common_pb2.Payload):
return _clone_payload(value)
from temporalio.workflow import payload_converter

payloads = payload_converter().to_payloads_wrapper([value])
return _clone_payload(payloads.payloads[0])


def _payload_to_value(payload: common_pb2.Payload) -> object:
wrapper = common_pb2.Payloads()
wrapper.payloads.add().CopyFrom(payload)
from temporalio.workflow import payload_converter

return typing.cast(
object,
payload_converter().from_payloads_wrapper(wrapper)[0],
)


def payload_from_proto(
proto: common_pb2.Payload,
) -> object:
return _payload_to_value(proto)


def payload_to_proto(
payload: object,
) -> common_pb2.Payload:
return _value_to_payload(payload)


def memo_from_proto(
proto: common_pb2.Memo,
) -> collections.abc.Mapping[str, object]:
return {key: _payload_to_value(value) for key, value in proto.fields.items()}


def memo_to_proto(
memo: collections.abc.Mapping[str, object],
) -> common_pb2.Memo:
message = common_pb2.Memo()
for key, value in memo.items():
message.fields[key].CopyFrom(_value_to_payload(value))
return message


def duration_from_proto(proto: google.protobuf.duration_pb2.Duration) -> timedelta:
return proto.ToTimedelta()


def duration_to_proto(
duration: timedelta,
) -> google.protobuf.duration_pb2.Duration:
proto = google.protobuf.duration_pb2.Duration()
proto.FromTimedelta(duration)
return proto


def workflow_id_reuse_policy_from_proto(
policy: workflow_enums_pb2.WorkflowIdReusePolicy.ValueType,
) -> temporalio.common.WorkflowIDReusePolicy:
return temporalio.common.WorkflowIDReusePolicy(int(policy))


def workflow_id_reuse_policy_to_proto(
policy: temporalio.common.WorkflowIDReusePolicy,
) -> workflow_enums_pb2.WorkflowIdReusePolicy.ValueType:
return typing.cast(workflow_enums_pb2.WorkflowIdReusePolicy.ValueType, int(policy))


def workflow_id_conflict_policy_from_proto(
policy: workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType,
) -> temporalio.common.WorkflowIDConflictPolicy:
return temporalio.common.WorkflowIDConflictPolicy(int(policy))


def workflow_id_conflict_policy_to_proto(
policy: temporalio.common.WorkflowIDConflictPolicy,
) -> workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType:
return typing.cast(
workflow_enums_pb2.WorkflowIdConflictPolicy.ValueType, int(policy)
)


def search_attributes_to_proto(
search_attributes: temporalio.common.TypedSearchAttributes,
) -> common_pb2.SearchAttributes:
proto = common_pb2.SearchAttributes()
temporalio.converter.encode_search_attributes(search_attributes, proto)
return proto


def priority_from_proto(
proto: common_pb2.Priority,
) -> temporalio.common.Priority:
return temporalio.common.Priority._from_proto(proto) # pyright: ignore[reportPrivateUsage]


def priority_to_proto(
priority: temporalio.common.Priority,
) -> common_pb2.Priority:
return priority._to_proto() # pyright: ignore[reportPrivateUsage]


def versioning_override_to_proto(
versioning_override: temporalio.common.VersioningOverride,
) -> temporalio.api.workflow.v1.VersioningOverride:
return versioning_override._to_proto() # pyright: ignore[reportPrivateUsage]
Loading
Loading