Skip to content

@lastshotlabs/slingshot-polls

npm install @lastshotlabs/slingshot-polls

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(): RateLimitBackend

Source: packages/slingshot-polls/src/lib/rateLimit.ts

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

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> = {},): SlingshotPackageDefinition

Source: packages/slingshot-polls/src/plugin.ts

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 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 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

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

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

Source: packages/slingshot-polls/src/entities/factories.ts

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

Zod validation schema for PollsPluginConfig.

Validated at plugin construction time and frozen (Rule 12).

Source: packages/slingshot-polls/src/validation/config.ts

FieldDescription
disableRoutesPoll route keys to skip when mounting routes. Default: [].
maxOptionLengthMaximum poll option length in characters. Default: 200.
maxOptionsMaximum number of answer options allowed on a poll. Default: 10.
maxQuestionLengthMaximum poll question length in characters. Default: 500.
mountPathURL path prefix for poll routes. Default: /polls.
rateLimitRate-limiting configuration for poll routes.

Source: packages/slingshot-polls/src/validation/config.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

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

Source: packages/slingshot-polls/src/entities/factories.ts

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 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Source: packages/slingshot-polls/src/types/index.ts