Core Functions
itemPath
itemPath(type: T, repo: string, item: string, embed: string): string
Given the path parts, composes them into a GoatDB path.
itemPathGetPart
itemPathGetPart(path: string, part: 'type' | 'repo' | 'item' | 'embed'): T
Given a DB path and a path component, this function returns the relevant portion of the path.
itemPathGetRepoId
itemPathGetRepoId(path: string): string
Given a DB path, return just the repository prefix of it.
itemPathIsValid
itemPathIsValid(path: string): boolean
Checks if the given path is valid.
Valid paths must contain lowercase letters, numbers, and the characters
-
and _
. They must also contain at most 4 components separated by /
characters.
itemPathJoin
itemPathJoin(prefix: string, suffix: string): string
Joins the given prefix and suffix into a single path.
itemPathNormalize
itemPathNormalize(path: string): string
Normalizes the given path ensuring it has the correct number of parts and no trailing separator.
normalizeEmail
normalizeEmail(email: string): string
prettyJSON
prettyJSON(o: ReadonlyJSONValue): string
Converts a JSON value to a pretty-printed string.
If the input object has a toJSON method, it will be called first to get the serializable representation of the object.
SchemaEquals
SchemaEquals(s1: Schema, s2: Schema): boolean
Given two schemas, returns whether they're the same one or not.
SchemaGetFieldDef
SchemaGetFieldDef(s: S, field: F): FieldDef<S['fields'][F]['type']>
Given a schema and a field, returns its
SchemaGetFields
SchemaGetFields(s: Schema): readonly [string, FieldDef<ValueType>][]
Given a schema, this function returns its field definitions as an iterable.
SchemaGetRequiredFields
SchemaGetRequiredFields(s: Schema): readonly string[]
Given a schema, this functions returns an iterable of its required fields.
uniqueId
uniqueId(length: number): string
Generates a random ID string.
The generated ID is URL-safe, using only lowercase letters and numbers. The default length of 24 characters provides a large enough space to ensure a very low probability of collisions for most applications.
Note: This function uses Math.random() which is not cryptographically secure. Do not use for security-sensitive purposes.
With 36 possible characters (a-z, 0-9) and a length of 24, there are 36^24 (approximately 2.24 * 10^37) possible unique IDs, making collisions extremely unlikely for most use cases.