@osdk/client 2.1.0-rc.32 → 2.2.0-beta.1

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/build/browser/derivedProperties/createWithPropertiesObjectSet.js +106 -0
  3. package/build/browser/derivedProperties/createWithPropertiesObjectSet.js.map +1 -0
  4. package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js +100 -0
  5. package/build/browser/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -0
  6. package/build/browser/objectSet/ObjectSet.test.js +226 -0
  7. package/build/browser/objectSet/ObjectSet.test.js.map +1 -1
  8. package/build/browser/objectSet/createObjectSet.js +16 -0
  9. package/build/browser/objectSet/createObjectSet.js.map +1 -1
  10. package/build/browser/util/UserAgent.js +1 -1
  11. package/build/browser/util/UserAgent.js.map +1 -1
  12. package/build/cjs/{chunk-65QQ6SME.cjs → chunk-ACX536BS.cjs} +118 -16
  13. package/build/cjs/chunk-ACX536BS.cjs.map +1 -0
  14. package/build/cjs/index.cjs +22 -22
  15. package/build/cjs/index.cjs.map +1 -1
  16. package/build/cjs/public/internal.cjs +4 -4
  17. package/build/esm/derivedProperties/createWithPropertiesObjectSet.js +106 -0
  18. package/build/esm/derivedProperties/createWithPropertiesObjectSet.js.map +1 -0
  19. package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js +100 -0
  20. package/build/esm/derivedProperties/createWithPropertiesObjectSet.test.js.map +1 -0
  21. package/build/esm/objectSet/ObjectSet.test.js +226 -0
  22. package/build/esm/objectSet/ObjectSet.test.js.map +1 -1
  23. package/build/esm/objectSet/createObjectSet.js +16 -0
  24. package/build/esm/objectSet/createObjectSet.js.map +1 -1
  25. package/build/esm/util/UserAgent.js +1 -1
  26. package/build/esm/util/UserAgent.js.map +1 -1
  27. package/build/types/derivedProperties/createWithPropertiesObjectSet.d.ts +1 -0
  28. package/build/types/derivedProperties/createWithPropertiesObjectSet.d.ts.map +1 -0
  29. package/build/types/derivedProperties/createWithPropertiesObjectSet.test.d.ts +1 -0
  30. package/build/types/derivedProperties/createWithPropertiesObjectSet.test.d.ts.map +1 -0
  31. package/package.json +11 -11
  32. package/build/cjs/chunk-65QQ6SME.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,15 +1,5 @@
1
1
  # @osdk/client
2
2
 
3
- ## 2.1.0-rc.32
4
-
5
- ### Patch Changes
6
-
7
- - 55c05f2: Remove runtime derived properties from external types.
8
- - Updated dependencies [55c05f2]
9
- - @osdk/api@2.1.0-rc.32
10
- - @osdk/generator-converters@2.1.0-rc.32
11
- - @osdk/client.unstable@2.1.0-rc.32
12
-
13
3
  ## 2.1.0-beta.31
14
4
 
15
5
  ### Minor Changes
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import invariant from "tiny-invariant";
18
+ import { modernToLegacyWhereClause } from "../internal/conversions/modernToLegacyWhereClause.js";
19
+ const idCounter = 0;
20
+
21
+ /** @internal */
22
+ export function createWithPropertiesObjectSet(objectType, objectSet, definitionMap) {
23
+ return {
24
+ pivotTo: link => {
25
+ return createWithPropertiesObjectSet(objectType, {
26
+ type: "searchAround",
27
+ objectSet,
28
+ link
29
+ }, definitionMap);
30
+ },
31
+ where: clause => {
32
+ return createWithPropertiesObjectSet(objectType, {
33
+ type: "filter",
34
+ objectSet: objectSet,
35
+ where: modernToLegacyWhereClause(clause, objectType)
36
+ }, definitionMap);
37
+ },
38
+ aggregate: (aggregation, opt) => {
39
+ const splitAggregation = aggregation.split(":");
40
+ !(splitAggregation.length === 2 || splitAggregation[0] === "$count") ? process.env.NODE_ENV !== "production" ? invariant(false, "Invalid aggregation format") : invariant(false) : void 0;
41
+ const [aggregationPropertyName, aggregationOperation] = splitAggregation;
42
+ let aggregationOperationDefinition;
43
+ switch (aggregationOperation) {
44
+ case "sum":
45
+ case "avg":
46
+ case "min":
47
+ case "max":
48
+ case "exactDistinct":
49
+ case "approximateDistinct":
50
+ aggregationOperationDefinition = {
51
+ type: aggregationOperation,
52
+ selectedPropertyApiName: aggregationPropertyName
53
+ };
54
+ break;
55
+ case "approximatePercentile":
56
+ aggregationOperationDefinition = {
57
+ type: "approximatePercentile",
58
+ selectedPropertyApiName: aggregationPropertyName,
59
+ approximatePercentile: opt?.percentile ?? .5
60
+ };
61
+ break;
62
+ case "collectSet":
63
+ case "collectList":
64
+ aggregationOperationDefinition = {
65
+ type: aggregationOperation,
66
+ selectedPropertyApiName: aggregationPropertyName,
67
+ limit: opt?.limit ?? 100
68
+ };
69
+ break;
70
+ case undefined:
71
+ if (aggregationPropertyName === "$count") {
72
+ aggregationOperationDefinition = {
73
+ type: "count"
74
+ };
75
+ break;
76
+ }
77
+ default:
78
+ process.env.NODE_ENV !== "production" ? invariant(false, "Invalid aggregation operation " + aggregationOperation) : invariant(false);
79
+ }
80
+ const selectorResult = {
81
+ type: {}
82
+ };
83
+ definitionMap.set(selectorResult, {
84
+ type: "selection",
85
+ objectSet: objectSet,
86
+ operation: aggregationOperationDefinition
87
+ });
88
+ return selectorResult;
89
+ },
90
+ selectProperty: name => {
91
+ const selectorResult = {
92
+ type: {}
93
+ };
94
+ definitionMap.set(selectorResult, {
95
+ type: "selection",
96
+ objectSet: objectSet,
97
+ operation: {
98
+ type: "get",
99
+ selectedPropertyApiName: name
100
+ }
101
+ });
102
+ return selectorResult;
103
+ }
104
+ };
105
+ }
106
+ //# sourceMappingURL=createWithPropertiesObjectSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWithPropertiesObjectSet.js","names":["invariant","modernToLegacyWhereClause","idCounter","createWithPropertiesObjectSet","objectType","objectSet","definitionMap","pivotTo","link","type","where","clause","aggregate","aggregation","opt","splitAggregation","split","length","process","env","NODE_ENV","aggregationPropertyName","aggregationOperation","aggregationOperationDefinition","selectedPropertyApiName","approximatePercentile","percentile","limit","undefined","selectorResult","set","operation","selectProperty","name"],"sources":["createWithPropertiesObjectSet.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 { DerivedProperty, ObjectOrInterfaceDefinition } from \"@osdk/api\";\nimport type {\n DerivedPropertyDefinition,\n ObjectSet as WireObjectSet,\n SelectedPropertyOperation,\n} from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport { modernToLegacyWhereClause } from \"../internal/conversions/modernToLegacyWhereClause.js\";\n\nconst idCounter = 0;\n\n/** @internal */\nexport function createWithPropertiesObjectSet<\n Q extends ObjectOrInterfaceDefinition,\n>(\n objectType: Q,\n objectSet: WireObjectSet,\n definitionMap: Map<any, DerivedPropertyDefinition>,\n): DerivedProperty.SelectPropertyBuilder<Q, false> {\n const base: DerivedProperty.SelectPropertyBuilder<Q, false> = {\n pivotTo: (link) => {\n return createWithPropertiesObjectSet(objectType, {\n type: \"searchAround\",\n objectSet,\n link,\n }, definitionMap);\n },\n where: (clause) => {\n return createWithPropertiesObjectSet(objectType, {\n type: \"filter\",\n objectSet: objectSet,\n where: modernToLegacyWhereClause(clause, objectType),\n }, definitionMap);\n },\n aggregate: (aggregation: string, opt: any) => {\n const splitAggregation = aggregation.split(\":\");\n invariant(\n splitAggregation.length === 2 || splitAggregation[0] === \"$count\",\n \"Invalid aggregation format\",\n );\n const [aggregationPropertyName, aggregationOperation] = splitAggregation;\n let aggregationOperationDefinition: SelectedPropertyOperation;\n switch (aggregationOperation) {\n case \"sum\":\n case \"avg\":\n case \"min\":\n case \"max\":\n case \"exactDistinct\":\n case \"approximateDistinct\":\n aggregationOperationDefinition = {\n type: aggregationOperation,\n selectedPropertyApiName: aggregationPropertyName,\n };\n break;\n case \"approximatePercentile\":\n aggregationOperationDefinition = {\n type: \"approximatePercentile\",\n selectedPropertyApiName: aggregationPropertyName,\n approximatePercentile: opt?.percentile ?? .5,\n };\n break;\n case \"collectSet\":\n case \"collectList\":\n aggregationOperationDefinition = {\n type: aggregationOperation,\n selectedPropertyApiName: aggregationPropertyName,\n limit: opt?.limit ?? 100,\n };\n break;\n case undefined:\n if (aggregationPropertyName === \"$count\") {\n aggregationOperationDefinition = {\n type: \"count\",\n };\n break;\n }\n default:\n invariant(\n false,\n \"Invalid aggregation operation \" + aggregationOperation,\n );\n }\n const selectorResult: DerivedProperty.SelectorResult<any> = { type: {} };\n definitionMap.set(selectorResult, {\n type: \"selection\",\n objectSet: objectSet,\n operation: aggregationOperationDefinition,\n });\n return selectorResult;\n },\n selectProperty: (name) => {\n const selectorResult: DerivedProperty.SelectorResult<any> = { type: {} };\n definitionMap.set(selectorResult, {\n type: \"selection\",\n objectSet: objectSet,\n operation: {\n type: \"get\",\n selectedPropertyApiName: name,\n },\n });\n return selectorResult;\n },\n };\n\n return base;\n}\n"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,100 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { Employee } from "@osdk/client.test.ontology";
18
+ import { describe, expect, it } from "vitest";
19
+ import { createWithPropertiesObjectSet } from "./createWithPropertiesObjectSet.js";
20
+ describe(createWithPropertiesObjectSet, () => {
21
+ it("correctly creates basic object set with derived properties", () => {
22
+ const map = new Map();
23
+ const deriveObjectSet = createWithPropertiesObjectSet(Employee, {
24
+ type: "methodInput"
25
+ }, map);
26
+ const result = {
27
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
28
+ }["derivedPropertyName"](deriveObjectSet);
29
+ const definition = map.get(result);
30
+ expect(definition).toMatchInlineSnapshot(`
31
+ {
32
+ "objectSet": {
33
+ "link": "lead",
34
+ "objectSet": {
35
+ "type": "methodInput",
36
+ },
37
+ "type": "searchAround",
38
+ },
39
+ "operation": {
40
+ "selectedPropertyApiName": "employeeId",
41
+ "type": "get",
42
+ },
43
+ "type": "selection",
44
+ }
45
+ `);
46
+ });
47
+ it("correctly handles multiple definitions in one clause", () => {
48
+ const map = new Map();
49
+ const deriveObjectSet = createWithPropertiesObjectSet(Employee, {
50
+ type: "methodInput"
51
+ }, map);
52
+ const clause = {
53
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("startDate:approximatePercentile", {
54
+ percentile: 0.5
55
+ }),
56
+ "secondaryDerivedPropertyName": base => base.pivotTo("lead").aggregate("fullName:collectSet", {
57
+ limit: 10
58
+ })
59
+ };
60
+ const result = clause["derivedPropertyName"](deriveObjectSet);
61
+ const definition = map.get(result);
62
+ const secondResult = clause["secondaryDerivedPropertyName"](deriveObjectSet);
63
+ const secondDefinition = map.get(secondResult);
64
+ expect(definition).toMatchInlineSnapshot(`
65
+ {
66
+ "objectSet": {
67
+ "link": "lead",
68
+ "objectSet": {
69
+ "type": "methodInput",
70
+ },
71
+ "type": "searchAround",
72
+ },
73
+ "operation": {
74
+ "approximatePercentile": 0.5,
75
+ "selectedPropertyApiName": "startDate",
76
+ "type": "approximatePercentile",
77
+ },
78
+ "type": "selection",
79
+ }
80
+ `);
81
+ expect(secondDefinition).toMatchInlineSnapshot(`
82
+ {
83
+ "objectSet": {
84
+ "link": "lead",
85
+ "objectSet": {
86
+ "type": "methodInput",
87
+ },
88
+ "type": "searchAround",
89
+ },
90
+ "operation": {
91
+ "limit": 10,
92
+ "selectedPropertyApiName": "fullName",
93
+ "type": "collectSet",
94
+ },
95
+ "type": "selection",
96
+ }
97
+ `);
98
+ });
99
+ });
100
+ //# sourceMappingURL=createWithPropertiesObjectSet.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWithPropertiesObjectSet.test.js","names":["Employee","describe","expect","it","createWithPropertiesObjectSet","map","Map","deriveObjectSet","type","result","base","pivotTo","selectProperty","definition","get","toMatchInlineSnapshot","clause","aggregate","percentile","limit","secondResult","secondDefinition"],"sources":["createWithPropertiesObjectSet.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 { DerivedProperty } from \"@osdk/api\";\nimport { Employee } from \"@osdk/client.test.ontology\";\nimport type { DerivedPropertyDefinition } from \"@osdk/foundry.ontologies\";\nimport { describe, expect, it } from \"vitest\";\nimport { createWithPropertiesObjectSet } from \"./createWithPropertiesObjectSet.js\";\n\ndescribe(createWithPropertiesObjectSet, () => {\n it(\"correctly creates basic object set with derived properties\", () => {\n const map = new Map<any, DerivedPropertyDefinition>();\n const deriveObjectSet = createWithPropertiesObjectSet(Employee, {\n type: \"methodInput\",\n }, map);\n\n const clause = {\n \"derivedPropertyName\": (base) =>\n base.pivotTo(\"lead\").selectProperty(\"employeeId\"),\n } satisfies DerivedProperty.Clause<Employee>;\n\n const result = clause[\"derivedPropertyName\"](deriveObjectSet);\n const definition = map.get(result);\n expect(definition).toMatchInlineSnapshot(`\n {\n \"objectSet\": {\n \"link\": \"lead\",\n \"objectSet\": {\n \"type\": \"methodInput\",\n },\n \"type\": \"searchAround\",\n },\n \"operation\": {\n \"selectedPropertyApiName\": \"employeeId\",\n \"type\": \"get\",\n },\n \"type\": \"selection\",\n }\n `);\n });\n\n it(\"correctly handles multiple definitions in one clause\", () => {\n const map = new Map<any, DerivedPropertyDefinition>();\n const deriveObjectSet = createWithPropertiesObjectSet(Employee, {\n type: \"methodInput\",\n }, map);\n\n const clause: DerivedProperty.Clause<Employee> = {\n \"derivedPropertyName\": (base) =>\n base.pivotTo(\"lead\").aggregate(\"startDate:approximatePercentile\", {\n percentile: 0.5,\n }),\n\n \"secondaryDerivedPropertyName\": (base) =>\n base.pivotTo(\"lead\").aggregate(\"fullName:collectSet\", {\n limit: 10,\n }),\n };\n\n const result = clause[\"derivedPropertyName\"](deriveObjectSet);\n const definition = map.get(result);\n\n const secondResult = clause[\"secondaryDerivedPropertyName\"](\n deriveObjectSet,\n );\n const secondDefinition = map.get(secondResult);\n\n expect(definition).toMatchInlineSnapshot(`\n {\n \"objectSet\": {\n \"link\": \"lead\",\n \"objectSet\": {\n \"type\": \"methodInput\",\n },\n \"type\": \"searchAround\",\n },\n \"operation\": {\n \"approximatePercentile\": 0.5,\n \"selectedPropertyApiName\": \"startDate\",\n \"type\": \"approximatePercentile\",\n },\n \"type\": \"selection\",\n }\n `);\n\n expect(secondDefinition).toMatchInlineSnapshot(`\n {\n \"objectSet\": {\n \"link\": \"lead\",\n \"objectSet\": {\n \"type\": \"methodInput\",\n },\n \"type\": \"searchAround\",\n },\n \"operation\": {\n \"limit\": 10,\n \"selectedPropertyApiName\": \"fullName\",\n \"type\": \"collectSet\",\n },\n \"type\": \"selection\",\n }\n `);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,QAAQ,4BAA4B;AAErD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,6BAA6B,QAAQ,oCAAoC;AAElFH,QAAQ,CAACG,6BAA6B,EAAE,MAAM;EAC5CD,EAAE,CAAC,4DAA4D,EAAE,MAAM;IACrE,MAAME,GAAG,GAAG,IAAIC,GAAG,CAAiC,CAAC;IACrD,MAAMC,eAAe,GAAGH,6BAA6B,CAACJ,QAAQ,EAAE;MAC9DQ,IAAI,EAAE;IACR,CAAC,EAAEH,GAAG,CAAC;IAOP,MAAMI,MAAM,GALG;MACb,qBAAqB,EAAGC,IAAI,IAC1BA,IAAI,CAACC,OAAO,CAAC,MAAM,CAAC,CAACC,cAAc,CAAC,YAAY;IACpD,CAAC,CAEqB,qBAAqB,CAAC,CAACL,eAAe,CAAC;IAC7D,MAAMM,UAAU,GAAGR,GAAG,CAACS,GAAG,CAACL,MAAM,CAAC;IAClCP,MAAM,CAACW,UAAU,CAAC,CAACE,qBAAqB,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;EAEFZ,EAAE,CAAC,sDAAsD,EAAE,MAAM;IAC/D,MAAME,GAAG,GAAG,IAAIC,GAAG,CAAiC,CAAC;IACrD,MAAMC,eAAe,GAAGH,6BAA6B,CAACJ,QAAQ,EAAE;MAC9DQ,IAAI,EAAE;IACR,CAAC,EAAEH,GAAG,CAAC;IAEP,MAAMW,MAAwC,GAAG;MAC/C,qBAAqB,EAAGN,IAAI,IAC1BA,IAAI,CAACC,OAAO,CAAC,MAAM,CAAC,CAACM,SAAS,CAAC,iCAAiC,EAAE;QAChEC,UAAU,EAAE;MACd,CAAC,CAAC;MAEJ,8BAA8B,EAAGR,IAAI,IACnCA,IAAI,CAACC,OAAO,CAAC,MAAM,CAAC,CAACM,SAAS,CAAC,qBAAqB,EAAE;QACpDE,KAAK,EAAE;MACT,CAAC;IACL,CAAC;IAED,MAAMV,MAAM,GAAGO,MAAM,CAAC,qBAAqB,CAAC,CAACT,eAAe,CAAC;IAC7D,MAAMM,UAAU,GAAGR,GAAG,CAACS,GAAG,CAACL,MAAM,CAAC;IAElC,MAAMW,YAAY,GAAGJ,MAAM,CAAC,8BAA8B,CAAC,CACzDT,eACF,CAAC;IACD,MAAMc,gBAAgB,GAAGhB,GAAG,CAACS,GAAG,CAACM,YAAY,CAAC;IAE9ClB,MAAM,CAACW,UAAU,CAAC,CAACE,qBAAqB,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;IAEJb,MAAM,CAACmB,gBAAgB,CAAC,CAACN,qBAAqB,CAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC;EACN,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -410,6 +410,232 @@ describe("ObjectSet", () => {
410
410
  });
411
411
  });
412
412
  });
413
+ describe("Derived Properties Object Set", () => {
414
+ it("does not allow aggregate or selectProperty before a link type is selected", () => {
415
+ client(Employee).withProperties({
416
+ "derivedPropertyName": base =>
417
+ // @ts-expect-error
418
+ base.aggregate("employeeId:exactDistinct")
419
+ });
420
+ client(Employee).withProperties({
421
+ "derivedPropertyName": base =>
422
+ // @ts-expect-error
423
+ base.selectProperty("employeeId")
424
+ });
425
+ });
426
+ it("does not allow selectProperty when a many link was selected at any point", () => {
427
+ client(Employee).withProperties({
428
+ "derivedPropertyName": base => {
429
+ // @ts-expect-error
430
+ base.pivotTo("peeps").selectProperty("employeeId");
431
+
432
+ // @ts-expect-error
433
+ base.pivotTo("lead").pivotTo("peeps").selectProperty("employeeId");
434
+ return base.pivotTo("lead").selectProperty("employeeId");
435
+ }
436
+ });
437
+ });
438
+ it("enforces a return only of correct type", () => {
439
+ client(Employee).withProperties({
440
+ // @ts-expect-error
441
+ "derivedPropertyName": base => {
442
+ return base.pivotTo("peeps");
443
+ },
444
+ // @ts-expect-error
445
+ "derivedPropertyName2": () => {
446
+ return {
447
+ incorrect: "type"
448
+ };
449
+ }
450
+ });
451
+ });
452
+
453
+ // Executed code fails since we're providing bad strings to the function
454
+ it.fails("correctly narrows types of aggregate function", () => {
455
+ client(Employee).withProperties({
456
+ "derivedPropertyName": base => {
457
+ // @ts-expect-error
458
+ base.pivotTo("lead").aggregate("notAProperty:sum");
459
+
460
+ // @ts-expect-error
461
+ base.pivotTo("lead").aggregate(":avg");
462
+
463
+ // @ts-expect-error
464
+ base.pivotTo("lead").aggregate("employeeId:notAnOp");
465
+
466
+ // @ts-expect-error
467
+ base.pivotTo("lead").aggregate("");
468
+ base.pivotTo("lead").aggregate("employeeId:collectList");
469
+ return base.pivotTo("lead").aggregate("employeeId:sum");
470
+ }
471
+ });
472
+ });
473
+
474
+ // Executed code fails since we're providing bad strings to the function
475
+ it("correctly narrows types of options for aggregate functions", () => {
476
+ const objectSet = client(Employee).withProperties({
477
+ "derivedPropertyName": base => {
478
+ // @ts-expect-error
479
+ base.pivotTo("lead").aggregate("employeeId:approximateDistinct", {
480
+ limit: 1
481
+ });
482
+ base.pivotTo("lead").aggregate("employeeId:collectList", {
483
+ limit: 1
484
+ });
485
+ base.pivotTo("lead").aggregate("employeeId:collectSet", {
486
+ limit: 1
487
+ });
488
+ base.pivotTo("lead").aggregate("employeeId:collectList", {
489
+ // @ts-expect-error
490
+ percentile: 1
491
+ });
492
+ return base.pivotTo("lead").aggregate("employeeId:approximatePercentile", {
493
+ percentile: 0.5
494
+ });
495
+ }
496
+ });
497
+ expectTypeOf(objectSet).branded.toEqualTypeOf();
498
+ });
499
+ it("correctly narrows types of selectProperty function", () => {
500
+ client(Employee).withProperties({
501
+ "derivedPropertyName": base => {
502
+ // @ts-expect-error
503
+ base.pivotTo("lead").selectProperty("notAProperty");
504
+ return base.pivotTo("lead").selectProperty("employeeStatus");
505
+ }
506
+ });
507
+ });
508
+ it("propagates derived property type to future object set operations with correct types", () => {
509
+ client(Employee).withProperties({
510
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("employeeId:sum")
511
+ // @ts-expect-error
512
+ }).where({
513
+ "notAProperty": {
514
+ "$eq": 3
515
+ }
516
+ });
517
+ const numericAggregationObjectSet = client(Employee).withProperties({
518
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("employeeId:sum")
519
+ }).where({
520
+ "derivedPropertyName": {
521
+ "$eq": 3
522
+ }
523
+ });
524
+ expectTypeOf(numericAggregationObjectSet).toEqualTypeOf();
525
+ client(Employee).withProperties({
526
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("employeeId:collectList")
527
+ }).where({
528
+ "derivedPropertyName": {
529
+ "$isNull": false
530
+ }
531
+ })
532
+ // @ts-expect-error
533
+ .where({
534
+ "derivedPropertyName": {
535
+ "$eq": [1, 2]
536
+ }
537
+ });
538
+ const setAggregationObjectSet = client(Employee).withProperties({
539
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("fullName:collectSet")
540
+ });
541
+ setAggregationObjectSet.where({
542
+ "derivedPropertyName": {
543
+ "$isNull": false
544
+ }
545
+ });
546
+ setAggregationObjectSet.where({
547
+ // @ts-expect-error
548
+ "derivedPropertyName": {
549
+ "$eq": [1, 2]
550
+ }
551
+ });
552
+ expectTypeOf(setAggregationObjectSet).toEqualTypeOf();
553
+ const selectPropertyObjectSet = client(Employee).withProperties({
554
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
555
+ }).where({
556
+ "derivedPropertyName": {
557
+ "$eq": 3
558
+ }
559
+ });
560
+ expectTypeOf(selectPropertyObjectSet).toEqualTypeOf();
561
+ client(Employee).withProperties({
562
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("startDate")
563
+ }).where({
564
+ "derivedPropertyName": {
565
+ "$eq": "datetimeFilter"
566
+ }
567
+ });
568
+ });
569
+ it("correctly types multiple property definitions in one clause", () => {
570
+ const objectSet = client(Employee).withProperties({
571
+ "derivedPropertyName": base => base.pivotTo("lead").aggregate("employeeId:sum"),
572
+ "derivedPropertyName2": base => base.pivotTo("lead").selectProperty("fullName")
573
+ }).where({
574
+ "derivedPropertyName": {
575
+ "$eq": 3
576
+ }
577
+ }).where({
578
+ "derivedPropertyName2": {
579
+ "$eq": "name"
580
+ }
581
+ });
582
+ expectTypeOf(objectSet).toEqualTypeOf();
583
+ });
584
+ it("ensures other properties are consistently typed", () => {
585
+ client(Employee).withProperties({
586
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
587
+ }).where({
588
+ "fullName": {
589
+ "$eq": "A"
590
+ }
591
+ });
592
+ client(Employee).withProperties({
593
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
594
+ }).where({
595
+ "employeeId": {
596
+ "$eq": 2
597
+ }
598
+ });
599
+ });
600
+ it("allows fetching derived properties with correctly typed Osdk.Instance types", async () => {
601
+ const objectWithRdp = await client(Employee).withProperties({
602
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
603
+ }).fetchOne(50035);
604
+ expectTypeOf(objectWithRdp.derivedPropertyName).toEqualTypeOf();
605
+ expect(objectWithRdp.derivedPropertyName).toBe(1);
606
+ const objectWithUndefinedRdp = await client(Employee).withProperties({
607
+ "derivedPropertyName": base => base.pivotTo("lead").selectProperty("employeeId")
608
+ }).fetchOne(50036);
609
+ expect(objectWithUndefinedRdp.derivedPropertyName).toBeUndefined();
610
+ });
611
+ });
612
+ describe.each(["fetchOne", "fetchOneWithErrors"])("%s", k => {
613
+ describe("strictNonNull: false", () => {
614
+ describe("includeRid: true", () => {
615
+ it("returns bad data", async () => {
616
+ // Look at this
617
+ const opts = {
618
+ $__EXPERIMENTAL_strictNonNull: false,
619
+ $includeRid: true
620
+ };
621
+ const result = k === "fetchOne" ? await client(Employee).fetchOne(50033, opts) : (await client(Employee).fetchOneWithErrors(50033, opts)).value;
622
+ expect(result).not.toBeUndefined();
623
+ expectTypeOf(result).branded.toEqualTypeOf();
624
+ });
625
+ });
626
+ describe("includeRid: false", () => {
627
+ it("returns bad data", async () => {
628
+ const opts = {
629
+ $__EXPERIMENTAL_strictNonNull: false,
630
+ $includeRid: false
631
+ };
632
+ const result = k === "fetchOne" ? await client(Employee).fetchOne(50033, opts) : (await client(Employee).fetchOneWithErrors(50033, opts)).value;
633
+ expect(result).not.toBeUndefined();
634
+ expectTypeOf(result).branded.toEqualTypeOf();
635
+ });
636
+ });
637
+ });
638
+ });
413
639
  describe("conversions", () => {
414
640
  describe("strictNonNull: false", () => {
415
641
  it("returns bad data", async () => {