Documentation
¶
Overview ¶
SPDX-FileCopyrightText: 2025 Forkbomb BV
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-FileCopyrightText: 2025 Forkbomb BV
SPDX-License-Identifier: AGPL-3.0-or-later
Index ¶
- Variables
- func BuildPath(app core.App, rec *core.Record, tpl PathTemplate, candidateName string) (string, error)
- func Canonify(in string, exists ExistsFunc) (string, error)
- func CanonifyPlain(in string) string
- func CanonifyWithOptions(in string, exists ExistsFunc, opts CanonifyOptions) (string, error)
- func NormalizePath(path string) string
- func RegisterCanonifyHooks(app core.App)
- func Resolve(app core.App, path string) (*core.Record, error)
- func Validate(app core.App, path string) (*core.Record, error)
- type CanonifyOptions
- type ExistsFunc
- type Parent
- type PathTemplate
Constants ¶
This section is empty.
Variables ¶
var CanonifyPaths = map[string]PathTemplate{ "users": { Field: "name", CanonifiedField: "canonified_name", PathLength: 1, }, "organizations": { Field: "name", CanonifiedField: "canonified_name", PathLength: 1, }, "credential_issuers": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "credentials": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "credential_issuers", Field: "credential_issuer"}, PathLength: 3, }, "custom_checks": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "wallets": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "wallet_actions": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "wallets", Field: "wallet"}, PathLength: 3, }, "wallet_versions": { Field: "tag", CanonifiedField: "canonified_tag", Parent: &Parent{Collection: "wallets", Field: "wallet"}, PathLength: 3, }, "verifiers": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "use_cases_verifications": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "verifiers", Field: "verifier"}, PathLength: 3, }, "pipelines": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "pipeline_results": { Field: "workflow_id", CanonifiedField: "canonified_identifier", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "news": { Field: "title", CanonifiedField: "canonified_title", PathLength: 1, }, "mobile_runners": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "organizations", Field: "owner"}, PathLength: 2, }, "mobile_devices": { Field: "name", CanonifiedField: "canonified_name", Parent: &Parent{Collection: "mobile_runners", Field: "runner"}, PathLength: 3, }, }
var DefaultOptions = CanonifyOptions{
Separator: '-',
MinLen: 1,
Fallback: "item-name",
MaxAttempts: 1000000,
}
var ErrExhaustedAttempts = errors.New("could not find unique name: exhausted attempts")
ErrExhaustedAttempts returned when we couldn't find a free name within MaxAttempts.
Functions ¶
func BuildPath ¶
func BuildPath( app core.App, rec *core.Record, tpl PathTemplate, candidateName string, ) (string, error)
BuildPath constructs the path for a record
func Canonify ¶
func Canonify(in string, exists ExistsFunc) (string, error)
Canonify converts an arbitrary input string into a deterministic, compact, lowercased, ASCII-friendly slug and ensures uniqueness by consulting exists(name).
The exists callback will be called for each candidate (base name and sequential suffixes).
func CanonifyPlain ¶
CanonifyPlain computes the canonical string without checking uniqueness.
func CanonifyWithOptions ¶
func CanonifyWithOptions(in string, exists ExistsFunc, opts CanonifyOptions) (string, error)
CanonifyWithOptions same as Canonify but with configurable options.
func NormalizePath ¶
func RegisterCanonifyHooks ¶
RegisterCanonifyHooks registers hooks for canonifying names in specified collections.
For each collection, it registers two hooks: one for after creating a record, and one for after updating a record. Both hooks canonify the name of the record using the provided function, and save the updated record to persist the canonified field. The canonified field is named "canonified_name" or "canonified_title" depending on the source field name. The existsFunc parameter is used to check if a canonized name already exists in the collection. If the canonized name already exists, the function returns an error. If the source field is empty, the hooks skip the record and do not perform any action.
The function takes a PocketBase application as a parameter, and registers the hooks for the specified collections.
Types ¶
type CanonifyOptions ¶
CanonifyOptions controls behaviour of Canonify.
type ExistsFunc ¶
ExistsFunc is the callback used to ask if a candidate already exists in DB. Should be deterministic. A non-nil error means the lookup itself failed; Canonify returns it instead of trying further candidates.
func MakeExistsFunc ¶
func MakeExistsFunc( app core.App, collectionName string, rec *core.Record, excludeID string, ) ExistsFunc
MakeExistsFunc reports whether candidateName is already used by another record of collectionName under the same parent path. It returns an error when the path cannot be built (for example a missing parent record) or the lookup fails, because no other candidate name can succeed then.