Skip to main content

BYNK_ADAPTER_SRC

Constant BYNK_ADAPTER_SRC 

Source
pub const BYNK_ADAPTER_SRC: &str = "adapter bynk {\n\tuses bynk.locale.types\n\texports capability { Clock, Random, Logger, Fetch, Secrets, Locale, Idempotency, Events }\n\texports transparent { Uuid, Method, FetchError, Request, Response, EventEnvelope }\n\n\t---\n\tA UUID in canonical 8-4-4-4-12 lowercase-hex form.\n\t---\n\ttype Uuid = String where Matches(\"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\")\n\n\t---\n\tAn HTTP request method.\n\t---\n\ttype Method = enum { Get, Post, Put, Delete }\n\n\t---\n\tWhy an outbound `Fetch.send` failed: a network error, a timeout, or a\n\trequest whose headers `Fetch.send` refused to send (`InvalidHeader`). An\n\t`InvalidHeader` request never reaches the network: its `headers` named\n\tContent-Type or Authorization while the matching typed slot was `Some`,\n\tnamed a header the platform owns (`host`, `content-length`, and the other\n\tframing/hop-by-hop headers), named one header twice in different case, or\n\theld a name or value that is not a legal HTTP header; or a typed slot\n\t(`contentType`, `authorization`) held a value that is not a legal header\n\tvalue \u{2014} a secret with a stray newline, say. Retrying cannot fix it.\n\t---\n\ttype FetchError = enum { Network, Timeout, InvalidHeader }\n\n\t---\n\tAn outbound HTTP request, as passed to `Fetch.send`. `contentType` and\n\t`authorization` are the typed slots for the two common headers; `headers`\n\tcarries any other (`User-Agent`, `Accept`, `If-None-Match`, \u{2026}), and an empty\n\tmap (`Map.empty()`) sends none. Header names are case-insensitive. A\n\t`headers` entry for Content-Type or Authorization is accepted only while the\n\tmatching typed slot is `None` \u{2014} when both are given, `Fetch.send` returns\n\t`Err(InvalidHeader)` rather than let one silently win. Names the platform\n\towns \u{2014} `host`, `content-length`, `connection`, `keep-alive`, `te`,\n\t`trailer`, `transfer-encoding`, `upgrade`, `expect` \u{2014} are refused the same\n\tway, as is a duplicate name differing only in case.\n\t---\n\ttype Request = {\n\t\tmethod: Method,\n\t\turl: String,\n\t\tcontentType: Option[String],\n\t\tauthorization: Option[String],\n\t\theaders: Map[String, String],\n\t\tbody: Option[String],\n\t}\n\n\t---\n\tAn HTTP response: a status code, its headers, and a body. `headers` keys\n\tare lowercased (`res.headers.get(\"etag\")`); a header the server repeated\n\tarrives as one value, joined with \", \". That includes `set-cookie`, and\n\tthere the join is lossy: a cookie\'s `Expires` attribute holds a comma, so\n\ta joined `set-cookie` cannot be split back into its cookies reliably.\n\t---\n\ttype Response = {\n\t\tstatus: Int,\n\t\theaders: Map[String, String],\n\t\tbody: String,\n\t}\n\n\t---\n\tRuntime metadata carried alongside an event payload (Events track, slice\n\t2; design/tracks/events.md, spine #936), available as an `on event`\n\thandler\'s optional second parameter. `eventId` is minted once per\n\temission \u{2014} every subscriber of that emission sees the same value, making\n\tit the dedup key for the `Idempotency` capability\'s `dedup`/`remember`\n\tidiom. `publisherId` is the emitting context\'s qualified name, not the\n\temitting agent\'s instance identity: `Events.emit` is legal from a plain,\n\tkeyless service handler with no agent to report, so a context-scoped\n\tidentifier is the only one available uniformly at every legal emission\n\tsite (an amendment to design/bynk-design-notes.md \u{a7}7\'s \"the publisher is\n\tthe emitting agent\" framing). `schemaVersion` is the version the\n\tcross-build schema registry (`bynk.schema.lock`, Events slice 3c) computes\n\tfor the emitting event: unchanged shape keeps its stored version, a purely\n\tadditive shape change (only new defaulted fields) auto-bumps it, and a\n\tnon-additive change fails the build. An explicit `@schema(N)` annotation\n\t(slice 3b) is checked against that computed value rather than trusted\n\toutright \u{2014} a mismatch is a build error, not a silent override.\n\t---\n\ttype EventEnvelope = {\n\t\teventId: String,\n\t\tpublisherId: String,\n\t\temittedAt: Instant,\n\t\tschemaVersion: Int,\n\t}\n\n\t---\n\tReads the current wall-clock time, as Unix milliseconds.\n\t---\n\tcapability Clock {\n\t\tfn now() -> Effect[Instant]\n\t}\n\n\t---\n\tA source of randomness \u{2014} fresh UUIDs, bounded integers and random bytes.\n\n\t`int` draws from a general-purpose generator and is **not** for secrets:\n\tuse `bytes` for tokens, nonces and keys. `bytes(n)` returns `n` bytes from\n\tthe platform\'s cryptographically secure generator (`crypto.getRandomValues`);\n\t`n` must be between 1 and 65,536, and anything else fails the effect with an\n\terror naming the bound.\n\t---\n\tcapability Random {\n\t\tfn uuid() -> Effect[Uuid]\n\t\tfn int(lo: Int, hi: Int) -> Effect[Int]\n\t\tfn bytes(n: Int) -> Effect[Bytes]\n\t}\n\n\t---\n\tStructured logging at info and error levels.\n\t---\n\tcapability Logger {\n\t\tfn info(msg: String) -> Effect[()]\n\t\tfn error(msg: String) -> Effect[()]\n\t}\n\n\t---\n\tPerforms outbound HTTP requests.\n\t---\n\tcapability Fetch {\n\t\tfn send(req: Request) -> Effect[Result[Response, FetchError]]\n\t}\n\n\t---\n\tReads named secrets from the platform\'s secret store.\n\t---\n\tcapability Secrets {\n\t\tfn get(name: String) -> Effect[Option[String]]\n\t}\n\n\t---\n\tReads the current locale for this request/session. Slice 1: always\n\treturns a fixed reference tag (`\"en\"`) on every platform.\n\t---\n\tcapability Locale {\n\t\tfn current() -> Effect[LocaleTag]\n\t}\n\n\t---\n\tMechanical dedup for at-least-once delivery (design notes \u{a7}12). `dedup`\n\tchecks for a cached outcome under `key`; on a cache miss the caller\n\tcomputes its outcome and writes it back with `remember` (`record` is a\n\treserved keyword), which the caller must call to actually cache anything\n\t\u{2014} a `dedup` miss with no matching `remember` call simply recomputes every\n\ttime. `expiresAfter` sets the retention window a call to `remember`\n\testablishes. Slice 0 (design/tracks/idempotency-capability.md): a single\n\tin-memory provider, lost on process restart \u{2014} no durability guarantee yet.\n\t---\n\tcapability Idempotency {\n\t\tfn dedup[T](key: String) -> Effect[Option[T]]\n\t\tfn remember[T](key: String, value: T, expiresAfter: Duration) -> Effect[()]\n\t}\n\n\t---\n\tEmits an event declared by the calling context (Events track, slice 0;\n\tdesign/tracks/events.md, spine #936). Owner-only: the compiler rejects\n\t`emit[E]` when `E` is not an event declared in the emitting context, even\n\twhen `E` is otherwise visible via `consumes`. Fire-and-forget: releases at\n\thandler commit, so an aborted handler emits nothing \u{2014} a `dedup`/`remember`-\n\tstyle write-then-flush the provider itself is responsible for, not a\n\tdistinct control-flow form here. The explicit `[E]` type argument follows\n\tthe `Idempotency.remember[T]` precedent: a generic capability operation\'s\n\ttype parameter is never inferred, even where an argument\'s type would\n\tdetermine it.\n\t---\n\tcapability Events {\n\t\tfn emit[E](event: E) -> Effect[()]\n\t}\n\n\tprovides Clock = ClockProvider\n\n\tprovides Random = RandomProvider\n\n\tprovides Logger = LoggerProvider\n\n\tprovides Fetch = FetchProvider\n\n\tprovides Secrets = SecretsProvider\n\n\tprovides Locale = LocaleProvider\n\n\tprovides Idempotency = IdempotencyProvider given Clock\n\n\tprovides Events = EventsProvider\n}\n";
Expand description

The reserved bynk conformance-surface adapter (env-free core). It has no binding clause — the toolchain supplies one per platform (see Platform::bynk_binding_source).