@osdk/client 2.1.0-beta.1 → 2.1.0-beta.10
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 +146 -0
- package/build/browser/Client.d.ts +8 -21
- package/build/browser/Client.d.ts.map +1 -1
- package/build/browser/Client.js +2 -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 +4 -4
- 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 +1 -1
- package/build/browser/__unstable/createBulkLinksAsyncIterFactory.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 +43 -19
- package/build/browser/createClient.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 +3 -3
- 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/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 +3 -3
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.test.js +88 -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 +6 -0
- 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/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 +6 -0
- package/build/browser/object/convertWireToOsdkObjects/InternalSymbols.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +56 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.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 +197 -15
- 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 +35 -25
- 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/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 +64 -48
- package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js +65 -57
- package/build/browser/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/browser/objectSet/ObjectSetListenerWebsocket.test.js +116 -26
- 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/ontology/makeConjureContext.d.ts +1 -1
- package/build/browser/ontology/makeConjureContext.d.ts.map +1 -1
- package/build/browser/queries/applyQuery.js +1 -1
- 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.map +1 -1
- package/build/esm/Client.d.ts +8 -21
- package/build/esm/Client.d.ts.map +1 -1
- package/build/esm/Client.js +2 -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 +4 -4
- 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 +1 -1
- package/build/esm/__unstable/createBulkLinksAsyncIterFactory.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 +43 -19
- package/build/esm/createClient.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 +3 -3
- 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/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 +3 -3
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.test.js +88 -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 +6 -0
- 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/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 +6 -0
- package/build/esm/object/convertWireToOsdkObjects/InternalSymbols.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +56 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.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 +197 -15
- 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 +35 -25
- 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/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 +64 -48
- package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js +65 -57
- package/build/esm/objectSet/ObjectSetListenerWebsocket.js.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.test.js +116 -26
- 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/ontology/makeConjureContext.d.ts +1 -1
- package/build/esm/ontology/makeConjureContext.d.ts.map +1 -1
- package/build/esm/queries/applyQuery.js +1 -1
- 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.map +1 -1
- package/package.json +21 -17
|
@@ -43,6 +43,55 @@ const objectPrototypeCache = createClientCache(function (client, objectDef) {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
|
+
if (process.env.NODE_ENV !== "production") {
|
|
47
|
+
const installed = Symbol();
|
|
48
|
+
const gw = typeof window === "undefined" ? global : window;
|
|
49
|
+
if (!(installed in gw)) {
|
|
50
|
+
gw[installed] = true;
|
|
51
|
+
gw.devtoolsFormatters ??= [];
|
|
52
|
+
gw.devtoolsFormatters.push({
|
|
53
|
+
header: function (object) {
|
|
54
|
+
const raw = object[RawObject];
|
|
55
|
+
if (raw == null) return null;
|
|
56
|
+
return ["div", {}, `Osdk.Instance<${raw.$apiName}> { $primaryKey:`, ["object", {
|
|
57
|
+
object: raw.$primaryKey
|
|
58
|
+
}], `, $title:`, ["object", {
|
|
59
|
+
object: raw.$title
|
|
60
|
+
}], `, ... }`];
|
|
61
|
+
},
|
|
62
|
+
hasBody: function (object) {
|
|
63
|
+
return object[RawObject] != null;
|
|
64
|
+
},
|
|
65
|
+
body: function (object) {
|
|
66
|
+
const raw = object[RawObject];
|
|
67
|
+
if (raw == null) return null;
|
|
68
|
+
return ["ol", {
|
|
69
|
+
style: `
|
|
70
|
+
list-style-type: none;
|
|
71
|
+
padding-left: 0;
|
|
72
|
+
margin-top: 0;
|
|
73
|
+
margin-left: 18px
|
|
74
|
+
`
|
|
75
|
+
}, ["li", {}, "$raw:", ["object", {
|
|
76
|
+
object: raw
|
|
77
|
+
}]]
|
|
78
|
+
// ...Object.keys(raw).map(key => {
|
|
79
|
+
// return [
|
|
80
|
+
// "li",
|
|
81
|
+
// {},
|
|
82
|
+
// [
|
|
83
|
+
// "span",
|
|
84
|
+
// { style: "color: #888888" },
|
|
85
|
+
// `${key}: `,
|
|
86
|
+
// ],
|
|
87
|
+
// ["object", { object: raw[key] }], // ["span", {}, `${key}: `]],
|
|
88
|
+
// ];
|
|
89
|
+
// }),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
46
95
|
/** @internal */
|
|
47
96
|
export function createOsdkObject(client, objectDef, rawObj) {
|
|
48
97
|
// We use multiple layers of prototypes to maximize reuse and also to keep
|
|
@@ -90,7 +139,13 @@ export function createOsdkObject(client, objectDef, rawObj) {
|
|
|
90
139
|
if (instance != null) {
|
|
91
140
|
return instance;
|
|
92
141
|
}
|
|
93
|
-
const geotimeProp = new GeotimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p
|
|
142
|
+
const geotimeProp = new GeotimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p, rawValue.type === "geotimeSeriesValue" ? {
|
|
143
|
+
time: rawValue.timestamp,
|
|
144
|
+
value: {
|
|
145
|
+
type: "Point",
|
|
146
|
+
coordinates: rawValue.position
|
|
147
|
+
}
|
|
148
|
+
} : undefined);
|
|
94
149
|
target[CachedPropertiesRef].set(p, geotimeProp);
|
|
95
150
|
return geotimeProp;
|
|
96
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOsdkObject.js","names":["createAttachmentFromRid","GeotimeSeriesPropertyImpl","TimeSeriesPropertyImpl","createClientCache","get$as","get$link","CachedPropertiesRef","ClientRef","ObjectDefRef","RawObject","UnderlyingOsdkObject","objectPrototypeCache","client","objectDef","Object","create","value","get","newValues","assign","createOsdkObject","rawObj","objectHolderPrototype","writable","Map","holder","osdkObject","Proxy","ownKeys","target","Reflect","p","receiver","rawValue","propDef","properties","type","Array","isArray","map","a","rid","apiName","primaryKeyApiName","instance","geotimeProp","set","newValue","getOwnPropertyDescriptor","configurable","enumerable","undefined"],"sources":["createOsdkObject.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 { createAttachmentFromRid } from \"../../createAttachmentFromRid.js\";\nimport { GeotimeSeriesPropertyImpl } from \"../../createGeotimeSeriesProperty.js\";\nimport { TimeSeriesPropertyImpl } from \"../../createTimeseriesProperty.js\";\nimport { createClientCache } from \"../Cache.js\";\nimport { get$as } from \"./getDollarAs.js\";\nimport { get$link } from \"./getDollarLink.js\";\nimport { CachedPropertiesRef, ClientRef, ObjectDefRef, RawObject, UnderlyingOsdkObject, } from \"./InternalSymbols.js\";\nconst objectPrototypeCache = createClientCache(function (client, objectDef) {\n return Object.create(null, {\n [ObjectDefRef]: { value: objectDef },\n [ClientRef]: { value: client },\n \"$as\": { value: get$as(objectDef) },\n \"$link\": {\n get: function () {\n return get$link(this);\n },\n },\n \"$updateInternalValues\": {\n value: function (newValues) {\n this[RawObject] = Object.assign({}, this[RawObject], newValues);\n },\n },\n });\n});\n/** @internal */\nexport function createOsdkObject(client, objectDef, rawObj) {\n // We use multiple layers of prototypes to maximize reuse and also to keep\n // [RawObject] out of `ownKeys`. This keeps the code in the proxy below simpler.\n const objectHolderPrototype = Object.create(objectPrototypeCache.get(client, objectDef), {\n [RawObject]: {\n value: rawObj,\n writable: true, // so we can allow updates\n },\n [CachedPropertiesRef]: {\n value: new Map(),\n writable: true,\n },\n });\n // we separate the holder out so we can update\n // the underlying data without having to return a new object\n // we also need the holder so we can customize the console.log output\n const holder = Object.create(objectHolderPrototype);\n const osdkObject = new Proxy(holder, {\n ownKeys(target) {\n return Reflect.ownKeys(target[RawObject]);\n },\n get(target, p, receiver) {\n switch (p) {\n case UnderlyingOsdkObject:\n // effectively point back to the proxy\n return receiver;\n }\n if (p in target)\n return target[p];\n if (p in rawObj) {\n const rawValue = target[RawObject][p];\n const propDef = objectDef.properties[p];\n if (propDef) {\n if (propDef.type === \"attachment\") {\n if (Array.isArray(rawValue)) {\n return rawValue.map(a => createAttachmentFromRid(client, a.rid));\n }\n return createAttachmentFromRid(client, rawValue.rid);\n }\n if (propDef.type === \"numericTimeseries\"\n || propDef.type === \"stringTimeseries\") {\n return new TimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p);\n }\n if (propDef.type === \"geotimeSeriesReference\") {\n const instance = target[CachedPropertiesRef].get(p);\n if (instance != null) {\n return instance;\n }\n const geotimeProp = new GeotimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p);\n target[CachedPropertiesRef].set(p, geotimeProp);\n return geotimeProp;\n }\n }\n return rawValue;\n }\n // we do not do any fall through to avoid unexpected behavior\n },\n set(target, p, newValue) {\n // allow the prototype to update this value\n if (p === RawObject) {\n // symbol only exists internally so no one else can hit this\n target[p] = newValue;\n return true;\n }\n return false;\n },\n getOwnPropertyDescriptor(target, p) {\n if (p === RawObject) {\n return Reflect.getOwnPropertyDescriptor(target, p);\n }\n if (target[RawObject][p] != null) {\n return { configurable: true, enumerable: true };\n }\n return undefined;\n },\n });\n return osdkObject;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAuB,QAAQ,kCAAkC;AAC1E,SAASC,yBAAyB,QAAQ,sCAAsC;AAChF,SAASC,sBAAsB,QAAQ,mCAAmC;AAC1E,SAASC,iBAAiB,QAAQ,aAAa;AAC/C,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,YAAY,EAAEC,SAAS,EAAEC,oBAAoB,QAAS,sBAAsB;AACrH,MAAMC,oBAAoB,GAAGR,iBAAiB,CAAC,UAAUS,MAAM,EAAEC,SAAS,EAAE;EACxE,OAAOC,MAAM,CAACC,MAAM,CAAC,IAAI,EAAE;IACvB,CAACP,YAAY,GAAG;MAAEQ,KAAK,EAAEH;IAAU,CAAC;IACpC,CAACN,SAAS,GAAG;MAAES,KAAK,EAAEJ;IAAO,CAAC;IAC9B,KAAK,EAAE;MAAEI,KAAK,EAAEZ,MAAM,CAACS,SAAS;IAAE,CAAC;IACnC,OAAO,EAAE;MACLI,GAAG,EAAE,SAAAA,CAAA,EAAY;QACb,OAAOZ,QAAQ,CAAC,IAAI,CAAC;MACzB;IACJ,CAAC;IACD,uBAAuB,EAAE;MACrBW,KAAK,EAAE,SAAAA,CAAUE,SAAS,EAAE;QACxB,IAAI,CAACT,SAAS,CAAC,GAAGK,MAAM,CAACK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAACV,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AC,EAAE;MAChC,IAAIA,CAAC,KAAKtB,SAAS,EAAE;QACjB,OAAOqB,OAAO,CAACkB,wBAAwB,CAACnB,MAAM,EAAEE,CAAC,CAAC;MACtD;MACA,IAAIF,MAAM,CAACpB,SAAS,CAAC,CAACsB,CAAC,CAAC,IAAI,IAAI,EAAE;QAC9B,OAAO;UAAEkB,YAAY,EAAE,IAAI;UAAEC,UAAU,EAAE;QAAK,CAAC;MACnD;MACA,OAAOC,SAAS;IACpB;EACJ,CAAC,CAAC;EACF,OAAOzB,UAAU;AACrB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createOsdkObject.js","names":["createAttachmentFromRid","GeotimeSeriesPropertyImpl","TimeSeriesPropertyImpl","createClientCache","get$as","get$link","CachedPropertiesRef","ClientRef","ObjectDefRef","RawObject","UnderlyingOsdkObject","objectPrototypeCache","client","objectDef","Object","create","value","get","newValues","assign","process","env","NODE_ENV","installed","Symbol","gw","window","global","devtoolsFormatters","push","header","object","raw","$apiName","$primaryKey","$title","hasBody","body","style","createOsdkObject","rawObj","objectHolderPrototype","writable","Map","holder","osdkObject","Proxy","ownKeys","target","Reflect","p","receiver","rawValue","propDef","properties","type","Array","isArray","map","a","rid","apiName","primaryKeyApiName","instance","geotimeProp","time","timestamp","coordinates","position","undefined","set","newValue","getOwnPropertyDescriptor","configurable","enumerable"],"sources":["createOsdkObject.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 { createAttachmentFromRid } from \"../../createAttachmentFromRid.js\";\nimport { GeotimeSeriesPropertyImpl } from \"../../createGeotimeSeriesProperty.js\";\nimport { TimeSeriesPropertyImpl } from \"../../createTimeseriesProperty.js\";\nimport { createClientCache } from \"../Cache.js\";\nimport { get$as } from \"./getDollarAs.js\";\nimport { get$link } from \"./getDollarLink.js\";\nimport { CachedPropertiesRef, ClientRef, ObjectDefRef, RawObject, UnderlyingOsdkObject, } from \"./InternalSymbols.js\";\nconst objectPrototypeCache = createClientCache(function (client, objectDef) {\n return Object.create(null, {\n [ObjectDefRef]: { value: objectDef },\n [ClientRef]: { value: client },\n \"$as\": { value: get$as(objectDef) },\n \"$link\": {\n get: function () {\n return get$link(this);\n },\n },\n \"$updateInternalValues\": {\n value: function (newValues) {\n this[RawObject] = Object.assign({}, this[RawObject], newValues);\n },\n },\n });\n});\nif (process.env.NODE_ENV !== \"production\") {\n const installed = Symbol();\n const gw = typeof window === \"undefined\" ? global : window;\n if (!(installed in gw)) {\n gw[installed] = true;\n gw.devtoolsFormatters ??= [];\n gw.devtoolsFormatters.push({\n header: function (object) {\n const raw = object[RawObject];\n if (raw == null)\n return null;\n return [\n \"div\",\n {},\n `Osdk.Instance<${raw.$apiName}> { $primaryKey:`,\n [\"object\", { object: raw.$primaryKey }],\n `, $title:`,\n [\"object\", { object: raw.$title }],\n `, ... }`,\n ];\n },\n hasBody: function (object) {\n return object[RawObject] != null;\n },\n body: function (object) {\n const raw = object[RawObject];\n if (raw == null)\n return null;\n return [\n \"ol\",\n {\n style: `\n list-style-type: none;\n padding-left: 0;\n margin-top: 0;\n margin-left: 18px\n `,\n },\n [\"li\", {}, \"$raw:\", [\"object\", { object: raw }]],\n // ...Object.keys(raw).map(key => {\n // return [\n // \"li\",\n // {},\n // [\n // \"span\",\n // { style: \"color: #888888\" },\n // `${key}: `,\n // ],\n // [\"object\", { object: raw[key] }], // [\"span\", {}, `${key}: `]],\n // ];\n // }),\n ];\n },\n });\n }\n}\n/** @internal */\nexport function createOsdkObject(client, objectDef, rawObj) {\n // We use multiple layers of prototypes to maximize reuse and also to keep\n // [RawObject] out of `ownKeys`. This keeps the code in the proxy below simpler.\n const objectHolderPrototype = Object.create(objectPrototypeCache.get(client, objectDef), {\n [RawObject]: {\n value: rawObj,\n writable: true, // so we can allow updates\n },\n [CachedPropertiesRef]: {\n value: new Map(),\n writable: true,\n },\n });\n // we separate the holder out so we can update\n // the underlying data without having to return a new object\n // we also need the holder so we can customize the console.log output\n const holder = Object.create(objectHolderPrototype);\n const osdkObject = new Proxy(holder, {\n ownKeys(target) {\n return Reflect.ownKeys(target[RawObject]);\n },\n get(target, p, receiver) {\n switch (p) {\n case UnderlyingOsdkObject:\n // effectively point back to the proxy\n return receiver;\n }\n if (p in target)\n return target[p];\n if (p in rawObj) {\n const rawValue = target[RawObject][p];\n const propDef = objectDef.properties[p];\n if (propDef) {\n if (propDef.type === \"attachment\") {\n if (Array.isArray(rawValue)) {\n return rawValue.map(a => createAttachmentFromRid(client, a.rid));\n }\n return createAttachmentFromRid(client, rawValue.rid);\n }\n if (propDef.type === \"numericTimeseries\"\n || propDef.type === \"stringTimeseries\") {\n return new TimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p);\n }\n if (propDef.type === \"geotimeSeriesReference\") {\n const instance = target[CachedPropertiesRef].get(p);\n if (instance != null) {\n return instance;\n }\n const geotimeProp = new GeotimeSeriesPropertyImpl(client, objectDef.apiName, target[RawObject][objectDef.primaryKeyApiName], p, rawValue.type === \"geotimeSeriesValue\"\n ? {\n time: rawValue.timestamp,\n value: {\n type: \"Point\",\n coordinates: rawValue.position,\n },\n }\n : undefined);\n target[CachedPropertiesRef].set(p, geotimeProp);\n return geotimeProp;\n }\n }\n return rawValue;\n }\n // we do not do any fall through to avoid unexpected behavior\n },\n set(target, p, newValue) {\n // allow the prototype to update this value\n if (p === RawObject) {\n // symbol only exists internally so no one else can hit this\n target[p] = newValue;\n return true;\n }\n return false;\n },\n getOwnPropertyDescriptor(target, p) {\n if (p === RawObject) {\n return Reflect.getOwnPropertyDescriptor(target, p);\n }\n if (target[RawObject][p] != null) {\n return { configurable: true, enumerable: true };\n }\n return undefined;\n },\n });\n return osdkObject;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,uBAAuB,QAAQ,kCAAkC;AAC1E,SAASC,yBAAyB,QAAQ,sCAAsC;AAChF,SAASC,sBAAsB,QAAQ,mCAAmC;AAC1E,SAASC,iBAAiB,QAAQ,aAAa;AAC/C,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,YAAY,EAAEC,SAAS,EAAEC,oBAAoB,QAAS,sBAAsB;AACrH,MAAMC,oBAAoB,GAAGR,iBAAiB,CAAC,UAAUS,MAAM,EAAEC,SAAS,EAAE;EACxE,OAAOC,MAAM,CAACC,MAAM,CAAC,IAAI,EAAE;IACvB,CAACP,YAAY,GAAG;MAAEQ,KAAK,EAAEH;IAAU,CAAC;IACpC,CAACN,SAAS,GAAG;MAAES,KAAK,EAAEJ;IAAO,CAAC;IAC9B,KAAK,EAAE;MAAEI,KAAK,EAAEZ,MAAM,CAACS,SAAS;IAAE,CAAC;IACnC,OAAO,EAAE;MACLI,GAAG,EAAE,SAAAA,CAAA,EAAY;QACb,OAAOZ,QAAQ,CAAC,IAAI,CAAC;MACzB;IACJ,CAAC;IACD,uBAAuB,EAAE;MACrBW,KAAK,EAAE,SAAAA,CAAUE,SAAS,EAAE;QACxB,IAAI,CAACT,SAAS,CAAC,GAAGK,MAAM,CAACK,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAACV,SAAS,CAAC,EAAES,SAAS,CAAC;MACnE;IACJ;EACJ,CAAC,CAAC;AACN,CAAC,CAAC;AACF,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACvC,MAAMC,SAAS,GAAGC,MAAM,CAAC,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QACjB;QACAuC,MAAM,CAACE,CAAC,CAAC,GAAGqB,QAAQ;QACpB,OAAO,IAAI;MACf;MACA,OAAO,KAAK;IAChB,CAAC;IACDC,wBAAwBA,CAACxB,MAAM,EAAEE,CAAC,EAAE;MAChC,IAAIA,CAAC,KAAKzC,SAAS,EAAE;QACjB,OAAOwC,OAAO,CAACuB,wBAAwB,CAACxB,MAAM,EAAEE,CAAC,CAAC;MACtD;MACA,IAAIF,MAAM,CAACvC,SAAS,CAAC,CAACyC,CAAC,CAAC,IAAI,IAAI,EAAE;QAC9B,OAAO;UAAEuB,YAAY,EAAE,IAAI;UAAEC,UAAU,EAAE;QAAK,CAAC;MACnD;MACA,OAAOL,SAAS;IACpB;EACJ,CAAC,CAAC;EACF,OAAOxB,UAAU;AACrB","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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AACA,SAAS9C,0BAA0BA,CAACkD,IAAI,EAAEvD,cAAc,EAAE;EACtD,KAAK,MAAM2C,GAAG,IAAIY,IAAI,EAAE;IACpB,IAAIvD,cAAc,EAAE;MAChB,OAAO2C,GAAG,CAACa,KAAK;IACpB;IACA,IAAIb,GAAG,CAACa,KAAK,EAAE;MACXb,GAAG,CAACc,IAAI,GAAGd,GAAG,CAACa,KAAK;MACpB,OAAOb,GAAG,CAACa,KAAK;IACpB;IACA;IACAb,GAAG,CAACzB,QAAQ,GAAGyB,GAAG,CAACe,SAAS;IAC5B;IACA;IACAf,GAAG,CAACO,WAAW,GAAGP,GAAG,CAACe,SAAS;IAC/B;IACAf,GAAG,CAACF,WAAW,GAAGE,GAAG,CAACgB,YAAY;IAClChB,GAAG,CAACiB,MAAM,GAAGjB,GAAG,CAACkB,OAAO;IACxB;IACA,OAAOlB,GAAG,CAACe,SAAS;IACpB,OAAOf,GAAG,CAACgB,YAAY;IACvB,OAAOhB,GAAG,CAACkB,OAAO;EACtB;AACJ","ignoreList":[]}
|
|
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","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,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,GAA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S,CAAC4B,YAAY,GAAG7C,gBAAgB,CAAC,IAAI,IAAI,EAAE;IACpD,MAAM2D,OAAO,GAAG,iOAAiO;IACjP,IAAI7D,MAAM,CAACM,MAAM,EAAE;MACfN,MAAM,CAACM,MAAM,CAACwD,IAAI,CAACD,OAAO,CAAC;IAC/B,CAAC,MACI;MACD;MACAE,OAAO,CAACC,KAAK,CAAC,YAAYH,OAAO,EAAE,CAAC;IACxC;IACA,MAAM,IAAI7B,KAAK,CAAC6B,OAAO,CAAC;EAC5B;AACJ;AACA,SAASrD,0BAA0BA,CAACyD,IAAI,EAAE9D,cAAc,EAAE;EACtD,KAAK,MAAMqD,GAAG,IAAIS,IAAI,EAAE;IACpB,IAAI9D,cAAc,EAAE;MAChB,OAAOqD,GAAG,CAACU,KAAK;IACpB;IACA,IAAIV,GAAG,CAACU,KAAK,EAAE;MACXV,GAAG,CAACW,IAAI,GAAGX,GAAG,CAACU,KAAK;MACpB,OAAOV,GAAG,CAACU,KAAK;IACpB;IACA;IACAV,GAAG,CAACnC,QAAQ,KAAKmC,GAAG,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");
|
|
@@ -91,7 +98,7 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
91
98
|
expect(emptyAttachment).toBeUndefined();
|
|
92
99
|
expect(emptyAttachmentArray).toBeUndefined();
|
|
93
100
|
});
|
|
94
|
-
it("works even with unknown apiNames", async () => {
|
|
101
|
+
it("works even with unknown apiNames - old", async () => {
|
|
95
102
|
const clientCtx = createMinimalClient({
|
|
96
103
|
ontologyRid: $ontologyRid
|
|
97
104
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
@@ -105,7 +112,21 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
105
112
|
const prototypeAfter = Object.getPrototypeOf(object2);
|
|
106
113
|
expect(prototypeBefore).not.toBe(prototypeAfter);
|
|
107
114
|
});
|
|
108
|
-
it("
|
|
115
|
+
it("works even with unknown apiNames - new", async () => {
|
|
116
|
+
const clientCtx = createMinimalClient({
|
|
117
|
+
ontologyRid: $ontologyRid
|
|
118
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
119
|
+
createSharedClientContext("https://stack.palantir.com", async () => "myAccessToken", "userAgent");
|
|
120
|
+
let object = {
|
|
121
|
+
__apiName: Employee.apiName,
|
|
122
|
+
__primaryKey: 0
|
|
123
|
+
};
|
|
124
|
+
const prototypeBefore = Object.getPrototypeOf(object);
|
|
125
|
+
let object2 = await convertWireToOsdkObjects2(clientCtx, [object], undefined, undefined, undefined, false);
|
|
126
|
+
const prototypeAfter = Object.getPrototypeOf(object2);
|
|
127
|
+
expect(prototypeBefore).not.toBe(prototypeAfter);
|
|
128
|
+
});
|
|
129
|
+
it("updates interface when underlying changes - old", async () => {
|
|
109
130
|
const clientCtx = createMinimalClient({
|
|
110
131
|
ontologyRid: $ontologyRid
|
|
111
132
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
@@ -137,7 +158,39 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
137
158
|
expect(obj).toBe(objAsFoo.$as(Employee));
|
|
138
159
|
expect(objAsFoo).toBe(obj.$as(FooInterface));
|
|
139
160
|
});
|
|
140
|
-
it("
|
|
161
|
+
it("updates interface when underlying changes - new", async () => {
|
|
162
|
+
const clientCtx = createMinimalClient({
|
|
163
|
+
ontologyRid: $ontologyRid
|
|
164
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
165
|
+
const [obj] = await convertWireToOsdkObjects2(clientCtx, [{
|
|
166
|
+
__apiName: "Employee",
|
|
167
|
+
__primaryKey: 0,
|
|
168
|
+
__title: "Steve",
|
|
169
|
+
fullName: "Steve",
|
|
170
|
+
employeeId: "5"
|
|
171
|
+
}], undefined);
|
|
172
|
+
expect(obj.fullName).toEqual("Steve");
|
|
173
|
+
expect(Object.keys(obj).sort()).toEqual(["$apiName", "$objectType", "$primaryKey", "$title", "employeeId", "fullName"].sort());
|
|
174
|
+
const objAsFoo = obj.$as(FooInterface);
|
|
175
|
+
expect(objAsFoo).toMatchObject({
|
|
176
|
+
fooSpt: obj.fullName,
|
|
177
|
+
$apiName: FooInterface.apiName,
|
|
178
|
+
$primaryKey: obj.$primaryKey,
|
|
179
|
+
$objectType: obj.$objectType,
|
|
180
|
+
$title: obj.$title
|
|
181
|
+
});
|
|
182
|
+
console.log(obj);
|
|
183
|
+
console.log(objAsFoo);
|
|
184
|
+
obj.$updateInternalValues({
|
|
185
|
+
fullName: "Bob"
|
|
186
|
+
});
|
|
187
|
+
expect(obj.fullName).toEqual("Bob");
|
|
188
|
+
expect(objAsFoo.fooSpt).toEqual(obj.fullName);
|
|
189
|
+
expect(Object.keys(objAsFoo).sort()).toEqual(["$apiName", "$objectType", "$primaryKey", "$title", "fooSpt"].sort());
|
|
190
|
+
expect(obj).toBe(objAsFoo.$as(Employee));
|
|
191
|
+
expect(objAsFoo).toBe(obj.$as(FooInterface));
|
|
192
|
+
});
|
|
193
|
+
it("reconstitutes interfaces properly without rid - old", async () => {
|
|
141
194
|
const clientCtx = createMinimalClient({
|
|
142
195
|
ontologyRid: $ontologyRid
|
|
143
196
|
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
@@ -169,6 +222,37 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
169
222
|
}
|
|
170
223
|
`);
|
|
171
224
|
});
|
|
225
|
+
it("reconstitutes interfaces properly without rid - new", async () => {
|
|
226
|
+
const clientCtx = createMinimalClient({
|
|
227
|
+
ontologyRid: $ontologyRid
|
|
228
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
229
|
+
const [objAsFoo] = await convertWireToOsdkObjects2(clientCtx, [{
|
|
230
|
+
__apiName: "Employee",
|
|
231
|
+
__primaryKey: 0,
|
|
232
|
+
__title: "Steve",
|
|
233
|
+
fullName: "Steve"
|
|
234
|
+
}], FooInterface.apiName, false, undefined, false, interfaceToObjectTypeMappings);
|
|
235
|
+
expect(objAsFoo).toMatchInlineSnapshot(`
|
|
236
|
+
{
|
|
237
|
+
"$apiName": "FooInterface",
|
|
238
|
+
"$objectType": "Employee",
|
|
239
|
+
"$primaryKey": 0,
|
|
240
|
+
"$title": "Steve",
|
|
241
|
+
"fooSpt": "Steve",
|
|
242
|
+
}
|
|
243
|
+
`);
|
|
244
|
+
const obj = objAsFoo.$as(Employee);
|
|
245
|
+
expect(obj.fullName).toEqual("Steve");
|
|
246
|
+
expect(obj).toMatchInlineSnapshot(`
|
|
247
|
+
{
|
|
248
|
+
"$apiName": "Employee",
|
|
249
|
+
"$objectType": "Employee",
|
|
250
|
+
"$primaryKey": 0,
|
|
251
|
+
"$title": "Steve",
|
|
252
|
+
"fullName": "Steve",
|
|
253
|
+
}
|
|
254
|
+
`);
|
|
255
|
+
});
|
|
172
256
|
it("reconstitutes interfaces properly with rid", async () => {
|
|
173
257
|
const clientCtx = createMinimalClient({
|
|
174
258
|
ontologyRid: $ontologyRid
|
|
@@ -206,29 +290,96 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
206
290
|
`);
|
|
207
291
|
expect(obj.$rid).toEqual("hiMom");
|
|
208
292
|
});
|
|
293
|
+
it("reconstitutes interfaces properly with rid - new", async () => {
|
|
294
|
+
const clientCtx = createMinimalClient({
|
|
295
|
+
ontologyRid: $ontologyRid
|
|
296
|
+
}, "https://stack.palantir.com", async () => "myAccessToken");
|
|
297
|
+
const [objAsFoo] = await convertWireToOsdkObjects2(clientCtx, [{
|
|
298
|
+
__apiName: "Employee",
|
|
299
|
+
__primaryKey: 0,
|
|
300
|
+
__title: "Steve",
|
|
301
|
+
__rid: "hiMom",
|
|
302
|
+
fullName: "Steve",
|
|
303
|
+
employeeId: 0
|
|
304
|
+
}], FooInterface.apiName, false, undefined, false, interfaceToObjectTypeMappings);
|
|
305
|
+
expect(objAsFoo).toMatchInlineSnapshot(`
|
|
306
|
+
{
|
|
307
|
+
"$apiName": "FooInterface",
|
|
308
|
+
"$objectType": "Employee",
|
|
309
|
+
"$primaryKey": 0,
|
|
310
|
+
"$rid": "hiMom",
|
|
311
|
+
"$title": "Steve",
|
|
312
|
+
"fooSpt": "Steve",
|
|
313
|
+
}
|
|
314
|
+
`);
|
|
315
|
+
expect(objAsFoo.$rid).toEqual("hiMom");
|
|
316
|
+
const obj = objAsFoo.$as(Employee);
|
|
317
|
+
expect(obj.fullName).toEqual("Steve");
|
|
318
|
+
expect(obj).toMatchInlineSnapshot(`
|
|
319
|
+
{
|
|
320
|
+
"$apiName": "Employee",
|
|
321
|
+
"$objectType": "Employee",
|
|
322
|
+
"$primaryKey": 0,
|
|
323
|
+
"$rid": "hiMom",
|
|
324
|
+
"$title": "Steve",
|
|
325
|
+
"employeeId": 0,
|
|
326
|
+
"fullName": "Steve",
|
|
327
|
+
}
|
|
328
|
+
`);
|
|
329
|
+
expect(obj.$rid).toEqual("hiMom");
|
|
330
|
+
});
|
|
209
331
|
describe("selection keys", () => {
|
|
210
332
|
it("throws when required is missing", async () => {
|
|
211
333
|
let object = {
|
|
212
334
|
__apiName: "Employee",
|
|
213
335
|
__primaryKey: 0
|
|
214
336
|
};
|
|
215
|
-
await expect(() => convertWireToOsdkObjects(client[
|
|
337
|
+
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
338
|
});
|
|
217
339
|
it("does not throw when optional is missing", async () => {
|
|
218
|
-
await expect(convertWireToOsdkObjects(client[
|
|
340
|
+
await expect(convertWireToOsdkObjects(client[additionalContext], [{
|
|
219
341
|
__apiName: "Employee",
|
|
220
342
|
__primaryKey: 0
|
|
221
343
|
}], undefined, undefined, ["fullName"], "throw")).resolves.to.not.toBeUndefined();
|
|
222
344
|
});
|
|
223
345
|
it("filters when it should", async () => {
|
|
224
|
-
const result = await convertWireToOsdkObjects(client[
|
|
346
|
+
const result = await convertWireToOsdkObjects(client[additionalContext], [{
|
|
225
347
|
__apiName: "Employee",
|
|
226
348
|
__primaryKey: 0
|
|
227
349
|
}], undefined, undefined, ["employeeId"], "drop");
|
|
228
350
|
expect(result.length).toBe(0);
|
|
229
351
|
});
|
|
230
352
|
it("does not filter when it shouldn't", async () => {
|
|
231
|
-
const result = await convertWireToOsdkObjects(client[
|
|
353
|
+
const result = await convertWireToOsdkObjects(client[additionalContext], [{
|
|
354
|
+
__apiName: "Employee",
|
|
355
|
+
__primaryKey: 0
|
|
356
|
+
}], undefined, undefined, ["fullName"], "drop");
|
|
357
|
+
expect(result.length).toBe(1);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
describe("selection keys - new", () => {
|
|
361
|
+
it("throws when required is missing", async () => {
|
|
362
|
+
let object = {
|
|
363
|
+
__apiName: "Employee",
|
|
364
|
+
__primaryKey: 0
|
|
365
|
+
};
|
|
366
|
+
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]`);
|
|
367
|
+
});
|
|
368
|
+
it("does not throw when optional is missing", async () => {
|
|
369
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
370
|
+
__apiName: "Employee",
|
|
371
|
+
__primaryKey: 0
|
|
372
|
+
}], undefined, undefined, ["fullName"], "throw")).resolves.to.not.toBeUndefined();
|
|
373
|
+
});
|
|
374
|
+
it("filters when it should", async () => {
|
|
375
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
376
|
+
__apiName: "Employee",
|
|
377
|
+
__primaryKey: 0
|
|
378
|
+
}], undefined, undefined, ["employeeId"], "drop");
|
|
379
|
+
expect(result.length).toBe(0);
|
|
380
|
+
});
|
|
381
|
+
it("does not filter when it shouldn't", async () => {
|
|
382
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
232
383
|
__apiName: "Employee",
|
|
233
384
|
__primaryKey: 0
|
|
234
385
|
}], undefined, undefined, ["fullName"], "drop");
|
|
@@ -241,24 +392,55 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
241
392
|
__apiName: "Employee",
|
|
242
393
|
__primaryKey: 0
|
|
243
394
|
};
|
|
244
|
-
await expect(() =>
|
|
395
|
+
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]`);
|
|
396
|
+
});
|
|
397
|
+
it("does not throw when required is present", async () => {
|
|
398
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
399
|
+
__apiName: "Employee",
|
|
400
|
+
__primaryKey: 0,
|
|
401
|
+
"employeeId": 0
|
|
402
|
+
}], undefined, undefined, undefined, "throw")).resolves.to.not.toBeUndefined();
|
|
403
|
+
});
|
|
404
|
+
it("filters when it should", async () => {
|
|
405
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
406
|
+
__apiName: "Employee",
|
|
407
|
+
__primaryKey: 0
|
|
408
|
+
}], undefined, undefined, undefined, "drop");
|
|
409
|
+
expect(result.length).toBe(0);
|
|
410
|
+
});
|
|
411
|
+
it("does not filter when it shouldn't", async () => {
|
|
412
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
413
|
+
__apiName: "Employee",
|
|
414
|
+
__primaryKey: 0,
|
|
415
|
+
"employeeId": 0
|
|
416
|
+
}], undefined, undefined, undefined, "drop");
|
|
417
|
+
expect(result.length).toBe(1);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
describe("without selection keys - new", () => {
|
|
421
|
+
it("throws when required is missing", async () => {
|
|
422
|
+
let object = {
|
|
423
|
+
__apiName: "Employee",
|
|
424
|
+
__primaryKey: 0
|
|
425
|
+
};
|
|
426
|
+
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
427
|
});
|
|
246
428
|
it("does not throw when required is present", async () => {
|
|
247
|
-
await expect(
|
|
429
|
+
await expect(convertWireToOsdkObjects2(client[additionalContext], [{
|
|
248
430
|
__apiName: "Employee",
|
|
249
431
|
__primaryKey: 0,
|
|
250
432
|
"employeeId": 0
|
|
251
433
|
}], undefined, undefined, undefined, "throw")).resolves.to.not.toBeUndefined();
|
|
252
434
|
});
|
|
253
435
|
it("filters when it should", async () => {
|
|
254
|
-
const result = await
|
|
436
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
255
437
|
__apiName: "Employee",
|
|
256
438
|
__primaryKey: 0
|
|
257
439
|
}], undefined, undefined, undefined, "drop");
|
|
258
440
|
expect(result.length).toBe(0);
|
|
259
441
|
});
|
|
260
442
|
it("does not filter when it shouldn't", async () => {
|
|
261
|
-
const result = await
|
|
443
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
262
444
|
__apiName: "Employee",
|
|
263
445
|
__primaryKey: 0,
|
|
264
446
|
"employeeId": 0
|
|
@@ -267,11 +449,11 @@ describe("convertWireToOsdkObjects", () => {
|
|
|
267
449
|
});
|
|
268
450
|
});
|
|
269
451
|
it("behaves correctly when converting", async () => {
|
|
270
|
-
const result = await
|
|
452
|
+
const result = await convertWireToOsdkObjects2(client[additionalContext], [{
|
|
271
453
|
__apiName: "Employee",
|
|
272
454
|
__primaryKey: 0,
|
|
273
455
|
fooSpt: "hi"
|
|
274
|
-
}], "FooInterface", undefined, ["fooSpt"], "drop");
|
|
456
|
+
}], "FooInterface", undefined, ["fooSpt"], "drop", interfaceToObjectTypeMappings);
|
|
275
457
|
expect(result.length).toBe(1);
|
|
276
458
|
});
|
|
277
459
|
});
|