nvent 0.5.15 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +181 -8
- package/dist/module.json +1 -1
- package/dist/module.mjs +1257 -1196
- package/dist/runtime/app/composables/useFunctionCall.d.ts +17 -0
- package/dist/runtime/app/composables/useFunctionCall.js +25 -0
- package/dist/runtime/app/composables/useNventStream.d.ts +23 -0
- package/dist/runtime/app/composables/useNventStream.js +58 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.d.ts +19 -0
- package/dist/runtime/nitro/plugins/00.iii-lifecycle.js +62 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.d.ts +15 -0
- package/dist/runtime/nitro/plugins/01.iii-worker.js +91 -0
- package/dist/runtime/nitro/routes/stream-proxy.d.ts +17 -0
- package/dist/runtime/nitro/routes/stream-proxy.js +45 -0
- package/dist/runtime/nitro/utils/console.d.ts +32 -0
- package/dist/runtime/nitro/utils/console.js +95 -0
- package/dist/runtime/nitro/utils/defineFunction.d.ts +378 -3
- package/dist/runtime/nitro/utils/defineFunction.js +224 -4
- package/dist/runtime/nitro/utils/engine.d.ts +25 -0
- package/dist/runtime/nitro/utils/engine.js +130 -0
- package/dist/runtime/nitro/utils/nventDir.d.ts +1 -0
- package/dist/runtime/nitro/utils/nventDir.js +20 -0
- package/dist/runtime/nitro/utils/useIii.d.ts +23 -0
- package/dist/runtime/nitro/utils/useIii.js +14 -0
- package/dist/runtime/nitro/utils/workers/node.d.ts +24 -0
- package/dist/runtime/nitro/utils/workers/node.js +57 -0
- package/dist/runtime/nitro/utils/workers/python.d.ts +67 -0
- package/dist/runtime/nitro/utils/workers/python.js +220 -0
- package/dist/runtime/python/nvent.py +208 -0
- package/dist/runtime/python/worker_runtime.py +659 -0
- package/dist/runtime/virtual.d.ts +17 -0
- package/dist/types.d.mts +5 -1
- package/package.json +11 -14
- package/dist/runtime/adapters/base/index.d.ts +0 -6
- package/dist/runtime/adapters/base/index.js +0 -1
- package/dist/runtime/adapters/base/store-validator.d.ts +0 -48
- package/dist/runtime/adapters/base/store-validator.js +0 -147
- package/dist/runtime/adapters/builtin/file-queue.d.ts +0 -67
- package/dist/runtime/adapters/builtin/file-queue.js +0 -499
- package/dist/runtime/adapters/builtin/file-store.d.ts +0 -32
- package/dist/runtime/adapters/builtin/file-store.js +0 -206
- package/dist/runtime/adapters/builtin/file-stream.d.ts +0 -39
- package/dist/runtime/adapters/builtin/file-stream.js +0 -56
- package/dist/runtime/adapters/builtin/index.d.ts +0 -10
- package/dist/runtime/adapters/builtin/index.js +0 -5
- package/dist/runtime/adapters/builtin/memory-queue.d.ts +0 -52
- package/dist/runtime/adapters/builtin/memory-queue.js +0 -243
- package/dist/runtime/adapters/builtin/memory-store.d.ts +0 -69
- package/dist/runtime/adapters/builtin/memory-store.js +0 -357
- package/dist/runtime/adapters/builtin/memory-stream.d.ts +0 -21
- package/dist/runtime/adapters/builtin/memory-stream.js +0 -56
- package/dist/runtime/adapters/factory.d.ts +0 -31
- package/dist/runtime/adapters/factory.js +0 -135
- package/dist/runtime/adapters/index.d.ts +0 -8
- package/dist/runtime/adapters/index.js +0 -3
- package/dist/runtime/adapters/interfaces/index.d.ts +0 -11
- package/dist/runtime/adapters/interfaces/index.js +0 -3
- package/dist/runtime/adapters/interfaces/queue.d.ts +0 -155
- package/dist/runtime/adapters/interfaces/queue.js +0 -0
- package/dist/runtime/adapters/interfaces/store.d.ts +0 -299
- package/dist/runtime/adapters/interfaces/store.js +0 -0
- package/dist/runtime/adapters/interfaces/stream.d.ts +0 -62
- package/dist/runtime/adapters/interfaces/stream.js +0 -0
- package/dist/runtime/adapters/registry.d.ts +0 -85
- package/dist/runtime/adapters/registry.js +0 -161
- package/dist/runtime/config/index.d.ts +0 -23
- package/dist/runtime/config/index.js +0 -200
- package/dist/runtime/config/types.d.ts +0 -439
- package/dist/runtime/config/types.js +0 -0
- package/dist/runtime/events/eventBus.d.ts +0 -20
- package/dist/runtime/events/eventBus.js +0 -35
- package/dist/runtime/events/types.d.ts +0 -144
- package/dist/runtime/events/types.js +0 -0
- package/dist/runtime/events/utils/scheduleTrigger.d.ts +0 -8
- package/dist/runtime/events/utils/scheduleTrigger.js +0 -71
- package/dist/runtime/events/utils/stallDetector.d.ts +0 -83
- package/dist/runtime/events/utils/stallDetector.js +0 -318
- package/dist/runtime/events/utils/triggerRuntime.d.ts +0 -58
- package/dist/runtime/events/utils/triggerRuntime.js +0 -212
- package/dist/runtime/events/wiring/flowWiring.d.ts +0 -34
- package/dist/runtime/events/wiring/flowWiring.js +0 -1258
- package/dist/runtime/events/wiring/registry.d.ts +0 -19
- package/dist/runtime/events/wiring/registry.js +0 -43
- package/dist/runtime/events/wiring/stateWiring.d.ts +0 -37
- package/dist/runtime/events/wiring/stateWiring.js +0 -92
- package/dist/runtime/events/wiring/streamWiring.d.ts +0 -36
- package/dist/runtime/events/wiring/streamWiring.js +0 -156
- package/dist/runtime/events/wiring/triggerWiring.d.ts +0 -21
- package/dist/runtime/events/wiring/triggerWiring.js +0 -422
- package/dist/runtime/nitro/plugins/00.adapters.d.ts +0 -14
- package/dist/runtime/nitro/plugins/00.adapters.js +0 -73
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.d.ts +0 -5
- package/dist/runtime/nitro/plugins/01.ws-lifecycle.js +0 -69
- package/dist/runtime/nitro/plugins/02.workers.d.ts +0 -2
- package/dist/runtime/nitro/plugins/02.workers.js +0 -92
- package/dist/runtime/nitro/plugins/03.triggers.d.ts +0 -12
- package/dist/runtime/nitro/plugins/03.triggers.js +0 -55
- package/dist/runtime/nitro/routes/webhook.await.d.ts +0 -23
- package/dist/runtime/nitro/routes/webhook.await.js +0 -112
- package/dist/runtime/nitro/routes/webhook.trigger.d.ts +0 -86
- package/dist/runtime/nitro/routes/webhook.trigger.js +0 -73
- package/dist/runtime/nitro/utils/adapters.d.ts +0 -66
- package/dist/runtime/nitro/utils/adapters.js +0 -51
- package/dist/runtime/nitro/utils/awaitPatterns/event.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/event.js +0 -128
- package/dist/runtime/nitro/utils/awaitPatterns/index.d.ts +0 -28
- package/dist/runtime/nitro/utils/awaitPatterns/index.js +0 -55
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.d.ts +0 -16
- package/dist/runtime/nitro/utils/awaitPatterns/schedule.js +0 -83
- package/dist/runtime/nitro/utils/awaitPatterns/time.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/time.js +0 -71
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.d.ts +0 -15
- package/dist/runtime/nitro/utils/awaitPatterns/webhook.js +0 -128
- package/dist/runtime/nitro/utils/defineFunctionConfig.d.ts +0 -378
- package/dist/runtime/nitro/utils/defineFunctionConfig.js +0 -3
- package/dist/runtime/nitro/utils/defineHooks.d.ts +0 -95
- package/dist/runtime/nitro/utils/defineHooks.js +0 -9
- package/dist/runtime/nitro/utils/registerAdapter.d.ts +0 -59
- package/dist/runtime/nitro/utils/registerAdapter.js +0 -13
- package/dist/runtime/nitro/utils/useAwait.d.ts +0 -83
- package/dist/runtime/nitro/utils/useAwait.js +0 -169
- package/dist/runtime/nitro/utils/useEventManager.d.ts +0 -15
- package/dist/runtime/nitro/utils/useEventManager.js +0 -26
- package/dist/runtime/nitro/utils/useFlow.d.ts +0 -66
- package/dist/runtime/nitro/utils/useFlow.js +0 -310
- package/dist/runtime/nitro/utils/useHookRegistry.d.ts +0 -40
- package/dist/runtime/nitro/utils/useHookRegistry.js +0 -25
- package/dist/runtime/nitro/utils/useNventLogger.d.ts +0 -42
- package/dist/runtime/nitro/utils/useNventLogger.js +0 -54
- package/dist/runtime/nitro/utils/useRunContext.d.ts +0 -6
- package/dist/runtime/nitro/utils/useRunContext.js +0 -102
- package/dist/runtime/nitro/utils/useStreamTopics.d.ts +0 -83
- package/dist/runtime/nitro/utils/useStreamTopics.js +0 -94
- package/dist/runtime/nitro/utils/useTrigger.d.ts +0 -150
- package/dist/runtime/nitro/utils/useTrigger.js +0 -311
- package/dist/runtime/nitro/utils/wsPeerManager.d.ts +0 -44
- package/dist/runtime/nitro/utils/wsPeerManager.js +0 -32
- package/dist/runtime/scheduler/index.d.ts +0 -33
- package/dist/runtime/scheduler/index.js +0 -42
- package/dist/runtime/scheduler/scheduler.d.ts +0 -132
- package/dist/runtime/scheduler/scheduler.js +0 -799
- package/dist/runtime/scheduler/types.d.ts +0 -122
- package/dist/runtime/scheduler/types.js +0 -0
- package/dist/runtime/worker/node/runner.d.ts +0 -95
- package/dist/runtime/worker/node/runner.js +0 -272
- package/dist/runtime/worker/python/get_config.py +0 -64
- package/dist/runtime/worker/system/awaitHandlers.d.ts +0 -27
- package/dist/runtime/worker/system/awaitHandlers.js +0 -230
- package/dist/runtime/worker/system/index.d.ts +0 -24
- package/dist/runtime/worker/system/index.js +0 -39
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# nvent — Python helpers for step files
|
|
2
|
+
#
|
|
3
|
+
# This file is written to two places by the nvent Nuxt module:
|
|
4
|
+
# 1. The venv's site-packages/ → for VS Code / Pylance import resolution
|
|
5
|
+
# 2. .nuxt/iii-workers/nvent.py → overrides at runtime (imports real FlowContext from _runtime)
|
|
6
|
+
#
|
|
7
|
+
# The try/except below makes the same file work in both contexts:
|
|
8
|
+
# - Inside a worker process: _runtime is on sys.path → real FlowContext with state/enqueue
|
|
9
|
+
# - During static analysis (VS Code): _runtime not found → inline stubs used instead
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
from typing import Any, Optional
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
# Worker runtime context — _runtime.py is in the same directory on sys.path
|
|
16
|
+
from _runtime import http, queue, cron, FlowContext # noqa: F401
|
|
17
|
+
from iii import ApiRequest, ApiResponse # noqa: F401
|
|
18
|
+
except ImportError:
|
|
19
|
+
# Static analysis / outside worker — provide type-correct stubs
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from iii import ApiRequest, ApiResponse # noqa: F401
|
|
23
|
+
except ImportError:
|
|
24
|
+
class ApiRequest: # type: ignore[no-redef]
|
|
25
|
+
"""HTTP request input for http-triggered Python functions.
|
|
26
|
+
|
|
27
|
+
The engine sends camelCase fields to Python workers:
|
|
28
|
+
req.headers — dict[str, str]
|
|
29
|
+
req.method — 'GET' | 'POST' | ...
|
|
30
|
+
req.pathParams — dict[str, str]
|
|
31
|
+
req.queryParams — dict[str, str]
|
|
32
|
+
req.body — parsed body (dict/list/str), or None for GET/HEAD
|
|
33
|
+
"""
|
|
34
|
+
headers: dict[str, str]
|
|
35
|
+
method: str
|
|
36
|
+
pathParams: dict[str, str]
|
|
37
|
+
queryParams: dict[str, str]
|
|
38
|
+
body: Optional[Any]
|
|
39
|
+
|
|
40
|
+
ApiResponse = object # type: ignore[assignment,misc]
|
|
41
|
+
|
|
42
|
+
def http(method: str, path: str) -> dict:
|
|
43
|
+
"""HTTP trigger: http("POST", "/my-endpoint")"""
|
|
44
|
+
return {"type": "http", "method": method.upper(), "path": path}
|
|
45
|
+
|
|
46
|
+
def queue(topic: str) -> dict:
|
|
47
|
+
"""Queue trigger: queue("order.created")"""
|
|
48
|
+
return {"type": "queue", "topic": topic}
|
|
49
|
+
|
|
50
|
+
def cron(expression: str) -> dict:
|
|
51
|
+
"""Cron trigger: cron("0 0 * * * * *") (7-field: sec min hour dom month dow year)"""
|
|
52
|
+
return {"type": "cron", "expression": expression}
|
|
53
|
+
|
|
54
|
+
class IStream:
|
|
55
|
+
"""Access to the iii Stream module.
|
|
56
|
+
|
|
57
|
+
**Implicit API** (recommended): ``set(item_id, data)`` uses the function's
|
|
58
|
+
flow name as the stream name and the current trace ID as the group ID.
|
|
59
|
+
All steps in the same request chain share the same trace → same channel.
|
|
60
|
+
|
|
61
|
+
**Explicit API**: ``set_in(name, group, item_id, data)`` targets any stream.
|
|
62
|
+
|
|
63
|
+
Example — implicit (most common)::
|
|
64
|
+
|
|
65
|
+
# Returns subscription info for the HTTP client:
|
|
66
|
+
return ApiResponse(statusCode=200, body=ctx.stream.subscription())
|
|
67
|
+
|
|
68
|
+
# Any step in the same trace writes here — no groupId needed:
|
|
69
|
+
await ctx.stream.set("step-1", {"step": 1, "total": 4, "label": "Tokenizing"})
|
|
70
|
+
await ctx.stream.send({"type": "done"})
|
|
71
|
+
|
|
72
|
+
Example — explicit (cross-flow or custom group)::
|
|
73
|
+
|
|
74
|
+
await ctx.stream.set_in("other-flow", "group-abc", "item-1", data)
|
|
75
|
+
"""
|
|
76
|
+
# Implicit helpers
|
|
77
|
+
async def set(self, item_id: str, data: dict) -> None:
|
|
78
|
+
"""Set (create/update) an item in the implicit stream channel (flow + traceId)."""
|
|
79
|
+
...
|
|
80
|
+
async def send(self, data: dict) -> None:
|
|
81
|
+
"""Send a custom event to all subscribers of the implicit stream channel."""
|
|
82
|
+
...
|
|
83
|
+
def subscription(self) -> dict:
|
|
84
|
+
"""Return ``{"streamName": ..., "groupId": ...}`` for the implicit channel.
|
|
85
|
+
Return this from an HTTP handler for the client to subscribe.
|
|
86
|
+
"""
|
|
87
|
+
...
|
|
88
|
+
# Explicit helpers
|
|
89
|
+
async def set_in(self, name: str, group: str, item_id: str, data: dict) -> None:
|
|
90
|
+
"""Set (create/update) an item in an explicit stream group."""
|
|
91
|
+
...
|
|
92
|
+
async def get_item(self, name: str, group: str, item_id: str) -> dict:
|
|
93
|
+
"""Get a single item from a stream group."""
|
|
94
|
+
...
|
|
95
|
+
async def delete_item(self, name: str, group: str, item_id: str) -> None:
|
|
96
|
+
"""Delete an item from a stream group."""
|
|
97
|
+
...
|
|
98
|
+
async def list_items(self, name: str, group: str) -> list:
|
|
99
|
+
"""List all items in a stream group."""
|
|
100
|
+
...
|
|
101
|
+
async def send_to(self, name: str, group: str, data: dict) -> None:
|
|
102
|
+
"""Send a custom event to all subscribers of an explicit stream group."""
|
|
103
|
+
...
|
|
104
|
+
|
|
105
|
+
class ILogger:
|
|
106
|
+
"""Structured logger available as ctx.logger."""
|
|
107
|
+
def info(self, msg: str, data: Any = None) -> None: ...
|
|
108
|
+
def warn(self, msg: str, data: Any = None) -> None: ...
|
|
109
|
+
def error(self, msg: str, data: Any = None) -> None: ...
|
|
110
|
+
def debug(self, msg: str, data: Any = None) -> None: ...
|
|
111
|
+
def trace(self, msg: str, data: Any = None) -> None: ...
|
|
112
|
+
|
|
113
|
+
class IState:
|
|
114
|
+
"""Key-value state store available as ctx.state.
|
|
115
|
+
Scope is automatically bound to the function ID.
|
|
116
|
+
"""
|
|
117
|
+
async def get(self, key: str) -> Any:
|
|
118
|
+
"""Read a value. Returns None if not set."""
|
|
119
|
+
...
|
|
120
|
+
async def set(self, key: str, value: Any) -> None:
|
|
121
|
+
"""Write a value."""
|
|
122
|
+
...
|
|
123
|
+
async def delete(self, key: str) -> None:
|
|
124
|
+
"""Delete a key."""
|
|
125
|
+
...
|
|
126
|
+
async def list(self) -> list:
|
|
127
|
+
"""List all keys in this function's scope."""
|
|
128
|
+
...
|
|
129
|
+
|
|
130
|
+
class FlowContext:
|
|
131
|
+
"""Execution context passed as the second argument to every handler.
|
|
132
|
+
|
|
133
|
+
Example — HTTP step that streams results::
|
|
134
|
+
|
|
135
|
+
async def handler(req: ApiRequest, ctx: FlowContext):
|
|
136
|
+
await ctx.enqueue({"topic": "pipeline.analyze", "data": {"text": req.body["text"]}})
|
|
137
|
+
return ApiResponse(statusCode=200, body=ctx.stream.subscription())
|
|
138
|
+
|
|
139
|
+
Example — queue step that publishes progress::
|
|
140
|
+
|
|
141
|
+
async def handler(data: dict, ctx: FlowContext):
|
|
142
|
+
await ctx.stream.set("step-1", {"step": 1, "total": 4, "label": "Tokenizing"})
|
|
143
|
+
await ctx.stream.set("result", {"done": True, **stats})
|
|
144
|
+
|
|
145
|
+
Multi-trigger step::
|
|
146
|
+
|
|
147
|
+
async def handler(input, ctx: FlowContext):
|
|
148
|
+
return await ctx.match({
|
|
149
|
+
"http": lambda req: ApiResponse(statusCode=200, body={"ok": True}),
|
|
150
|
+
"queue": lambda data: process(data),
|
|
151
|
+
"cron": lambda: run_sweep(),
|
|
152
|
+
})
|
|
153
|
+
"""
|
|
154
|
+
logger: ILogger
|
|
155
|
+
state: IState
|
|
156
|
+
stream: IStream
|
|
157
|
+
trigger_type: str
|
|
158
|
+
|
|
159
|
+
@property
|
|
160
|
+
def stream_name(self) -> str:
|
|
161
|
+
"""The stream name used by implicit ``ctx.stream.set()`` / ``ctx.stream.send()``."""
|
|
162
|
+
...
|
|
163
|
+
|
|
164
|
+
async def enqueue(self, payload: dict) -> None:
|
|
165
|
+
"""Emit a message to a topic.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
await ctx.enqueue({"topic": "order.created", "data": {"id": "x"}})
|
|
169
|
+
```
|
|
170
|
+
"""
|
|
171
|
+
...
|
|
172
|
+
|
|
173
|
+
async def enqueue_named(self, payload: dict) -> dict:
|
|
174
|
+
"""Dispatch directly to a function via a named queue.
|
|
175
|
+
|
|
176
|
+
Unlike ``enqueue()``, this targets a specific function and routes it
|
|
177
|
+
through a named queue for FIFO ordering, concurrency control, or
|
|
178
|
+
custom retry behaviour. Requires the queue to be declared in
|
|
179
|
+
nvent's ``queue_configs``.
|
|
180
|
+
|
|
181
|
+
Returns ``{"messageReceiptId": "..."}`` immediately.
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
result = await ctx.enqueue_named({
|
|
185
|
+
"queue": "orders",
|
|
186
|
+
"function_id": "orders::process",
|
|
187
|
+
"data": {"orderId": "123"},
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
"""
|
|
191
|
+
...
|
|
192
|
+
|
|
193
|
+
async def match(self, handlers: dict[str, Any]) -> Any:
|
|
194
|
+
"""Route to a sub-handler based on the trigger type.
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
return await ctx.match({
|
|
198
|
+
"http": lambda req: ApiResponse(statusCode=200, body={"ok": True}),
|
|
199
|
+
"queue": lambda data: process(data),
|
|
200
|
+
"cron": lambda: run_sweep(),
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
"""
|
|
204
|
+
...
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
__all__ = ["http", "queue", "cron", "FlowContext", "ApiRequest", "ApiResponse"]
|
|
208
|
+
|