<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:
WorkPool.store(Mail)→yield* MailStore - Tag-keyed multi — array:
[WorkPool.store(Mail), …]→yield* AppStore.at(Mail) - Custom-keyed — object:
{ mail: WorkPool.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 const Service: <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:
WorkPool.store(Mail) → yield* MailStore
- Tag-keyed multi — array:
[WorkPool.store(Mail), …] → yield* AppStore.at(Mail)
- Custom-keyed — object:
{ mail: WorkPool.store(Mail), … } → yield* AppStore.at("mail")
layerMemory uses in-memory refs. layer({ filename }) persists to SQLite (filename required).
Service = <function (type parameter) Self in <Self>(id: string): <const Args extends ReadonlyArray<unknown>>(...args: Args) => IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Self>(id: stringid: string) => {
const const define: <
const Args extends ReadonlyArray<unknown>
>(
...args: Args
) => IsSingleStoreInput<
InputOfArgs<Args>
> extends true
? SingleStoreTagClass<
Self,
string,
ContractForSingleInput<InputOfArgs<Args>>
>
: StoreTagClass<
Self,
string,
RegsOfStoreInput<InputOfArgs<Args>>
>
define = defineStoreTag<Self, string>(id: string): <Args>(...args: Args) => IsSingleStoreInput<InputOfArgs<Args>> extends true ? SingleStoreTagClass<Self, string, ContractForSingleInput<InputOfArgs<Args>>> : StoreTagClass<Self, string, RegsOfStoreInput<InputOfArgs<Args>>>defineStoreTag<function (type parameter) Self in <Self>(id: string): <const Args extends ReadonlyArray<unknown>>(...args: Args) => IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Self, typeof id: stringid extends string ? typeof id: stringid : never>(id: stringid);
return <const function (type parameter) Args in <const Args extends ReadonlyArray<unknown>>(...args: Args): IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Args extends interface ReadonlyArray<T>ReadonlyArray<unknown>>(...args: const Args extends ReadonlyArray<unknown>args: function (type parameter) Args in <const Args extends ReadonlyArray<unknown>>(...args: Args): IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Args) => {
type type Input = Args extends readonly [
infer Only
]
? Only
: Args
Input = function (type parameter) Args in <const Args extends ReadonlyArray<unknown>>(...args: Args): IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Args extends readonly [infer function (type parameter) OnlyOnly] ? function (type parameter) OnlyOnly : function (type parameter) Args in <const Args extends ReadonlyArray<unknown>>(...args: Args): IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Args;
const const input: Inputinput = (args: const Args extends ReadonlyArray<unknown>args.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 1 ? args: const Args extends ReadonlyArray<unknown>args[0]! : args: const Args extends ReadonlyArray<unknown>args) as type Input = Args extends readonly [
infer Only
]
? Only
: Args
Input;
const const storeClass: IsSingleStoreInput<Input> extends true
? SingleStoreTagClass<
Self,
string,
ContractForSingleInput<Input>
>
: StoreTagClass<
Self,
string,
RegsOfStoreInput<Input>
>
storeClass = const define: <readonly [Input]>(args_0: Input) => IsSingleStoreInput<InputOfArgs<Args>> extends true ? SingleStoreTagClass<Self, Id, ContractForSingleInput<InputOfArgs<Args>>> : StoreTagClass<Self, Id, RegsOfStoreInput<InputOfArgs<Args>>>define(const input: Inputinput);
return const attachStoreLayers: <Self, string, IsSingleStoreInput<Input> extends true ? SingleStoreTagClass<Self, string, ContractForSingleInput<Input>> : StoreTagClass<Self, string, RegsOfStoreInput<Input>>>(storeClass: IsSingleStoreInput<Input> extends true ? SingleStoreTagClass<Self, string, ContractForSingleInput<Input>> : StoreTagClass<Self, string, RegsOfStoreInput<Input>>) => (IsSingleStoreInput<Input> extends true ? SingleStoreTagClass<Self, string, ContractForSingleInput<Input>> : StoreTagClass<Self, string, RegsOfStoreInput<Input>>) & StoreLayers<...>Attach layerMemory / layer to a registration-only store class.
attachStoreLayers<function (type parameter) Self in <Self>(id: string): <const Args extends ReadonlyArray<unknown>>(...args: Args) => IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Self, string, typeof const storeClass: IsSingleStoreInput<Input> extends true
? SingleStoreTagClass<
Self,
string,
ContractForSingleInput<Input>
>
: StoreTagClass<
Self,
string,
RegsOfStoreInput<Input>
>
storeClass>(const storeClass: IsSingleStoreInput<Input> extends true
? SingleStoreTagClass<
Self,
string,
ContractForSingleInput<Input>
>
: StoreTagClass<
Self,
string,
RegsOfStoreInput<Input>
>
storeClass) as type IsSingleStoreInput<Input> = Input extends readonly unknown[] ? false : Input extends StoreRegistrationAny ? true : Input extends StandaloneRegInput ? true : falseBare single registration passed to
Store.Service
(not [] / {}).
IsSingleStoreInput<type Input = Args extends readonly [
infer Only
]
? Only
: Args
Input> extends true
? type SingleStoreServiceClass<Self = unknown, Id extends string = string, C extends StoreContractValue = StoreContractValue> = Context.ServiceClass<Self, Id, Simplify<Simplify<StoreShapeHandleTree<C["shapes"]>> & Simplify<{ readonly [K in CustomHandleKeys<C>]: CustomMethodOf<C, K>; }>>> & {
readonly [storeRegsSym]: ReadonlyArray<NormalizedStoreRegistration>;
readonly [storeSingleSym]: true;
readonly [storeNamedSym]: false;
readonly [storeDefaultLogLevelSym]?: StoreLogLevel;
} & StoreLayers<...>
Single-registration store class with attached
Storage
layers.
SingleStoreServiceClass<function (type parameter) Self in <Self>(id: string): <const Args extends ReadonlyArray<unknown>>(...args: Args) => IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Self, string, type ContractForSingleInput<Input> = Input extends StoreRegistrationAny ? ContractFromRegistration<Input> extends infer C extends StoreContractValue ? C : never : Input extends {
readonly contract: infer C extends StoreContractValue;
readonly scopeKey: string;
readonly spec: StoreSpec;
} ? C : never
Contract carried by a bare single
Store.Service
registration.
ContractForSingleInput<type Input = Args extends readonly [
infer Only
]
? Only
: Args
Input>>
: type StoreServiceClass<
Self = unknown,
Id extends string = string,
Regs = readonly NormalizedStoreRegistration<
string,
string,
Readonly<Record<string, StoreSpecEntry>>
>[]
> = Context.ServiceClass<
Self,
Id,
StoreBundle<Regs>
> & {
readonly at: StoreAtMethod<Self, Regs>
readonly [storeRegsSym]: Regs
readonly [storeNamedSym]: boolean
readonly [storeDefaultLogLevelSym]?: StoreLogLevel
} & StoreLayers<Self>
Aggregate store class with attached
Storage
layers.
StoreServiceClass<function (type parameter) Self in <Self>(id: string): <const Args extends ReadonlyArray<unknown>>(...args: Args) => IsSingleStoreInput<Input> extends true ? SingleStoreServiceClass<Self, string, ContractForSingleInput<Input>> : StoreServiceClass<Self, string, RegsOfStoreInput<Input>>Self, string, type RegsOfStoreInput<Input> = Input extends StoreRegistration<infer K extends string, infer S extends Readonly<Record<string, StoreSpecEntry>>> ? ContractFromRegistration<Input> extends infer C extends StoreContractValue ? C extends never ? [NormalizedStoreRegistration<K, K, S>] : [WithContract<K, K, S, C, RegTag<Input>>] : [NormalizedStoreRegistration<K, K, S>] : Input extends {
...;
} ? IsStoreContractValue<...> extends infer C extends StoreContractValue ? C extends never ? [...] : [...] : [...] : Input extends readonly (StoreRegistrationAny | StandaloneRegInput)[] ? NormalizeRegistrationArray<...> : Input extends Record<...> ? NormalizeObjectRegs<...> : Input extends readonly (readonly (StoreRegistrationAny | StandaloneRegInput)[])[] ? Input[0] extends readonly (StoreRegistrationAny | StandaloneRegInput)[] ? NormalizeRegistrationArray<...> : readonly NormalizedStoreRegistration<...>[] : readonly NormalizedStoreRegistration<...>[]
RegsOfStoreInput<type Input = Args extends readonly [
infer Only
]
? Only
: Args
Input>>;
};
};