Hyperlinkv0.8.0-beta.28

Store

Store.Serviceconstsrc/Store.ts:1450
<Self>(id: string): <const Args extends ReadonlyArray<unknown>>(
  ...args: Args
) => IsSingleStoreInput<Input> extends true
  ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>>
  : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>

Declare an app store — class extends with layerMemory / layer.

Three input shapes:

  • Single store — bare registration: QueueHyperlink.store(Mail)yield* MailStore
  • Tag-keyed multi — array: [QueueHyperlink.store(Mail), …]yield* AppStore.at(Mail)
  • Custom-keyed — object: { mail: QueueHyperlink.store(Mail), … }yield* AppStore.at("mail")

layerMemory uses in-memory refs. layer({ filename }) persists to SQLite (filename required).

constructorslayerMemorylayer
Source src/Store.ts:145011 lines
export const Service = <Self>(id: string) => {
  const define = defineStoreTag<Self, typeof id extends string ? typeof id : never>(id);
  return <const Args extends ReadonlyArray<unknown>>(...args: Args) => {
    type Input = Args extends readonly [infer Only] ? Only : Args;
    const input = (args.length === 1 ? args[0]! : args) as Input;
    const storeClass = define(input);
    return attachStoreLayers<Self, string, typeof storeClass>(storeClass) as IsSingleStoreInput<Input> extends true
      ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>>
      : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>;
  };
};