/** * @module ibgib-helper.mts * * specific to ibgib but not to any particular subdomain */ import { HashAlgorithm } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs'; import { Ib, IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs'; import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs'; import { SpecialIbGibType } from './other-types.mjs'; import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs'; import { FlatIbGibGraph } from './graph-types.mjs'; import { SpaceQualifiedAddrInfo, SpaceQualifiedIbGibAddr } from './ibgib-types.mjs'; /** * Returns a space-qualified address string. * Format: `v:1^spaceId:^` */ export declare function getSpaceQualifiedIbGibAddr(optsOrSpaceId: { spaceId: string; ibGibAddr: string; } | string, rawIbGibAddr?: string): SpaceQualifiedIbGibAddr; /** * helper function to just determine if an addr is a space-qualified addr or not * @returns true if space-qualified, else false */ export declare function isSpaceQualifiedAddr(addr: any): boolean; /** * Parses a space-qualified address string into version, spaceId, ibGibAddr, ib, and gib. */ export declare function parseSpaceQualifiedIbGibAddr({ sqAddr }: { sqAddr: string; }): SpaceQualifiedAddrInfo; /** * Gets ibgibs that are directly related to the given `ibGib` via `rel8nNames`. * * @returns map of rel8nName -> ibgibs that are related. */ export declare function getRel8dIbGibs({ ibGib, rel8nNames, space, }: { ibGib: IbGib_V1; rel8nNames?: string[]; space: IbGibSpaceAny; }): Promise<{ [rel8nName: string]: IbGib_V1[]; }>; /** * Utility function to generate hard-coded ibgibs to use at runtime "on-chain" but * written at compile-time in (for now) "off-chain" source code. * * Because this is supposed to create and re-create deterministically the equivalent * of a non-primitive ibgib "constant", this function creates a single ibgib with... * * one ancestor * * no past, dna, or tjp rel8ns * * no tjp timestamp or uuid * * no nCounter * * ## validation * * * validates the given `ib` against `ibRegExpPattern` or default regexp. * * validates that rel8ns doesn't include default forbidden rel8n names or * atow `'tjp'`. * * ## intent * * I want to be able to create deterministic ibGibs that I can reference at * runtime, similar to an ibgib primitive (e.g. "root^gib"), but with the * integrity of the `gib` hash. This way, I can reference a deterministic ibgib * from code at compile time, and at runtime this will have a corresponding * ibgib datum with gib-hashed integrity. * * ## example * * I want to create a "hard-coded" schema ibgib that I rel8 to some protocol * ibgib. So I'll create the data here, which lives in source control in a text file, * and then I'll render that as an ibgib that verifies integrity. If I as a coder change * it at all, then the `gib` of course will be different. */ export declare function constantIbGib({ parentPrimitiveIb, ib, ibRegExpPattern, data, rel8ns, }: { parentPrimitiveIb: Ib; ib: Ib; /** * for checking the constant's generated ib */ ibRegExpPattern?: string; data?: TData; rel8ns?: TRel8ns; }): Promise>; /** * Binaries require special handling, since they do not conform to the * "normal" IbGib_V1 data structure per se. This stems from wanting to * be able to have binaries (jpgs, gifs, etc. especially) able to * sit on a server and be served as regular files. * * @returns string in expected template for binaries in this app. */ export declare function getBinIb({ binHash, binExt, binEncoding }: { binHash: string; binExt?: string; binEncoding?: string; }): IbGibAddr; /** * @deprecated * * use {@link parseBinIb} */ export declare function getBinHashAndExt({ addr }: { addr: IbGibAddr; }): { binHash: string; binExt: string; binEncoding?: string; }; /** * parses a given addr that is expected to be for a {@link BinIbGib_V1}. * * @throws an error if addr is not for a {@link BinIbGib_V1} (via {@link isBinary}) * * @returns parsed bin ib information */ export declare function parseBinIb({ addr }: { addr: IbGibAddr; }): { binHash: string; binExt: string; binEncoding?: string; }; /** * atow (01/2024) this looks to see... * * * that data is truthy (if ibGib is truthy) * * gib is a UUID * * ## dev note * * this is tightly coupled with {@link getBinIb} and {@link parseBinIb} * * @returns true if analysis of ibgib indicates it is a {@link BinIbGib_V1}, else false */ export declare function isBinary({ ibGib, addr, }: { ibGib?: IbGib_V1; addr?: IbGibAddr; }): boolean; /** * Recursively hashes some string {@link recursionCount} number of times. */ export declare function hash16816({ s, algorithm, recursionCount, saltPrependedPerHash, }: { /** * string to hash */ s: string; /** * algorithm to use. defaults to 'SHA-256' */ algorithm: HashAlgorithm; /** * number of recursions to do. Defaults to 16816. */ recursionCount: number; saltPrependedPerHash: string; }): Promise; /** * creates atow (10/2023) space-delimited ib in the form of `meta special ${type}`. * * @returns ib for given `type` * @throws error if `type` doesn't match {@link SPECIAL_IBGIB_TYPE_REGEXP} * * @see {@link getSpecialTypeFromIb} * @see {@link SPECIAL_IBGIB_TYPE_REGEXP} */ export declare function getSpecialIbGibIb({ type }: { type: SpecialIbGibType; }): Ib; /** * extracts the {@link SpecialIbGibType} from the given `ib`. * * @returns type {@link SpecialIbGibType} * * @see {@link getSpecialIbGibIb} * @see {@link SPECIAL_IBGIB_TYPE_REGEXP} */ export declare function getSpecialTypeFromIb({ ib }: { ib: Ib; }): SpecialIbGibType; /** * gets a special ib and tacks on ^gib for a constant address. * * used in primitives (ancestors for special ibgibs), as well as as of atow * (11/2023) the "latest" special ibgib. * * @returns special IbGibAddr */ export declare function getSpecialIbGibAddr({ type }: { type: SpecialIbGibType; }): string; export declare function getSpecialConfigKey({ type }: { type: SpecialIbGibType; }): string; export declare function isSpecial({ ib, ibGib }: { ib?: Ib; ibGib?: IbGib_V1; }): boolean; /** * returns ib for a given root. ATOW this is simply "root {text}" * * @returns ib for the given rootText */ export declare function getRootIb(rootText: string): string; /** * Tags for this app have the form: tag [tagText] * * @param tagText e.g. "Favorites" * * @example * For the Favorites tag, the ib would be "tag Favorites" */ export declare function tagTextToIb(tagText: string): string; /** * Living: has tjp and dna. * Stones: does not have Dna, maybe has tjp. * * Splits the given `ibGibs` into two maps, one that includes the ibgibs that * have a tjp (temporal junction point) AND dna ("living") and those that do not * have both tjp AND dna ("stones"). * * ## notes * * Having dna implies having a tjp, but the reverse is not necessarily true. * Sometimes you want an ibgib that has a tjp so you can, e.g., reference the * entire timeline easily. But at the same time you don't want to keep track of * the transforms, perhaps this is because you don't want to be able to merge * timelines. */ export declare function splitPerTjpAndOrDna({ ibGibs, filterPrimitives, }: { ibGibs: IbGib_V1[]; filterPrimitives?: boolean; }): { /** ibgibs have both tjp and dna */ mapWithTjp_YesDna: { [gib: string]: IbGib_V1; }; /** ibgibs have tjp but NO dna */ mapWithTjp_NoDna: { [gib: string]: IbGib_V1; }; /** ibgibs that have no tjp (and implicitly no dna) */ mapWithoutTjps: { [gib: string]: IbGib_V1; }; }; /** * Takes incoming `ibGibs`, filters out those that do * not have tjps( i.e. non-timelines), and groups * the timeline ibgibs by tjp in ascending order. * * This means that each map entry will be in the form: * `[tjpAddr] => [ibgib0 (tjp), ibgib1, ibgib2, ..., ibgibN (latest)]` * * ## notes * * * sorts by `ibgib.data.n`. If this is undefined, will not sort in ascending * order properly. * * @returns filtered, sorted map of incoming `ibGibs` [tjpAddr] => timeline [ibgib0 (tjp), ibgib1, ibgib2, ..., ibgibN (latest)] */ export declare function getTimelinesGroupedByTjp({ ibGibs, }: { /** * group of source ibGibs to filter/group/sort by tjp. */ ibGibs: IbGib_V1[]; }): { [tjpAddr: string]: IbGib_V1[]; }; /** * Helper function that checks the given `ibGib` to see if it * either has a tjp or is a tjp itself. * * ## notes * * Only unique ibGibs are meant to have tjps, or rather, if an * ibGib timeline is expected to be unique over "time", then the * tjp is an extremely convenient mechanism that provides a * "name" for that timeline. * * Otherwise, if they are not unique, then successive "different" * timelines cannot be easily referenced by their first unique * frame in time, making it much harder to pub/sub updates among * other things. (If there are no unique frames, then they are * the same ibGib.) * * ## tjp = temporal junction point * * I've written elsewhere on this as well. Refer to B2tF2. * * @returns true if the ibGib has/is a tjp, else false */ export declare function hasTjp({ ibGib }: { ibGib: IbGib_V1; }): boolean; export declare function hasDna({ ibGib }: { ibGib: IbGib_V1; }): boolean; /** * Extracts the tjp addr from the ibgib record. If there is no tjp addr found, * then refers to `defaultIfNone` arg to determine if it returns undefined or * the incoming ibgib's addr. * @returns extracted tjp addr or undefined, depending on if found and defaultIfNone value */ export declare function getTjpAddr({ ibGib, defaultIfNone, }: { ibGib: IbGib_V1; defaultIfNone?: 'incomingAddr' | 'undefined'; }): IbGibAddr | undefined; /** * builds a map of the given ibgib's addrs to each's corresponding tjp addr. * * @returns a map of ibgib addr -> tjp addr */ export declare function getTjpAddrs({ ibGibs, defaultIfNone, }: { ibGibs: IbGib_V1[]; defaultIfNone?: 'incomingAddr' | 'undefined'; }): { [ibGibAddr: IbGibAddr]: IbGibAddr | undefined; }; /** * Returns true if the given {@param ibGib} is the temporal junction * point for a given ibGib timeline. */ export declare function isTjp_Naive({ ibGib, naive, }: { ibGib: IbGib_V1; naive?: boolean; }): Promise; export declare function toDto({ ibGib, }: { ibGib: IbGib_V1; }): IbGib_V1; /** * helpful for differentiating discriminated unions. * * technically, atow, anything with an ib meets the minimum requirements for an * ibgib. this is because you can think of any value as being a metadata * "header" with other derivative & metadatas as being absent. * * For example, a string value "my string yo" is all you have to go on if you * don't have a hash which would be metadata about that value. its address would * be "my string yo^gib" as it's a primitive, and its intrinisic data would just * be a duplicate of the ib, so it's left undefined, and there are no extrinsic * rel8ns so rel8ns would be undefined. * * ## driving use case * * In doing rxjs replacement, I'm needing to tell if an error coming down the * pipe is ErrorIbGib_V1 | Error | string. * * @param obj any object. note: if falsy, returns false * @returns true if the obj is an ibgib, else false */ export declare function isIbGib(obj: any): obj is IbGib_V1; /** * extracts timestamp info from the given `ibGib`. * * ## about * * not all ibGibs have timestamps (data.timestamp) and they may be in the form * of a timestamp string. this may actually be a timestamp string for a Date * object or it could be a string of ticks from date.getTime(). or maybe * downstream someone just does a number instead of a string. * * so this function is supposed to be good at figuring this out given an * `ibGib`. * * ## todo * * 1. we could add an optional path parameter that allows us to specify the * path(s) of things that should be timestamps. * * 2. we could have a simple extractTimestamp(value: any) that does the same * thing and then call that from this function. * * @returns info object that has the timestamp in various formats (if valid) or an error msg (if invalid) */ export declare function getTimestampInfo({ ibGib, data, timestamp, }: { ibGib?: IbGib_V1; data?: IbGibData_V1; timestamp?: string; }): { valid: true; date: Date; utc: string; ticks: string; ms: number | undefined; } | { valid: false; emsg: string; }; /** * First we combine {@link readCache_graph} and {@link readCache_array} into * one unified cache. This can even be empty (if both empty/falsy). * * Then looks in {@link space} for all other addrs (throws if *any* not found). * * Then creates the result array, which will be in the same order as incoming * {@link addrs} (so this acts like a fancy .map() call). * * @throws if any addr is not found * * ## notes * * Since you can pass in empty cache(s), you can actually use this as a generic * getIbGibs function that throws if you don't want to use `getFromSpace` and * parse the results. (which is what I find I want more and more the lazier I * get). */ export declare function getIbGibsFromCache_fallbackToSpaces({ addrs, readCache_graph, readCache_array, space, }: { addrs: IbGibAddr[]; readCache_graph?: FlatIbGibGraph; readCache_array?: IbGib_V1[]; space: IbGibSpaceAny; }): Promise; /** * naive general purpose helper guard function based off of a given ibgib's * `ib` property. * * uses conventional V1 `ib` schema, expecting space-delimited `ib` with the * first piece being the atom. * * @param x - any object, usually known to be an ibgib * @param atom - the expected atom that determines the type of ibgib * @returns true if `x.ib` contains `atom` and thus is `TIbGib`, else false */ export declare function isIbGibWithAtom(x: any, atom: string): x is TIbGib; /** * Retrieves an ibgib node strictly from the specified space. * If given a space-qualified address, strips the prefix and fetches from `space`. */ export declare function getIbGibFromSpace({ addr, space, metaspace, }: { addr: string; space: IbGibSpaceAny; metaspace?: any; }): Promise; /** * Retrieves multiple ibgib nodes strictly from the specified space in a single batch. * If given space-qualified addresses, strips prefixes and fetches from `space`. * * @throws error if any of the ibgibs are not able to be gotten. */ export declare function getIbGibsFromSpace({ addrs, space, }: { addrs: string[]; space: IbGibSpaceAny; }): Promise; /** * Pure helper: given a known ibGib that belongs to a timeline, resolves the * latest frame of that timeline as recorded in `space`'s metastones. * * Returns the latest ibGib if it is strictly newer than `ibGib`; otherwise * returns the original `ibGib` unchanged. * * This function is intentionally free of side-effects and has no dependency on * MetaspaceService so it can be unit-tested in isolation. */ export declare function resolveLatestIbGibInSpace({ ibGib, space, }: { ibGib: T; space: IbGibSpaceAny; }): Promise; /** * Pure helper (plural): given an array of known ibGibs that belong to timelines, * resolves the latest frame of each timeline as recorded in `space`'s metastones. * * For each incoming ibGib: * - If a newer frame is found in `space`, returns the latest ibGib. * - Otherwise returns the original `ibGib` unchanged. * * Preserves the exact ordering of the incoming `ibGibs` array. * Uses batched calls (`getLatestAddrs` and `getIbGibsFromSpace`) for maximum performance. */ export declare function resolveLatestIbGibsInSpace({ ibGibs, space, }: { ibGibs: T[]; space: IbGibSpaceAny; }): Promise; //# sourceMappingURL=ibgib-helper.d.mts.map