app

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

food-writer-cases.ts (1684B)


      1 import {
      2   buildFoodTemplate,
      3   type FoodDraft
      4 } from '../../src/lib/contracts/food-availability-v1/write.ts';
      5 import { foodUnits } from '../../src/lib/contracts/food-availability-v1/values.ts';
      6 const base: FoodDraft = {
      7   identifier: 'writer-fixed-id',
      8   title: 'Fresh food',
      9   description: 'Fresh food available locally.',
     10   location: 'Victoria',
     11   published_at: 1700000000,
     12   created_at: 1700000060,
     13   amount: '9999999999999999999999999999',
     14   currency: 'CAD',
     15   unit: 'g',
     16   quantity: '10',
     17   status: 'active'
     18 };
     19 const drafts: readonly FoodDraft[] = [
     20   ...foodUnits.map((unit) => ({ ...base, unit, identifier: `writer-${unit}` })),
     21   {
     22     ...base,
     23     identifier: 'writer-free-unspecified',
     24     amount: '0',
     25     quantity: undefined
     26   },
     27   { ...base, identifier: 'writer-sold', status: 'sold' },
     28   {
     29     ...base,
     30     identifier: 'writer-unicode',
     31     title: '🥕',
     32     description: '🥕'.repeat(241),
     33     contact: {
     34       type: 'https',
     35       value: 'https://farm.example/contact',
     36       public: true
     37     }
     38   },
     39   {
     40     ...base,
     41     identifier: 'writer-email',
     42     contact: { type: 'email', value: 'seller@example.com', public: true }
     43   },
     44   {
     45     ...base,
     46     identifier: 'writer-phone',
     47     contact: { type: 'phone', value: '+12505550123', public: true }
     48   },
     49   { ...base, identifier: 'writer-max-content', description: 'x'.repeat(16384) }
     50 ];
     51 export const webTemplates = drafts.map((draft, index) => {
     52   const result = buildFoodTemplate(draft);
     53   if (!result.ok) throw new Error(result.error.code);
     54   return {
     55     id: `web_writer_${index.toString().padStart(3, '0')}`,
     56     created_at: draft.created_at,
     57     wire_parts: result.wire_parts,
     58     summary: result.summary
     59   };
     60 });