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

    Class AbstractDoipClientAbstract

    This class implements the DoipClient interface and provides common functionality for all DOIP client implementations.

    Concrete implementations need to provide the performOperationViaRequest method to handle the actual communication with DOIP services, as well as a close method to handle resource cleanup. This class will define all convenience methods by means of performOperationViaRequest.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    defaultOptions?: Options

    Default options for all operations performed by this client. These options can be overridden by providing options to individual method calls.

    Methods

    • Performs a DOIP operation.

      This method must be implemented by concrete subclasses to handle the actual communication with DOIP services.

      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

    • 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

    • This method creates a copy of the request and adds authentication information and attributes from the options or default options if not already present.

      Parameters

      • doipRequest: DoipRequest

        The DOIP request to augment

      • Optionaloptions: Options

        Optional request options

      Returns DoipRequest

      The augmented DOIP request

    • 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);
      }
    • Parses a DoipResponse into a DigitalObject, throwing an error if the DoipResponse does not have the expected structure.

      Parameters

      Returns Promise<DigitalObject>

      The DigitalObject given by the DOIP response

    • Parses a DoipResponse into a SearchResults, throwing an error if the DoipResponse does not have the expected structure.

      Type Parameters

      • T

        The type of items in the search results. Either string or DigitalObject.

      Parameters

      Returns Promise<SearchResults<T>>

      The SearchResults given by the DOIP response