{"version":3,"sources":["../../../../../node_modules/.pnpm/@osdk+foundry.ontologies@2.44.0/node_modules/@osdk/foundry.ontologies/build/esm/public/OntologyTransaction.js","../../../src/transactions/WriteableClient.ts","../../../src/transactions/EditRequestManager.ts","../../../src/transactions/toPropertyDataValue.ts","../../../src/transactions/createWriteableClient.ts","../../../src/transactions/flushEdits.ts","../../../src/utils/getApiGatewayBaseUrl.ts"],"names":["__export","foundryPlatformFetch","createClientWithTransaction","readFileSync","parseYaml"],"mappings":";;;;;;;;;AAAA,IAAA,2BAAA,GAAA,EAAA;AAAAA,0BAAA,CAAA,2BAAA,EAAA;AAAA,EAAA,SAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAiBA,IAAM,UAAA,GAAa,CAAC,CAAA,EAAG,2CAAA,EAA6C,CAAC,CAAA;AAS9D,SAAS,SAAA,CAAU,SAAS,IAAA,EAAM;AACvC,EAAA,OAAOC,sCAAA,CAAsB,IAAA,EAAM,UAAA,EAAY,GAAG,IAAI,CAAA;AACxD;;;ACXO,IAAM,sBAAA,GAAyB,OAAO,wBAAwB,CAAA;;;ACC9D,IAAM,qBAAN,MAAyB;AAAA,EAC9B,eAAe,EAAC;AAAA,EAChB,eAAA,GAAkB,IAAA;AAAA,EAClB,aAAA,GAAgB,IAAA;AAAA,EAChB,WAAA,GAAc,IAAA;AAAA,EACd,YAAY,MAAA,EAAQ;AAClB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AAAA,EACA,SAAS,IAAA,EAAM;AACb,IAAA,IAAI,KAAK,eAAA,EAAiB;AACxB,MAAA,IAAI,KAAK,WAAA,EAAa;AAEpB,QAAA,IAAA,CAAK,YAAA,CAAa,KAAK,IAAI,CAAA;AAC3B,QAAA,OAAO,IAAA,CAAK,eAAA;AAAA,MACd;AACA,MAAA,IAAI,KAAK,aAAA,EAAe;AAEtB,QAAA,IAAA,CAAK,YAAA,CAAa,KAAK,IAAI,CAAA;AAC3B,QAAA,OAAO,IAAA,CAAK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AAAA,EAC/F;AACA,EAAA,MAAM,gBAAA,GAAmB,UAAU,mBAAmB,CAAA;AACtD,EAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,mBAAmB,CAAA,4CAAA,CAA8C,CAAA;AAAA,EACtF;AACA,EAAA,MAAM,IAAA,GAAO,YAAY,gBAAgB,CAAA;AACzC,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACrB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,mBAAmB,CAAA,kCAAA,CAAoC,CAAA;AAAA,EAC9F;AACA,EAAA,OAAO,KAAK,CAAC,CAAA;AACf","file":"unstable-do-not-use.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { foundryPlatformFetch as $foundryPlatformFetch } from \"@osdk/shared.net.platformapi\";\n//\nconst _postEdits = [1, \"/v2/ontologies/{0}/transactions/{1}/edits\", 3];\n/**\n * Applies a set of edits to a transaction in order.\n *\n * @alpha\n *\n * Required Scopes: [api:ontologies-read]\n * URL: /v2/ontologies/{ontology}/transactions/{transactionId}/edits\n */\nexport function postEdits($ctx, ...args) {\n  return $foundryPlatformFetch($ctx, _postEdits, ...args);\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @internal */\nexport const writeableClientContext = Symbol(\"writeableClientContext\");","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { OntologyTransactions } from \"@osdk/foundry.ontologies\";\nimport { writeableClientContext } from \"./WriteableClient.js\";\nexport class EditRequestManager {\n  pendingEdits = [];\n  inFlightRequest = null;\n  queuedRequest = null;\n  editTimeout = null;\n  constructor(client) {\n    this.client = client;\n  }\n  postEdit(edit) {\n    if (this.inFlightRequest) {\n      if (this.editTimeout) {\n        // This means we are in the same tick that the request was created, meaning we can just add to the same request\n        this.pendingEdits.push(edit);\n        return this.inFlightRequest;\n      }\n      if (this.queuedRequest) {\n        // This means we already have a queued request that will run after the inFlightRequest finishes, so we can just add to that one\n        this.pendingEdits.push(edit);\n        return this.queuedRequest;\n      }\n      // This means a request has already been sent to the wire but not been returned, so we need to queue up a new request for when that one finishes\n      this.queuedRequest = this.inFlightRequest.then(async () => {\n        this.inFlightRequest = this.queuedRequest;\n        this.queuedRequest = null;\n        this.pendingEdits.push(edit);\n        await this.dispatchRequest();\n      });\n      return this.queuedRequest;\n    } else {\n      // There is no request in flight, which means we should create a new one\n      this.inFlightRequest = this.createInitialPromiseWithTimeout(edit);\n      return this.inFlightRequest;\n    }\n  }\n  createInitialPromiseWithTimeout(edit) {\n    return new Promise(resolve => {\n      this.pendingEdits.push(edit);\n      this.editTimeout = setTimeout(async () => {\n        this.editTimeout = null;\n        await this.dispatchRequest();\n        if (!this.queuedRequest) {\n          // The queued request will see this inFlightRequest resolve and should set the inFlightRequest to itself\n          this.inFlightRequest = null;\n        }\n        resolve();\n      }, 0);\n    });\n  }\n  async dispatchRequest() {\n    const copiedEdits = this.pendingEdits;\n    this.pendingEdits = [];\n    await OntologyTransactions.postEdits(this.client, await this.client[writeableClientContext].ontologyRid, this.client[writeableClientContext].transactionId, {\n      edits: copiedEdits\n    }, {\n      preview: true\n    });\n  }\n  async flushPendingEdits() {\n    if (this.editTimeout) {\n      clearTimeout(this.editTimeout);\n      this.editTimeout = null;\n      if (this.pendingEdits.length > 0) {\n        await this.dispatchRequest();\n        this.inFlightRequest = null;\n      }\n    }\n    if (this.inFlightRequest) {\n      await this.inFlightRequest;\n    }\n    if (this.queuedRequest) {\n      await this.queuedRequest;\n    }\n    if (this.pendingEdits.length > 0) {\n      await this.dispatchRequest();\n    }\n  }\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function toPropertyDataValue(value) {\n  if (value == null) {\n    return null; // This differs from how actions handles null, which expects a specific enum value.\n  }\n  if (Array.isArray(value)) {\n    return value.map(item => toPropertyDataValue(item));\n  }\n  if (typeof value === \"object\") {\n    const result = {};\n    for (const key in value) {\n      result[key] = toPropertyDataValue(value[key]);\n    }\n    return result;\n  }\n\n  // expected to pass through - boolean, byte, date, decimal, float, double, integer, long, short, string, timestamp, object type reference\n  return value;\n}","/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createClientWithTransaction } from \"@osdk/client/unstable-do-not-use\";\nimport { EditRequestManager } from \"./EditRequestManager.js\";\nimport { toPropertyDataValue } from \"./toPropertyDataValue.js\";\nimport { writeableClientContext } from \"./WriteableClient.js\";\nexport function createWriteableClient(transactionId, ...args) {\n  const ontologyRid = args[1];\n  let editRequestManager;\n  const client = createClientWithTransaction(transactionId, () => editRequestManager.flushPendingEdits(), ...args);\n  editRequestManager = new EditRequestManager(client) // This cast is safe because we create the writeable client properties below.\n  ;\n\n  // We use define properties because the client has non-enumerable properties that we want to preserve.\n  const writeableClient = Object.defineProperties(client, {\n    link: {\n      value(source, apiName, target) {\n        if (!Array.isArray(target)) {\n          return editRequestManager.postEdit({\n            type: \"addLink\",\n            objectType: source.$apiName,\n            primaryKey: source.$primaryKey,\n            linkType: apiName,\n            linkedObjectPrimaryKey: target.$primaryKey\n          });\n        }\n        const promises = [];\n        for (const elem of target) {\n          promises.push(editRequestManager.postEdit({\n            type: \"addLink\",\n            objectType: source.$apiName,\n            primaryKey: source.$primaryKey,\n            linkType: apiName,\n            linkedObjectPrimaryKey: elem.$primaryKey\n          }));\n        }\n        return Promise.all(promises).then(() => undefined);\n      }\n    },\n    unlink: {\n      value(source, apiName, target) {\n        if (!Array.isArray(target)) {\n          return editRequestManager.postEdit({\n            type: \"removeLink\",\n            objectType: source.$apiName,\n            primaryKey: source.$primaryKey,\n            linkType: apiName,\n            linkedObjectPrimaryKey: target.$primaryKey\n          });\n        }\n        const promises = [];\n        for (const elem of target) {\n          promises.push(editRequestManager.postEdit({\n            type: \"removeLink\",\n            objectType: source.$apiName,\n            primaryKey: source.$primaryKey,\n            linkType: apiName,\n            linkedObjectPrimaryKey: elem.$primaryKey\n          }));\n        }\n        return Promise.all(promises).then(() => undefined);\n      }\n    },\n    create: {\n      async value(obj, properties) {\n        const propertyMap = {};\n        for (const [key, value] of Object.entries(properties)) {\n          if (key.startsWith(\"$\")) continue;\n          propertyMap[key] = toPropertyDataValue(value);\n        }\n        return editRequestManager.postEdit({\n          type: \"addObject\",\n          objectType: obj.apiName,\n          properties: propertyMap\n        });\n      }\n    },\n    update: {\n      value(locator, properties) {\n        const propertyMap = {};\n        for (const [key, value] of Object.entries(properties)) {\n          if (key.startsWith(\"$\")) continue;\n          propertyMap[key] = toPropertyDataValue(value);\n        }\n        return editRequestManager.postEdit({\n          type: \"modifyObject\",\n          objectType: locator.$apiName,\n          primaryKey: locator.$primaryKey,\n          properties: propertyMap\n        });\n      }\n    },\n    delete: {\n      value(obj) {\n        return editRequestManager.postEdit({\n          type: \"deleteObject\",\n          objectType: obj.$apiName,\n          primaryKey: obj.$primaryKey\n        });\n      }\n    },\n    [writeableClientContext]: {\n      value: {\n        ontologyRid,\n        transactionId,\n        editRequestManager\n      }\n    }\n  });\n  return writeableClient;\n}","/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { writeableClientContext } from \"./WriteableClient.js\";\nexport async function flushEdits(client) {\n  await client[writeableClientContext].editRequestManager.flushPendingEdits();\n  return;\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { readFileSync } from \"fs\";\nimport { parse as parseYaml } from \"yaml\";\nconst FOUNDRY_SERVICE_DISCOVERY_V2_ENV_VAR = \"FOUNDRY_SERVICE_DISCOVERY_V2\";\nconst API_GATEWAY_SERVICE = \"api_gateway\";\n/**\n * Type guard to check if config is an object with uris property\n */\nfunction hasUrisProperty(config) {\n  return !Array.isArray(config) && \"uris\" in config && Array.isArray(config.uris) && config.uris.every(uri => typeof uri === \"string\");\n}\n\n/**\n * Extracts URIs from either array or object format\n */\nfunction extractUris(config) {\n  return hasUrisProperty(config) ? config.uris : config;\n}\n\n/**\n * Retrieves the API Gateway base URL from the Function's environment.\n *\n * This function is intended to be used only from within a function. Usage of this utility elsewhere may result\n * in errors since the environment may not be properly configured.\n *\n * @returns The API Gateway base URL (e.g., \"https://example.palantirfoundry.com\")\n * @throws Error if the API Gateway base URL has not been properly configured in the function's environment.\n *\n * @example\n * ```typescript\n * const baseUrl = getApiGatewayBaseUrl();\n * // Returns: \"https://example.palantirfoundry.com\"\n * ```\n */\nexport function getApiGatewayBaseUrl() {\n  const filePath = process.env[FOUNDRY_SERVICE_DISCOVERY_V2_ENV_VAR];\n  if (!filePath) {\n    throw new Error(`${FOUNDRY_SERVICE_DISCOVERY_V2_ENV_VAR} environment variable is not set`);\n  }\n  let fileContent;\n  try {\n    fileContent = readFileSync(filePath, \"utf-8\");\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    throw new Error(`Failed to read service discovery file at ${filePath}: ${errorMessage}`);\n  }\n  let discovery;\n  try {\n    discovery = parseYaml(fileContent);\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    throw new Error(`Failed to parse service discovery YAML file at ${filePath}: ${errorMessage}`);\n  }\n  const apiGatewayConfig = discovery[API_GATEWAY_SERVICE];\n  if (!apiGatewayConfig) {\n    throw new Error(`${API_GATEWAY_SERVICE} service not found in service discovery file`);\n  }\n  const uris = extractUris(apiGatewayConfig);\n  if (uris.length === 0) {\n    throw new Error(`No URIs found for ${API_GATEWAY_SERVICE} service in service discovery file`);\n  }\n  return uris[0];\n}"]}