app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

local-records.ts (3568B)


      1 // Local record vocabulary, not Nostr schemas, installed identity or effect
      2 // capabilities. Storage codecs admit structure; repositories own CAS/effects.
      3 // JSON-shaped own enumerable data fields only; no getters are acquired.
      4 export function exactLocalFields(
      5   value: unknown,
      6   fields: readonly string[]
      7 ): value is Record<string, unknown> {
      8   if (typeof value !== 'object' || value === null || Array.isArray(value))
      9     return false;
     10   let count = 0;
     11   function own(key: string): boolean {
     12     const descriptor = Object.getOwnPropertyDescriptor(value, key);
     13     return (
     14       descriptor !== undefined &&
     15       descriptor.get === undefined &&
     16       descriptor.set === undefined
     17     );
     18   }
     19   for (const key in value) {
     20     if (!fields.includes(key) || !own(key)) return false;
     21     count++;
     22   }
     23   return count === fields.length;
     24 }
     25 export type PublicDraftForm = Readonly<{
     26   title: string;
     27   description: string;
     28   location: string;
     29   amount: string;
     30   currency: string;
     31   unit: string;
     32   quantity: string;
     33   contactType: '' | 'email' | 'phone' | 'https';
     34   contactValue: string;
     35 }>;
     36 export type PublicDraftRecord = Readonly<{
     37   schema: 1;
     38   family: 'public_draft';
     39   owner: string;
     40   id: string;
     41   revision: number;
     42   savedAtMilliseconds: number;
     43   form: PublicDraftForm;
     44 }>;
     45 export type PublicCaptureSource =
     46   | Readonly<{ type: 'draft'; id: string; revision: number }>
     47   | Readonly<{ type: 'public_head'; wire: string }>;
     48 export type PreferenceCaptureSource = Readonly<{
     49   type: 'inbox_head';
     50   // Null retains no base event; it never proves global absence/lookup readiness.
     51   wire: string | null;
     52 }>;
     53 export type CapturedTemplate<Kind extends 30402 | 5 | 10050> = Readonly<{
     54   kind: Kind;
     55   wire: string;
     56   hash: string;
     57   targets: readonly string[];
     58   policyFingerprint: string;
     59 }>;
     60 export type SignedPublicArtifact = Readonly<{
     61   eventId: string;
     62   wire: string;
     63 }>;
     64 // Recorded local observation metadata, not independently proven relay/operator
     65 // evidence. Exact readback and a named ACK remain distinct, even when both exist.
     66 export type PublicTargetReceipt = Readonly<{
     67   actionId: string;
     68   origin: string;
     69   role: 'publication' | 'preference';
     70   attempt: number;
     71   eventId: string;
     72   status: 'accepted' | 'refused' | 'timed_out' | 'unknown' | 'stopped';
     73   observedAtMilliseconds: number;
     74   readbackWire: string | null;
     75   // Preference-only actual discovery source; origin remains the ACK write target.
     76   // Absence is legacy metadata, never an inferred cross-source observation.
     77   readbackOrigin?: string;
     78 }>;
     79 export type PublicOperationRecord = Readonly<{
     80   schema: 1;
     81   family: 'public_operation';
     82   owner: string;
     83   id: string;
     84   revision: number;
     85   source: PublicCaptureSource;
     86   capture: CapturedTemplate<30402 | 5>;
     87   artifact: SignedPublicArtifact | null;
     88   receipts: readonly PublicTargetReceipt[];
     89 }>;
     90 export type PreferenceOperationRecord = Readonly<{
     91   schema: 1;
     92   family: 'preference_operation';
     93   owner: string;
     94   id: string;
     95   revision: number;
     96   source: PreferenceCaptureSource;
     97   consent: 'explicit_review';
     98   capture: CapturedTemplate<10050>;
     99   artifact: SignedPublicArtifact | null;
    100   receipts: readonly PublicTargetReceipt[];
    101 }>;
    102 // Private body/subject/contact/product associations have no member in this
    103 // public union. Encrypted private-send records retain their own later owner.
    104 export type PublicRecord =
    105   PublicDraftRecord | PublicOperationRecord | PreferenceOperationRecord;
    106 export type ConversationMappingRecord = Readonly<{
    107   schema: 1;
    108   family: 'conversation_handle';
    109   owner: string;
    110   id: string;
    111   peer: string;
    112 }>;