@osdk/client 2.1.0-beta.2 → 2.1.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +297 -0
- package/build/browser/Client.d.ts +6 -22
- package/build/browser/Client.d.ts.map +1 -1
- package/build/browser/Client.js +3 -1
- package/build/browser/Client.js.map +1 -1
- package/build/browser/MinimalClientContext.d.ts +1 -1
- package/build/browser/MinimalClientContext.d.ts.map +1 -1
- package/build/browser/__unstable/ConjureSupport.js +5 -5
- package/build/browser/__unstable/ConjureSupport.js.map +1 -1
- package/build/browser/__unstable/createBulkLinksAsyncIterFactory.d.ts +1 -6
- package/build/browser/__unstable/createBulkLinksAsyncIterFactory.d.ts.map +1 -1
- package/build/browser/__unstable/createBulkLinksAsyncIterFactory.js +2 -2
- package/build/browser/__unstable/createBulkLinksAsyncIterFactory.js.map +1 -1
- package/build/browser/actions/actions.test.js +28 -0
- package/build/browser/actions/actions.test.js.map +1 -1
- package/build/browser/actions/applyAction.js +1 -1
- package/build/browser/actions/applyAction.js.map +1 -1
- package/build/browser/createClient.d.ts +1 -1
- package/build/browser/createClient.d.ts.map +1 -1
- package/build/browser/createClient.js +41 -19
- package/build/browser/createClient.js.map +1 -1
- package/build/browser/createClient.test.js +24 -0
- package/build/browser/createClient.test.js.map +1 -1
- package/build/browser/createGeotimeSeriesProperty.d.ts +1 -1
- package/build/browser/createGeotimeSeriesProperty.d.ts.map +1 -1
- package/build/browser/createGeotimeSeriesProperty.js +4 -1
- package/build/browser/createGeotimeSeriesProperty.js.map +1 -1
- package/build/browser/createMinimalClient.js +9 -4
- package/build/browser/createMinimalClient.js.map +1 -1
- package/build/browser/createPlatformClient.d.ts +1 -1
- package/build/browser/createPlatformClient.d.ts.map +1 -1
- package/build/browser/createTimeseriesProperty.d.ts.map +1 -1
- package/build/browser/fetchMetadata.test.js +14 -0
- package/build/browser/fetchMetadata.test.js.map +1 -1
- package/build/browser/index.d.ts +2 -2
- package/build/browser/index.d.ts.map +1 -1
- package/build/browser/index.js +1 -1
- package/build/browser/index.js.map +1 -1
- package/build/browser/intellisense.test.js +1 -1
- package/build/browser/intellisense.test.js.map +1 -1
- package/build/browser/internal/conversions/legacyToModernSingleAggregationResult.js +1 -1
- package/build/browser/internal/conversions/legacyToModernSingleAggregationResult.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js +11 -3
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.test.js +208 -7
- package/build/browser/internal/conversions/modernToLegacyWhereClause.test.js.map +1 -1
- package/build/browser/object/AttachmentUpload.d.ts.map +1 -1
- package/build/browser/object/AttachmentUpload.js +5 -7
- package/build/browser/object/AttachmentUpload.js.map +1 -1
- package/build/browser/object/aggregate.js +4 -5
- package/build/browser/object/aggregate.js.map +1 -1
- package/build/browser/object/aggregate.test.js +6 -9
- package/build/browser/object/aggregate.test.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.d.ts +1 -10
- package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.d.ts.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/InternalSymbols.d.ts +0 -7
- package/build/browser/object/convertWireToOsdkObjects/InternalSymbols.d.ts.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/InternalSymbols.js +4 -3
- package/build/browser/object/convertWireToOsdkObjects/InternalSymbols.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js +41 -85
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.test.js +0 -6
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.test.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +60 -89
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarAs.js +2 -2
- package/build/browser/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/getDollarLink.js +14 -38
- package/build/browser/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.js +42 -6
- package/build/browser/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.test.js +177 -45
- package/build/browser/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/browser/object/fetchPage.d.ts.map +1 -1
- package/build/browser/object/fetchPage.js +34 -23
- package/build/browser/object/fetchPage.js.map +1 -1
- package/build/browser/object/fetchPage.test.js +75 -1
- package/build/browser/object/fetchPage.test.js.map +1 -1
- package/build/browser/object/object.test.d.ts.map +1 -1
- package/build/browser/object/object.test.js +25 -1
- package/build/browser/object/object.test.js.map +1 -1
- package/build/browser/object/timeseries.test.js +10 -0
- package/build/browser/object/timeseries.test.js.map +1 -1
- package/build/browser/objectSet/InterfaceObjectSet.test.d.ts +2 -0
- package/build/browser/objectSet/InterfaceObjectSet.test.d.ts.map +1 -0
- package/build/browser/objectSet/InterfaceObjectSet.test.js +61 -0
- package/build/browser/objectSet/InterfaceObjectSet.test.js.map +1 -0
- package/build/browser/objectSet/ObjectSet.test.js +162 -48
- package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js +136 -74
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js +150 -42
- package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
- package/build/browser/objectSet/createObjectSet.js +10 -8
- package/build/browser/objectSet/createObjectSet.js.map +1 -1
- package/build/browser/objectSet/toConjureObjectSet.js +2 -0
- package/build/browser/objectSet/toConjureObjectSet.js.map +1 -1
- package/build/browser/ontology/makeConjureContext.d.ts +1 -1
- package/build/browser/ontology/makeConjureContext.d.ts.map +1 -1
- package/build/browser/public/internal.d.ts +4 -0
- package/build/browser/public/internal.d.ts.map +1 -0
- package/build/browser/public/internal.js +19 -0
- package/build/browser/public/internal.js.map +1 -0
- package/build/browser/public-utils/createAndFetchTempObjectSetRid.d.ts +11 -0
- package/build/browser/public-utils/createAndFetchTempObjectSetRid.d.ts.map +1 -0
- package/build/browser/public-utils/createAndFetchTempObjectSetRid.js +32 -0
- package/build/browser/public-utils/createAndFetchTempObjectSetRid.js.map +1 -0
- package/build/browser/public-utils/hydrateAttachmentFromRid.d.ts +10 -0
- package/build/browser/public-utils/hydrateAttachmentFromRid.d.ts.map +1 -0
- package/build/{esm/createAttachmentFromRid.js → browser/public-utils/hydrateAttachmentFromRid.js} +9 -4
- package/build/browser/public-utils/hydrateAttachmentFromRid.js.map +1 -0
- package/build/browser/public-utils/hydrateObjectSetFromRid.d.ts +11 -0
- package/build/browser/public-utils/hydrateObjectSetFromRid.d.ts.map +1 -0
- package/build/browser/public-utils/hydrateObjectSetFromRid.js +37 -0
- package/build/browser/public-utils/hydrateObjectSetFromRid.js.map +1 -0
- package/build/browser/queries/applyQuery.d.ts.map +1 -1
- package/build/browser/queries/applyQuery.js +3 -4
- package/build/browser/queries/applyQuery.js.map +1 -1
- package/build/browser/queries/queries.test.js +30 -2
- package/build/browser/queries/queries.test.js.map +1 -1
- package/build/browser/tsserver.js +1 -1
- package/build/browser/tsserver.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/browser/util/datetimeConverters.d.ts +22 -0
- package/build/browser/util/datetimeConverters.d.ts.map +1 -0
- package/build/browser/util/datetimeConverters.js +55 -0
- package/build/browser/util/datetimeConverters.js.map +1 -0
- package/build/browser/util/datetimeConverters.test.d.ts +2 -0
- package/build/browser/util/datetimeConverters.test.d.ts.map +1 -0
- package/build/browser/util/datetimeConverters.test.js +75 -0
- package/build/browser/util/datetimeConverters.test.js.map +1 -0
- package/build/browser/util/objectSetUtils.d.ts +4 -0
- package/build/browser/util/objectSetUtils.d.ts.map +1 -0
- package/build/browser/util/objectSetUtils.js +25 -0
- package/build/browser/util/objectSetUtils.js.map +1 -0
- package/build/browser/util/timeseriesUtils.d.ts +1 -1
- package/build/browser/util/timeseriesUtils.d.ts.map +1 -1
- package/build/browser/util/timeseriesUtils.js +1 -1
- package/build/browser/util/timeseriesUtils.js.map +1 -1
- package/build/browser/util/toDataValue.js +6 -0
- package/build/browser/util/toDataValue.js.map +1 -1
- package/build/browser/util/toDataValue.test.js +9 -1
- package/build/browser/util/toDataValue.test.js.map +1 -1
- package/build/browser/util/toDataValueQueries.js +6 -0
- package/build/browser/util/toDataValueQueries.js.map +1 -1
- package/build/esm/Client.d.ts +6 -22
- package/build/esm/Client.d.ts.map +1 -1
- package/build/esm/Client.js +3 -1
- package/build/esm/Client.js.map +1 -1
- package/build/esm/MinimalClientContext.d.ts +1 -1
- package/build/esm/MinimalClientContext.d.ts.map +1 -1
- package/build/esm/__unstable/ConjureSupport.js +5 -5
- package/build/esm/__unstable/ConjureSupport.js.map +1 -1
- package/build/esm/__unstable/createBulkLinksAsyncIterFactory.d.ts +1 -6
- package/build/esm/__unstable/createBulkLinksAsyncIterFactory.d.ts.map +1 -1
- package/build/esm/__unstable/createBulkLinksAsyncIterFactory.js +2 -2
- package/build/esm/__unstable/createBulkLinksAsyncIterFactory.js.map +1 -1
- package/build/esm/actions/actions.test.js +28 -0
- package/build/esm/actions/actions.test.js.map +1 -1
- package/build/esm/actions/applyAction.js +1 -1
- package/build/esm/actions/applyAction.js.map +1 -1
- package/build/esm/createClient.d.ts +1 -1
- package/build/esm/createClient.d.ts.map +1 -1
- package/build/esm/createClient.js +41 -19
- package/build/esm/createClient.js.map +1 -1
- package/build/esm/createClient.test.js +24 -0
- package/build/esm/createClient.test.js.map +1 -1
- package/build/esm/createGeotimeSeriesProperty.d.ts +1 -1
- package/build/esm/createGeotimeSeriesProperty.d.ts.map +1 -1
- package/build/esm/createGeotimeSeriesProperty.js +4 -1
- package/build/esm/createGeotimeSeriesProperty.js.map +1 -1
- package/build/esm/createMinimalClient.js +9 -4
- package/build/esm/createMinimalClient.js.map +1 -1
- package/build/esm/createPlatformClient.d.ts +1 -1
- package/build/esm/createPlatformClient.d.ts.map +1 -1
- package/build/esm/createTimeseriesProperty.d.ts.map +1 -1
- package/build/esm/fetchMetadata.test.js +14 -0
- package/build/esm/fetchMetadata.test.js.map +1 -1
- package/build/esm/index.d.ts +2 -2
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/intellisense.test.js +1 -1
- package/build/esm/intellisense.test.js.map +1 -1
- package/build/esm/internal/conversions/legacyToModernSingleAggregationResult.js +1 -1
- package/build/esm/internal/conversions/legacyToModernSingleAggregationResult.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js +11 -3
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.test.js +208 -7
- package/build/esm/internal/conversions/modernToLegacyWhereClause.test.js.map +1 -1
- package/build/esm/object/AttachmentUpload.d.ts.map +1 -1
- package/build/esm/object/AttachmentUpload.js +5 -7
- package/build/esm/object/AttachmentUpload.js.map +1 -1
- package/build/esm/object/aggregate.js +4 -5
- package/build/esm/object/aggregate.js.map +1 -1
- package/build/esm/object/aggregate.test.js +6 -9
- package/build/esm/object/aggregate.test.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts +1 -10
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InternalSymbols.d.ts +0 -7
- package/build/esm/object/convertWireToOsdkObjects/InternalSymbols.d.ts.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InternalSymbols.js +4 -3
- package/build/esm/object/convertWireToOsdkObjects/InternalSymbols.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js +41 -85
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.test.js +0 -6
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.test.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +60 -89
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarAs.js +2 -2
- package/build/esm/object/convertWireToOsdkObjects/getDollarAs.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/getDollarLink.js +14 -38
- package/build/esm/object/convertWireToOsdkObjects/getDollarLink.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.js +42 -6
- package/build/esm/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.test.js +177 -45
- package/build/esm/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/esm/object/fetchPage.d.ts.map +1 -1
- package/build/esm/object/fetchPage.js +34 -23
- package/build/esm/object/fetchPage.js.map +1 -1
- package/build/esm/object/fetchPage.test.js +75 -1
- package/build/esm/object/fetchPage.test.js.map +1 -1
- package/build/esm/object/object.test.d.ts.map +1 -1
- package/build/esm/object/object.test.js +25 -1
- package/build/esm/object/object.test.js.map +1 -1
- package/build/esm/object/timeseries.test.js +10 -0
- package/build/esm/object/timeseries.test.js.map +1 -1
- package/build/esm/objectSet/InterfaceObjectSet.test.d.ts +2 -0
- package/build/esm/objectSet/InterfaceObjectSet.test.d.ts.map +1 -0
- package/build/esm/objectSet/InterfaceObjectSet.test.js +61 -0
- package/build/esm/objectSet/InterfaceObjectSet.test.js.map +1 -0
- package/build/esm/objectSet/ObjectSet.test.js +162 -48
- package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js +136 -77
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js +150 -42
- package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js.map +1 -1
- package/build/esm/objectSet/createObjectSet.js +10 -8
- package/build/esm/objectSet/createObjectSet.js.map +1 -1
- package/build/esm/objectSet/toConjureObjectSet.js +2 -0
- package/build/esm/objectSet/toConjureObjectSet.js.map +1 -1
- package/build/esm/ontology/makeConjureContext.d.ts +1 -1
- package/build/esm/ontology/makeConjureContext.d.ts.map +1 -1
- package/build/esm/public/internal.d.ts +4 -0
- package/build/esm/public/internal.d.ts.map +1 -0
- package/build/esm/public/internal.js +19 -0
- package/build/esm/public/internal.js.map +1 -0
- package/build/esm/public-utils/createAndFetchTempObjectSetRid.d.ts +11 -0
- package/build/esm/public-utils/createAndFetchTempObjectSetRid.d.ts.map +1 -0
- package/build/esm/public-utils/createAndFetchTempObjectSetRid.js +32 -0
- package/build/esm/public-utils/createAndFetchTempObjectSetRid.js.map +1 -0
- package/build/esm/public-utils/hydrateAttachmentFromRid.d.ts +10 -0
- package/build/esm/public-utils/hydrateAttachmentFromRid.d.ts.map +1 -0
- package/build/{browser/createAttachmentFromRid.js → esm/public-utils/hydrateAttachmentFromRid.js} +9 -4
- package/build/esm/public-utils/hydrateAttachmentFromRid.js.map +1 -0
- package/build/esm/public-utils/hydrateObjectSetFromRid.d.ts +11 -0
- package/build/esm/public-utils/hydrateObjectSetFromRid.d.ts.map +1 -0
- package/build/esm/public-utils/hydrateObjectSetFromRid.js +37 -0
- package/build/esm/public-utils/hydrateObjectSetFromRid.js.map +1 -0
- package/build/esm/queries/applyQuery.d.ts.map +1 -1
- package/build/esm/queries/applyQuery.js +3 -4
- package/build/esm/queries/applyQuery.js.map +1 -1
- package/build/esm/queries/queries.test.js +30 -2
- package/build/esm/queries/queries.test.js.map +1 -1
- package/build/esm/tsserver.js +1 -1
- package/build/esm/tsserver.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/esm/util/datetimeConverters.d.ts +22 -0
- package/build/esm/util/datetimeConverters.d.ts.map +1 -0
- package/build/esm/util/datetimeConverters.js +55 -0
- package/build/esm/util/datetimeConverters.js.map +1 -0
- package/build/esm/util/datetimeConverters.test.d.ts +2 -0
- package/build/esm/util/datetimeConverters.test.d.ts.map +1 -0
- package/build/esm/util/datetimeConverters.test.js +75 -0
- package/build/esm/util/datetimeConverters.test.js.map +1 -0
- package/build/esm/util/objectSetUtils.d.ts +4 -0
- package/build/esm/util/objectSetUtils.d.ts.map +1 -0
- package/build/esm/util/objectSetUtils.js +25 -0
- package/build/esm/util/objectSetUtils.js.map +1 -0
- package/build/esm/util/timeseriesUtils.d.ts +1 -1
- package/build/esm/util/timeseriesUtils.d.ts.map +1 -1
- package/build/esm/util/timeseriesUtils.js +1 -1
- package/build/esm/util/timeseriesUtils.js.map +1 -1
- package/build/esm/util/toDataValue.js +6 -0
- package/build/esm/util/toDataValue.js.map +1 -1
- package/build/esm/util/toDataValue.test.js +9 -1
- package/build/esm/util/toDataValue.test.js.map +1 -1
- package/build/esm/util/toDataValueQueries.js +6 -0
- package/build/esm/util/toDataValueQueries.js.map +1 -1
- package/package.json +23 -19
- package/build/browser/createAttachmentFromRid.d.ts +0 -10
- package/build/browser/createAttachmentFromRid.d.ts.map +0 -1
- package/build/browser/createAttachmentFromRid.js.map +0 -1
- package/build/esm/createAttachmentFromRid.d.ts +0 -10
- package/build/esm/createAttachmentFromRid.d.ts.map +0 -1
- package/build/esm/createAttachmentFromRid.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDollarLink.js","names":["getWireObjectSet","fetchSingle","fetchSingleWithErrors","ClientRef","ObjectDefRef","
|
|
1
|
+
{"version":3,"file":"getDollarLink.js","names":["getWireObjectSet","fetchSingle","fetchSingleWithErrors","ClientRef","ObjectDefRef","UnderlyingOsdkObject","get$link","holder","client","objDef","rawObj","Object","freeze","fromEntries","keys","links","map","linkName","linkDef","objectSet","objectSetFactory","where","primaryKeyApiName","$primaryKey","pivotTo","value","multiplicity","fetchOne","options","fetchOneWithErrors"],"sources":["getDollarLink.js"],"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 { getWireObjectSet } from \"../../objectSet/createObjectSet.js\";\nimport { fetchSingle, fetchSingleWithErrors } from \"../fetchSingle.js\";\nimport { ClientRef, ObjectDefRef, UnderlyingOsdkObject, } from \"./InternalSymbols.js\";\n/** @internal */\nexport function get$link(holder) {\n const client = holder[ClientRef];\n const objDef = holder[ObjectDefRef];\n const rawObj = holder[UnderlyingOsdkObject];\n return Object.freeze(Object.fromEntries(Object.keys(objDef.links).map((linkName) => {\n const linkDef = objDef.links[linkName];\n const objectSet = client.objectSetFactory(objDef, client)\n .where({\n [objDef.primaryKeyApiName]: rawObj.$primaryKey,\n })\n .pivotTo(linkName);\n const value = !linkDef.multiplicity\n ? {\n fetchOne: (options) => fetchSingle(client, objDef, options ?? {}, getWireObjectSet(objectSet)),\n fetchOneWithErrors: (options) => fetchSingleWithErrors(client, objDef, options ?? {}, getWireObjectSet(objectSet)),\n }\n : objectSet;\n return [linkName, value];\n })));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,oCAAoC;AACrE,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,mBAAmB;AACtE,SAASC,SAAS,EAAEC,YAAY,EAAEC,oBAAoB,QAAS,sBAAsB;AACrF;AACA,OAAO,SAASC,QAAQA,CAACC,MAAM,EAAE;EAC7B,MAAMC,MAAM,GAAGD,MAAM,CAACJ,SAAS,CAAC;EAChC,MAAMM,MAAM,GAAGF,MAAM,CAACH,YAAY,CAAC;EACnC,MAAMM,MAAM,GAAGH,MAAM,CAACF,oBAAoB,CAAC;EAC3C,OAAOM,MAAM,CAACC,MAAM,CAACD,MAAM,CAACE,WAAW,CAACF,MAAM,CAACG,IAAI,CAACL,MAAM,CAACM,KAAK,CAAC,CAACC,GAAG,CAAEC,QAAQ,IAAK;IAChF,MAAMC,OAAO,GAAGT,MAAM,CAACM,KAAK,CAACE,QAAQ,CAAC;IACtC,MAAME,SAAS,GAAGX,MAAM,CAACY,gBAAgB,CAACX,MAAM,EAAED,MAAM,CAAC,CACpDa,KAAK,CAAC;MACP,CAACZ,MAAM,CAACa,iBAAiB,GAAGZ,MAAM,CAACa;IACvC,CAAC,CAAC,CACGC,OAAO,CAACP,QAAQ,CAAC;IACtB,MAAMQ,KAAK,GAAG,CAACP,OAAO,CAACQ,YAAY,GAC7B;MACEC,QAAQ,EAAGC,OAAO,IAAK3B,WAAW,CAACO,MAAM,EAAEC,MAAM,EAAEmB,OAAO,IAAI,CAAC,CAAC,EAAE5B,gBAAgB,CAACmB,SAAS,CAAC,CAAC;MAC9FU,kBAAkB,EAAGD,OAAO,IAAK1B,qBAAqB,CAACM,MAAM,EAAEC,MAAM,EAAEmB,OAAO,IAAI,CAAC,CAAC,EAAE5B,gBAAgB,CAACmB,SAAS,CAAC;IACrH,CAAC,GACCA,SAAS;IACf,OAAO,CAACF,QAAQ,EAAEQ,KAAK,CAAC;EAC5B,CAAC,CAAC,CAAC,CAAC;AACR","ignoreList":[]}
|
|
@@ -39,7 +39,7 @@ export async function convertWireToOsdkObjects(client, objects, interfaceApiName
|
|
|
39
39
|
const ret = [];
|
|
40
40
|
for (const rawObj of objects) {
|
|
41
41
|
const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);
|
|
42
|
-
!objectDef ? invariant(false, `Missing definition for '${rawObj.$apiName}'`) : void 0;
|
|
42
|
+
!objectDef ? process.env.NODE_ENV !== "production" ? invariant(false, `Missing definition for '${rawObj.$apiName}'`) : invariant(false) : void 0;
|
|
43
43
|
// default value for when we are checking an object
|
|
44
44
|
let objProps;
|
|
45
45
|
let conforming = true;
|
|
@@ -65,6 +65,42 @@ export async function convertWireToOsdkObjects(client, objects, interfaceApiName
|
|
|
65
65
|
client.logger?.debug(`END convertWireToOsdkObjects()`);
|
|
66
66
|
return ret;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export async function convertWireToOsdkObjects2(client, objects, interfaceApiName, forceRemoveRid = false, selectedProps, strictNonNull = false, interfaceToObjectTypeMappings = {}) {
|
|
72
|
+
client.logger?.debug(`START convertWireToOsdkObjects2()`);
|
|
73
|
+
fixObjectPropertiesInPlace(objects, forceRemoveRid);
|
|
74
|
+
const ret = [];
|
|
75
|
+
for (const rawObj of objects) {
|
|
76
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);
|
|
77
|
+
!objectDef ? process.env.NODE_ENV !== "production" ? invariant(false, `Missing definition for '${rawObj.$apiName}'`) : invariant(false) : void 0;
|
|
78
|
+
const interfaceToObjMapping = interfaceApiName ? interfaceToObjectTypeMappings[interfaceApiName][rawObj.$apiName] : undefined;
|
|
79
|
+
const ifaceSelected = interfaceApiName && interfaceToObjMapping ? selectedProps ? Object.keys(interfaceToObjMapping).filter(val => {
|
|
80
|
+
selectedProps?.includes(interfaceToObjMapping[val]);
|
|
81
|
+
}) : [...Object.values(interfaceToObjMapping), objectDef.primaryKeyApiName] : undefined;
|
|
82
|
+
// default value for when we are checking an object
|
|
83
|
+
let objProps;
|
|
84
|
+
let conforming = true;
|
|
85
|
+
if (interfaceApiName && ifaceSelected) {
|
|
86
|
+
invariantInterfacesAsViews(objectDef, interfaceApiName, client);
|
|
87
|
+
objProps = ifaceSelected;
|
|
88
|
+
} else {
|
|
89
|
+
objProps = selectedProps ?? Object.keys(objectDef.properties);
|
|
90
|
+
}
|
|
91
|
+
conforming &&= isConforming(client, objectDef, rawObj, objProps);
|
|
92
|
+
if (strictNonNull === "throw" && !conforming) {
|
|
93
|
+
throw new Error("Unable to safely convert objects as some non nullable properties are null");
|
|
94
|
+
} else if (strictNonNull === "drop" && !conforming) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
let osdkObject = createOsdkObject(client, objectDef, rawObj);
|
|
98
|
+
if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);
|
|
99
|
+
ret.push(osdkObject);
|
|
100
|
+
}
|
|
101
|
+
client.logger?.debug(`END convertWireToOsdkObjects2()`);
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
68
104
|
/**
|
|
69
105
|
* Utility function that lets us take down selected property names from an interface
|
|
70
106
|
* and convert them to an array of property names on an object.
|
|
@@ -99,7 +135,7 @@ function reframeAsObjectInPlace(objectDef, interfaceApiName, rawObj) {
|
|
|
99
135
|
function isConforming(client, def, obj, propsToCheck) {
|
|
100
136
|
for (const propName of propsToCheck) {
|
|
101
137
|
if (def.properties[propName].nullable === false && obj[propName] == null) {
|
|
102
|
-
if (process
|
|
138
|
+
if (process.env.NODE_ENV !== "production") {
|
|
103
139
|
client.logger?.debug({
|
|
104
140
|
obj: {
|
|
105
141
|
$objectType: obj["$objectType"],
|
|
@@ -134,13 +170,13 @@ function fixObjectPropertiesInPlace(objs, forceRemoveRid) {
|
|
|
134
170
|
delete obj.__rid;
|
|
135
171
|
}
|
|
136
172
|
// Backend returns as __apiName but we want to stick to $ structure
|
|
137
|
-
obj.$apiName
|
|
173
|
+
obj.$apiName ??= obj.__apiName;
|
|
138
174
|
// for now these are the same but when we start doing interface projections the $objectType will always be underlying and
|
|
139
175
|
// the $apiName will be for the current view (in current designs)
|
|
140
|
-
obj.$objectType = obj
|
|
176
|
+
obj.$objectType = obj.$apiName;
|
|
141
177
|
// copying over for now as its always returned. In the future, this should just be inferred from underlying
|
|
142
|
-
obj.$primaryKey
|
|
143
|
-
obj.$title
|
|
178
|
+
obj.$primaryKey ??= obj.__primaryKey;
|
|
179
|
+
obj.$title ??= obj.__title;
|
|
144
180
|
// we don't want people to use these
|
|
145
181
|
delete obj.__apiName;
|
|
146
182
|
delete obj.__primaryKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertWireToOsdkObjects.js","names":["invariant","createOsdkObject","convertWireToOsdkObjects","client","objects","interfaceApiName","forceRemoveRid","selectedProps","strictNonNull","logger","debug","fixObjectPropertiesInPlace","ifaceDef","ontologyProvider","getInterfaceDefinition","undefined","ifaceSelected","Object","keys","properties","ret","rawObj","objectDef","getObjectDefinition","$apiName","objProps","conforming","invariantInterfacesAsViews","apiName","isConforming","reframeAsObjectInPlace","convertInterfacePropNamesToObjectPropNames","Error","osdkObject","$as","push","ifacePropsToMap","map","ifaceProp","interfaceMap","newProps","sptProp","regularProp","entries","value","assign","primaryKeyApiName","$primaryKey","def","obj","propsToCheck","propName","nullable","process","env","NODE_ENV","$objectType","warning","warn","console","error","objs","__rid","$rid","__apiName","__primaryKey","$title","__title"],"sources":["convertWireToOsdkObjects.js"],"sourcesContent":["/*\n * Copyright 2023 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 invariant from \"tiny-invariant\";\nimport { createOsdkObject } from \"./convertWireToOsdkObjects/createOsdkObject.js\";\n/**\n * If interfaceApiName is not undefined, converts the instances of the\n * interface into their respective\n * underlying concrete types and then returns the $as() representation\n * for the consumers.\n *\n * Otherwise just does the conversion\n *\n * May mutate in place for performance reasons. If you need a clean copy,\n * keep it first.\n *\n * However, you must use the returned value, which will be whatever is correct.\n *\n * @internal\n * @param interfaceApiName - if undefined\n */\nexport async function convertWireToOsdkObjects(client, objects, interfaceApiName, forceRemoveRid = false, selectedProps, strictNonNull = false) {\n client.logger?.debug(`START convertWireToOsdkObjects()`);\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n const ifaceDef = interfaceApiName\n ? await client.ontologyProvider.getInterfaceDefinition(interfaceApiName)\n : undefined;\n const ifaceSelected = ifaceDef\n ? (selectedProps ?? Object.keys(ifaceDef.properties))\n : undefined;\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n // default value for when we are checking an object\n let objProps;\n let conforming = true;\n if (ifaceDef && ifaceSelected) {\n // API returns interface spt names but we cache by real values\n invariantInterfacesAsViews(objectDef, ifaceDef.apiName, client);\n conforming &&= isConforming(client, ifaceDef, rawObj, ifaceSelected);\n reframeAsObjectInPlace(objectDef, ifaceDef.apiName, rawObj);\n objProps = convertInterfacePropNamesToObjectPropNames(objectDef, ifaceDef.apiName, ifaceSelected);\n }\n else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\"Unable to safely convert objects as some non nullable properties are null\");\n }\n else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n let osdkObject = createOsdkObject(client, objectDef, rawObj);\n if (interfaceApiName)\n osdkObject = osdkObject.$as(interfaceApiName);\n ret.push(osdkObject);\n }\n client.logger?.debug(`END convertWireToOsdkObjects()`);\n return ret;\n}\n/**\n * Utility function that lets us take down selected property names from an interface\n * and convert them to an array of property names on an object.\n */\nfunction convertInterfacePropNamesToObjectPropNames(objectDef, interfaceApiName, ifacePropsToMap) {\n return ifacePropsToMap.map((ifaceProp) => objectDef.interfaceMap[interfaceApiName][ifaceProp]);\n}\n/**\n * Takes a raw object from the wire (contextually as an interface) and\n * updates the fields to reflect the underlying objectDef instead\n * @param objectDef\n * @param interfaceApiName\n * @param client\n * @param rawObj\n */\nfunction reframeAsObjectInPlace(objectDef, interfaceApiName, rawObj) {\n const newProps = {};\n for (const [sptProp, regularProp] of Object.entries(objectDef.interfaceMap[interfaceApiName])) {\n if (sptProp in rawObj) {\n const value = rawObj[sptProp];\n delete rawObj[sptProp];\n if (value !== undefined) {\n newProps[regularProp] = value;\n }\n }\n }\n Object.assign(rawObj, newProps);\n if (!(objectDef.primaryKeyApiName in rawObj)) {\n rawObj[objectDef.primaryKeyApiName] = rawObj.$primaryKey;\n }\n}\nfunction isConforming(client, def, obj, propsToCheck) {\n for (const propName of propsToCheck) {\n if (def.properties[propName].nullable === false && obj[propName] == null) {\n if (process?.env?.NODE_ENV !== \"production\") {\n client.logger?.debug({\n obj: {\n $objectType: obj[\"$objectType\"],\n $primaryKey: obj[\"$primaryKey\"],\n },\n }, `Found object that does not conform to its definition. Expected ${def.apiName}'s ${propName} to not be null.`);\n }\n return false;\n }\n }\n return true;\n}\nfunction invariantInterfacesAsViews(objectDef, interfaceApiName, client) {\n if (objectDef.interfaceMap?.[interfaceApiName] == null) {\n const warning = \"Interfaces are only supported 'as views' but your metadata object is missing the correct information. This suggests your interfaces have not been migrated to the newer version yet and you cannot use this version of the SDK.\";\n if (client.logger) {\n client.logger.warn(warning);\n }\n else {\n // eslint-disable-next-line no-console\n console.error(`WARNING! ${warning}`);\n }\n throw new Error(warning);\n }\n}\nfunction fixObjectPropertiesInPlace(objs, forceRemoveRid) {\n for (const obj of objs) {\n if (forceRemoveRid) {\n delete obj.__rid;\n }\n if (obj.__rid) {\n obj.$rid = obj.__rid;\n delete obj.__rid;\n }\n // Backend returns as __apiName but we want to stick to $ structure\n obj.$apiName = obj.__apiName;\n // for now these are the same but when we start doing interface projections the $objectType will always be underlying and\n // the $apiName will be for the current view (in current designs)\n obj.$objectType = obj.__apiName;\n // copying over for now as its always returned. In the future, this should just be inferred from underlying\n obj.$primaryKey = obj.__primaryKey;\n obj.$title = obj.__title;\n // we don't want people to use these\n delete obj.__apiName;\n delete obj.__primaryKey;\n delete obj.__title;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,gDAAgD;AACjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,wBAAwBA,CAACC,MAAM,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,cAAc,GAAG,KAAK,EAAEC,aAAa,EAAEC,aAAa,GAAG,KAAK,EAAE;EAC5IL,MAAM,CAACM,MAAM,EAAEC,KAAK,CAAC,kCAAkC,CAAC;EACxDC,0BAA0B,CAACP,OAAO,EAAEE,cAAc,CAAC;EACnD,MAAMM,QAAQ,GAAGP,gBAAgB,GAC3B,MAAMF,MAAM,CAACU,gBAAgB,CAACC,sBAAsB,CAACT,gBAAgB,CAAC,GACtEU,SAAS;EACf,MAAMC,aAAa,GAAGJ,QAAQ,GACvBL,aAAa,IAAIU,MAAM,CAACC,IAAI,CAACN,QAAQ,CAACO,UAAU,CAAC,GAClDJ,SAAS;EACf,MAAMK,GAAG,GAAG,EAAE;EACd,KAAK,MAAMC,MAAM,IAAIjB,OAAO,EAAE;IAC1B,MAAMkB,SAAS,GAAG,MAAMnB,MAAM,CAACU,gBAAgB,CAACU,mBAAmB,CAACF,MAAM,CAACG,QAAQ,CAAC;IACpF,CAAUF,SAAS,GAAnBtB,SAAS,QAAY,2BAA2BqB,MAAM,CAACG,QAAQ,GAAG;IAClE;IACA,IAAIC,QAAQ;IACZ,IAAIC,UAAU,GAAG,IAAI;I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version":3,"file":"convertWireToOsdkObjects.js","names":["invariant","createOsdkObject","convertWireToOsdkObjects","client","objects","interfaceApiName","forceRemoveRid","selectedProps","strictNonNull","logger","debug","fixObjectPropertiesInPlace","ifaceDef","ontologyProvider","getInterfaceDefinition","undefined","ifaceSelected","Object","keys","properties","ret","rawObj","objectDef","getObjectDefinition","$apiName","process","env","NODE_ENV","objProps","conforming","invariantInterfacesAsViews","apiName","isConforming","reframeAsObjectInPlace","convertInterfacePropNamesToObjectPropNames","Error","osdkObject","$as","push","convertWireToOsdkObjects2","interfaceToObjectTypeMappings","interfaceToObjMapping","filter","val","includes","values","primaryKeyApiName","ifacePropsToMap","map","ifaceProp","interfaceMap","newProps","sptProp","regularProp","entries","value","assign","$primaryKey","def","obj","propsToCheck","propName","nullable","$objectType","warning","warn","console","error","objs","__rid","$rid","__apiName","__primaryKey","$title","__title"],"sources":["convertWireToOsdkObjects.js"],"sourcesContent":["/*\n * Copyright 2023 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 invariant from \"tiny-invariant\";\nimport { createOsdkObject } from \"./convertWireToOsdkObjects/createOsdkObject.js\";\n/**\n * If interfaceApiName is not undefined, converts the instances of the\n * interface into their respective\n * underlying concrete types and then returns the $as() representation\n * for the consumers.\n *\n * Otherwise just does the conversion\n *\n * May mutate in place for performance reasons. If you need a clean copy,\n * keep it first.\n *\n * However, you must use the returned value, which will be whatever is correct.\n *\n * @internal\n * @param interfaceApiName - if undefined\n */\nexport async function convertWireToOsdkObjects(client, objects, interfaceApiName, forceRemoveRid = false, selectedProps, strictNonNull = false) {\n client.logger?.debug(`START convertWireToOsdkObjects()`);\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n const ifaceDef = interfaceApiName\n ? await client.ontologyProvider.getInterfaceDefinition(interfaceApiName)\n : undefined;\n const ifaceSelected = ifaceDef\n ? (selectedProps ?? Object.keys(ifaceDef.properties))\n : undefined;\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n // default value for when we are checking an object\n let objProps;\n let conforming = true;\n if (ifaceDef && ifaceSelected) {\n // API returns interface spt names but we cache by real values\n invariantInterfacesAsViews(objectDef, ifaceDef.apiName, client);\n conforming &&= isConforming(client, ifaceDef, rawObj, ifaceSelected);\n reframeAsObjectInPlace(objectDef, ifaceDef.apiName, rawObj);\n objProps = convertInterfacePropNamesToObjectPropNames(objectDef, ifaceDef.apiName, ifaceSelected);\n }\n else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\"Unable to safely convert objects as some non nullable properties are null\");\n }\n else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n let osdkObject = createOsdkObject(client, objectDef, rawObj);\n if (interfaceApiName)\n osdkObject = osdkObject.$as(interfaceApiName);\n ret.push(osdkObject);\n }\n client.logger?.debug(`END convertWireToOsdkObjects()`);\n return ret;\n}\n/**\n * @internal\n */\nexport async function convertWireToOsdkObjects2(client, objects, interfaceApiName, forceRemoveRid = false, selectedProps, strictNonNull = false, interfaceToObjectTypeMappings = {}) {\n client.logger?.debug(`START convertWireToOsdkObjects2()`);\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n const interfaceToObjMapping = interfaceApiName\n ? interfaceToObjectTypeMappings[interfaceApiName][rawObj.$apiName]\n : undefined;\n const ifaceSelected = interfaceApiName && interfaceToObjMapping\n ? (selectedProps\n ? Object.keys(interfaceToObjMapping).filter(val => {\n selectedProps?.includes(interfaceToObjMapping[val]);\n })\n : [\n ...Object.values(interfaceToObjMapping),\n objectDef.primaryKeyApiName,\n ])\n : undefined;\n // default value for when we are checking an object\n let objProps;\n let conforming = true;\n if (interfaceApiName && ifaceSelected) {\n invariantInterfacesAsViews(objectDef, interfaceApiName, client);\n objProps = ifaceSelected;\n }\n else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\"Unable to safely convert objects as some non nullable properties are null\");\n }\n else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n let osdkObject = createOsdkObject(client, objectDef, rawObj);\n if (interfaceApiName)\n osdkObject = osdkObject.$as(interfaceApiName);\n ret.push(osdkObject);\n }\n client.logger?.debug(`END convertWireToOsdkObjects2()`);\n return ret;\n}\n/**\n * Utility function that lets us take down selected property names from an interface\n * and convert them to an array of property names on an object.\n */\nfunction convertInterfacePropNamesToObjectPropNames(objectDef, interfaceApiName, ifacePropsToMap) {\n return ifacePropsToMap.map((ifaceProp) => objectDef.interfaceMap[interfaceApiName][ifaceProp]);\n}\n/**\n * Takes a raw object from the wire (contextually as an interface) and\n * updates the fields to reflect the underlying objectDef instead\n * @param objectDef\n * @param interfaceApiName\n * @param client\n * @param rawObj\n */\nfunction reframeAsObjectInPlace(objectDef, interfaceApiName, rawObj) {\n const newProps = {};\n for (const [sptProp, regularProp] of Object.entries(objectDef.interfaceMap[interfaceApiName])) {\n if (sptProp in rawObj) {\n const value = rawObj[sptProp];\n delete rawObj[sptProp];\n if (value !== undefined) {\n newProps[regularProp] = value;\n }\n }\n }\n Object.assign(rawObj, newProps);\n if (!(objectDef.primaryKeyApiName in rawObj)) {\n rawObj[objectDef.primaryKeyApiName] = rawObj.$primaryKey;\n }\n}\nfunction isConforming(client, def, obj, propsToCheck) {\n for (const propName of propsToCheck) {\n if (def.properties[propName].nullable === false && obj[propName] == null) {\n if (process.env.NODE_ENV !== \"production\") {\n client.logger?.debug({\n obj: {\n $objectType: obj[\"$objectType\"],\n $primaryKey: obj[\"$primaryKey\"],\n },\n }, `Found object that does not conform to its definition. Expected ${def.apiName}'s ${propName} to not be null.`);\n }\n return false;\n }\n }\n return true;\n}\nfunction invariantInterfacesAsViews(objectDef, interfaceApiName, client) {\n if (objectDef.interfaceMap?.[interfaceApiName] == null) {\n const warning = \"Interfaces are only supported 'as views' but your metadata object is missing the correct information. This suggests your interfaces have not been migrated to the newer version yet and you cannot use this version of the SDK.\";\n if (client.logger) {\n client.logger.warn(warning);\n }\n else {\n // eslint-disable-next-line no-console\n console.error(`WARNING! ${warning}`);\n }\n throw new Error(warning);\n }\n}\nfunction fixObjectPropertiesInPlace(objs, forceRemoveRid) {\n for (const obj of objs) {\n if (forceRemoveRid) {\n delete obj.__rid;\n }\n if (obj.__rid) {\n obj.$rid = obj.__rid;\n delete obj.__rid;\n }\n // Backend returns as __apiName but we want to stick to $ structure\n obj.$apiName ??= obj.__apiName;\n // for now these are the same but when we start doing interface projections the $objectType will always be underlying and\n // the $apiName will be for the current view (in current designs)\n obj.$objectType = obj.$apiName;\n // copying over for now as its always returned. In the future, this should just be inferred from underlying\n obj.$primaryKey ??= obj.__primaryKey;\n obj.$title ??= obj.__title;\n // we don't want people to use these\n delete obj.__apiName;\n delete obj.__primaryKey;\n delete obj.__title;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,gDAAgD;AACjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eA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,CAACY,SAAS;IAC9B;IACA;IACAZ,GAAG,CAACI,WAAW,GAAGJ,GAAG,CAACnC,QAAQ;IAC9B;IACAmC,GAAG,CAACF,WAAW,KAAKE,GAAG,CAACa,YAAY;IACpCb,GAAG,CAACc,MAAM,KAAKd,GAAG,CAACe,OAAO;IAC1B;IACA,OAAOf,GAAG,CAACY,SAAS;IACpB,OAAOZ,GAAG,CAACa,YAAY;IACvB,OAAOb,GAAG,CAACe,OAAO;EACtB;AACJ","ignoreList":[]}
|
|
@@ -14,15 +14,22 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { $ontologyRid, Employee, FooInterface, objectTypeWithAllPropertyTypes } from "@osdk/client.test.ontology";
|
|
17
|
-
import { symbolClientContext } from "@osdk/shared.client";
|
|
18
17
|
import { createSharedClientContext } from "@osdk/shared.client.impl";
|
|
19
18
|
import { apiServer } from "@osdk/shared.test";
|
|
20
19
|
import { afterAll, beforeAll, describe, expect, expectTypeOf, it } from "vitest";
|
|
20
|
+
import { additionalContext } from "../Client.js";
|
|
21
21
|
import { createClient } from "../createClient.js";
|
|
22
22
|
import { createMinimalClient } from "../createMinimalClient.js";
|
|
23
|
-
import { convertWireToOsdkObjects } from "./convertWireToOsdkObjects.js";
|
|
23
|
+
import { convertWireToOsdkObjects, convertWireToOsdkObjects2 } from "./convertWireToOsdkObjects.js";
|
|
24
24
|
describe("convertWireToOsdkObjects", () => {
|
|
25
25
|
let client;
|
|
26
|
+
const interfaceToObjectTypeMappings = {
|
|
27
|
+
FooInterface: {
|
|
28
|
+
Employee: {
|
|
29
|
+
fooSpt: "fullName"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
26
33
|
beforeAll(async () => {
|
|
27
34
|
apiServer.listen();
|
|
28
35
|
client = createClient("https://stack.palantir.com", $ontologyRid, async () => "myAccessToken");
|
|
@@ -34,7 +41,7 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
34
41
|
const {
|
|
35
42
|
data: [employee]
|
|
36
43
|
} = await client(Employee).fetchPage();
|
|
37
|
-
expect(Object.keys(employee).sort()).toEqual(["employeeId", "fullName", "office", "class", "startDate", "employeeStatus", "$apiName", "$objectType", "$primaryKey", "employeeLocation"].sort());
|
|
44
|
+
expect(Object.keys(employee).sort()).toEqual(["employeeId", "$title", "fullName", "office", "class", "startDate", "employeeSensor", "employeeStatus", "$apiName", "$objectType", "$primaryKey", "employeeLocation"].sort());
|
|
38
45
|
expect(Object.keys(employee.$as)).toEqual([]);
|
|
39
46
|
expect(Object.keys(employee.$link)).toEqual(["peeps", "lead", "officeLink"]);
|
|
40
47
|
});
|
|
@@ -56,10 +63,10 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
56
63
|
}]
|
|
57
64
|
}).fetchPage();
|
|
58
65
|
// Should not have $title
|
|
59
|
-
expect(JSON.stringify(employee)).toMatchInlineSnapshot(`"{"employeeId":50030,"fullName":"John Doe","office":"NYC","class":"Red","startDate":"2019-01-01","employeeStatus":{},"employeeLocation":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50030}"`);
|
|
66
|
+
expect(JSON.stringify(employee)).toMatchInlineSnapshot(`"{"employeeId":50030,"fullName":"John Doe","office":"NYC","class":"Red","startDate":"2019-01-01","employeeStatus":{},"employeeSensor":{},"employeeLocation":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50030}"`);
|
|
60
67
|
expect(JSON.stringify(employee.$as(FooInterface))).toMatchInlineSnapshot(`"{"$apiName":"FooInterface","$objectType":"Employee","$primaryKey":50030,"fooSpt":"John Doe"}"`);
|
|
61
68
|
// Should have $title
|
|
62
|
-
expect(JSON.stringify(employee2)).toMatchInlineSnapshot(`"{"employeeId":50031,"fullName":"Jane Doe","office":"SEA","class":"Blue","startDate":"2012-02-12","employeeStatus":{},"employeeLocation":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50031,"$title":"Jane Doe"}"`);
|
|
69
|
+
expect(JSON.stringify(employee2)).toMatchInlineSnapshot(`"{"employeeId":50031,"fullName":"Jane Doe","office":"SEA","class":"Blue","startDate":"2012-02-12","employeeStatus":{},"employeeSensor":{},"employeeLocation":{},"$apiName":"Employee","$objectType":"Employee","$primaryKey":50031,"$title":"Jane Doe"}"`);
|
|
63
70
|
expect(JSON.stringify(employee2.$as(FooInterface))).toMatchInlineSnapshot(`"{"$apiName":"FooInterface","$objectType":"Employee","$primaryKey":50031,"$title":"Jane Doe","fooSpt":"Jane Doe"}"`);
|
|
64
71
|
});
|
|
65
72
|
it("reuses the object prototype across objects", async () => {
|
|
@@ -91,7 +98,21 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
91
98
|
expect(emptyAttachment).toBeUndefined();
|
|
92
99
|
expect(emptyAttachmentArray).toBeUndefined();
|
|
93
100
|
});
|
|
94
|
-
it("
|
|
101
|
+
it("creates immutable objects", async () => {
|
|
102
|
+
const employees = await client(Employee).fetchPage();
|
|
103
|
+
expect(employees.data.length).toBeGreaterThanOrEqual(2);
|
|
104
|
+
const [a, b] = employees.data;
|
|
105
|
+
expect(a).toBeDefined();
|
|
106
|
+
expect(() => {
|
|
107
|
+
a.somePropertyThatShouldNotExist = 5;
|
|
108
|
+
}).toThrow();
|
|
109
|
+
const objAsFoo = a.$as(FooInterface);
|
|
110
|
+
expect(objAsFoo).toBeDefined();
|
|
111
|
+
expect(() => {
|
|
112
|
+
objAsFoo.somePropertyThatShouldNotExist = 5;
|
|
113
|
+
}).toThrow();
|
|
114
|
+
});
|
|
115
|
+
it("works even with unknown apiNames - old", async () => {
|
|
95
116
|
const clientCtx = createMinimalClient({
|
|
96
117
|
ontologyRid: $ontologyRid
|
|
97
118
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
@@ -105,39 +126,21 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
105
126
|
const prototypeAfter = Object.getPrototypeOf(object2);
|
|
106
127
|
expect(prototypeBefore).not.toBe(prototypeAfter);
|
|
107
128
|
});
|
|
108
|
-
it("
|
|
129
|
+
it("works even with unknown apiNames - new", async () => {
|
|
109
130
|
const clientCtx = createMinimalClient({
|
|
110
131
|
ontologyRid: $ontologyRid
|
|
111
132
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
expect(
|
|
121
|
-
const objAsFoo = obj.$as(FooInterface);
|
|
122
|
-
expect(objAsFoo).toMatchObject({
|
|
123
|
-
fooSpt: obj.fullName,
|
|
124
|
-
$apiName: FooInterface.apiName,
|
|
125
|
-
$primaryKey: obj.$primaryKey,
|
|
126
|
-
$objectType: obj.$objectType,
|
|
127
|
-
$title: obj.$title
|
|
128
|
-
});
|
|
129
|
-
console.log(obj);
|
|
130
|
-
console.log(objAsFoo);
|
|
131
|
-
obj.$updateInternalValues({
|
|
132
|
-
fullName: "Bob"
|
|
133
|
-
});
|
|
134
|
-
expect(obj.fullName).toEqual("Bob");
|
|
135
|
-
expect(objAsFoo.fooSpt).toEqual(obj.fullName);
|
|
136
|
-
expect(Object.keys(objAsFoo).sort()).toEqual(["$apiName", "$objectType", "$primaryKey", "$title", "fooSpt"].sort());
|
|
137
|
-
expect(obj).toBe(objAsFoo.$as(Employee));
|
|
138
|
-
expect(objAsFoo).toBe(obj.$as(FooInterface));
|
|
133
|
+
createSharedClientContext("https://stack.palantir.com", async () => "myAccessToken", "userAgent");
|
|
134
|
+
let object = {
|
|
135
|
+
__apiName: Employee.apiName,
|
|
136
|
+
__primaryKey: 0
|
|
137
|
+
};
|
|
138
|
+
const prototypeBefore = Object.getPrototypeOf(object);
|
|
139
|
+
let object2 = await convertWireToOsdkObjects2(clientCtx, [object], undefined, undefined, undefined, false);
|
|
140
|
+
const prototypeAfter = Object.getPrototypeOf(object2);
|
|
141
|
+
expect(prototypeBefore).not.toBe(prototypeAfter);
|
|
139
142
|
});
|
|
140
|
-
it("reconstitutes interfaces properly without rid", async () => {
|
|
143
|
+
it("reconstitutes interfaces properly without rid - old", async () => {
|
|
141
144
|
const clientCtx = createMinimalClient({
|
|
142
145
|
ontologyRid: $ontologyRid
|
|
143
146
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
@@ -169,6 +172,37 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
169
172
|
}
|
|
170
173
|
`);
|
|
171
174
|
});
|
|
175
|
+
it("reconstitutes interfaces properly without rid - new", async () => {
|
|
176
|
+
const clientCtx = createMinimalClient({
|
|
177
|
+
ontologyRid: $ontologyRid
|
|
178
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
179
|
+
const [objAsFoo] = await convertWireToOsdkObjects2(clientCtx, [{
|
|
180
|
+
__apiName: "Employee",
|
|
181
|
+
__primaryKey: 0,
|
|
182
|
+
__title: "Steve",
|
|
183
|
+
fullName: "Steve"
|
|
184
|
+
}], FooInterface.apiName, false, undefined, false, interfaceToObjectTypeMappings);
|
|
185
|
+
expect(objAsFoo).toMatchInlineSnapshot(`
|
|
186
|
+
{
|
|
187
|
+
"$apiName": "FooInterface",
|
|
188
|
+
"$objectType": "Employee",
|
|
189
|
+
"$primaryKey": 0,
|
|
190
|
+
"$title": "Steve",
|
|
191
|
+
"fooSpt": "Steve",
|
|
192
|
+
}
|
|
193
|
+
`);
|
|
194
|
+
const obj = objAsFoo.$as(Employee);
|
|
195
|
+
expect(obj.fullName).toEqual("Steve");
|
|
196
|
+
expect(obj).toMatchInlineSnapshot(`
|
|
197
|
+
{
|
|
198
|
+
"$apiName": "Employee",
|
|
199
|
+
"$objectType": "Employee",
|
|
200
|
+
"$primaryKey": 0,
|
|
201
|
+
"$title": "Steve",
|
|
202
|
+
"fullName": "Steve",
|
|
203
|
+
}
|
|
204
|
+
`);
|
|
205
|
+
});
|
|
172
206
|
it("reconstitutes interfaces properly with rid", async () => {
|
|
173
207
|
const clientCtx = createMinimalClient({
|
|
174
208
|
ontologyRid: $ontologyRid
|
|
@@ -206,29 +240,96 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
206
240
|
`);
|
|
207
241
|
expect(obj.$rid).toEqual("hiMom");
|
|
208
242
|
});
|
|
243
|
+
it("reconstitutes interfaces properly with rid - new", async () => {
|
|
244
|
+
const clientCtx = createMinimalClient({
|
|
245
|
+
ontologyRid: $ontologyRid
|
|
246
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
247
|
+
const [objAsFoo] = await convertWireToOsdkObjects2(clientCtx, [{
|
|
248
|
+
__apiName: "Employee",
|
|
249
|
+
__primaryKey: 0,
|
|
250
|
+
__title: "Steve",
|
|
251
|
+
__rid: "hiMom",
|
|
252
|
+
fullName: "Steve",
|
|
253
|
+
employeeId: 0
|
|
254
|
+
}], FooInterface.apiName, false, undefined, false, interfaceToObjectTypeMappings);
|
|
255
|
+
expect(objAsFoo).toMatchInlineSnapshot(`
|
|
256
|
+
{
|
|
257
|
+
"$apiName": "FooInterface",
|
|
258
|
+
"$objectType": "Employee",
|
|
259
|
+
"$primaryKey": 0,
|
|
260
|
+
"$rid": "hiMom",
|
|
261
|
+
"$title": "Steve",
|
|
262
|
+
"fooSpt": "Steve",
|
|
263
|
+
}
|
|
264
|
+
`);
|
|
265
|
+
expect(objAsFoo.$rid).toEqual("hiMom");
|
|
266
|
+
const obj = objAsFoo.$as(Employee);
|
|
267
|
+
expect(obj.fullName).toEqual("Steve");
|
|
268
|
+
expect(obj).toMatchInlineSnapshot(`
|
|
269
|
+
{
|
|
270
|
+
"$apiName": "Employee",
|
|
271
|
+
"$objectType": "Employee",
|
|
272
|
+
"$primaryKey": 0,
|
|
273
|
+
"$rid": "hiMom",
|
|
274
|
+
"$title": "Steve",
|
|
275
|
+
"employeeId": 0,
|
|
276
|
+
"fullName": "Steve",
|
|
277
|
+
}
|
|
278
|
+
`);
|
|
279
|
+
expect(obj.$rid).toEqual("hiMom");
|
|
280
|
+
});
|
|
209
281
|
describe("selection keys", () => {
|
|
210
282
|
it("throws when required is missing", async () => {
|
|
211
283
|
let object = {
|
|
212
284
|
__apiName: "Employee",
|
|
213
285
|
__primaryKey: 0
|
|
214
286
|
};
|
|
215
|
-
await expect(() => convertWireToOsdkObjects(client[
|
|
287
|
+
await expect(() => convertWireToOsdkObjects(client[additionalContext], [object], undefined, undefined, ["employeeId"], "throw")).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Unable to safely convert objects as some non nullable properties are null]`);
|
|
216
288
|
});
|
|
217
289
|
it("does not throw when optional is missing", async () => {
|
|
218
|
-
await expect(convertWireToOsdkObjects(client[
|
|
290
|
+
await expect(convertWireToOsdkObjects(client[additionalContext], [{
|
|
219
291
|
__apiName: "Employee",
|
|
220
292
|
__primaryKey: 0
|
|
221
293
|
}], undefined, undefined, ["fullName"], "throw")).resolves.to.not.toBeUndefined();
|
|
222
294
|
});
|
|
223
295
|
it("filters when it should", async () => {
|
|
224
|
-
const result = await convertWireToOsdkObjects(client[
|
|
296
|
+
const result = await convertWireToOsdkObjects(client[additionalContext], [{
|
|
225
297
|
__apiName: "Employee",
|
|
226
298
|
__primaryKey: 0
|
|
227
299
|
}], undefined, undefined, ["employeeId"], "drop");
|
|
228
300
|
expect(result.length).toBe(0);
|
|
229
301
|
});
|
|
230
302
|
it("does not filter when it shouldn't", async () => {
|
|
231
|
-
const result = await convertWireToOsdkObjects(client[
|
|
303
|
+
const result = await convertWireToOsdkObjects(client[additionalContext], [{
|
|
304
|
+
__apiName: "Employee",
|
|
305
|
+
__primaryKey: 0
|
|
306
|
+
}], undefined, undefined, ["fullName"], "drop");
|
|
307
|
+
expect(result.length).toBe(1);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
describe("selection keys - new", () => {
|
|
311
|
+
it("throws when required is missing", async () => {
|
|
312
|
+
let object = {
|
|
313
|
+
__apiName: "Employee",
|
|
314
|
+
__primaryKey: 0
|
|
315
|
+
};
|
|
316
|
+
await expect(() => convertWireToOsdkObjects2(client[additionalContext], [object], undefined, undefined, ["employeeId"], "throw")).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Unable to safely convert objects as some non nullable properties are null]`);
|
|
317
|
+
});
|
|
318
|
+
it("does not throw when optional is missing", async () => {
|
|
319
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
320
|
+
__apiName: "Employee",
|
|
321
|
+
__primaryKey: 0
|
|
322
|
+
}], undefined, undefined, ["fullName"], "throw")).resolves.to.not.toBeUndefined();
|
|
323
|
+
});
|
|
324
|
+
it("filters when it should", async () => {
|
|
325
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
326
|
+
__apiName: "Employee",
|
|
327
|
+
__primaryKey: 0
|
|
328
|
+
}], undefined, undefined, ["employeeId"], "drop");
|
|
329
|
+
expect(result.length).toBe(0);
|
|
330
|
+
});
|
|
331
|
+
it("does not filter when it shouldn't", async () => {
|
|
332
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
232
333
|
__apiName: "Employee",
|
|
233
334
|
__primaryKey: 0
|
|
234
335
|
}], undefined, undefined, ["fullName"], "drop");
|
|
@@ -241,24 +342,55 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
241
342
|
__apiName: "Employee",
|
|
242
343
|
__primaryKey: 0
|
|
243
344
|
};
|
|
244
|
-
await expect(() =>
|
|
345
|
+
await expect(() => convertWireToOsdkObjects2(client[additionalContext], [object], undefined, undefined, undefined, "throw")).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Unable to safely convert objects as some non nullable properties are null]`);
|
|
346
|
+
});
|
|
347
|
+
it("does not throw when required is present", async () => {
|
|
348
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
349
|
+
__apiName: "Employee",
|
|
350
|
+
__primaryKey: 0,
|
|
351
|
+
"employeeId": 0
|
|
352
|
+
}], undefined, undefined, undefined, "throw")).resolves.to.not.toBeUndefined();
|
|
353
|
+
});
|
|
354
|
+
it("filters when it should", async () => {
|
|
355
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
356
|
+
__apiName: "Employee",
|
|
357
|
+
__primaryKey: 0
|
|
358
|
+
}], undefined, undefined, undefined, "drop");
|
|
359
|
+
expect(result.length).toBe(0);
|
|
360
|
+
});
|
|
361
|
+
it("does not filter when it shouldn't", async () => {
|
|
362
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
363
|
+
__apiName: "Employee",
|
|
364
|
+
__primaryKey: 0,
|
|
365
|
+
"employeeId": 0
|
|
366
|
+
}], undefined, undefined, undefined, "drop");
|
|
367
|
+
expect(result.length).toBe(1);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
describe("without selection keys - new", () => {
|
|
371
|
+
it("throws when required is missing", async () => {
|
|
372
|
+
let object = {
|
|
373
|
+
__apiName: "Employee",
|
|
374
|
+
__primaryKey: 0
|
|
375
|
+
};
|
|
376
|
+
await expect(() => convertWireToOsdkObjects2(client[additionalContext], [object], undefined, undefined, undefined, "throw")).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Unable to safely convert objects as some non nullable properties are null]`);
|
|
245
377
|
});
|
|
246
378
|
it("does not throw when required is present", async () => {
|
|
247
|
-
await expect(
|
|
379
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
248
380
|
__apiName: "Employee",
|
|
249
381
|
__primaryKey: 0,
|
|
250
382
|
"employeeId": 0
|
|
251
383
|
}], undefined, undefined, undefined, "throw")).resolves.to.not.toBeUndefined();
|
|
252
384
|
});
|
|
253
385
|
it("filters when it should", async () => {
|
|
254
|
-
const result = await
|
|
386
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
255
387
|
__apiName: "Employee",
|
|
256
388
|
__primaryKey: 0
|
|
257
389
|
}], undefined, undefined, undefined, "drop");
|
|
258
390
|
expect(result.length).toBe(0);
|
|
259
391
|
});
|
|
260
392
|
it("does not filter when it shouldn't", async () => {
|
|
261
|
-
const result = await
|
|
393
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
262
394
|
__apiName: "Employee",
|
|
263
395
|
__primaryKey: 0,
|
|
264
396
|
"employeeId": 0
|
|
@@ -267,11 +399,11 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
267
399
|
});
|
|
268
400
|
});
|
|
269
401
|
it("behaves correctly when converting", async () => {
|
|
270
|
-
const result = await
|
|
402
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
271
403
|
__apiName: "Employee",
|
|
272
404
|
__primaryKey: 0,
|
|
273
405
|
fooSpt: "hi"
|
|
274
|
-
}], "FooInterface", undefined, ["fooSpt"], "drop");
|
|
406
|
+
}], "FooInterface", undefined, ["fooSpt"], "drop", interfaceToObjectTypeMappings);
|
|
275
407
|
expect(result.length).toBe(1);
|
|
276
408
|
});
|
|
277
409
|
});
|