DOIP Client Library - JavaScript Version
    Preparing search index...

    Interface DoipClient

    Interface for a client used to communicate with a DOIP service. It handles operations like retrieving, creating, updating, and deleting digital objects, as well as searching and other DOIP operations. All operations are accessible through performOperation; other methods are provided for convenience.

    interface DoipClient {
        performOperation(
            doipRequest: DoipRequest,
            options?: Options,
        ): Promise<DoipResponse>;
        performOperation(
            targetId: string,
            operationId: string,
            input?:
                | ArrayBuffer
                | ArrayBufferView<ArrayBufferLike>
                | Blob
                | Json
                | InDoipMessage
                | ReadableStream<Uint8Array<ArrayBufferLike>>,
            options?: Options,
        ): Promise<DoipResponse>;
        close(): Promise<void>;
        targetIdForService(options?: Options): string;
        hello(options?: Options): Promise<DigitalObject>;
        retrieve(
            targetId: string,
            options?: Options,
        ): Promise<null | DigitalObject>;
        listOperations(targetId: string, options?: Options): Promise<string[]>;
        searchIds(
            query: string,
            params?: QueryParams,
            options?: Options,
        ): Promise<SearchResults<string>>;
        search(
            query: string,
            params?: QueryParams,
            options?: Options,
        ): Promise<SearchResults<DigitalObject>>;
        delete(targetId: string, options?: Options): Promise<void>;
        retrieveElementBytes(
            targetId: string,
            elementId: string,
            options?: Options,
        ): Promise<null | Body>;
        retrievePartialElementBytes(
            targetId: string,
            elementId: string,
            start: undefined | null | number,
            end: undefined | null | number,
            options?: Options,
        ): Promise<null | Body>;
        create(
            digitalObject: DigitalObject,
            options?: Options,
        ): Promise<DigitalObject>;
        update(
            digitalObject: DigitalObject,
            options?: Options,
        ): Promise<DigitalObject>;
    }

    Implemented by

    Index

    Methods

    • Performs a DOIP operation using a DoipRequest object.

      Parameters

      • doipRequest: DoipRequest

        The DOIP request to perform

      • Optionaloptions: Options

        Optional request options for this operation

      Returns Promise<DoipResponse>

      A promise that resolves to a DoipResponse. The caller is responsible for closing the DoipResponse.

      const request = {
      targetId: 'service',
      operationId: '0.DOIP/Op.Hello'
      };
      const response = await client.performOperation(request);
      console.log(await response.asJson()); // asJson closes the response
    • Performs a DOIP operation by specifying the target ID, operation ID, and optional input.

      Parameters

      • targetId: string

        The ID of the target digital object or service

      • operationId: string

        The ID of the operation to perform

      • Optionalinput:
            | ArrayBuffer
            | ArrayBufferView<ArrayBufferLike>
            | Blob
            | Json
            | InDoipMessage
            | ReadableStream<Uint8Array<ArrayBufferLike>>

        Optional input for the operation

      • Optionaloptions: Options

        Optional request options for this operation

      Returns Promise<DoipResponse>

      A promise that resolves to a DoipResponse. The caller is responsible for closing the DoipResponse.

      const response = await client.performOperation('service', '0.DOIP/Op.Hello');
      console.log(await response.asJson()); // asJson closes the response
    • Closes the client and releases any resources.

      Returns Promise<void>

    • Determines the ID for a service, based on the options given. If options does not specify a service ID, there may be a client default. Defaults to service if no other info is specified.

      Parameters

      • Optionaloptions: Options

        Optional request options

      Returns string

      The ID for the service

    • Sends a hello request to the service to get information about the service and verify connectivity.

      Parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to a DigitalObject containing information about the service

      DoipError for error responses

      const serviceInfo = await client.hello();
      console.log(serviceInfo);
    • Retrieves a digital object by ID.

      Parameters

      • targetId: string

        The ID of the digital object to retrieve

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | DigitalObject>

      A promise that resolves to the retrieved DigitalObject, or null if not found

      DoipError for error responses

      const object = await client.retrieve('20.500.123/1');
      if (object) {
      console.log(object.attributes.content);
      }
    • Retrieves a list of operations that can be performed on the specified target.

      Parameters

      • targetId: string

        The ID of the target digital object or service

      • Optionaloptions: Options

        Optional request options

      Returns Promise<string[]>

      A promise that resolves to an array of operation IDs

      DoipError for error responses

      // List operations for a specific object
      const operations = await client.listOperations('20.500.123/1');
      console.log(operations);

      // List operations for the service using the default service ID
      const serviceOps = await client.listOperations('service');
      console.log(serviceOps);
    • Searches for digital objects matching the specified query and returns only their IDs.

      Parameters

      • query: string

        The search query

      • Optionalparams: QueryParams

        Optional query parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<SearchResults<string>>

      A promise that resolves to SearchResults which among other properties is an async iterable iterator of digital object IDs The caller is responsible for closing the SearchResults.

      DoipError for error responses

      const results = await client.searchIds('type:Document');
      try {
      for await (const id of results) {
      console.log(id);
      }
      } finally {
      await results.close();
      }
    • Searches for digital objects matching the specified query and returns the complete digital objects.

      Parameters

      • query: string

        The search query

      • Optionalparams: QueryParams

        Optional query parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<SearchResults<DigitalObject>>

      A promise that resolves to SearchResults which among other properties is an async iterable iterator of digital objects. The caller is responsible for closing the SearchResults.

      DoipError for error responses

      const results = await client.search('type:Document');
      console.log(`Number of results: ${results.size}`);
      try {
      for await (const object of results) {
      console.log(`${object.id}: ${object.attributes.content.name}`);
      }
      } finally {
      await results.close();
      }
    • Deletes a digital object by ID.

      Parameters

      • targetId: string

        The ID of the digital object to delete

      • Optionaloptions: Options

        Optional request options

      Returns Promise<void>

      A promise that resolves when the deletion is complete

      DoipError for error responses

      await client.delete('20.500.123/1');
      
    • Retrieves the body of a specific element of a digital object by its ID.

      Parameters

      • targetId: string

        The ID of the digital object

      • elementId: string

        The ID of the element to retrieve

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | Body>

      A promise that resolves to the element body, or null if not found

      DoipError for error responses

      // Get the bytes of a binary element payload
      const elementBody = await client.retrieveElementBytes('20.500.123/1', 'attachment-binary');
      if (elementBody) {
      const buffer = await elementBody.arrayBuffer();
      const bytes = new Uint8Array(buffer);
      console.log(`length: ${bytes.length}`);
      // process bytes
      }

      // Get text from a text element body
      const elementBody = await client.retrieveElementBytes('20.500.123/1', 'attachment-text');
      if (elementBody) {
      const text = await elementBody.text();
      console.log(text);
      }
    • Retrieves a specific byte range of an element of a digital object.

      Parameters

      • targetId: string

        The ID of the digital object

      • elementId: string

        The ID of the element to retrieve

      • start: undefined | null | number

        The starting byte position (inclusive)

      • end: undefined | null | number

        The ending byte position (inclusive)

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | Body>

      A promise that resolves to the partial element body, or null if not found

      DoipError for error responses

      // Retrieve the first 1000 bytes of a binary element body
      const elementBody = await client.retrievePartialElementBytes('20.500.123/1', 'attachment-binary', 0, 999);
      if (elementBody) {
      const buffer = await elementBody.arrayBuffer();
      const bytes = new Uint8Array(buffer);
      console.log(`length: ${bytes.length}`);
      }

      // Retrieve bytes from the middle of a text element body
      const elementBody = await client.retrievePartialElementBytes('20.500.123/1', 'text', 2, 5);
      if (elementBody) {
      console.log(await elementBody.text());
      }
    • Creates a new digital object.

      Parameters

      • digitalObject: DigitalObject

        The digital object to create

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to the created digital object

      DoipError for error responses

      const object = {
      type: 'Document',
      attributes: {
      content: {
      name: 'Example Document'
      }
      }
      };
      const createdObject = await client.create(object);
      console.log(createdObject.id);
    • Updates an existing digital object.

      Parameters

      • digitalObject: DigitalObject

        The digital object to update

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to the updated digital object

      DoipError for error responses

      const object = await client.retrieve('20.500.123/1');
      if (object) {
      object.attributes.content.name = 'Updated Example Document';
      const updatedObject = await client.update(object);
      console.log(updatedObject.attributes.content.name);
      }