Skip to content
Myr

functions.ts

This file

Path

packages/sdk/src/functions.ts

83 lines · 2.5 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–16why, one step back
1import { Ask } from "@repo/protocol/domain/ask";
2import { AskKind } from "@repo/protocol/domain/kind";3import { Territory } from "@repo/protocol/domain/territory";4import { Schema } from "effect";56// The domain's own schemas for a person's handle, a kind's name and a7// module, reached through the domain schemas that hold them, so facts decode8// to the same branded values the rest of the platform uses.9const Handle = Ask.fields.askedBy;1011const KindName = AskKind.fields.name;1213const Module = Territory.fields.module;1415const LandingCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));16

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 17why, one step back
17/** The rule sees these facts and nothing else: no clock, no network, no repo. */

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 18–28why, one step back
18export const ProposalFacts = Schema.Struct({
19 kind: KindName,20 proposer: Handle,21 /** The proposer's landings in the territory that stayed unreverted. */22 record: LandingCount,23 territory: Module,24});2526export type ProposalFacts = typeof ProposalFacts.Type;2728/**

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 29why, one step back
29 * Whether a proposal opens its ask on its own, without a maintainer. Write one

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 30–80why, one step back
30 * only when the kind's data can't say it: `(p) => p.record >= 3`.
31 */32export type OpensAlone = (proposal: ProposalFacts) => boolean;3334export const ClaimantFacts = Schema.Struct({35 handle: Handle,36 kind: KindName,37 /** Their landings in the territory that stayed unreverted. */38 record: LandingCount,39 territory: Module,40 vouched: Schema.Boolean,41});4243export type ClaimantFacts = typeof ClaimantFacts.Type;4445/**46 * Whether a person may claim an ask, when the kinds' `claimers` data can't47 * say it: `(c) => c.vouched || c.record > 0`.48 */49export type Admit = (claimant: ClaimantFacts) => boolean;5051export interface ProjectFunctions {52 readonly admit: Admit | undefined;53 readonly opensAlone: OpensAlone | undefined;54}5556export interface KindFunctions {57 readonly opensAlone: OpensAlone | undefined;58}5960/**61 * The key a definition keeps its functions under. It is a symbol and not62 * enumerable, so encoding, spreading or printing the data never meets them.63 */64export const Functions: unique symbol = Symbol.for("@repo/sdk/Functions");6566export interface WithFunctions<F> {67 readonly [Functions]: F;68}6970export const withFunctions = <A extends Readonly<Record<string, unknown>>, F>(71 data: A,72 functions: F73): A & WithFunctions<F> => {74 const carried = { ...data, [Functions]: functions };7576 Object.defineProperty(carried, Functions, { enumerable: false });7778 return carried;79};80

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

line 81why, one step back
81/** For the rules evaluator: `functionsOf(definition).opensAlone?.(facts)`. */

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 82–83why, one step back
82export const functionsOf = <F>(definition: WithFunctions<F>): F =>
83 definition[Functions];