Skip to main content

useSubResource

Standalone composable for fetching a sub-resource collection hanging off an OpenRegister object (e.g. /{register}/{schema}/{id}/tasks). State is scoped to the calling component — no shared store.

Use this when:

  • The sub-resource is app-specific and doesn't warrant a global store plugin.
  • The response shape is non-standard (e.g. CalDAV tasks, ICommentsManager notes) and needs a transform function.
  • The calling component is the only consumer of the data.

For sub-resources that need shared state across components (audit trails, relations, files, …), use the dedicated store plugins instead — see store plugins.

Signature

import { useSubResource } from '@conduction/nextcloud-vue'
import { useObjectStore } from '@conduction/nextcloud-vue'

const store = useObjectStore()

const tasks = useSubResource(store, 'tasks', {
limit: 20,
transform: (task) => ({
id: task.uid || task.id,
title: task.summary,
deadline: task.due,
status: task.status,
}),
})

await tasks.fetch('case', caseId, { _search: 'open', _page: 1 })
console.log(tasks.data.results)

Parameters

ArgTypeDescription
storeobjectAn object-store instance. Must expose objectTypeRegistry and _options.baseUrl (any store created with useObjectStore or createCrudStore satisfies this).
endpointstringURL path segment appended after the object ID. E.g. 'tasks' yields .../{id}/tasks.
options.limitnumberDefault _limit. Default 20.
options.transform(item) => itemOptional per-item mapping applied to responseData.results.

Return value

KeyTypeDescription
datareactive{ results, total, page, pages, limit, offset }.
loadingRef<boolean>True while a fetch is in flight.
errorRef<object | null>Parsed error (parseResponseError shape) or a network-error object.
fetch(type, objectId, params?)FunctionFetch the sub-resource collection. Returns the (transformed) results array. On HTTP failure the error ref is set and [] is returned.
clear()FunctionReset state to defaults.

URL construction

${store._options.baseUrl}/${registry.register}/${registry.schema}/${objectId}/${endpoint}?<params>

registry is store.objectTypeRegistry[type]; if the type isn't registered, fetch throws synchronously inside its try block.

Request

  • buildHeaders() (see build-headers) supplies CSRF and JSON headers.
  • buildQueryString(params) (see build-query-string) serialises params.
  • A TypeError from fetch is surfaced through networkError (see network-error); any other thrown error is wrapped into the same shape as parseResponseError output.
  • Store plugins — When you want shared state instead of per-component state.
  • useObjectStore — Typical source of the store argument.