@lastshotlabs/slingshot-polls
npm install @lastshotlabs/slingshot-polls
Functions
Section titled “Functions”createInMemoryRateLimiter
Section titled “createInMemoryRateLimiter”Per-operation rate limiting for polls.
Ships with an in-memory sliding window backend. A Redis-backed backend can
be added later by implementing the RateLimitBackend interface.
function createInMemoryRateLimiter(): RateLimitBackendSource: packages/slingshot-polls/src/lib/rateLimit.ts
createPollSourcePolicy
Section titled “createPollSourcePolicy”Poll policy factories.
Polls are content-agnostic — the poll entity has no idea whether it was
created inside a chat room or a community thread. Authorization is
delegated to consumer packages via definePolicyDispatch on the
sourceType discriminator field.
Handler maps are caller-provided (owned by the package closure per Rule 3),
not module-scoped. Per-source-type handlers are declared at construction
time on the sourceHandlers and voteHandlers fields of the polls package
config; there is no runtime registration API.
function createPollSourcePolicy(handlers: Map<string, PolicyResolver<PollRecord, Partial<PollRecord>>>,): PolicyResolver<PollRecord, Partial<PollRecord>>Source: packages/slingshot-polls/src/policy/index.ts
createPollsPackage
Section titled “createPollsPackage”Polls package factory.
Creates a SlingshotPackageDefinition that mounts the Poll and PollVote
entities, the vote and create guards, the results route, and the auto-close
sweep interval.
Every adapter, middleware, sweep handle, and rate-limit tracker is built via a factory that captures state in closure (Rule 3). Multiple package instances in the same process do not share state.
function createPollsPackage(rawConfig: Partial<PollsPluginConfig> = {},): SlingshotPackageDefinitionSource: packages/slingshot-polls/src/plugin.ts
createPollVotePolicy
Section titled “createPollVotePolicy”Poll policy factories.
Polls are content-agnostic — the poll entity has no idea whether it was
created inside a chat room or a community thread. Authorization is
delegated to consumer packages via definePolicyDispatch on the
sourceType discriminator field.
Handler maps are caller-provided (owned by the package closure per Rule 3),
not module-scoped. Per-source-type handlers are declared at construction
time on the sourceHandlers and voteHandlers fields of the polls package
config; there is no runtime registration API.
function createPollVotePolicy(handlers: Map<string, PolicyResolver<PollVoteRecord, Partial<PollVoteRecord>>>,): PolicyResolver<PollVoteRecord, Partial<PollVoteRecord>>Source: packages/slingshot-polls/src/policy/index.ts
POLL_SOURCE_POLICY_KEY
Section titled “POLL_SOURCE_POLICY_KEY”Poll policy factories.
Polls are content-agnostic — the poll entity has no idea whether it was
created inside a chat room or a community thread. Authorization is
delegated to consumer packages via definePolicyDispatch on the
sourceType discriminator field.
Handler maps are caller-provided (owned by the package closure per Rule 3),
not module-scoped. Per-source-type handlers are declared at construction
time on the sourceHandlers and voteHandlers fields of the polls package
config; there is no runtime registration API.
Source: packages/slingshot-polls/src/policy/index.ts
POLL_VOTE_POLICY_KEY
Section titled “POLL_VOTE_POLICY_KEY”Poll policy factories.
Polls are content-agnostic — the poll entity has no idea whether it was
created inside a chat room or a community thread. Authorization is
delegated to consumer packages via definePolicyDispatch on the
sourceType discriminator field.
Handler maps are caller-provided (owned by the package closure per Rule 3),
not module-scoped. Per-source-type handlers are declared at construction
time on the sourceHandlers and voteHandlers fields of the polls package
config; there is no runtime registration API.
Source: packages/slingshot-polls/src/policy/index.ts
Constants
Section titled “Constants”CLIENT_SAFE_POLL_EVENTS
Section titled “CLIENT_SAFE_POLL_EVENTS”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
A poll attached to a piece of content. Created alongside the content
(the content stores the resulting pollId in its sidecar) and
referenced by every consumer package via that ID.
Polls are content-agnostic: sourceType is a free-form string like
'chat:message' or 'community:thread' so consumers can query their
own polls without this package knowing about their entities.
Source: packages/slingshot-polls/src/entities/poll.ts
POLL_VOTE_ERRORS
Section titled “POLL_VOTE_ERRORS”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
pollFactories
Section titled “pollFactories”Source: packages/slingshot-polls/src/entities/factories.ts
pollOperations
Section titled “pollOperations”Named operations for Poll and PollVote entities.
Standard operations use op.lookup, op.transition, and op.aggregate.
The results handler is mounted manually in the plugin — it needs
cross-entity access (poll + votes) that a single entity’s op.custom
factory cannot provide.
Source: packages/slingshot-polls/src/operations/index.ts
Public contract for slingshot-polls.
Cross-package consumers resolve PollsRuntimeCap through
ctx.capabilities.require(...) to read the active polls runtime
(poll/vote adapters, sweep handle). The legacy plugin-state slot at
POLLS_RUNTIME_KEY is still published in parallel during the bridge period.
Source: packages/slingshot-polls/src/public.ts
pollsPluginConfigSchema
Section titled “pollsPluginConfigSchema”Zod validation schema for PollsPluginConfig.
Validated at plugin construction time and frozen (Rule 12).
Source: packages/slingshot-polls/src/validation/config.ts
PollsPluginConfigSchema
Section titled “PollsPluginConfigSchema”Config Fields
Section titled “Config Fields”| Field | Description |
|---|---|
disableRoutes | Poll route keys to skip when mounting routes. Default: []. |
maxOptionLength | Maximum poll option length in characters. Default: 200. |
maxOptions | Maximum number of answer options allowed on a poll. Default: 10. |
maxQuestionLength | Maximum poll question length in characters. Default: 500. |
mountPath | URL path prefix for poll routes. Default: /polls. |
rateLimit | Rate-limiting configuration for poll routes. |
Source: packages/slingshot-polls/src/validation/config.ts
PollsRuntimeCap
Section titled “PollsRuntimeCap”Public contract for slingshot-polls.
Cross-package consumers resolve PollsRuntimeCap through
ctx.capabilities.require(...) to read the active polls runtime
(poll/vote adapters, sweep handle). The legacy plugin-state slot at
POLLS_RUNTIME_KEY is still published in parallel during the bridge period.
Source: packages/slingshot-polls/src/public.ts
PollVote
Section titled “PollVote”A single vote cast against a poll. One row per user per selected
option — multi-select polls allow multiple rows for the same
(pollId, userId) pair with different optionIndex values.
Source: packages/slingshot-polls/src/entities/pollVote.ts
pollVoteFactories
Section titled “pollVoteFactories”Source: packages/slingshot-polls/src/entities/factories.ts
pollVoteOperations
Section titled “pollVoteOperations”Named operations for Poll and PollVote entities.
Standard operations use op.lookup, op.transition, and op.aggregate.
The results handler is mounted manually in the plugin — it needs
cross-entity access (poll + votes) that a single entity’s op.custom
factory cannot provide.
Source: packages/slingshot-polls/src/operations/index.ts
Interfaces
Section titled “Interfaces”PollClosedEvent
Section titled “PollClosedEvent”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollCreatedEvent
Section titled “PollCreatedEvent”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollCreateInput
Section titled “PollCreateInput”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollDeletedEvent
Section titled “PollDeletedEvent”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollRecord
Section titled “PollRecord”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollResult
Section titled “PollResult”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollResultsParams
Section titled “PollResultsParams”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollResultsResponse
Section titled “PollResultsResponse”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsPluginConfig
Section titled “PollsPluginConfig”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsPluginState
Section titled “PollsPluginState”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitBucket
Section titled “PollsRateLimitBucket”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitConfig
Section titled “PollsRateLimitConfig”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitRule
Section titled “PollsRateLimitRule”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteCreateInput
Section titled “PollVoteCreateInput”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollVotedEvent
Section titled “PollVotedEvent”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteRecord
Section titled “PollVoteRecord”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteRetractedEvent
Section titled “PollVoteRetractedEvent”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
RateLimitBackend
Section titled “RateLimitBackend”Per-operation rate limiting for polls.
Ships with an in-memory sliding window backend. A Redis-backed backend can
be added later by implementing the RateLimitBackend interface.
Source: packages/slingshot-polls/src/lib/rateLimit.ts
PollPolicyKey
Section titled “PollPolicyKey”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollsRouteKey
Section titled “PollsRouteKey”Public types for @lastshotlabs/slingshot-polls.
All consumer-facing types are defined here and re-exported from the package entry point. Internal types live in implementation files.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteErrorCode
Section titled “PollVoteErrorCode”Source: packages/slingshot-polls/src/types/index.ts