@osdk/client 2.2.0-beta.14 → 2.2.0-beta.16
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 +26 -0
- package/build/browser/__unstable/ConjureSupport.js.map +1 -1
- package/build/browser/logger/BaseLogger.js +7 -1
- package/build/browser/logger/BaseLogger.js.map +1 -1
- package/build/browser/logger/BrowserLogger.js +67 -0
- package/build/browser/logger/BrowserLogger.js.map +1 -0
- package/build/browser/logger/MinimalLogger.js +12 -14
- package/build/browser/logger/MinimalLogger.js.map +1 -1
- package/build/browser/logger/MinimalLogger.test.js +60 -0
- package/build/browser/logger/MinimalLogger.test.js.map +1 -0
- package/build/browser/logger/TestLogger.js +3 -6
- package/build/browser/logger/TestLogger.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.js +0 -5
- package/build/browser/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/browser/object/fetchPage.js +2 -2
- package/build/browser/object/fetchPage.js.map +1 -1
- package/build/browser/ontology/loadFullObjectMetadata.js +0 -1
- package/build/browser/ontology/loadFullObjectMetadata.js.map +1 -1
- package/build/browser/public/internal.js +2 -0
- package/build/browser/public/internal.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/extractRdpDefinition.js +74 -21
- package/build/browser/util/extractRdpDefinition.js.map +1 -1
- package/build/browser/util/extractRdpDefinition.test.js +93 -4
- package/build/browser/util/extractRdpDefinition.test.js.map +1 -1
- package/build/cjs/Logger-a5UcHtrk.d.cts +19 -0
- package/build/cjs/{chunk-VT3UM6EP.cjs → chunk-6KYD7ZWT.cjs} +83 -14
- package/build/cjs/chunk-6KYD7ZWT.cjs.map +1 -0
- package/build/cjs/{chunk-USHAX4EP.cjs → chunk-KAJABLKV.cjs} +94 -37
- package/build/cjs/chunk-KAJABLKV.cjs.map +1 -0
- package/build/cjs/index.cjs +47 -114
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -19
- package/build/cjs/public/internal.cjs +61 -6
- package/build/cjs/public/internal.cjs.map +1 -1
- package/build/cjs/public/internal.d.cts +50 -2
- package/build/cjs/public/unstable-do-not-use.cjs +8 -8
- package/build/esm/__unstable/ConjureSupport.js.map +1 -1
- package/build/esm/logger/BaseLogger.js +7 -1
- package/build/esm/logger/BaseLogger.js.map +1 -1
- package/build/esm/logger/BrowserLogger.js +67 -0
- package/build/esm/logger/BrowserLogger.js.map +1 -0
- package/build/esm/logger/MinimalLogger.js +12 -14
- package/build/esm/logger/MinimalLogger.js.map +1 -1
- package/build/esm/logger/MinimalLogger.test.js +60 -0
- package/build/esm/logger/MinimalLogger.test.js.map +1 -0
- package/build/esm/logger/TestLogger.js +3 -6
- package/build/esm/logger/TestLogger.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.js +0 -5
- package/build/esm/object/convertWireToOsdkObjects.js.map +1 -1
- package/build/esm/object/fetchPage.js +2 -2
- package/build/esm/object/fetchPage.js.map +1 -1
- package/build/esm/ontology/loadFullObjectMetadata.js +0 -1
- package/build/esm/ontology/loadFullObjectMetadata.js.map +1 -1
- package/build/esm/public/internal.js +2 -0
- package/build/esm/public/internal.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/extractRdpDefinition.js +74 -21
- package/build/esm/util/extractRdpDefinition.js.map +1 -1
- package/build/esm/util/extractRdpDefinition.test.js +93 -4
- package/build/esm/util/extractRdpDefinition.test.js.map +1 -1
- package/build/types/__unstable/ConjureSupport.d.ts +2 -2
- package/build/types/logger/BaseLogger.d.ts +4 -1
- package/build/types/logger/BaseLogger.d.ts.map +1 -1
- package/build/types/logger/BrowserLogger.d.ts +10 -0
- package/build/types/logger/BrowserLogger.d.ts.map +1 -0
- package/build/types/logger/MinimalLogger.d.ts +2 -1
- package/build/types/logger/MinimalLogger.d.ts.map +1 -1
- package/build/types/logger/MinimalLogger.test.d.ts +1 -0
- package/build/types/logger/MinimalLogger.test.d.ts.map +1 -0
- package/build/types/logger/TestLogger.d.ts +2 -2
- package/build/types/logger/TestLogger.d.ts.map +1 -1
- package/build/types/object/convertWireToOsdkObjects.d.ts.map +1 -1
- package/build/types/public/internal.d.ts +2 -0
- package/build/types/public/internal.d.ts.map +1 -1
- package/build/types/util/extractRdpDefinition.d.ts +1 -1
- package/build/types/util/extractRdpDefinition.d.ts.map +1 -1
- package/package.json +11 -11
- package/build/cjs/chunk-USHAX4EP.cjs.map +0 -1
- package/build/cjs/chunk-VT3UM6EP.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MinimalLogger.test.js","names":["beforeEach","describe","expect","it","vi","MinimalLogger","orderedLevels","consoleMocks","Object","fromEntries","map","name","spyOn","console","consoleMock","values","mockClear","logger","debug","not","toHaveBeenCalled","for","level","idx","findIndex","a","toBeGreaterThan","shouldNotOutput","slice","shouldOutput","x","levelToCheck","shouldLog","calls","mock","length"],"sources":["MinimalLogger.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MockInstance } from \"vitest\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { MinimalLogger } from \"./MinimalLogger.js\";\n\nconst orderedLevels = [\n \"trace\",\n \"debug\",\n \"info\",\n \"warn\",\n \"error\",\n \"fatal\",\n] as const;\n\ndescribe(MinimalLogger, () => {\n const consoleTypes = [\"log\", \"error\", \"warn\", \"trace\"] as const;\n type consoleTypes = typeof consoleTypes[number];\n\n const consoleMocks = Object.fromEntries(\n consoleTypes.map(name =>\n [name, vi.spyOn(console, name)] as [consoleTypes, MockInstance<any>]\n ),\n ) as Record<\n typeof consoleTypes[number],\n MockInstance<any>\n >;\n\n beforeEach(() => {\n for (const consoleMock of Object.values(consoleMocks)) {\n consoleMock.mockClear();\n }\n });\n\n it(\"does not debug log by default\", () => {\n const logger = new MinimalLogger();\n logger.debug(\"hi\");\n\n for (const consoleMock of Object.values(consoleMocks)) {\n expect(consoleMock).not.toHaveBeenCalled();\n }\n });\n\n it(\"can log\", () => {\n new MinimalLogger({}, {});\n });\n\n describe.for(orderedLevels)(\"For level %s\", (level) => {\n const idx = orderedLevels.findIndex(a => a === level);\n expect(idx).toBeGreaterThan(-1);\n\n const shouldNotOutput = orderedLevels.slice(0, idx);\n const shouldOutput = orderedLevels.slice(idx);\n\n const x = [\n ...shouldNotOutput.map(x => [x, false] as const),\n ...shouldOutput.map(x => [x, true] as const),\n ];\n\n it.for(x)(\"It should log for %s? %s\", ([levelToCheck, shouldLog]) => {\n const logger = new MinimalLogger({}, { level });\n\n logger[levelToCheck](\"logging\");\n\n let calls = 0;\n\n for (const consoleMock of Object.values(consoleMocks)) {\n calls += consoleMock.mock.calls.length;\n }\n\n if (shouldLog) {\n expect(calls === 1, `Should log one time but got ${calls}`);\n } else {\n expect(calls === 0, \"should not call console.thing\");\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AAC7D,SAASC,aAAa,QAAQ,oBAAoB;AAElD,MAAMC,aAAa,GAAG,CACpB,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,CACC;AAEVL,QAAQ,CAACI,aAAa,EAAE,MAAM;EAI5B,MAAME,YAAY,GAAGC,MAAM,CAACC,WAAW,CAHlB,CAAC,KAAK,EAAE,OAAO,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ChD,GAAGD,YAAY,CAACnB,GAAG,CAACoB,CAAC,IAAI,CAACA,CAAC,EAAE,IAAI,CAAU,CAAC,CAC7C;IAED3B,EAAE,CAACkB,GAAG,CAACS,CAAC,CAAC,CAAC,0BAA0B,EAAE,CAAC,CAACC,YAAY,EAAEC,SAAS,CAAC,KAAK;MACnE,MAAMf,MAAM,GAAG,IAAIZ,aAAa,CAAC,CAAC,CAAC,EAAE;QAAEiB;MAAM,CAAC,CAAC;MAE/CL,MAAM,CAACc,YAAY,CAAC,CAAC,SAAS,CAAC;MAE/B,IAAIE,KAAK,GAAG,CAAC;MAEb,KAAK,MAAMnB,WAAW,IAAIN,MAAM,CAACO,MAAM,CAACR,YAAY,CAAC,EAAE;QACrD0B,KAAK,IAAInB,WAAW,CAACoB,IAAI,CAACD,KAAK,CAACE,MAAM;MACxC;MAEA,IAAIH,SAAS,EAAE;QACb9B,MAAM,CAAC+B,KAAK,KAAK,CAAC,EAAE,+BAA+BA,KAAK,EAAE,CAAC;MAC7D,CAAC,MAAM;QACL/B,MAAM,CAAC+B,KAAK,KAAK,CAAC,EAAE,+BAA+B,CAAC;MACtD;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -39,14 +39,11 @@ export class TestLogger extends BaseLogger {
|
|
|
39
39
|
...options,
|
|
40
40
|
level: options.level ?? "error"
|
|
41
41
|
}, TestLogger);
|
|
42
|
-
for (const k of ["trace", "debug", "info", "warn", "error", "fatal"]) {
|
|
43
|
-
this[k] = this.#createLogMethod(k, bindings, options);
|
|
44
|
-
}
|
|
45
42
|
}
|
|
46
|
-
|
|
43
|
+
createLogMethod(name, bindings) {
|
|
47
44
|
const msgs = [colors[name][1](name)];
|
|
48
|
-
if (options?.msgPrefix) {
|
|
49
|
-
msgs.push(colors[name][0](options.msgPrefix));
|
|
45
|
+
if (this.options?.msgPrefix) {
|
|
46
|
+
msgs.push(colors[name][0](this.options.msgPrefix));
|
|
50
47
|
}
|
|
51
48
|
if (typeof bindings === "object" && "methodName" in bindings) {
|
|
52
49
|
msgs.push(chalk.magenta(`.${bindings.methodName}()`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestLogger.js","names":["Chalk","vi","BaseLogger","chalk","colors","debug","cyan","bgCyan","info","green","bgGreen","trace","gray","bgGray","error","red","bgRed","warn","yellow","bgYellow","fatal","redBright","bgRedBright","TestLogger","constructor","bindings","options","level","
|
|
1
|
+
{"version":3,"file":"TestLogger.js","names":["Chalk","vi","BaseLogger","chalk","colors","debug","cyan","bgCyan","info","green","bgGreen","trace","gray","bgGray","error","red","bgRed","warn","yellow","bgYellow","fatal","redBright","bgRedBright","TestLogger","constructor","bindings","options","level","createLogMethod","name","msgs","msgPrefix","push","magenta","methodName","fn","console","bind","join"],"sources":["TestLogger.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Chalk } from \"chalk\";\nimport { vi } from \"vitest\";\nimport { BaseLogger } from \"./BaseLogger.js\";\nimport type { LogFn, Logger } from \"./Logger.js\";\n\nconst chalk = new Chalk(); // new Chalk({ level: 3 });\n\nconst colors = {\n debug: [chalk.cyan, chalk.bgCyan],\n info: [chalk.green, chalk.bgGreen],\n trace: [chalk.gray, chalk.bgGray],\n error: [chalk.red, chalk.bgRed],\n warn: [chalk.yellow, chalk.bgYellow],\n fatal: [chalk.redBright, chalk.bgRedBright],\n} as const;\n\n/**\n * A logger suitable for using in unit tests.\n * - It uses chalk for colors (Node and browser console.log supports)\n * - Does not rely on async behavior of `pino`.\n */\nexport class TestLogger extends BaseLogger implements Logger {\n constructor(\n bindings: Record<string, any> = {},\n options: { level?: string; msgPrefix?: string } = {},\n ) {\n super(\n bindings,\n { ...options, level: options.level ?? \"error\" },\n TestLogger,\n );\n }\n\n protected createLogMethod(\n name: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\",\n bindings: Record<string, any>,\n ): LogFn {\n const msgs: string[] = [colors[name][1](name)];\n\n if (this.options?.msgPrefix) {\n msgs.push(colors[name][0](this.options.msgPrefix));\n }\n\n if (typeof bindings === \"object\" && \"methodName\" in bindings) {\n msgs.push(chalk.magenta(`.${bindings.methodName}()`));\n }\n\n // eslint-disable-next-line no-console\n return vi.fn<LogFn>(console[name === \"fatal\" ? \"error\" : name].bind(\n console,\n msgs.join(\" \"),\n )) as LogFn;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,QAAQ,OAAO;AAC7B,SAASC,EAAE,QAAQ,QAAQ;AAC3B,SAASC,UAAU,QAAQ,iBAAiB;AAG5C,MAAMC,KAAK,GAAG,IAAIH,KAAK,CAAC,CAAC,CAAC,CAAC;;AAE3B,MAAMI,MAAM,GAAG;EACbC,KAAK,EAAE,CAACF,KAAK,CAACG,IAAI,EAAEH,KAAK,CAACI,MAAM,CAAC;EACjCC,IAAI,EAAE,CAACL,KAAK,CAACM,KAAK,EAAEN,KAAK,CAACO,OAAO,CAAC;EAClCC,KAAK,EAAE,CAACR,KAAK,CAACS,IAAI,EAAET,KAAK,CAACU,MAAM,CAAC;EACjCC,KAAK,EAAE,CAACX,KAAK,CAACY,GAAG,EAAEZ,KAAK,CAACa,KAAK,CAAC;EAC/BC,IAAI,EAAE,CAACd,KAAK,CAACe,MAAM,EAAEf,KAAK,CAACgB,QAAQ,CAAC;EACpCC,KAAK,EAAE,CAACjB,KAAK,CAACkB,SAAS,EAAElB,KAAK,CAACmB,WAAW;AAC5C,CAAU;;AAEV;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,SAASrB,UAAU,CAAmB;EAC3DsB,WAAWA,CACTC,QAA6B,GAAG,CAAC,CAAC,EAClCC,OAA+C,GAAG,CAAC,CAAC,EACpD;IACA,KAAK,CACHD,QAAQ,EACR;MAAE,GAAGC,OAAO;MAAEC,KAAK,EAAED,OAAO,CAACC,KAAK,IAAI;IAAQ,CAAC,EAC/CJ,UACF,CAAC;EACH;EAEUK,eAAeA,CACvBC,IAA6D,EAC7DJ,QAA6B,EACtB;IACP,MAAMK,IAAc,GAAG,CAAC1B,MAAM,CAACyB,IAAI,CAAC,CAAC,CAAC,CAAC,CAACA,IAAI,CAAC,CAAC;IAE9C,IAAI,IAAI,CAACH,OAAO,EAAEK,SAAS,EAAE;MAC3BD,IAAI,CAACE,IAAI,CAAC5B,MAAM,CAACyB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAACH,OAAO,CAACK,SAAS,CAAC,CAAC;IACpD;IAEA,IAAI,OAAON,QAAQ,KAAK,QAAQ,IAAI,YAAY,IAAIA,QAAQ,EAAE;MAC5DK,IAAI,CAACE,IAAI,CAAC7B,KAAK,CAAC8B,OAAO,CAAC,IAAIR,QAAQ,CAACS,UAAU,IAAI,CAAC,CAAC;IACvD;;IAEA;IACA,OAAOjC,EAAE,CAACkC,EAAE,CAAQC,OAAO,CAACP,IAAI,KAAK,OAAO,GAAG,OAAO,GAAGA,IAAI,CAAC,CAACQ,IAAI,CACjED,OAAO,EACPN,IAAI,CAACQ,IAAI,CAAC,GAAG,CACf,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -33,8 +33,6 @@ import { createOsdkObject } from "./convertWireToOsdkObjects/createOsdkObject.js
|
|
|
33
33
|
* @param interfaceApiName - if undefined
|
|
34
34
|
*/
|
|
35
35
|
export async function convertWireToOsdkObjects(client, objects, interfaceApiName, forceRemoveRid = false, derivedPropertyTypesByName, selectedProps, strictNonNull = false) {
|
|
36
|
-
client.logger?.debug(`START convertWireToOsdkObjects()`);
|
|
37
|
-
|
|
38
36
|
// remove the __ prefixed properties and convert them to $ prefixed.
|
|
39
37
|
// updates in place
|
|
40
38
|
fixObjectPropertiesInPlace(objects, forceRemoveRid);
|
|
@@ -67,14 +65,12 @@ export async function convertWireToOsdkObjects(client, objects, interfaceApiName
|
|
|
67
65
|
if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);
|
|
68
66
|
ret.push(osdkObject);
|
|
69
67
|
}
|
|
70
|
-
client.logger?.debug(`END convertWireToOsdkObjects()`);
|
|
71
68
|
return ret;
|
|
72
69
|
}
|
|
73
70
|
/**
|
|
74
71
|
* @internal
|
|
75
72
|
*/
|
|
76
73
|
export async function convertWireToOsdkObjects2(client, objects, interfaceApiName, derivedPropertyTypeByName, forceRemoveRid = false, selectedProps, strictNonNull = false, interfaceToObjectTypeMappings = {}) {
|
|
77
|
-
client.logger?.debug(`START convertWireToOsdkObjects2()`);
|
|
78
74
|
fixObjectPropertiesInPlace(objects, forceRemoveRid);
|
|
79
75
|
const ret = [];
|
|
80
76
|
for (const rawObj of objects) {
|
|
@@ -104,7 +100,6 @@ export async function convertWireToOsdkObjects2(client, objects, interfaceApiNam
|
|
|
104
100
|
if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);
|
|
105
101
|
ret.push(osdkObject);
|
|
106
102
|
}
|
|
107
|
-
client.logger?.debug(`END convertWireToOsdkObjects2()`);
|
|
108
103
|
return ret;
|
|
109
104
|
}
|
|
110
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertWireToOsdkObjects.js","names":["invariant","createOsdkObject","convertWireToOsdkObjects","client","objects","interfaceApiName","forceRemoveRid","derivedPropertyTypesByName","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","derivedPropertyTypeByName","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.ts"],"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 */\n\nimport type {\n InterfaceMetadata,\n NullabilityAdherence,\n ObjectMetadata,\n} from \"@osdk/api\";\nimport type {\n InterfaceToObjectTypeMappings,\n InterfaceTypeApiName,\n OntologyObjectV2,\n} from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport {\n type FetchedObjectTypeDefinition,\n} from \"../ontology/OntologyProvider.js\";\nimport { createOsdkObject } from \"./convertWireToOsdkObjects/createOsdkObject.js\";\nimport type { InterfaceHolder } from \"./convertWireToOsdkObjects/InterfaceHolder.js\";\nimport type { ObjectHolder } from \"./convertWireToOsdkObjects/ObjectHolder.js\";\nimport type { SimpleOsdkProperties } from \"./SimpleOsdkProperties.js\";\n\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(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n forceRemoveRid: boolean = false,\n derivedPropertyTypesByName: Record<\n string,\n ObjectMetadata.Property\n >,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull: NullabilityAdherence = false,\n): Promise<Array<ObjectHolder | InterfaceHolder>> {\n client.logger?.debug(`START convertWireToOsdkObjects()`);\n\n // remove the __ prefixed properties and convert them to $ prefixed.\n // updates in place\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n\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\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(\n rawObj.$apiName,\n );\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n\n // default value for when we are checking an object\n let objProps;\n\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\n conforming &&= isConforming(client, ifaceDef, rawObj, ifaceSelected);\n\n reframeAsObjectInPlace(objectDef, ifaceDef.apiName, rawObj);\n\n objProps = convertInterfacePropNamesToObjectPropNames(\n objectDef,\n ifaceDef.apiName,\n ifaceSelected,\n );\n } else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\n \"Unable to safely convert objects as some non nullable properties are null\",\n );\n } else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n\n let osdkObject: ObjectHolder | InterfaceHolder = createOsdkObject(\n client,\n objectDef,\n rawObj,\n derivedPropertyTypesByName,\n );\n if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);\n\n ret.push(osdkObject);\n }\n\n client.logger?.debug(`END convertWireToOsdkObjects()`);\n return ret;\n}\n\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<InterfaceHolder>>;\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<ObjectHolder>>;\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<ObjectHolder | InterfaceHolder>>;\n/**\n * @internal\n */\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid: boolean = false,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull: NullabilityAdherence = false,\n interfaceToObjectTypeMappings: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n > = {},\n): Promise<Array<ObjectHolder | InterfaceHolder>> {\n client.logger?.debug(`START convertWireToOsdkObjects2()`);\n\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(\n rawObj.$apiName,\n );\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n\n const interfaceToObjMapping = interfaceApiName\n ? interfaceToObjectTypeMappings[interfaceApiName as InterfaceTypeApiName][\n rawObj.$apiName\n ]\n : undefined;\n\n const ifaceSelected = interfaceApiName && interfaceToObjMapping\n ? (selectedProps\n ? Object.keys(interfaceToObjMapping).filter(\n val => {\n selectedProps?.includes(interfaceToObjMapping[val]);\n },\n )\n : [\n ...Object.values(interfaceToObjMapping),\n objectDef.primaryKeyApiName,\n ])\n : undefined;\n\n // default value for when we are checking an object\n let objProps;\n\n let conforming = true;\n if (interfaceApiName && ifaceSelected) {\n invariantInterfacesAsViews(objectDef, interfaceApiName, client);\n\n objProps = ifaceSelected;\n } else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\n \"Unable to safely convert objects as some non nullable properties are null\",\n );\n } else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n\n let osdkObject: ObjectHolder | InterfaceHolder = createOsdkObject(\n client,\n objectDef,\n rawObj,\n derivedPropertyTypeByName,\n );\n if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);\n\n ret.push(osdkObject);\n }\n\n client.logger?.debug(`END convertWireToOsdkObjects2()`);\n return ret;\n}\n\n/**\n * @internal\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 */\nexport function convertInterfacePropNamesToObjectPropNames(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n ifacePropsToMap: readonly string[],\n): string[] {\n return ifacePropsToMap.map((ifaceProp) =>\n objectDef.interfaceMap[interfaceApiName][ifaceProp]\n );\n}\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(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n rawObj: OntologyObjectV2,\n) {\n const newProps: Record<string, any> = {};\n for (\n const [sptProp, regularProp] of Object.entries(\n objectDef.interfaceMap[interfaceApiName],\n )\n ) {\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\n if (!(objectDef.primaryKeyApiName in rawObj)) {\n rawObj[objectDef.primaryKeyApiName] = rawObj.$primaryKey;\n }\n}\n\nfunction isConforming(\n client: MinimalClient,\n def:\n | InterfaceMetadata\n | ObjectMetadata,\n obj: OntologyObjectV2,\n propsToCheck: readonly string[],\n) {\n for (const propName of propsToCheck) {\n if (\n propName in def.properties && def.properties[propName].nullable === false\n && obj[propName] == null\n ) {\n if (process.env.NODE_ENV !== \"production\") {\n client.logger?.debug(\n {\n obj: {\n $apiName: obj[\"$apiName\"],\n $objectType: obj[\"$objectType\"],\n $primaryKey: obj[\"$primaryKey\"],\n },\n },\n `Found object that does not conform to its definition. Expected ${def.apiName}'s ${propName} to not be null.`,\n );\n }\n return false;\n }\n }\n return true;\n}\n\nfunction invariantInterfacesAsViews(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n client: MinimalClient,\n): asserts objectDef is typeof objectDef & { interfaceMap: {} } {\n if (objectDef.interfaceMap?.[interfaceApiName] == null) {\n const warning =\n \"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 } else {\n // eslint-disable-next-line no-console\n console.error(`WARNING! ${warning}`);\n }\n throw new Error(warning);\n }\n}\n\nfunction fixObjectPropertiesInPlace(\n objs: OntologyObjectV2[],\n forceRemoveRid: boolean,\n): asserts objs is SimpleOsdkProperties[] {\n for (const obj of objs) {\n if (forceRemoveRid) {\n delete obj.__rid;\n }\n\n if (obj.__rid) {\n obj.$rid = obj.__rid;\n delete obj.__rid;\n }\n\n // Backend returns as __apiName but we want to stick to $ structure\n obj.$apiName ??= obj.__apiName;\n\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\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\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;;AAYA,OAAOA,SAAS,MAAM,gBAAgB;AAKtC,SAASC,gBAAgB,QAAQ,gDAAgD;AAKjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,wBAAwBA,CAC5CC,MAAqB,EACrBC,OAA2B,EAC3BC,gBAAoC,EACpCC,cAAuB,GAAG,KAAK,EAC/BC,0BAGC,EACDC,aAAqC,EACrCC,aAAmC,GAAG,KAAK,EACK;EAChDN,MAAM,CAACO,MAAM,EAAEC,KAAK,CAAC,kCAAkC,CAAC;;EAExD;EACA;EACAC,0BAA0B,CAACR,OAAO,EAAEE,cAAc,CAAC;EAEnD,MAAMO,QAAQ,GAAGR,gBAAgB,GAC7B,MAAMF,MAAM,CAACW,gBAAgB,CAACC,sBAAsB,CAACV,gBAAgB,CAAC,GACtEW,SAAS;EACb,MAAMC,a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G,CAACe,OAAO;;IAE1B;IACA,OAAOf,GAAG,CAACY,SAAS;IACpB,OAAOZ,GAAG,CAACa,YAAY;IACvB,OAAOb,GAAG,CAACe,OAAO;EACpB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"convertWireToOsdkObjects.js","names":["invariant","createOsdkObject","convertWireToOsdkObjects","client","objects","interfaceApiName","forceRemoveRid","derivedPropertyTypesByName","selectedProps","strictNonNull","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","derivedPropertyTypeByName","interfaceToObjectTypeMappings","interfaceToObjMapping","filter","val","includes","values","primaryKeyApiName","ifacePropsToMap","map","ifaceProp","interfaceMap","newProps","sptProp","regularProp","entries","value","assign","$primaryKey","def","obj","propsToCheck","propName","nullable","logger","debug","$objectType","warning","warn","console","error","objs","__rid","$rid","__apiName","__primaryKey","$title","__title"],"sources":["convertWireToOsdkObjects.ts"],"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 */\n\nimport type {\n InterfaceMetadata,\n NullabilityAdherence,\n ObjectMetadata,\n} from \"@osdk/api\";\nimport type {\n InterfaceToObjectTypeMappings,\n InterfaceTypeApiName,\n OntologyObjectV2,\n} from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport {\n type FetchedObjectTypeDefinition,\n} from \"../ontology/OntologyProvider.js\";\nimport { createOsdkObject } from \"./convertWireToOsdkObjects/createOsdkObject.js\";\nimport type { InterfaceHolder } from \"./convertWireToOsdkObjects/InterfaceHolder.js\";\nimport type { ObjectHolder } from \"./convertWireToOsdkObjects/ObjectHolder.js\";\nimport type { SimpleOsdkProperties } from \"./SimpleOsdkProperties.js\";\n\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(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n forceRemoveRid: boolean = false,\n derivedPropertyTypesByName: Record<\n string,\n ObjectMetadata.Property\n >,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull: NullabilityAdherence = false,\n): Promise<Array<ObjectHolder | InterfaceHolder>> {\n // remove the __ prefixed properties and convert them to $ prefixed.\n // updates in place\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n\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\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(\n rawObj.$apiName,\n );\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n\n // default value for when we are checking an object\n let objProps;\n\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\n conforming &&= isConforming(client, ifaceDef, rawObj, ifaceSelected);\n\n reframeAsObjectInPlace(objectDef, ifaceDef.apiName, rawObj);\n\n objProps = convertInterfacePropNamesToObjectPropNames(\n objectDef,\n ifaceDef.apiName,\n ifaceSelected,\n );\n } else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\n \"Unable to safely convert objects as some non nullable properties are null\",\n );\n } else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n\n let osdkObject: ObjectHolder | InterfaceHolder = createOsdkObject(\n client,\n objectDef,\n rawObj,\n derivedPropertyTypesByName,\n );\n if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);\n\n ret.push(osdkObject);\n }\n\n return ret;\n}\n\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<InterfaceHolder>>;\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<ObjectHolder>>;\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid?: boolean,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull?: NullabilityAdherence,\n interfaceToObjectTypeMappings?: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n >,\n): Promise<Array<ObjectHolder | InterfaceHolder>>;\n/**\n * @internal\n */\nexport async function convertWireToOsdkObjects2(\n client: MinimalClient,\n objects: OntologyObjectV2[],\n interfaceApiName: string | undefined,\n derivedPropertyTypeByName: Record<\n string,\n ObjectMetadata.Property\n >,\n forceRemoveRid: boolean = false,\n selectedProps?: ReadonlyArray<string>,\n strictNonNull: NullabilityAdherence = false,\n interfaceToObjectTypeMappings: Record<\n InterfaceTypeApiName,\n InterfaceToObjectTypeMappings\n > = {},\n): Promise<Array<ObjectHolder | InterfaceHolder>> {\n fixObjectPropertiesInPlace(objects, forceRemoveRid);\n\n const ret = [];\n for (const rawObj of objects) {\n const objectDef = await client.ontologyProvider.getObjectDefinition(\n rawObj.$apiName,\n );\n invariant(objectDef, `Missing definition for '${rawObj.$apiName}'`);\n\n const interfaceToObjMapping = interfaceApiName\n ? interfaceToObjectTypeMappings[interfaceApiName as InterfaceTypeApiName][\n rawObj.$apiName\n ]\n : undefined;\n\n const ifaceSelected = interfaceApiName && interfaceToObjMapping\n ? (selectedProps\n ? Object.keys(interfaceToObjMapping).filter(\n val => {\n selectedProps?.includes(interfaceToObjMapping[val]);\n },\n )\n : [\n ...Object.values(interfaceToObjMapping),\n objectDef.primaryKeyApiName,\n ])\n : undefined;\n\n // default value for when we are checking an object\n let objProps;\n\n let conforming = true;\n if (interfaceApiName && ifaceSelected) {\n invariantInterfacesAsViews(objectDef, interfaceApiName, client);\n\n objProps = ifaceSelected;\n } else {\n objProps = selectedProps ?? Object.keys(objectDef.properties);\n }\n\n conforming &&= isConforming(client, objectDef, rawObj, objProps);\n\n if (strictNonNull === \"throw\" && !conforming) {\n throw new Error(\n \"Unable to safely convert objects as some non nullable properties are null\",\n );\n } else if (strictNonNull === \"drop\" && !conforming) {\n continue;\n }\n\n let osdkObject: ObjectHolder | InterfaceHolder = createOsdkObject(\n client,\n objectDef,\n rawObj,\n derivedPropertyTypeByName,\n );\n if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);\n\n ret.push(osdkObject);\n }\n\n return ret;\n}\n\n/**\n * @internal\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 */\nexport function convertInterfacePropNamesToObjectPropNames(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n ifacePropsToMap: readonly string[],\n): string[] {\n return ifacePropsToMap.map((ifaceProp) =>\n objectDef.interfaceMap[interfaceApiName][ifaceProp]\n );\n}\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(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n rawObj: OntologyObjectV2,\n) {\n const newProps: Record<string, any> = {};\n for (\n const [sptProp, regularProp] of Object.entries(\n objectDef.interfaceMap[interfaceApiName],\n )\n ) {\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\n if (!(objectDef.primaryKeyApiName in rawObj)) {\n rawObj[objectDef.primaryKeyApiName] = rawObj.$primaryKey;\n }\n}\n\nfunction isConforming(\n client: MinimalClient,\n def:\n | InterfaceMetadata\n | ObjectMetadata,\n obj: OntologyObjectV2,\n propsToCheck: readonly string[],\n) {\n for (const propName of propsToCheck) {\n if (\n propName in def.properties && def.properties[propName].nullable === false\n && obj[propName] == null\n ) {\n if (process.env.NODE_ENV !== \"production\") {\n client.logger?.debug(\n {\n obj: {\n $apiName: obj[\"$apiName\"],\n $objectType: obj[\"$objectType\"],\n $primaryKey: obj[\"$primaryKey\"],\n },\n },\n `Found object that does not conform to its definition. Expected ${def.apiName}'s ${propName} to not be null.`,\n );\n }\n return false;\n }\n }\n return true;\n}\n\nfunction invariantInterfacesAsViews(\n objectDef: FetchedObjectTypeDefinition,\n interfaceApiName: string,\n client: MinimalClient,\n): asserts objectDef is typeof objectDef & { interfaceMap: {} } {\n if (objectDef.interfaceMap?.[interfaceApiName] == null) {\n const warning =\n \"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 } else {\n // eslint-disable-next-line no-console\n console.error(`WARNING! ${warning}`);\n }\n throw new Error(warning);\n }\n}\n\nfunction fixObjectPropertiesInPlace(\n objs: OntologyObjectV2[],\n forceRemoveRid: boolean,\n): asserts objs is SimpleOsdkProperties[] {\n for (const obj of objs) {\n if (forceRemoveRid) {\n delete obj.__rid;\n }\n\n if (obj.__rid) {\n obj.$rid = obj.__rid;\n delete obj.__rid;\n }\n\n // Backend returns as __apiName but we want to stick to $ structure\n obj.$apiName ??= obj.__apiName;\n\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\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\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;;AAYA,OAAOA,SAAS,MAAM,gBAAgB;AAKtC,SAASC,gBAAgB,QAAQ,gDAAgD;AAKjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,wBAAwBA,CAC5CC,MAAqB,EACrBC,OAA2B,EAC3BC,gBAAoC,EACpCC,cAAuB,GAAG,KAAK,EAC/BC,0BAGC,EACDC,aAAqC,EACrCC,aAAmC,GAAG,KAAK,EACK;EAChD;EACA;EACAC,0BAA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AAG,CAACiB,OAAO;;IAE1B;IACA,OAAOjB,GAAG,CAACc,SAAS;IACpB,OAAOd,GAAG,CAACe,YAAY;IACvB,OAAOf,GAAG,CAACiB,OAAO;EACpB;AACF","ignoreList":[]}
|
|
@@ -69,7 +69,7 @@ async function fetchInterfacePage(client, interfaceType, args, objectSet) {
|
|
|
69
69
|
});
|
|
70
70
|
result.data = await client.objectFactory(client, result.data,
|
|
71
71
|
// drop readonly
|
|
72
|
-
interfaceType.apiName, !args.$includeRid, await extractRdpDefinition(client, objectSet
|
|
72
|
+
interfaceType.apiName, !args.$includeRid, await extractRdpDefinition(client, objectSet));
|
|
73
73
|
return result;
|
|
74
74
|
}
|
|
75
75
|
const result = await OntologiesV2.OntologyObjectSets.loadMultipleObjectTypes(addUserAgentAndRequestContextHeaders(client, interfaceType), await client.ontologyRid, applyFetchArgs(args, {
|
|
@@ -158,7 +158,7 @@ export async function fetchObjectPage(client, objectType, args, objectSet) {
|
|
|
158
158
|
excludeRid: !args?.$includeRid
|
|
159
159
|
}));
|
|
160
160
|
return Promise.resolve({
|
|
161
|
-
data: await client.objectFactory(client, r.data, undefined, undefined, await extractRdpDefinition(client, objectSet
|
|
161
|
+
data: await client.objectFactory(client, r.data, undefined, undefined, await extractRdpDefinition(client, objectSet), args.$select),
|
|
162
162
|
nextPageToken: r.nextPageToken,
|
|
163
163
|
totalCount: r.totalCount
|
|
164
164
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchPage.js","names":["OntologiesV2","addUserAgentAndRequestContextHeaders","extractRdpDefinition","resolveBaseObjectSetType","augment","type","properties","apiName","objectSetToSearchJsonV2","objectSet","expectedApiName","existingWhere","undefined","objectType","Error","interfaceType","where","value","resolveInterfaceObjectSet","interfaceTypeApiName","args","$includeAllBaseObjectProperties","objectSets","includeAllBaseObjectProperties","fetchInterfacePage","client","$__UNSTABLE_useOldInterfaceApis","result","OntologyInterfaces","search","ontologyRid","applyFetchArgs","augmentedProperties","augmentedSharedPropertyTypes","otherInterfaceTypes","selectedObjectTypes","selectedSharedPropertyTypes","$select","preview","data","objectFactory","$includeRid","OntologyObjectSets","loadMultipleObjectTypes","select","excludeRid","Promise","resolve","objectFactory2","interfaceToObjectTypeMappings","nextPageToken","totalCount","fetchPageInternal","fetchObjectPage","fetchPageWithErrorsInternal","e","error","fetchPage","fetchPageWithErrors","body","$nextPageToken","pageToken","$pageSize","pageSize","$orderBy","orderBy","fields","Object","entries","map","field","direction","r","load"],"sources":["fetchPage.ts"],"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 */\n\nimport type {\n Augment,\n Augments,\n FetchPageArgs,\n FetchPageResult,\n InterfaceDefinition,\n NullabilityAdherence,\n ObjectOrInterfaceDefinition,\n ObjectTypeDefinition,\n PropertyKeys,\n Result,\n} from \"@osdk/api\";\nimport type { PageSize, PageToken } from \"@osdk/foundry.core\";\nimport type {\n LoadObjectSetRequestV2,\n LoadObjectSetV2MultipleObjectTypesRequest,\n ObjectSet,\n OntologyObjectV2,\n SearchJsonQueryV2,\n SearchObjectsForInterfaceRequest,\n SearchOrderByV2,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport { extractRdpDefinition } from \"../util/extractRdpDefinition.js\";\nimport { resolveBaseObjectSetType } from \"../util/objectSetUtils.js\";\n\nexport function augment<\n Q extends ObjectOrInterfaceDefinition,\n T extends PropertyKeys<Q>,\n>(\n type: Q,\n ...properties: T[]\n): Augment<Q, T> {\n return { [type.apiName]: properties } as any;\n}\n\n/** @internal */\nexport function objectSetToSearchJsonV2(\n objectSet: ObjectSet,\n expectedApiName: string,\n existingWhere: SearchJsonQueryV2 | undefined = undefined,\n): SearchJsonQueryV2 | undefined {\n if (objectSet.type === \"base\" || objectSet.type === \"interfaceBase\") {\n if (objectSet.type === \"base\" && objectSet.objectType !== expectedApiName) {\n throw new Error(\n `Expected objectSet.objectType to be ${expectedApiName}, but got ${objectSet.objectType}`,\n );\n }\n if (\n objectSet.type === \"interfaceBase\"\n && objectSet.interfaceType !== expectedApiName\n ) {\n throw new Error(\n `Expected objectSet.objectType to be ${expectedApiName}, but got ${objectSet.interfaceType}`,\n );\n }\n\n return existingWhere;\n }\n\n if (objectSet.type === \"filter\") {\n return objectSetToSearchJsonV2(\n objectSet.objectSet,\n expectedApiName,\n existingWhere == null ? objectSet.where : {\n type: \"and\",\n value: [existingWhere, objectSet.where],\n },\n );\n }\n\n throw new Error(`Unsupported objectSet type: ${objectSet.type}`);\n}\n\n/** @internal */\nexport function resolveInterfaceObjectSet(\n objectSet: ObjectSet,\n interfaceTypeApiName: string,\n args: FetchPageArgs<any, any, any, any, any, any>,\n): ObjectSet {\n return args?.$includeAllBaseObjectProperties\n ? {\n type: \"intersect\",\n objectSets: [objectSet, {\n type: \"interfaceBase\",\n interfaceType: interfaceTypeApiName,\n includeAllBaseObjectProperties: true,\n }],\n }\n : objectSet;\n}\n\nasync function fetchInterfacePage<\n Q extends InterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n interfaceType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet,\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n if (args.$__UNSTABLE_useOldInterfaceApis) {\n const result = await OntologiesV2.OntologyInterfaces\n .search(\n addUserAgentAndRequestContextHeaders(client, interfaceType),\n await client.ontologyRid,\n interfaceType.apiName,\n applyFetchArgs<SearchObjectsForInterfaceRequest>(args, {\n augmentedProperties: {},\n augmentedSharedPropertyTypes: {},\n otherInterfaceTypes: [],\n selectedObjectTypes: [],\n selectedSharedPropertyTypes: args.$select as undefined | string[]\n ?? [],\n where: objectSetToSearchJsonV2(objectSet, interfaceType.apiName),\n }),\n { preview: true },\n );\n\n result.data = await client.objectFactory(\n client,\n result.data as OntologyObjectV2[], // drop readonly\n interfaceType.apiName,\n !args.$includeRid,\n await extractRdpDefinition(client, objectSet, interfaceType.apiName),\n );\n return result as any;\n }\n const result = await OntologiesV2.OntologyObjectSets.loadMultipleObjectTypes(\n addUserAgentAndRequestContextHeaders(client, interfaceType),\n await client.ontologyRid,\n applyFetchArgs<LoadObjectSetV2MultipleObjectTypesRequest>(args, {\n objectSet: resolveInterfaceObjectSet(\n objectSet,\n interfaceType.apiName,\n args,\n ),\n select: ((args?.$select as string[] | undefined) ?? []),\n excludeRid: !args?.$includeRid,\n }),\n { preview: true },\n );\n return Promise.resolve({\n data: await client.objectFactory2(\n client,\n result.data,\n interfaceType.apiName,\n {},\n !args.$includeRid,\n args.$select,\n false,\n result.interfaceToObjectTypeMappings,\n ),\n nextPageToken: result.nextPageToken,\n totalCount: result.totalCount,\n }) as unknown as Promise<FetchPageResult<Q, L, R, S, T>>;\n}\n\n/** @internal */\nexport async function fetchPageInternal<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n A extends Augments,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet,\n args: FetchPageArgs<Q, L, R, A, S, T> = {},\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n if (objectType.type === \"interface\") {\n return await fetchInterfacePage(\n client,\n objectType,\n args,\n objectSet,\n ) as any; // fixme\n } else {\n return await fetchObjectPage(\n client,\n objectType,\n args,\n objectSet,\n ) as any; // fixme\n }\n}\n\n/** @internal */\nexport async function fetchPageWithErrorsInternal<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n A extends Augments,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet,\n args: FetchPageArgs<Q, L, R, A, S, T> = {},\n): Promise<Result<FetchPageResult<Q, L, R, S, T>>> {\n try {\n const result = await fetchPageInternal(client, objectType, objectSet, args);\n return { value: result };\n } catch (e) {\n if (e instanceof Error) {\n return { error: e };\n }\n return { error: e as Error };\n }\n}\n\n/**\n * @param client\n * @param objectType\n * @param args\n * @param objectSet\n * @returns\n * @internal\n */\nexport async function fetchPage<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n return fetchPageInternal(client, objectType, objectSet, args);\n}\n\n/** @internal */\nexport async function fetchPageWithErrors<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n): Promise<Result<FetchPageResult<Q, L, R, S, T>>> {\n return fetchPageWithErrorsInternal(client, objectType, objectSet, args);\n}\n\nfunction applyFetchArgs<\n X extends {\n orderBy?: SearchOrderByV2;\n pageToken?: PageToken;\n pageSize?: PageSize;\n },\n>(\n args: FetchPageArgs<any, any, any, any, any, any>,\n body: X,\n): X {\n if (args?.$nextPageToken) {\n body.pageToken = args.$nextPageToken;\n }\n\n if (args?.$pageSize != null) {\n body.pageSize = args.$pageSize;\n }\n\n if (args?.$orderBy != null) {\n body.orderBy = {\n fields: Object.entries(args.$orderBy).map(([field, direction]) => ({\n field,\n direction,\n })),\n };\n }\n\n return body;\n}\n\n/** @internal */\nexport async function fetchObjectPage<\n Q extends ObjectTypeDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, Augments, S, T>,\n objectSet: ObjectSet,\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n const r = await OntologiesV2.OntologyObjectSets.load(\n addUserAgentAndRequestContextHeaders(client, objectType),\n await client.ontologyRid,\n applyFetchArgs<LoadObjectSetRequestV2>(args, {\n objectSet,\n // We have to do the following case because LoadObjectSetRequestV2 isn't readonly\n select: ((args?.$select as string[] | undefined) ?? []), // FIXME?\n excludeRid: !args?.$includeRid,\n }),\n );\n\n return Promise.resolve({\n data: await client.objectFactory(\n client,\n r.data as OntologyObjectV2[],\n undefined,\n undefined,\n await extractRdpDefinition(client, objectSet, objectType.apiName),\n args.$select,\n ),\n nextPageToken: r.nextPageToken,\n totalCount: r.totalCount,\n }) as unknown as Promise<FetchPageResult<Q, L, R, S, T>>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA,OAAO,KAAKA,YAAY,MAAM,0BAA0B;AAExD,SAASC,oCAAoC,QAAQ,iDAAiD;AACtG,SAASC,oBAAoB,QAAQ,iCAAiC;AACtE,SAASC,wBAAwB,QAAQ,2BAA2B;AAEpE,OAAO,SAASC,OAAOA,CAIrBC,IAAO,EACP,GAAGC,UAAe,EACH;EACf,OAAO;IAAE,CAACD,IAAI,CAACE,OAAO,GAAGD;EAAW,CAAC;AACvC;;AAEA;AACA,OAAO,SAASE,uBAAuBA,CACrCC,SAAoB,EACpBC,eAAuB,EACvBC,aAA4C,GAAGC,SAAS,EACzB;EAC/B,IAAIH,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AU,CAAC,EACxD,MAAMY,MAAM,CAACK,WAAW,EACxBC,cAAc,CAAyBX,IAAI,EAAE;IAC3CX,SAAS;IACT;IACAmC,MAAM,EAAIxB,IAAI,EAAEiB,OAAO,IAA6B,EAAG;IAAE;IACzDQ,UAAU,EAAE,CAACzB,IAAI,EAAEqB;EACrB,CAAC,CACH,CAAC;EAED,OAAOK,OAAO,CAACC,OAAO,CAAC;IACrBR,IAAI,EAAE,MAAMd,MAAM,CAACe,aAAa,CAC9Bf,MAAM,EACN+C,CAAC,CAACjC,IAAI,EACN3B,SAAS,EACTA,SAAS,EACT,MAAMV,oBAAoB,CAACuB,MAAM,EAAEhB,SAAS,EAAEI,UAAU,CAACN,OAAO,CAAC,EACjEa,IAAI,CAACiB,OACP,CAAC;IACDa,aAAa,EAAEsB,CAAC,CAACtB,aAAa;IAC9BC,UAAU,EAAEqB,CAAC,CAACrB;EAChB,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fetchPage.js","names":["OntologiesV2","addUserAgentAndRequestContextHeaders","extractRdpDefinition","resolveBaseObjectSetType","augment","type","properties","apiName","objectSetToSearchJsonV2","objectSet","expectedApiName","existingWhere","undefined","objectType","Error","interfaceType","where","value","resolveInterfaceObjectSet","interfaceTypeApiName","args","$includeAllBaseObjectProperties","objectSets","includeAllBaseObjectProperties","fetchInterfacePage","client","$__UNSTABLE_useOldInterfaceApis","result","OntologyInterfaces","search","ontologyRid","applyFetchArgs","augmentedProperties","augmentedSharedPropertyTypes","otherInterfaceTypes","selectedObjectTypes","selectedSharedPropertyTypes","$select","preview","data","objectFactory","$includeRid","OntologyObjectSets","loadMultipleObjectTypes","select","excludeRid","Promise","resolve","objectFactory2","interfaceToObjectTypeMappings","nextPageToken","totalCount","fetchPageInternal","fetchObjectPage","fetchPageWithErrorsInternal","e","error","fetchPage","fetchPageWithErrors","body","$nextPageToken","pageToken","$pageSize","pageSize","$orderBy","orderBy","fields","Object","entries","map","field","direction","r","load"],"sources":["fetchPage.ts"],"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 */\n\nimport type {\n Augment,\n Augments,\n FetchPageArgs,\n FetchPageResult,\n InterfaceDefinition,\n NullabilityAdherence,\n ObjectOrInterfaceDefinition,\n ObjectTypeDefinition,\n PropertyKeys,\n Result,\n} from \"@osdk/api\";\nimport type { PageSize, PageToken } from \"@osdk/foundry.core\";\nimport type {\n LoadObjectSetRequestV2,\n LoadObjectSetV2MultipleObjectTypesRequest,\n ObjectSet,\n OntologyObjectV2,\n SearchJsonQueryV2,\n SearchObjectsForInterfaceRequest,\n SearchOrderByV2,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport { extractRdpDefinition } from \"../util/extractRdpDefinition.js\";\nimport { resolveBaseObjectSetType } from \"../util/objectSetUtils.js\";\n\nexport function augment<\n Q extends ObjectOrInterfaceDefinition,\n T extends PropertyKeys<Q>,\n>(\n type: Q,\n ...properties: T[]\n): Augment<Q, T> {\n return { [type.apiName]: properties } as any;\n}\n\n/** @internal */\nexport function objectSetToSearchJsonV2(\n objectSet: ObjectSet,\n expectedApiName: string,\n existingWhere: SearchJsonQueryV2 | undefined = undefined,\n): SearchJsonQueryV2 | undefined {\n if (objectSet.type === \"base\" || objectSet.type === \"interfaceBase\") {\n if (objectSet.type === \"base\" && objectSet.objectType !== expectedApiName) {\n throw new Error(\n `Expected objectSet.objectType to be ${expectedApiName}, but got ${objectSet.objectType}`,\n );\n }\n if (\n objectSet.type === \"interfaceBase\"\n && objectSet.interfaceType !== expectedApiName\n ) {\n throw new Error(\n `Expected objectSet.objectType to be ${expectedApiName}, but got ${objectSet.interfaceType}`,\n );\n }\n\n return existingWhere;\n }\n\n if (objectSet.type === \"filter\") {\n return objectSetToSearchJsonV2(\n objectSet.objectSet,\n expectedApiName,\n existingWhere == null ? objectSet.where : {\n type: \"and\",\n value: [existingWhere, objectSet.where],\n },\n );\n }\n\n throw new Error(`Unsupported objectSet type: ${objectSet.type}`);\n}\n\n/** @internal */\nexport function resolveInterfaceObjectSet(\n objectSet: ObjectSet,\n interfaceTypeApiName: string,\n args: FetchPageArgs<any, any, any, any, any, any>,\n): ObjectSet {\n return args?.$includeAllBaseObjectProperties\n ? {\n type: \"intersect\",\n objectSets: [objectSet, {\n type: \"interfaceBase\",\n interfaceType: interfaceTypeApiName,\n includeAllBaseObjectProperties: true,\n }],\n }\n : objectSet;\n}\n\nasync function fetchInterfacePage<\n Q extends InterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n interfaceType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet,\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n if (args.$__UNSTABLE_useOldInterfaceApis) {\n const result = await OntologiesV2.OntologyInterfaces\n .search(\n addUserAgentAndRequestContextHeaders(client, interfaceType),\n await client.ontologyRid,\n interfaceType.apiName,\n applyFetchArgs<SearchObjectsForInterfaceRequest>(args, {\n augmentedProperties: {},\n augmentedSharedPropertyTypes: {},\n otherInterfaceTypes: [],\n selectedObjectTypes: [],\n selectedSharedPropertyTypes: args.$select as undefined | string[]\n ?? [],\n where: objectSetToSearchJsonV2(objectSet, interfaceType.apiName),\n }),\n { preview: true },\n );\n\n result.data = await client.objectFactory(\n client,\n result.data as OntologyObjectV2[], // drop readonly\n interfaceType.apiName,\n !args.$includeRid,\n await extractRdpDefinition(client, objectSet),\n );\n return result as any;\n }\n const result = await OntologiesV2.OntologyObjectSets.loadMultipleObjectTypes(\n addUserAgentAndRequestContextHeaders(client, interfaceType),\n await client.ontologyRid,\n applyFetchArgs<LoadObjectSetV2MultipleObjectTypesRequest>(args, {\n objectSet: resolveInterfaceObjectSet(\n objectSet,\n interfaceType.apiName,\n args,\n ),\n select: ((args?.$select as string[] | undefined) ?? []),\n excludeRid: !args?.$includeRid,\n }),\n { preview: true },\n );\n return Promise.resolve({\n data: await client.objectFactory2(\n client,\n result.data,\n interfaceType.apiName,\n {},\n !args.$includeRid,\n args.$select,\n false,\n result.interfaceToObjectTypeMappings,\n ),\n nextPageToken: result.nextPageToken,\n totalCount: result.totalCount,\n }) as unknown as Promise<FetchPageResult<Q, L, R, S, T>>;\n}\n\n/** @internal */\nexport async function fetchPageInternal<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n A extends Augments,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet,\n args: FetchPageArgs<Q, L, R, A, S, T> = {},\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n if (objectType.type === \"interface\") {\n return await fetchInterfacePage(\n client,\n objectType,\n args,\n objectSet,\n ) as any; // fixme\n } else {\n return await fetchObjectPage(\n client,\n objectType,\n args,\n objectSet,\n ) as any; // fixme\n }\n}\n\n/** @internal */\nexport async function fetchPageWithErrorsInternal<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n A extends Augments,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet,\n args: FetchPageArgs<Q, L, R, A, S, T> = {},\n): Promise<Result<FetchPageResult<Q, L, R, S, T>>> {\n try {\n const result = await fetchPageInternal(client, objectType, objectSet, args);\n return { value: result };\n } catch (e) {\n if (e instanceof Error) {\n return { error: e };\n }\n return { error: e as Error };\n }\n}\n\n/**\n * @param client\n * @param objectType\n * @param args\n * @param objectSet\n * @returns\n * @internal\n */\nexport async function fetchPage<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n return fetchPageInternal(client, objectType, objectSet, args);\n}\n\n/** @internal */\nexport async function fetchPageWithErrors<\n Q extends ObjectOrInterfaceDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, any, S, T>,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n): Promise<Result<FetchPageResult<Q, L, R, S, T>>> {\n return fetchPageWithErrorsInternal(client, objectType, objectSet, args);\n}\n\nfunction applyFetchArgs<\n X extends {\n orderBy?: SearchOrderByV2;\n pageToken?: PageToken;\n pageSize?: PageSize;\n },\n>(\n args: FetchPageArgs<any, any, any, any, any, any>,\n body: X,\n): X {\n if (args?.$nextPageToken) {\n body.pageToken = args.$nextPageToken;\n }\n\n if (args?.$pageSize != null) {\n body.pageSize = args.$pageSize;\n }\n\n if (args?.$orderBy != null) {\n body.orderBy = {\n fields: Object.entries(args.$orderBy).map(([field, direction]) => ({\n field,\n direction,\n })),\n };\n }\n\n return body;\n}\n\n/** @internal */\nexport async function fetchObjectPage<\n Q extends ObjectTypeDefinition,\n L extends PropertyKeys<Q>,\n R extends boolean,\n S extends NullabilityAdherence,\n T extends boolean,\n>(\n client: MinimalClient,\n objectType: Q,\n args: FetchPageArgs<Q, L, R, Augments, S, T>,\n objectSet: ObjectSet,\n): Promise<FetchPageResult<Q, L, R, S, T>> {\n const r = await OntologiesV2.OntologyObjectSets.load(\n addUserAgentAndRequestContextHeaders(client, objectType),\n await client.ontologyRid,\n applyFetchArgs<LoadObjectSetRequestV2>(args, {\n objectSet,\n // We have to do the following case because LoadObjectSetRequestV2 isn't readonly\n select: ((args?.$select as string[] | undefined) ?? []), // FIXME?\n excludeRid: !args?.$includeRid,\n }),\n );\n\n return Promise.resolve({\n data: await client.objectFactory(\n client,\n r.data as OntologyObjectV2[],\n undefined,\n undefined,\n await extractRdpDefinition(client, objectSet),\n args.$select,\n ),\n nextPageToken: r.nextPageToken,\n totalCount: r.totalCount,\n }) as unknown as Promise<FetchPageResult<Q, L, R, S, T>>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA,OAAO,KAAKA,YAAY,MAAM,0BAA0B;AAExD,SAASC,oCAAoC,QAAQ,iDAAiD;AACtG,SAASC,oBAAoB,QAAQ,iCAAiC;AACtE,SAASC,wBAAwB,QAAQ,2BAA2B;AAEpE,OAAO,SAASC,OAAOA,CAIrBC,IAAO,EACP,GAAGC,UAAe,EACH;EACf,OAAO;IAAE,CAACD,IAAI,CAACE,OAAO,GAAGD;EAAW,CAAC;AACvC;;AAEA;AACA,OAAO,SAASE,uBAAuBA,CACrCC,SAAoB,EACpBC,eAAuB,EACvBC,aAA4C,GAAGC,SAAS,EACzB;EAC/B,IAAIH,SAAS,CAACJ,IAAI,KAAK,MAAM,IAAII,SAAS,CAACJ,IAAI,KAAK,eAAe,EAAE;IACnE,IAAII,SAAS,CAACJ,IAAI,KAAK,MAAM,IAAII,SAAS,CAACI,UAAU,KAAKH,eAAe,EAAE;MACzE,MAAM,IAAII,KAAK,CACb,uCAAuCJ,eAAe,aAAaD,SAAS,CAACI,UAAU,EACzF,CAAC;IACH;IACA,IACEJ,SAAS,CAACJ,IAAI,KAAK,eAAe,IAC/BI,SAAS,CAACM,aAAa,KAAKL,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SAAS,EACTA,SAAS,EACT,MAAMV,oBAAoB,CAACuB,MAAM,EAAEhB,SAAS,CAAC,EAC7CW,IAAI,CAACiB,OACP,CAAC;IACDa,aAAa,EAAEsB,CAAC,CAACtB,aAAa;IAC9BC,UAAU,EAAEqB,CAAC,CAACrB;EAChB,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -21,7 +21,6 @@ export async function loadFullObjectMetadata(client, objectType) {
|
|
|
21
21
|
preview: true
|
|
22
22
|
});
|
|
23
23
|
const ret = wireObjectTypeFullMetadataToSdkObjectMetadata(full, true);
|
|
24
|
-
client.logger?.debug(`END loadFullObjectMetadata(${objectType})`);
|
|
25
24
|
return {
|
|
26
25
|
...ret
|
|
27
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadFullObjectMetadata.js","names":["OntologiesV2","wireObjectTypeFullMetadataToSdkObjectMetadata","loadFullObjectMetadata","client","objectType","full","ObjectTypesV2","getFullMetadata","ontologyRid","preview","ret"
|
|
1
|
+
{"version":3,"file":"loadFullObjectMetadata.js","names":["OntologiesV2","wireObjectTypeFullMetadataToSdkObjectMetadata","loadFullObjectMetadata","client","objectType","full","ObjectTypesV2","getFullMetadata","ontologyRid","preview","ret"],"sources":["loadFullObjectMetadata.ts"],"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 */\n\nimport type { ObjectMetadata } from \"@osdk/api\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport { wireObjectTypeFullMetadataToSdkObjectMetadata } from \"@osdk/generator-converters\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\n\nexport async function loadFullObjectMetadata(\n client: MinimalClient,\n objectType: string,\n): Promise<ObjectMetadata & { rid: string }> {\n const full = await OntologiesV2.ObjectTypesV2.getFullMetadata(\n client,\n await client.ontologyRid,\n objectType,\n { preview: true },\n );\n const ret = wireObjectTypeFullMetadataToSdkObjectMetadata(full, true);\n return { ...ret };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAO,KAAKA,YAAY,MAAM,0BAA0B;AACxD,SAASC,6CAA6C,QAAQ,4BAA4B;AAG1F,OAAO,eAAeC,sBAAsBA,CAC1CC,MAAqB,EACrBC,UAAkB,EACyB;EAC3C,MAAMC,IAAI,GAAG,MAAML,YAAY,CAACM,aAAa,CAACC,eAAe,CAC3DJ,MAAM,EACN,MAAMA,MAAM,CAACK,WAAW,EACxBJ,UAAU,EACV;IAAEK,OAAO,EAAE;EAAK,CAClB,CAAC;EACD,MAAMC,GAAG,GAAGT,6CAA6C,CAACI,IAAI,EAAE,IAAI,CAAC;EACrE,OAAO;IAAE,GAAGK;EAAI,CAAC;AACnB","ignoreList":[]}
|
|
@@ -17,4 +17,6 @@
|
|
|
17
17
|
export { createAndFetchTempObjectSetRid } from "../public-utils/createAndFetchTempObjectSetRid.js";
|
|
18
18
|
export { hydrateAttachmentFromRid } from "../public-utils/hydrateAttachmentFromRid.js";
|
|
19
19
|
export { hydrateObjectSetFromRid } from "../public-utils/hydrateObjectSetFromRid.js";
|
|
20
|
+
export { BrowserLogger } from "../logger/BrowserLogger.js";
|
|
21
|
+
export { MinimalLogger } from "../logger/MinimalLogger.js";
|
|
20
22
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","names":["createAndFetchTempObjectSetRid","hydrateAttachmentFromRid","hydrateObjectSetFromRid"],"sources":["internal.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { createAndFetchTempObjectSetRid } from \"../public-utils/createAndFetchTempObjectSetRid.js\";\nexport { hydrateAttachmentFromRid } from \"../public-utils/hydrateAttachmentFromRid.js\";\nexport { hydrateObjectSetFromRid } from \"../public-utils/hydrateObjectSetFromRid.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,8BAA8B,QAAQ,mDAAmD;AAClG,SAASC,wBAAwB,QAAQ,6CAA6C;AACtF,SAASC,uBAAuB,QAAQ,4CAA4C","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"internal.js","names":["createAndFetchTempObjectSetRid","hydrateAttachmentFromRid","hydrateObjectSetFromRid","BrowserLogger","MinimalLogger"],"sources":["internal.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { createAndFetchTempObjectSetRid } from \"../public-utils/createAndFetchTempObjectSetRid.js\";\nexport { hydrateAttachmentFromRid } from \"../public-utils/hydrateAttachmentFromRid.js\";\nexport { hydrateObjectSetFromRid } from \"../public-utils/hydrateObjectSetFromRid.js\";\n\nexport { BrowserLogger } from \"../logger/BrowserLogger.js\";\nexport { MinimalLogger } from \"../logger/MinimalLogger.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,8BAA8B,QAAQ,mDAAmD;AAClG,SAASC,wBAAwB,QAAQ,6CAA6C;AACtF,SAASC,uBAAuB,QAAQ,4CAA4C;AAEpF,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,aAAa,QAAQ,4BAA4B","ignoreList":[]}
|
|
@@ -15,31 +15,46 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import invariant from "tiny-invariant";
|
|
18
|
-
export async function extractRdpDefinition(clientCtx, objectSet
|
|
19
|
-
return (await extractRdpDefinitionInternal(clientCtx, objectSet,
|
|
18
|
+
export async function extractRdpDefinition(clientCtx, objectSet) {
|
|
19
|
+
return (await extractRdpDefinitionInternal(clientCtx, objectSet, undefined)).definitions;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/* @internal
|
|
23
23
|
* Returns a tuple of the derived property definitions and the object type that the derived property is defined on.
|
|
24
24
|
*/
|
|
25
25
|
async function extractRdpDefinitionInternal(clientCtx, objectSet, methodInputObjectType) {
|
|
26
|
-
const result = {};
|
|
27
26
|
switch (objectSet.type) {
|
|
28
27
|
case "searchAround":
|
|
29
28
|
{
|
|
30
|
-
const
|
|
29
|
+
const {
|
|
30
|
+
definitions,
|
|
31
|
+
childObjectType
|
|
32
|
+
} = await extractRdpDefinitionInternal(clientCtx, objectSet.objectSet, methodInputObjectType);
|
|
33
|
+
if (childObjectType === undefined || childObjectType === "") {
|
|
34
|
+
return {
|
|
35
|
+
definitions: {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
31
38
|
const objDef = await clientCtx.ontologyProvider.getObjectDefinition(childObjectType);
|
|
32
39
|
const linkDef = objDef.links[objectSet.link];
|
|
33
40
|
!linkDef ? process.env.NODE_ENV !== "production" ? invariant(false, `Missing link definition for '${objectSet.link}'`) : invariant(false) : void 0;
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
41
|
+
return {
|
|
42
|
+
definitions,
|
|
43
|
+
childObjectType: objDef.links[objectSet.link].targetType
|
|
44
|
+
};
|
|
38
45
|
}
|
|
39
46
|
case "withProperties":
|
|
40
47
|
{
|
|
41
48
|
// These are the definitions and current object type for all object set operations prior to the definition (e.g. filter, pivotTo, etc.)
|
|
42
|
-
const
|
|
49
|
+
const {
|
|
50
|
+
definitions,
|
|
51
|
+
childObjectType
|
|
52
|
+
} = await extractRdpDefinitionInternal(clientCtx, objectSet.objectSet, methodInputObjectType);
|
|
53
|
+
if (childObjectType === undefined || childObjectType === "") {
|
|
54
|
+
return {
|
|
55
|
+
definitions: {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
43
58
|
for (const [name, definition] of Object.entries(objectSet.derivedProperties)) {
|
|
44
59
|
if (definition.type !== "selection") {
|
|
45
60
|
continue;
|
|
@@ -49,24 +64,40 @@ async function extractRdpDefinitionInternal(clientCtx, objectSet, methodInputObj
|
|
|
49
64
|
case "collectSet":
|
|
50
65
|
case "get":
|
|
51
66
|
// This is the object set construction for the derived property definition construction. We pass in childObjectType so that when we reach MethodInputObjectSet, we know where to start looking.
|
|
52
|
-
const
|
|
67
|
+
const {
|
|
68
|
+
childObjectType: operationLevelObjectType
|
|
69
|
+
} = await extractRdpDefinitionInternal(clientCtx, definition.objectSet, childObjectType);
|
|
70
|
+
if (operationLevelObjectType === undefined || operationLevelObjectType === "") {
|
|
71
|
+
return {
|
|
72
|
+
definitions: {}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
53
75
|
const objDef = await clientCtx.ontologyProvider.getObjectDefinition(operationLevelObjectType);
|
|
54
|
-
|
|
76
|
+
definitions[name] = objDef.properties[definition.operation.selectedPropertyApiName];
|
|
55
77
|
default:
|
|
56
78
|
continue;
|
|
57
79
|
}
|
|
58
80
|
}
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
81
|
+
return {
|
|
82
|
+
definitions,
|
|
83
|
+
childObjectType
|
|
84
|
+
};
|
|
63
85
|
}
|
|
64
86
|
case "methodInput":
|
|
65
|
-
return
|
|
87
|
+
return {
|
|
88
|
+
definitions: {},
|
|
89
|
+
childObjectType: methodInputObjectType
|
|
90
|
+
};
|
|
66
91
|
case "base":
|
|
67
|
-
return
|
|
92
|
+
return {
|
|
93
|
+
definitions: {},
|
|
94
|
+
childObjectType: objectSet.objectType
|
|
95
|
+
};
|
|
68
96
|
case "interfaceBase":
|
|
69
|
-
return
|
|
97
|
+
return {
|
|
98
|
+
definitions: {},
|
|
99
|
+
childObjectType: objectSet.interfaceType
|
|
100
|
+
};
|
|
70
101
|
case "filter":
|
|
71
102
|
case "asBaseObjectTypes":
|
|
72
103
|
case "asType":
|
|
@@ -74,12 +105,34 @@ async function extractRdpDefinitionInternal(clientCtx, objectSet, methodInputObj
|
|
|
74
105
|
return extractRdpDefinitionInternal(clientCtx, objectSet.objectSet, methodInputObjectType);
|
|
75
106
|
// These will throw in OSS so we should throw here so no request is made
|
|
76
107
|
case "intersect":
|
|
77
|
-
case "static":
|
|
78
108
|
case "subtract":
|
|
79
109
|
case "union":
|
|
110
|
+
const objectSets = objectSet.objectSets;
|
|
111
|
+
const objectSetTypes = await Promise.all(objectSets.map(os => extractRdpDefinitionInternal(clientCtx, os, methodInputObjectType)));
|
|
112
|
+
const definitions = objectSetTypes.reduce((acc, {
|
|
113
|
+
definitions
|
|
114
|
+
}) => ({
|
|
115
|
+
...acc,
|
|
116
|
+
...definitions
|
|
117
|
+
}), {});
|
|
118
|
+
!(Object.keys(definitions).length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "Object sets combined using intersect, subtract, or union must not contain any derived property definitions") : invariant(false) : void 0;
|
|
119
|
+
const firstValidChildObjectType = objectSetTypes.find(({
|
|
120
|
+
childObjectType
|
|
121
|
+
}) => childObjectType != null)?.childObjectType;
|
|
122
|
+
!objectSetTypes.every(({
|
|
123
|
+
childObjectType
|
|
124
|
+
}) => childObjectType === firstValidChildObjectType || childObjectType == null) ? process.env.NODE_ENV !== "production" ? invariant(false, "All object sets in an intersect, subtract, or union must have the same child object type") : invariant(false) : void 0;
|
|
125
|
+
return {
|
|
126
|
+
definitions: {},
|
|
127
|
+
childObjectType: firstValidChildObjectType
|
|
128
|
+
};
|
|
129
|
+
case "static":
|
|
80
130
|
case "reference":
|
|
81
|
-
|
|
82
|
-
|
|
131
|
+
// Static and reference object sets are always intersected with a base object set, so we can just return no child object type.
|
|
132
|
+
return {
|
|
133
|
+
definitions: {}
|
|
134
|
+
};
|
|
135
|
+
// We don't have to worry about new object sets being added and doing a runtime break and breaking people since the OSDK is always constructing these.
|
|
83
136
|
default:
|
|
84
137
|
process.env.NODE_ENV !== "production" ? invariant(false, `Unsupported object set type for Runtime Derived Properties`) : invariant(false);
|
|
85
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractRdpDefinition.js","names":["invariant","extractRdpDefinition","clientCtx","objectSet","methodInputObjectType","extractRdpDefinitionInternal","result","type","definitions","childObjectType","objDef","ontologyProvider","getObjectDefinition","linkDef","links","link","process","env","NODE_ENV","targetType","name","definition","Object","entries","derivedProperties","operation","_","operationLevelObjectType","properties","selectedPropertyApiName","objectType","interfaceType"],"sources":["extractRdpDefinition.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectMetadata } from \"@osdk/api\";\nimport type { ObjectSet } from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\n\nexport async function extractRdpDefinition(\n clientCtx: MinimalClient,\n objectSet: ObjectSet,\n methodInputObjectType: string,\n): Promise<\n Record<string, ObjectMetadata.Property>\n> {\n return (await extractRdpDefinitionInternal(\n clientCtx,\n objectSet,\n methodInputObjectType,\n ))[0];\n}\n\n/* @internal\n* Returns a tuple of the derived property definitions and the object type that the derived property is defined on.\n*/\nasync function extractRdpDefinitionInternal(\n clientCtx: MinimalClient,\n objectSet: ObjectSet,\n methodInputObjectType: string,\n): Promise<\n [Record<string, ObjectMetadata.Property>, string]\n> {\n const result: Record<string, ObjectMetadata.Property> = {};\n\n switch (objectSet.type) {\n case \"searchAround\": {\n const [definitions, childObjectType] = await extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n const objDef = await clientCtx.ontologyProvider.getObjectDefinition(\n childObjectType,\n );\n const linkDef = objDef.links[objectSet.link];\n invariant(linkDef, `Missing link definition for '${objectSet.link}'`);\n return [\n { ...result, ...definitions },\n objDef.links[objectSet.link].targetType,\n ];\n }\n case \"withProperties\": {\n // These are the definitions and current object type for all object set operations prior to the definition (e.g. filter, pivotTo, etc.)\n const [definitions, childObjectType] = await extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n\n for (\n const [name, definition] of Object.entries(objectSet.derivedProperties)\n ) {\n if (definition.type !== \"selection\") {\n continue;\n }\n\n switch (definition.operation.type) {\n case \"collectList\":\n case \"collectSet\":\n case \"get\":\n // This is the object set construction for the derived property definition construction. We pass in childObjectType so that when we reach MethodInputObjectSet, we know where to start looking.\n const [_, operationLevelObjectType] =\n await extractRdpDefinitionInternal(\n clientCtx,\n definition.objectSet,\n childObjectType,\n );\n const objDef = await clientCtx.ontologyProvider.getObjectDefinition(\n operationLevelObjectType,\n );\n\n result[name] =\n objDef.properties[definition.operation.selectedPropertyApiName];\n\n default:\n continue;\n }\n }\n return [{ ...result, ...definitions }, childObjectType];\n }\n case \"methodInput\":\n return [{}, methodInputObjectType];\n case \"base\":\n return [{}, objectSet.objectType];\n case \"interfaceBase\":\n return [{}, objectSet.interfaceType];\n case \"filter\":\n case \"asBaseObjectTypes\":\n case \"asType\":\n case \"nearestNeighbors\":\n return extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n // These will throw in OSS so we should throw here so no request is made\n case \"intersect\":\n case \"static\":\n case \"subtract\":\n case \"union\":\n case \"reference\":\n return [{}, \"\"];\n // We don't have to worry about new object sets being added and breaking people since the OSDK is always constructing these.\n default:\n const _: never = objectSet;\n invariant(\n false,\n `Unsupported object set type for Runtime Derived Properties`,\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,SAAS,MAAM,gBAAgB;AAGtC,OAAO,eAAeC,oBAAoBA,CACxCC,SAAwB,EACxBC,SAAoB,EACpBC,qBAA6B,EAG7B;EACA,OAAO,CAAC,MAAMC,4BAA4B,CACxCH,SAAS,EACTC,SAAS,EACTC,qBACF,CAAC,EAAE,CAAC,CAAC;AACP;;AAEA;AACA;AACA;AACA,eAAeC,4BAA4BA,CACzCH,SAAwB,EACxBC,SAAoB,EACpBC,qBAA6B,EAG7B;EACA,MAAME,MAA+C,GAAG,CAAC,CAAC;EAE1D,QAAQH,SAAS,CAACI,IAAI;IACpB,KAAK,cAAc;MAAE;QACnB,MAAM,CAACC,WAAW,EAAEC,eAAe,CAAC,GAAG,MAAMJ,4BAA4B,CACvEH,SAAS,EACTC,SAAS,CAACA,SAAS,EACnBC,qBACF,CAAC;QACD,MAAMM,MAAM,GAAG,MAAMR,SAAS,CAACS,gBAAgB,CAACC,mBAAmB,C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MAChB,OAAO,CAAC,CAAC,CAAC,EAAEL,qBAAqB,CAAC;IACpC,KAAK,MAAM;MACT,OAAO,CAAC,CAAC,CAAC,EAAED,SAAS,CAAC2B,UAAU,CAAC;IACnC,KAAK,eAAe;MAClB,OAAO,CAAC,CAAC,CAAC,EAAE3B,SAAS,CAAC4B,aAAa,CAAC;IACtC,KAAK,QAAQ;IACb,KAAK,mBAAmB;IACxB,KAAK,QAAQ;IACb,KAAK,kBAAkB;MACrB,OAAO1B,4BAA4B,CACjCH,SAAS,EACTC,SAAS,CAACA,SAAS,EACnBC,qBACF,CAAC;IACH;IACA,KAAK,WAAW;IAChB,KAAK,QAAQ;IACb,KAAK,UAAU;IACf,KAAK,OAAO;IACZ,KAAK,WAAW;MACd,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACjB;IACA;MAEEY,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAAlB,SAAS,QAEP,4DAA4D,IAF9DA,SAAS;EAIb;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"extractRdpDefinition.js","names":["invariant","extractRdpDefinition","clientCtx","objectSet","extractRdpDefinitionInternal","undefined","definitions","methodInputObjectType","type","childObjectType","objDef","ontologyProvider","getObjectDefinition","linkDef","links","link","process","env","NODE_ENV","targetType","name","definition","Object","entries","derivedProperties","operation","operationLevelObjectType","properties","selectedPropertyApiName","objectType","interfaceType","objectSets","objectSetTypes","Promise","all","map","os","reduce","acc","keys","length","firstValidChildObjectType","find","every"],"sources":["extractRdpDefinition.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectMetadata } from \"@osdk/api\";\nimport type { ObjectSet } from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\n\nexport async function extractRdpDefinition(\n clientCtx: MinimalClient,\n objectSet: ObjectSet,\n): Promise<\n Record<string, ObjectMetadata.Property>\n> {\n return (await extractRdpDefinitionInternal(\n clientCtx,\n objectSet,\n undefined,\n )).definitions;\n}\n\n/* @internal\n* Returns a tuple of the derived property definitions and the object type that the derived property is defined on.\n*/\nasync function extractRdpDefinitionInternal(\n clientCtx: MinimalClient,\n objectSet: ObjectSet,\n methodInputObjectType: string | undefined,\n): Promise<\n {\n definitions: Record<string, ObjectMetadata.Property>;\n childObjectType?: string;\n }\n> {\n switch (objectSet.type) {\n case \"searchAround\": {\n const { definitions, childObjectType } =\n await extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n\n if (childObjectType === undefined || childObjectType === \"\") {\n return { definitions: {} };\n }\n const objDef = await clientCtx.ontologyProvider.getObjectDefinition(\n childObjectType,\n );\n const linkDef = objDef.links[objectSet.link];\n invariant(linkDef, `Missing link definition for '${objectSet.link}'`);\n return {\n definitions,\n childObjectType: objDef.links[objectSet.link].targetType,\n };\n }\n case \"withProperties\": {\n // These are the definitions and current object type for all object set operations prior to the definition (e.g. filter, pivotTo, etc.)\n const { definitions, childObjectType } =\n await extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n if (childObjectType === undefined || childObjectType === \"\") {\n return { definitions: {} };\n }\n\n for (\n const [name, definition] of Object.entries(objectSet.derivedProperties)\n ) {\n if (definition.type !== \"selection\") {\n continue;\n }\n\n switch (definition.operation.type) {\n case \"collectList\":\n case \"collectSet\":\n case \"get\":\n // This is the object set construction for the derived property definition construction. We pass in childObjectType so that when we reach MethodInputObjectSet, we know where to start looking.\n const { childObjectType: operationLevelObjectType } =\n await extractRdpDefinitionInternal(\n clientCtx,\n definition.objectSet,\n childObjectType,\n );\n if (\n operationLevelObjectType === undefined\n || operationLevelObjectType === \"\"\n ) {\n return { definitions: {} };\n }\n const objDef = await clientCtx.ontologyProvider.getObjectDefinition(\n operationLevelObjectType,\n );\n\n definitions[name] =\n objDef.properties[definition.operation.selectedPropertyApiName];\n\n default:\n continue;\n }\n }\n return { definitions, childObjectType };\n }\n case \"methodInput\":\n return { definitions: {}, childObjectType: methodInputObjectType };\n case \"base\":\n return { definitions: {}, childObjectType: objectSet.objectType };\n case \"interfaceBase\":\n return { definitions: {}, childObjectType: objectSet.interfaceType };\n case \"filter\":\n case \"asBaseObjectTypes\":\n case \"asType\":\n case \"nearestNeighbors\":\n return extractRdpDefinitionInternal(\n clientCtx,\n objectSet.objectSet,\n methodInputObjectType,\n );\n // These will throw in OSS so we should throw here so no request is made\n case \"intersect\":\n case \"subtract\":\n case \"union\":\n const objectSets = objectSet.objectSets;\n const objectSetTypes = await Promise.all(\n objectSets.map((os) =>\n extractRdpDefinitionInternal(\n clientCtx,\n os,\n methodInputObjectType,\n )\n ),\n );\n\n const definitions = objectSetTypes.reduce(\n (acc, { definitions }) => ({ ...acc, ...definitions }),\n {},\n );\n invariant(\n Object.keys(definitions).length === 0,\n \"Object sets combined using intersect, subtract, or union must not contain any derived property definitions\",\n );\n\n const firstValidChildObjectType = objectSetTypes.find(\n ({ childObjectType }) => childObjectType != null,\n )?.childObjectType;\n invariant(\n objectSetTypes.every(\n ({ childObjectType }) =>\n childObjectType === firstValidChildObjectType\n || childObjectType == null,\n ),\n \"All object sets in an intersect, subtract, or union must have the same child object type\",\n );\n\n return {\n definitions: {},\n childObjectType: firstValidChildObjectType,\n };\n case \"static\":\n case \"reference\":\n // Static and reference object sets are always intersected with a base object set, so we can just return no child object type.\n return { definitions: {} };\n // We don't have to worry about new object sets being added and doing a runtime break and breaking people since the OSDK is always constructing these.\n default:\n const _: never = objectSet;\n invariant(\n false,\n `Unsupported object set type for Runtime Derived Properties`,\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,SAAS,MAAM,gBAAgB;AAGtC,OAAO,eAAeC,oBAAoBA,CACxCC,SAAwB,EACxBC,SAAoB,EAGpB;EACA,OAAO,CAAC,MAAMC,4BAA4B,CACxCF,SAAS,EACTC,SAAS,EACTE,SACF,CAAC,EAAEC,WAAW;AAChB;;AAEA;AACA;AACA;AACA,eAAeF,4BAA4BA,CACzCF,SAAwB,EACxBC,SAAoB,EACpBI,qBAAyC,EAMzC;EACA,QAAQJ,SAAS,CAACK,IAAI;IACpB,KAAK,cAAc;MAAE;QACnB,MAAM;UAAEF,WAAW;UAAEG;QAAgB,CAAC,GACpC,MAAML,4BAA4B,CAChCF,SAAS,EACTC,SAAS,CAACA,SAAS,EACnBI,qBACF,CAAC;QAEH,IAAIE,eAAe,KAAKJ,SAAS,IAAII,eAAe,KAAK,EAAE,EAAE;UAC3D,OAAO;YAAEH,WAAW,EAAE,CAAC;UAAE,CAAC;QAC5B;QACA,MAAMI,MAAM,GAAG,MAAMR,SAAS,CAACS,gBAAgB,CAACC,mBAAmB,CACjEH,eACF,CAAC;QACD,MAAMI,OAAO,GAAGH,MAAM,CAACI,KAAK,CAACX,SAAS,CAACY,IAAI,CAAC;QAC5C,CAAUF,OAAO,GAAAG,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAjBlB,SAAS,QAAU,gCAAgCG,SAAS,CAACY,IAAI,GAAG,IAApEf,SAAS;QACT,OAAO;UACLM,WAAW;UACXG,eAAe,EAAEC,MAAM,CAACI,KAAK,CAACX,SAAS,CAACY,IAAI,CAAC,CAACI;QAChD,CAAC;MACH;IACA,KAAK,gBAAgB;MAAE;QACrB;QACA,MAAM;UAAEb,WAAW;UAAEG;QAAgB,CAAC,GACpC,MAAML,4BAA4B,CAChCF,SAAS,EACTC,SAAS,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