Entry Registry
Entry Registry
Seção intitulada “Entry Registry”Consulte e modifique entradas registradas. Acesse metadados, snapshots e historico de versoes.
Carregamento
Seção intitulada “Carregamento”local registry = require("registry")Estrutura de Entry
Seção intitulada “Estrutura de Entry”{ id = "app.lib:assert", -- string: "namespace:name" kind = "function.lua", -- string: tipo da entrada meta = {type = "test"}, -- table: metadados pesquisaveis data = {...} -- any: payload da entrada}Obter Entry
Seção intitulada “Obter Entry”local entry, err = registry.get("app.lib:assert")Permissão: registry.get no ID da entrada
Encontrar Entries
Seção intitulada “Encontrar Entries”local entries, err = registry.find({kind = "function.lua"})local entries, err = registry.find({kind = "http.endpoint", namespace = "app.api"})Campos de filtro correspondem aos metadados da entrada.
Parse de ID
Seção intitulada “Parse de ID”local id = registry.parse_id("app.lib:assert")-- id.ns = "app.lib", id.name = "assert"Snapshots
Seção intitulada “Snapshots”Visao point-in-time do registry:
local snap, err = registry.snapshot() -- estado atuallocal snap, err = registry.snapshot_at(5) -- na versão 5Métodos de Snapshot
Seção intitulada “Métodos de Snapshot”| Método | Retorna | Descrição |
|---|---|---|
snap:entries() | Entry[], error | Todas as entradas acessiveis |
snap:get(id) | Entry, error | Entrada unica por ID |
snap:find(filter) | Entry[] | Filtrar entradas |
snap:namespace(ns) | Entry[] | Entradas no namespace |
snap:version() | Version | Versão do snapshot |
snap:changes() | Changes | Criar changeset |
Versoes
Seção intitulada “Versoes”local version, err = registry.current_version()local versions, err = registry.versions()
print(version:id()) -- ID numericoprint(version:string()) -- string de exibicaolocal prev = version:previous() -- versão anterior ou nillocal next = version:next() -- próxima versão ou nilHistorico
Seção intitulada “Historico”local hist, err = registry.history()local versions, err = hist:versions()local version, err = hist:get_version(5)local snap, err = hist:snapshot_at(version)Changesets
Seção intitulada “Changesets”Construir e aplicar modificacoes:
local snap, err = registry.snapshot()local changes = snap:changes()
changes:create({ id = "test:new_entry", kind = "test.kind", meta = {type = "test"}, data = {config = "value"}})
changes:update({ id = "test:existing", kind = "test.kind", meta = {updated = true}, data = {new_value = true}})
changes:delete("test:old_entry")
local new_version, err = changes:apply()Permissão: registry.apply para changes:apply()
Métodos de Changes
Seção intitulada “Métodos de Changes”| Método | Descrição |
|---|---|
changes:create(entry) | Adicionar operação create |
changes:update(entry) | Adicionar operação update |
changes:delete(id) | Adicionar operação delete (string ou {ns, name}) |
changes:ops() | Obter operações pendentes |
changes:apply() | Aplicar mudancas, retorna nova Version |
Aplicar Versão
Seção intitulada “Aplicar Versão”Rollback ou forward para uma versão específica:
local prev = current_version:previous()local ok, err = registry.apply_version(prev)Permissão: registry.apply_version
Construir Delta
Seção intitulada “Construir Delta”Computar operações para transicao entre estados:
local from = {{id = "test:a", kind = "test", meta = {}, data = {}}}local to = {{id = "test:b", kind = "test", meta = {}, data = {}}}
local ops, err = registry.build_delta(from, to)for _, op in ipairs(ops) do print(op.kind, op.entry.id) -- "entry.create", "entry.update", "entry.delete"endPermissões
Seção intitulada “Permissões”| Permissão | Recurso | Descrição |
|---|---|---|
registry.get | ID da entrada | Ler entrada (também filtra resultados de find/entries) |
registry.apply | - | Aplicar changeset |
registry.apply_version | - | Aplicar/rollback versão |
| Condição | Tipo |
|---|---|
| Entrada não encontrada | errors.NOT_FOUND |
| Versão não encontrada | errors.NOT_FOUND |
| Permissão negada | errors.PERMISSION_DENIED |
| Parâmetro inválido | errors.INVALID |
| Sem mudancas para aplicar | errors.INVALID |
| Registry não disponível | errors.INTERNAL |
Veja Error Handling para trabalhar com erros.