/** * Callable Resource Types * * Types for callable resource patterns where * `resource(id)` returns a scoped resource and `resource.list()` etc. * access collection-level operations. */ import type { ListParams } from '@timeback/internal-client-infra'; import type { AssessmentLineItemCreateInput, ClassCreateInput, ComponentResourceCreateInput, CourseComponentCreateInput, CourseCreateInput, CourseStructureInput, LineItemCreateInput, ResourceCreateInput, SchoolCreateInput, UserCreateInput } from '@timeback/types/zod'; import type { Paginator } from '../lib'; import type { ScopedAssessmentLineItemResource } from '../resources/assessment/line-items'; import type { ScopedLineItemResource } from '../resources/gradebook/line-items'; import type { ScopedResourceResource } from '../resources/resources/resources'; import type { ScopedTermResource } from '../resources/rostering/academic-sessions'; import type { ScopedClassResource } from '../resources/rostering/classes'; import type { ScopedCourseResource } from '../resources/rostering/courses'; import type { ScopedSchoolResource } from '../resources/rostering/schools'; import type { ScopedStudentResource, ScopedTeacherResource, ScopedUserResource } from '../resources/rostering/users'; import type { AcademicSession, AcademicSessionFilterFields, AssessmentLineItem, AssessmentLineItemFilterFields, Base, Class, ClassFilterFields, ComponentResource, ComponentResourceFilterFields, Course, CourseComponent, CourseComponentFilterFields, CourseFilterFields, CreateResponse, LineItem, LineItemFilterFields, Organization, OrganizationFilterFields, Resource, ResourceFilterFields, User, UserFilterFields } from './index'; import type { ListParamsNoSearch, ListParamsWithSearch } from './list-params'; /** * Base interface for callable resources. * Resources that support scoping by ID implement this pattern. * * @template T - The entity type * @template F - Filter fields type * @template S - Scoped resource type returned when called with an ID * @template I - Input type for create/update (defaults to Partial) */ export interface CallableResource, P extends ListParams = ListParams, W = void> { /** Get a scoped resource for a specific entity */ (id: string): S; /** List the first page of entities */ list(params?: P): Promise>; /** List all entities (fetches all pages) */ listAll(params?: P): Promise; /** Get the first matching entity, or undefined if none match */ first(params?: P): Promise; /** Stream entities with lazy pagination */ stream(params?: P): Paginator; /** Get a single entity by ID */ get(id: string): Promise; /** Check whether a single entity exists by ID */ exists(id: string): Promise; /** Create a new entity */ create(data: I): Promise; /** Update an existing entity */ update(id: string, data: Partial): Promise; /** Create or update an entity (falls back to create on 404) */ upsert(id: string, data: Omit): Promise; /** Delete an entity */ delete(id: string): Promise; } /** * Read-only callable resource (no create/update/delete). * * @template T - The entity type * @template F - Filter fields type * @template S - Scoped resource type returned when called with an ID */ export interface ReadOnlyCallableResource = ListParams> { /** Get a scoped resource for a specific entity */ (id: string): S; /** List the first page of entities */ list(params?: P): Promise>; /** List all entities (fetches all pages) */ listAll(params?: P): Promise; /** Get the first matching entity, or undefined if none match */ first(params?: P): Promise; /** Stream entities with lazy pagination */ stream(params?: P): Paginator; /** Get a single entity by ID */ get(id: string): Promise; /** Check whether a single entity exists by ID */ exists(id: string): Promise; } /** * Callable courses resource. * * @example * ```typescript * // Collection operations * const courses = await client.courses.list() * const course = await client.courses.get(id) * * // Scoped operations * const classes = await client.courses(courseId).classes() * ``` */ export interface CoursesCallable extends CallableResource> { /** List all course components */ components(params?: ListParamsNoSearch): Promise; /** Stream course components with lazy pagination */ streamComponents(params?: ListParamsNoSearch): Paginator; /** Get a specific course component */ getComponent(sourcedId: string): Promise; /** Create a new course component */ createComponent(data: CourseComponentCreateInput): Promise; /** Update a course component */ updateComponent(sourcedId: string, data: CourseComponentCreateInput): Promise; /** Delete a course component */ deleteComponent(sourcedId: string): Promise; /** List all component resources */ componentResources(params?: ListParamsNoSearch): Promise; /** Stream component resources with lazy pagination */ streamComponentResources(params?: ListParamsNoSearch): Paginator; /** Get a specific component resource */ getComponentResource(sourcedId: string): Promise; /** Create a new component resource */ createComponentResource(data: ComponentResourceCreateInput): Promise; /** Update a component resource */ updateComponentResource(sourcedId: string, data: ComponentResourceCreateInput): Promise; /** Delete a component resource */ deleteComponentResource(sourcedId: string): Promise; /** Create a course structure from QTI tests */ createStructure(data: CourseStructureInput): Promise; } /** * Callable classes resource. * * @example * ```typescript * // Collection operations * const classes = await client.classes.list() * const cls = await client.classes.get(id) * * // Scoped operations * const students = await client.classes(classId).students() * const lineItems = await client.classes(classId).lineItems() * ``` */ export type ClassesCallable = CallableResource>; /** * Callable schools resource. * * @example * ```typescript * // Collection operations * const schools = await client.schools.list() * const school = await client.schools.get(id) * * // Scoped operations * const classes = await client.schools(schoolId).classes() * const students = await client.schools(schoolId).students() * ``` */ export type SchoolsCallable = CallableResource>; /** * Callable users resource. * * @example * ```typescript * // Collection operations * const users = await client.users.list() * const user = await client.users.get(id) * * // Scoped operations * const resources = await client.users(userId).resources() * const classes = await client.users(userId).classes() * ``` */ export type UsersCallable = CallableResource>; /** * Callable students resource (read-only). * * @example * ```typescript * // Collection operations * const students = await client.students.list() * const student = await client.students.get(id) * * // Scoped operations * const classes = await client.students(studentId).classes() * ``` */ export type StudentsCallable = ReadOnlyCallableResource>; /** * Callable teachers resource (read-only). * * @example * ```typescript * // Collection operations * const teachers = await client.teachers.list() * const teacher = await client.teachers.get(id) * * // Scoped operations * const classes = await client.teachers(teacherId).classes() * ``` */ export type TeachersCallable = ReadOnlyCallableResource>; /** * Callable terms resource (read-only). * * @example * ```typescript * // Collection operations * const terms = await client.terms.list() * const term = await client.terms.get(id) * * // Scoped operations * const classes = await client.terms(termId).classes() * ``` */ export type TermsCallable = ReadOnlyCallableResource>; /** * Callable line items resource. * * @example * ```typescript * // Collection operations * const lineItems = await client.lineItems.list() * const lineItem = await client.lineItems.get(id) * * // Scoped operations * const results = await client.lineItems(lineItemId).results() * ``` */ export interface LineItemsCallable extends CallableResource, LineItem> { } /** * Callable assessment line items resource. * * @example * ```typescript * // Collection operations * const lineItems = await client.assessmentLineItems.list() * const lineItem = await client.assessmentLineItems.get(id) * * // Partial update * await client.assessmentLineItems.patch(id, { score: 95 }) * ``` */ export interface AssessmentLineItemsCallable extends CallableResource, AssessmentLineItem> { /** Partially update an assessment line item (only specified fields are changed) */ patch(id: string, data: Partial): Promise; } /** * Callable resources resource. * * @example * ```typescript * // Collection operations * const resources = await client.resources.list() * const resource = await client.resources.get(id) * * // Nested resource queries (following convention) * const classResources = await client.classes(classId).resources() * const courseResources = await client.courses(courseId).resources() * const userResources = await client.users(userId).resources() * * // Export * await client.resources.export(resourceId) * ``` */ export interface ResourcesCallable extends CallableResource> { /** Export a resource to Common Cartridge (.zip) as an ArrayBuffer */ export(resourceId: string): Promise; } //# sourceMappingURL=callable.d.ts.map