Multiple Issues With TypeScript Functions

Hey y’all - I’m back after getting some guidance about AIP Logic recently.

I tried making a TypeScript Function in a Code Repository that would call an AIP Logic function and then create some ontology objects, but am running into multiple issues.

Function works in preview, not in publish

Here’s a simple function. It works when I go to function preview.

import { Client } from "@osdk/client";
import {
  MasterObjective,
  DevsmaCandidateObjectiveAlignment,
  MasterItem,
} from "@osdk/generated";
import { Osdk } from "@osdk/client";

export default async function getAligmentSuggestions(
  client: Client,
  item: Osdk.Instance<MasterItem>,
  objective: Osdk.Instance<MasterObjective>
): Promise<string> {
  const alignmentSuggestions = await client(DevsmaCandidateObjectiveAlignment)
    .where({
      itemId: item.id,
      objectiveId: objective.id,
    })
    .fetchPage();

  if (alignmentSuggestions.data.length === 0) {
    return "NO";
  } else {
    return `YES ${alignmentSuggestions.data.length} ITEMS`;
  }
}

It does not work when I try to publish, giving me an error in some kind of intermediary build file that is not in the repo.

************************************************************************
ERROR
======

Failed to compile code. Fix the errors and try again.
======
Errors: 
src/_ontologyObjectFactory/typescript-functions/src/functions/getAlignmentSuggestions.ts(48,57): error TS2349: This expression is not callable.
  Each member of the union type '(<const L extends PropertyKeys<MasterItem>, const R extends boolean, const S extends false | "throw" = "throw">(primaryKey: string, options?: SelectArg<MasterItem, L, R, S> | undefined) => Promise<...>) | (<const L extends PropertyKeys<...>, const R extends boolean, const S extends false | "throw" = "throw">(primary...' has signatures, but none of those signatures are compatible with each other.
src/_ontologyObjectFactory/typescript-functions/src/functions/getAlignmentSuggestions.ts(48,88): error TS7006: Parameter 'osdkObject' implicitly has an 'any' type.

************************************************************************

Query function never added

Secondly, I have an AIP Logic function that I intend to call with this Code Repository function. I add it in the Resource imports tab, and I’ve set enableQueries: true in typescript-functions/functions.json, which looks like this:

{
  "useOntologyApiNames": true,
  "enableModelFunctions": true,
  "enableModelGraphFunctions": false,
  "enableDiscoverImproperOntologyAccess": false,
  "enableQueries": true,
  "enableModelMetadata": false,
  "useDeploymentApiNames": true,
  "enableVectorProperties": true,
  "enableTimeSeriesProperties": false,
  "enableExternalSystems": true,
  "enableMediaReferenceProperties": false
}

But no matter what I do, including removing my non-working toy function up above, the @osdk/generated exports never have anything in the queries section.

export {} from './ontology/queries.js';
export * as $Queries from './ontology/queries.js';

Any ideas on what I might be doing wrong here?

Hi @steven.merrill , the first issue you flagged with publish failing is a bug on our side, for which we’ll have a fix shortly. For the second issue, calling queries is currently not supported in the v2 experimental TypeScript template, but will be over the coming weeks.

Edit: Both issues raised here have been addressed, please upgrade your repository to the latest version in Authoring.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.