agentleFS
elbwalkerelbwalker/walkerOS/skills/walkeros-understanding-stores/SKILL.md

walkeros-understanding-stores

Skill354 starsChanged 5 years agoMITView on GitHub

Stores provide key-value storage that other components (sources, transformers, destinations) consume via environment injection. They are the 4th component type in Flow.Json alongside sources, transformers, and destinations. Core principle: Stores are passive infrastructure. They don't process events or participate in chains; they provide state that other components read and write. See packages/core/src/types/store.ts for the canonical interface. All methods can be sync or async (return Promise). Stores hold one canonical value type: structured data (StoreValue), with binary (Uint8Array) as a first-class…

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All methods can be sync or async (return Promise).

    line 37
  2. Very specific:

    Use $store.storeId in a component's env to inject a store instance:

    line 127
  3. Distinctive:

    Use this for the common "cache in front of a slow backing store" pattern (API, GCS, Sheets, etc.).

    line 203
  4. Very specific:

    Read-only store for a third-party API, such as a CRM.

    line 304
  5. Very specific:

    After startFlow(), stores are available on the collector instance:

    line 324
  6. Very specific:

    Every store package must export schemas and examples via dev.ts, matching the convention used by sources and destinations:

    line 382
  7. Very specific:

    Add ./dev export to package.json:

    line 424

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Understanding walkerOS Stores

Overview

Stores provide key-value storage that other components (sources, transformers, destinations) consume via environment injection. They are the 4th component type in Flow.Json alongside sources, transformers, and destinations.

Core principle: Stores are passive infrastructure. They don't process events or participate in chains; they provide state that other components read and write.

Store interface

See packages/core/src/types/store.ts for the canonical interface.

Instance

PropertyTypePurposeRequired
typestringStore type identifierRequired
configStore.ConfigSettings and envRequired
get(key) => StoreValue | undefinedRead a valueRequired
set(key, value, ttl?) => voidWrite a value (see below)Required
delete(key) => voidRemove a valueRequired
destroyDestroyFnCleanup on shutdownOptional

All methods can be sync or async (return Promise).

Value type and file mode

Stores hold one canonical value type: structured data (StoreValue), with binary (Uint8Array) as a first-class leaf. StoreValue is string | number | boolean | null | Uint8Array | StoreValue[] | { [key: string]: StoreValue } (undefined is reserved as the "miss" sentinel and is never a stored value). A shared codec in @walkeros/core/node (serializeStoreValue / deserializeStoreValue, Node only, StoreCodecError on a bad value) round-trips that value to and from each backing.

Store.Config.file?: boolean (default false) picks the mode, decided once at init:

  • Structured (default): values are StoreValue data, serialized by the shared codec.
  • File (file: true): a byte-native backend (fs, S3, GCS) persists raw bytes byte-exact. set() accepts a Uint8Array or string and stores it untouched; get() hands the exact bytes back. Use for serving assets such as walker.js. The Sheets store is structured-only and rejects file: true at init.

TTL is owned by the cache layer, not the store. The store persists values; a cache wrapper manages expiry. The ttl argument of set is only a hint for TTL-native backends: the fs, S3, GCS and Sheets stores ignore it and keep the value. flow_validate warns when a store sets both file: true and cache, and when a @walkeros/server-transformer-file is wired to a byte-native store that does not set file: true.

Init function (context pattern)

Stores use the same context-based init pattern as other components:

import type { Store } from '@walkeros/core';

export const storeMyStore: Store.Init = (context) => {
  const { config, env, logger, id } = context;
  const settings = config.settings || {};

  return {
    type: 'my-store',
    config,
    get(key) {
      /* ... */
    },
    set(key, value, ttl) {
      /* ... */
    },
    delete(key) {
      /* ... */
    },
    destroy() {
      /* cleanup */
    },
  };
};

Context contains:

PropertyTypePurpose
configStore.ConfigSettings from flow config
envStore.EnvEnvironment dependencies
loggerLogger.InstanceScoped logger
idstringStore identifier
collectorCollector.InstanceReference to collector

Lifecycle

Stores have the simplest lifecycle of all component types:

Startup:  Stores → Destinations → Transformers → Sources
Shutdown: Sources → Destinations → Transformers → Stores
  • Init first: Stores init before all other components so they're available when sources/transformers/destinations start
  • Destroy last: Stores destroy after all other components so transformers can flush during their own destroy
  • No lazy init: Unlike destinations, stores don't support require or deferred activation; they are always eager

Wiring stores via $store.

Bundled mode (flow.json)

Use $store.storeId in a component's env to inject a store instance:

{
  "stores": {
    "assets": {
      "package": "@walkeros/server-store-fs",
      "config": { "file": true, "settings": { "basePath": "./public" } }
    }
  },
  "transformers": {
    "file": {
      "package": "@walkeros/server-transformer-file",
      "config": { "settings": { "prefix": "/static" } },
      "env": { "store": "$store.assets" }
    }
  }
}

The bundler resolves $store.assets to a runtime reference. Invalid references are caught at build time. walkeros validate also catches typos at validation time, including unknown store names and the colon-instead-of-dot mistake (e.g. $store:assets is flagged with the suggested form $store.assets).

Integrated mode (TypeScript)

Pass the store definition object itself, no $store. prefix:

import { startFlow } from '@walkeros/collector';
import { storeFsInit } from '@walkeros/server-store-fs';
import { transformerFile } from '@walkeros/server-transformer-file';

const assets = {
  code: storeFsInit,
  config: { file: true, settings: { basePath: './public' } },
};

await startFlow({
  stores: { assets },
  transformers: {
    file: {
      code: transformerFile,
      env: { store: assets }, // same object as stores.assets
    },
  },
});

Note: In integrated mode, put the same store definition object in stores and in env. The collector replaces it with the initialized instance at startup, matched by object identity (a copy does not match), and only for top-level env keys. The $store. string prefix is a bundler feature: in startFlow it stays a plain string.

Available stores

Built-in cache tier (__cache)

The collector ships a built-in in-memory cache with LRU eviction, TTL, and entry/byte caps. Enable it on any store by setting Flow.Store.cache. No separate package import needed:

{
  "stores": {
    "files": {
      "package": "@walkeros/server-store-fs",
      "config": { "settings": { "basePath": "./data" } },
      "cache": { "rules": [{ "ttl": 60 }] }
    }
  }
}

Use this for the common "cache in front of a slow backing store" pattern (API, GCS, Sheets, etc.).

@walkeros/server-store-fs (filesystem)

File-based store for serving static assets. Server-only.

import { storeFsInit } from '@walkeros/server-store-fs';

@walkeros/server-store-s3 (S3-compatible object storage)

S3-compatible store using s3mini (~26 KB minified, zero dependencies). Works with AWS S3, Cloudflare R2, Scaleway, DigitalOcean Spaces, Backblaze B2, MinIO, and any S3-compatible provider. Structured by default (stored as application/json); set file: true to serve raw bytes byte-exact with the real mime. Server-only.

import { storeS3Init } from '@walkeros/server-store-s3';

Settings:

SettingTypeRequiredDefaultPurpose
bucketstringYes-S3 bucket name
endpointstringYes-S3-compatible endpoint URL
accessKeyIdstringYes-S3 access key ID
secretAccessKeystringYes-S3 secret access key
regionstringNo"auto"AWS region (SigV4 signing)
prefixstringNo-Key prefix for scoping

Primary use case: Serving static files in managed deployments where files live in a bucket rather than being baked into a Docker image.

@walkeros/server-store-gcs (Google Cloud Storage)

Zero-dependency GCS store using raw fetch + GCS JSON API. Built-in auth: ADC on Cloud Run / GKE, or explicit service account JWT. Server-only.

import { storeGcsInit } from '@walkeros/server-store-gcs';

Settings:

SettingTypeRequiredDefaultPurpose
bucketstringYes-GCS bucket name
prefixstringNo-Key prefix for scoping

Credentials live at config.credentials (sibling of settings): a service-account JSON (string | object) for non-GCP environments, set as $secret.<NAME> (an unset secret stops the flow at startup); omit it for ADC. A value missing client_email or private_key is ignored without a log line, and the store falls back to ADC, the runtime's default credentials.

Primary use case: Serving static files on GCP infrastructure (Cloud Run, GKE) where ADC handles authentication.

@walkeros/server-store-sheets (Google Sheets)

Zero-dependency Google Sheets store using raw fetch + Sheets v4 REST API. One row per key, one cell per value (JSON-serialized). Built-in auth shared with the GCS store. Server-only. Structured-only: cells hold structured JSON, so it rejects file: true at init and rejects values carrying a binary (Uint8Array) leaf. Use fs, S3, or GCS for byte-exact serving.

import { storeSheetsInit } from '@walkeros/server-store-sheets';

Settings:

SettingTypeRequiredDefaultPurpose
idstringYes-Spreadsheet ID (segment in URL)
sheetstringNo'Sheet1'Sheet (tab) name
keystringNo'A'Column letter for keys
valuestringNo'B'Column letter for JSON values
headerRowsnumberNo1Header rows to skip when reading

Credentials live at config.credentials (sibling of settings): a service-account JSON (string | object) for non-GCP environments, set as $secret.<NAME> (an unset secret stops the flow at startup); omit it for ADC. A value that is not valid JSON, or is missing client_email or private_key, is ignored without a log line, and the store falls back to ADC, the runtime's default credentials.

Primary use case: Demos and small prototypes where the spreadsheet is the operator-facing UI for tweaking lookup data. Quota: 60 read and 60 write requests per minute per user per project. Enable the built-in cache via Flow.Store.cache on the store declaration to absorb the quota, otherwise quota burns in seconds. Not a production CRM substitute. See Website: Sheets Store for the cache-wiring example.

@walkeros/server-store-api (third-party HTTP API)

Read-only store for a third-party API, such as a CRM. settings.url is an absolute URL with one {key} placeholder after the host; each get is one GET with the encoded key. A 404, 204 or JSON null is a miss; any other failure throws a StepError. Pass an optional bearer token as config.credentials ({ "token": "$secret.NAME" }). set, delete and file: true are refused. Misses are not cached by the cache block.

import { storeApiInit } from '@walkeros/server-store-api';

Stores in flow config

Declare any store consumed by one or more components in the stores section of the flow config and wire it via $store.<id> in component env. The built-in cache tier (Flow.Store.cache) covers the "fast in-memory cache in front of a slow backing store" pattern without a separate memory store.

Accessing stores at runtime

After startFlow(), stores are available on the collector instance:

const { collector } = await startFlow({
  stores: {
    files: { code: storeFsInit, config: { settings: { basePath: './data' } } },
  },
});

// Read/write
await collector.stores.files.set('key', 'value'); // fs keeps it, no expiry
const value = await collector.stores.files.get('key');
await collector.stores.files.delete('key');

Hooks

Store operations (get, set, delete) are wrapped with useHooks during initialization, enabling pre/post interception via the collector's hooks system.

Available hook names:

Hook namePre hookPost hook
StoreGetpreStoreGetpostStoreGet
StoreSetpreStoreSetpostStoreSet
StoreDeletepreStoreDeletepostStoreDelete

Hooks fire on every store operation regardless of which component triggered it (cache system, transformer via env, destination via env, direct access on collector.stores).

const { collector } = await startFlow({
  stores: {
    files: { code: storeFsInit, config: { settings: { basePath: './data' } } },
  },
});

// Intercept all store reads
collector.hooks.preStoreGet = ({ fn }, key) => {
  console.log('Reading key:', key);
  return fn(key);
};

Key differences from other components

AspectSources/Transformers/DestinationsStores
Event flowParticipate in push chainNo push, no chain
next/beforeChain connection fieldsNone (passive)
LifecycleInit after storesInit first, destroy last
requireDeferred activation supportedAlways eager
Interfacepush(event, context)get/set/delete(key)

Dev exports (dev.ts)

Every store package must export schemas and examples via dev.ts, matching the convention used by sources and destinations:

Required files

src/
├── schemas/
│   ├── settings.ts   # Zod schema for store settings
│   └── index.ts      # Re-export + zodToSchema() conversion
├── examples/
│   └── index.ts      # Example Store.Config objects
└── dev.ts            # export * as schemas; export * as examples

Schema pattern

// src/schemas/settings.ts
import { z } from '@walkeros/core/dev';

export const SettingsSchema = z.object({
  mySetting: z.string().describe('Setting description for docs and MCP'),
});

export type Settings = z.infer<typeof SettingsSchema>;

// src/schemas/index.ts
import { zodToSchema } from '@walkeros/core/dev';
import { SettingsSchema } from './settings';
export { SettingsSchema, type Settings } from './settings';
export const settings = zodToSchema(SettingsSchema);

tsup + package.json

// tsup.config.ts
import { defineConfig, buildModules, buildDev } from '@walkeros/config/tsup';
export default defineConfig([buildModules(), buildDev()]);

Add ./dev export to package.json:

"./dev": {
  "types": "./dist/dev.d.ts",
  "import": "./dist/dev.mjs",
  "require": "./dist/dev.js"
}

Why this matters

  • buildDev() generates dist/walkerOS.json at build time
  • MCP tools fetch walkerOS.json from CDN for package discovery and schema validation
  • Website docs import that walkerOS.json and render the settings with <Configuration type="store" data={data} /> instead of hardcoded markdown tables
  • Without dev.ts, a store is invisible to MCP and docs tables rot

Hints (Optional)

Stores can optionally export hints: lightweight, actionable context for AI agents beyond what schemas and examples already provide. Create src/hints.ts:

import type { Hint } from '@walkeros/core';

export const hints: Hint.Hints = {
  'persistence-behavior': {
    text: 'Describes persistence guarantees. See settings schema for options.',
  },
};

Export from src/dev.ts alongside schemas and examples:

export * as schemas from './schemas';
export * as examples from './examples';
export { hints } from './hints';

Most stores don't need hints; only add them for non-obvious behaviors, prerequisites, or troubleshooting patterns.

Setup (optional)

Stores can implement an optional setup() lifecycle to provision external resources, for example creating a SQLite table, initializing an S3 bucket, or running a one-off schema migration. Setup is never invoked by the runtime, push, init, or deploy. It runs only when an operator explicitly types walkeros setup store.<name>.

The signature is (ctx: LifecycleContext<Config<T>, Env<T>>) => Promise<unknown>, where LifecycleContext carries { id, config, env, logger }. Idempotency is the package's responsibility: the framework adds no opinion. Use resolveSetup(ctx.config.setup, DEFAULTS) from @walkeros/core to normalize the boolean | object shape into a concrete options object.

See walkeros-create-destination, walkeros-create-source, walkeros-understanding-destinations, walkeros-understanding-sources, and the walkeros setup CLI documentation for the authoring template and operator workflow.

Related Skills

  • walkeros-understanding-flow - Architecture and Flow structure
  • walkeros-understanding-transformers - Transformer interface and env pattern
  • walkeros-using-store-cache - Store-level cache and the declarative state block for fetch/stash without $code:, including state.mapping to pick and shape what a lookup returns (paths relative to the value read, result merged into the target, declared fallbacks applied on a miss). state never uses a file: true store. Full reference: Website: State
  • walkeros-using-cli - Bundling flows with stores

Source files:

  • packages/core/src/types/store.ts - Store types
  • packages/collector/src/store.ts - initStores implementation
  • packages/server/stores/fs/src/ - Filesystem store package
  • packages/server/stores/s3/src/ - S3 store package
  • packages/server/stores/gcs/src/ - GCS store package
  • packages/server/stores/sheets/src/ - Google Sheets store package

Documentation:

  • Website: Flow - Flow configuration
  • Website: Stores - Stores overview
  • Website: S3 Store - S3 store documentation
  • Website: FS Store - Filesystem store documentation
  • Website: GCS Store - GCS store documentation
  • Website: Sheets Store - Google Sheets store documentation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.