@osdk/generator-converters 1.5.0
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/build/js/index.cjs +129 -0
- package/build/js/index.cjs.map +1 -0
- package/build/js/index.mjs +126 -0
- package/build/js/index.mjs.map +1 -0
- package/build/types/empty.test.d.ts +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/wireObjectTypeFullMetadataToSdkObjectTypeDefinition.d.ts +3 -0
- package/build/types/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.d.ts +3 -0
- package/build/types/wirePropertyV2ToSdkPropertyDefinition.d.ts +3 -0
- package/changelog/@unreleased/pr-89.v2.yml +5 -0
- package/package.json +59 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts
|
|
4
|
+
function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
5
|
+
switch (input.dataType.type) {
|
|
6
|
+
case "integer":
|
|
7
|
+
case "double":
|
|
8
|
+
case "string":
|
|
9
|
+
case "boolean":
|
|
10
|
+
case "attachment":
|
|
11
|
+
case "byte":
|
|
12
|
+
case "decimal":
|
|
13
|
+
case "float":
|
|
14
|
+
case "geopoint":
|
|
15
|
+
case "geoshape":
|
|
16
|
+
case "long":
|
|
17
|
+
case "short": {
|
|
18
|
+
return input.dataType.type;
|
|
19
|
+
}
|
|
20
|
+
case "date": {
|
|
21
|
+
return "datetime";
|
|
22
|
+
}
|
|
23
|
+
case "timestamp": {
|
|
24
|
+
return "timestamp";
|
|
25
|
+
}
|
|
26
|
+
case "timeseries":
|
|
27
|
+
case "array":
|
|
28
|
+
case "marking":
|
|
29
|
+
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
30
|
+
default:
|
|
31
|
+
input.dataType;
|
|
32
|
+
throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/wirePropertyV2ToSdkPropertyDefinition.ts
|
|
37
|
+
function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
38
|
+
switch (input.dataType.type) {
|
|
39
|
+
case "integer":
|
|
40
|
+
case "string":
|
|
41
|
+
case "byte":
|
|
42
|
+
case "decimal":
|
|
43
|
+
case "double":
|
|
44
|
+
case "float":
|
|
45
|
+
case "long":
|
|
46
|
+
case "short":
|
|
47
|
+
case "boolean":
|
|
48
|
+
case "date":
|
|
49
|
+
case "attachment":
|
|
50
|
+
case "geopoint":
|
|
51
|
+
case "geoshape":
|
|
52
|
+
case "timestamp":
|
|
53
|
+
case "timeseries":
|
|
54
|
+
case "marking":
|
|
55
|
+
return {
|
|
56
|
+
multiplicity: false,
|
|
57
|
+
description: input.description,
|
|
58
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
59
|
+
nullable: isNullable
|
|
60
|
+
};
|
|
61
|
+
case "array": {
|
|
62
|
+
return {
|
|
63
|
+
multiplicity: true,
|
|
64
|
+
description: input.description,
|
|
65
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
66
|
+
nullable: true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
input.dataType;
|
|
71
|
+
throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
75
|
+
switch (propertyType.type) {
|
|
76
|
+
case "integer":
|
|
77
|
+
case "string":
|
|
78
|
+
case "byte":
|
|
79
|
+
case "decimal":
|
|
80
|
+
case "double":
|
|
81
|
+
case "float":
|
|
82
|
+
case "long":
|
|
83
|
+
case "short":
|
|
84
|
+
case "boolean":
|
|
85
|
+
case "attachment":
|
|
86
|
+
case "geopoint":
|
|
87
|
+
case "geoshape":
|
|
88
|
+
case "timestamp":
|
|
89
|
+
case "marking":
|
|
90
|
+
return propertyType.type;
|
|
91
|
+
case "date":
|
|
92
|
+
return "datetime";
|
|
93
|
+
case "array":
|
|
94
|
+
return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);
|
|
95
|
+
case "timeseries":
|
|
96
|
+
if (propertyType.itemType.type === "string") {
|
|
97
|
+
return "stringTimeseries";
|
|
98
|
+
}
|
|
99
|
+
return "numericTimeseries";
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Unexecpected data type ${JSON.stringify(propertyType)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/wireObjectTypeFullMetadataToSdkObjectTypeDefinition.ts
|
|
106
|
+
function wireObjectTypeFullMetadataToSdkObjectTypeDefinition(objectTypeWithLink, v2) {
|
|
107
|
+
if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === void 0) {
|
|
108
|
+
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
type: "object",
|
|
112
|
+
apiName: objectTypeWithLink.objectType.apiName,
|
|
113
|
+
description: objectTypeWithLink.objectType.description,
|
|
114
|
+
primaryKeyApiName: objectTypeWithLink.objectType.primaryKey,
|
|
115
|
+
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
116
|
+
links: Object.fromEntries(objectTypeWithLink.linkTypes.map((linkType) => {
|
|
117
|
+
return [linkType.apiName, {
|
|
118
|
+
multiplicity: linkType.cardinality === "MANY",
|
|
119
|
+
targetType: linkType.objectTypeApiName
|
|
120
|
+
}];
|
|
121
|
+
})),
|
|
122
|
+
properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
exports.wireObjectTypeFullMetadataToSdkObjectTypeDefinition = wireObjectTypeFullMetadataToSdkObjectTypeDefinition;
|
|
127
|
+
exports.wirePropertyV2ToSdkPropertyDefinition = wirePropertyV2ToSdkPropertyDefinition;
|
|
128
|
+
//# sourceMappingURL=out.js.map
|
|
129
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts","../../src/wirePropertyV2ToSdkPropertyDefinition.ts","../../src/wireObjectTypeFullMetadataToSdkObjectTypeDefinition.ts"],"names":[],"mappings":";AAgBO,SAAS,4CAA4C,OAAO;AACjE,UAAQ,MAAM,SAAS,MAAM;AAAA,IAC3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,SACH;AACE,aAAO,MAAM,SAAS;AAAA,IACxB;AAAA,IACF,KAAK,QACH;AACE,aAAO;AAAA,IACT;AAAA,IACF,KAAK,aACH;AACE,aAAO;AAAA,IACT;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,YAAM,IAAI,MAAM,sCAAsC,MAAM,SAAS,IAAI,EAAE;AAAA,IAC7E;AACE,YAAM,IAAI,MAAM;AAChB,YAAM,IAAI,MAAM,4CAA4C,MAAM,QAAQ,EAAE;AAAA,EAChF;AACF;;;ACjCO,SAAS,sCAAsC,OAAO,aAAa,MAAM;AAC9E,UAAQ,MAAM,SAAS,MAAM;AAAA,IAC3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAA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,mBAAmB,WAAW,UAAU,MAAM,QAAW;AACpG,UAAM,IAAI,MAAM,eAAe,mBAAmB,WAAW,UAAU,iBAAiB,mBAAmB,WAAW,OAAO,EAAE;AAAA,EACjI;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS,mBAAmB,WAAW;AAAA,IACvC,aAAa,mBAAmB,WAAW;AAAA,IAC3C,mBAAmB,mBAAmB,WAAW;AAAA,IACjD,gBAAgB,4CAA4C,mBAAmB,WAAW,WAAW,mBAAmB,WAAW,UAAU,CAAC;AAAA,IAC9I,OAAO,OAAO,YAAY,mBAAmB,UAAU,IAAI,cAAY;AACrE,aAAO,CAAC,SAAS,SAAS;AAAA,QACxB,cAAc,SAAS,gBAAgB;AAAA,QACvC,YAAY,SAAS;AAAA,MACvB,CAAC;AAAA,IACH,CAAC,CAAC;AAAA,IACF,YAAY,OAAO,YAAY,OAAO,QAAQ,mBAAmB,WAAW,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,sCAAsC,OAAO,EAAE,MAAM,mBAAmB,WAAW,eAAe,IAAI,CAAC,CAAC,CAAC;AAAA,EAC/N;AACF","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\nexport function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {\n switch (input.dataType.type) {\n case \"integer\":\n case \"double\":\n case \"string\":\n case \"boolean\":\n case \"attachment\":\n case \"byte\":\n case \"decimal\":\n case \"float\":\n case \"geopoint\":\n case \"geoshape\":\n case \"long\":\n case \"short\":\n {\n return input.dataType.type;\n }\n case \"date\":\n {\n return \"datetime\";\n }\n case \"timestamp\":\n {\n return \"timestamp\";\n }\n case \"timeseries\":\n case \"array\":\n case \"marking\":\n throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);\n default:\n const _ = input.dataType;\n throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);\n }\n}","/*\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\nexport function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {\n switch (input.dataType.type) {\n case \"integer\":\n case \"string\":\n case \"byte\":\n case \"decimal\":\n case \"double\":\n case \"float\":\n case \"long\":\n case \"short\":\n case \"boolean\":\n case \"date\":\n case \"attachment\":\n case \"geopoint\":\n case \"geoshape\":\n case \"timestamp\":\n case \"timeseries\":\n case \"marking\":\n return {\n multiplicity: false,\n description: input.description,\n type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),\n nullable: isNullable\n };\n case \"array\":\n {\n return {\n multiplicity: true,\n description: input.description,\n type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),\n nullable: true\n };\n }\n default:\n const _ = input.dataType;\n throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);\n }\n}\nfunction objectPropertyTypeToSdkPropertyDefinition(propertyType) {\n switch (propertyType.type) {\n case \"integer\":\n case \"string\":\n case \"byte\":\n case \"decimal\":\n case \"double\":\n case \"float\":\n case \"long\":\n case \"short\":\n case \"boolean\":\n case \"attachment\":\n case \"geopoint\":\n case \"geoshape\":\n case \"timestamp\":\n case \"marking\":\n return propertyType.type;\n case \"date\":\n return \"datetime\";\n case \"array\":\n return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);\n case \"timeseries\":\n if (propertyType.itemType.type === \"string\") {\n return \"stringTimeseries\";\n }\n return \"numericTimeseries\";\n default:\n const _ = propertyType;\n throw new Error(`Unexecpected data type ${JSON.stringify(propertyType)}`);\n }\n}","/*\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 { wirePropertyV2ToSdkPrimaryKeyTypeDefinition } from \"./wirePropertyV2ToSdkPrimaryKeyTypeDefinition\";\nimport { wirePropertyV2ToSdkPropertyDefinition } from \"./wirePropertyV2ToSdkPropertyDefinition\";\nexport function wireObjectTypeFullMetadataToSdkObjectTypeDefinition(objectTypeWithLink, v2) {\n if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === undefined) {\n throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);\n }\n return {\n type: \"object\",\n apiName: objectTypeWithLink.objectType.apiName,\n description: objectTypeWithLink.objectType.description,\n primaryKeyApiName: objectTypeWithLink.objectType.primaryKey,\n primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),\n links: Object.fromEntries(objectTypeWithLink.linkTypes.map(linkType => {\n return [linkType.apiName, {\n multiplicity: linkType.cardinality === \"MANY\",\n targetType: linkType.objectTypeApiName\n }];\n })),\n properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))\n };\n}"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts
|
|
2
|
+
function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {
|
|
3
|
+
switch (input.dataType.type) {
|
|
4
|
+
case "integer":
|
|
5
|
+
case "double":
|
|
6
|
+
case "string":
|
|
7
|
+
case "boolean":
|
|
8
|
+
case "attachment":
|
|
9
|
+
case "byte":
|
|
10
|
+
case "decimal":
|
|
11
|
+
case "float":
|
|
12
|
+
case "geopoint":
|
|
13
|
+
case "geoshape":
|
|
14
|
+
case "long":
|
|
15
|
+
case "short": {
|
|
16
|
+
return input.dataType.type;
|
|
17
|
+
}
|
|
18
|
+
case "date": {
|
|
19
|
+
return "datetime";
|
|
20
|
+
}
|
|
21
|
+
case "timestamp": {
|
|
22
|
+
return "timestamp";
|
|
23
|
+
}
|
|
24
|
+
case "timeseries":
|
|
25
|
+
case "array":
|
|
26
|
+
case "marking":
|
|
27
|
+
throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);
|
|
28
|
+
default:
|
|
29
|
+
input.dataType;
|
|
30
|
+
throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/wirePropertyV2ToSdkPropertyDefinition.ts
|
|
35
|
+
function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {
|
|
36
|
+
switch (input.dataType.type) {
|
|
37
|
+
case "integer":
|
|
38
|
+
case "string":
|
|
39
|
+
case "byte":
|
|
40
|
+
case "decimal":
|
|
41
|
+
case "double":
|
|
42
|
+
case "float":
|
|
43
|
+
case "long":
|
|
44
|
+
case "short":
|
|
45
|
+
case "boolean":
|
|
46
|
+
case "date":
|
|
47
|
+
case "attachment":
|
|
48
|
+
case "geopoint":
|
|
49
|
+
case "geoshape":
|
|
50
|
+
case "timestamp":
|
|
51
|
+
case "timeseries":
|
|
52
|
+
case "marking":
|
|
53
|
+
return {
|
|
54
|
+
multiplicity: false,
|
|
55
|
+
description: input.description,
|
|
56
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
57
|
+
nullable: isNullable
|
|
58
|
+
};
|
|
59
|
+
case "array": {
|
|
60
|
+
return {
|
|
61
|
+
multiplicity: true,
|
|
62
|
+
description: input.description,
|
|
63
|
+
type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),
|
|
64
|
+
nullable: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
input.dataType;
|
|
69
|
+
throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function objectPropertyTypeToSdkPropertyDefinition(propertyType) {
|
|
73
|
+
switch (propertyType.type) {
|
|
74
|
+
case "integer":
|
|
75
|
+
case "string":
|
|
76
|
+
case "byte":
|
|
77
|
+
case "decimal":
|
|
78
|
+
case "double":
|
|
79
|
+
case "float":
|
|
80
|
+
case "long":
|
|
81
|
+
case "short":
|
|
82
|
+
case "boolean":
|
|
83
|
+
case "attachment":
|
|
84
|
+
case "geopoint":
|
|
85
|
+
case "geoshape":
|
|
86
|
+
case "timestamp":
|
|
87
|
+
case "marking":
|
|
88
|
+
return propertyType.type;
|
|
89
|
+
case "date":
|
|
90
|
+
return "datetime";
|
|
91
|
+
case "array":
|
|
92
|
+
return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);
|
|
93
|
+
case "timeseries":
|
|
94
|
+
if (propertyType.itemType.type === "string") {
|
|
95
|
+
return "stringTimeseries";
|
|
96
|
+
}
|
|
97
|
+
return "numericTimeseries";
|
|
98
|
+
default:
|
|
99
|
+
throw new Error(`Unexecpected data type ${JSON.stringify(propertyType)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/wireObjectTypeFullMetadataToSdkObjectTypeDefinition.ts
|
|
104
|
+
function wireObjectTypeFullMetadataToSdkObjectTypeDefinition(objectTypeWithLink, v2) {
|
|
105
|
+
if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === void 0) {
|
|
106
|
+
throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
type: "object",
|
|
110
|
+
apiName: objectTypeWithLink.objectType.apiName,
|
|
111
|
+
description: objectTypeWithLink.objectType.description,
|
|
112
|
+
primaryKeyApiName: objectTypeWithLink.objectType.primaryKey,
|
|
113
|
+
primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),
|
|
114
|
+
links: Object.fromEntries(objectTypeWithLink.linkTypes.map((linkType) => {
|
|
115
|
+
return [linkType.apiName, {
|
|
116
|
+
multiplicity: linkType.cardinality === "MANY",
|
|
117
|
+
targetType: linkType.objectTypeApiName
|
|
118
|
+
}];
|
|
119
|
+
})),
|
|
120
|
+
properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { wireObjectTypeFullMetadataToSdkObjectTypeDefinition, wirePropertyV2ToSdkPropertyDefinition };
|
|
125
|
+
//# sourceMappingURL=out.js.map
|
|
126
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts","../../src/wirePropertyV2ToSdkPropertyDefinition.ts","../../src/wireObjectTypeFullMetadataToSdkObjectTypeDefinition.ts"],"names":[],"mappings":";AAgBO,SAAS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MACvB,CAAC;AAAA,IACH,CAAC,CAAC;AAAA,IACF,YAAY,OAAO,YAAY,OAAO,QAAQ,mBAAmB,WAAW,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,sCAAsC,OAAO,EAAE,MAAM,mBAAmB,WAAW,eAAe,IAAI,CAAC,CAAC,CAAC;AAAA,EAC/N;AACF","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\nexport function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(input) {\n switch (input.dataType.type) {\n case \"integer\":\n case \"double\":\n case \"string\":\n case \"boolean\":\n case \"attachment\":\n case \"byte\":\n case \"decimal\":\n case \"float\":\n case \"geopoint\":\n case \"geoshape\":\n case \"long\":\n case \"short\":\n {\n return input.dataType.type;\n }\n case \"date\":\n {\n return \"datetime\";\n }\n case \"timestamp\":\n {\n return \"timestamp\";\n }\n case \"timeseries\":\n case \"array\":\n case \"marking\":\n throw new Error(`Type not supported for primaryKey: ${input.dataType.type}`);\n default:\n const _ = input.dataType;\n throw new Error(`Unknown type encountered for primaryKey: ${input.dataType}`);\n }\n}","/*\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\nexport function wirePropertyV2ToSdkPropertyDefinition(input, isNullable = true) {\n switch (input.dataType.type) {\n case \"integer\":\n case \"string\":\n case \"byte\":\n case \"decimal\":\n case \"double\":\n case \"float\":\n case \"long\":\n case \"short\":\n case \"boolean\":\n case \"date\":\n case \"attachment\":\n case \"geopoint\":\n case \"geoshape\":\n case \"timestamp\":\n case \"timeseries\":\n case \"marking\":\n return {\n multiplicity: false,\n description: input.description,\n type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),\n nullable: isNullable\n };\n case \"array\":\n {\n return {\n multiplicity: true,\n description: input.description,\n type: objectPropertyTypeToSdkPropertyDefinition(input.dataType),\n nullable: true\n };\n }\n default:\n const _ = input.dataType;\n throw new Error(`Unexpected data type ${JSON.stringify(input.dataType)}`);\n }\n}\nfunction objectPropertyTypeToSdkPropertyDefinition(propertyType) {\n switch (propertyType.type) {\n case \"integer\":\n case \"string\":\n case \"byte\":\n case \"decimal\":\n case \"double\":\n case \"float\":\n case \"long\":\n case \"short\":\n case \"boolean\":\n case \"attachment\":\n case \"geopoint\":\n case \"geoshape\":\n case \"timestamp\":\n case \"marking\":\n return propertyType.type;\n case \"date\":\n return \"datetime\";\n case \"array\":\n return objectPropertyTypeToSdkPropertyDefinition(propertyType.subType);\n case \"timeseries\":\n if (propertyType.itemType.type === \"string\") {\n return \"stringTimeseries\";\n }\n return \"numericTimeseries\";\n default:\n const _ = propertyType;\n throw new Error(`Unexecpected data type ${JSON.stringify(propertyType)}`);\n }\n}","/*\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 { wirePropertyV2ToSdkPrimaryKeyTypeDefinition } from \"./wirePropertyV2ToSdkPrimaryKeyTypeDefinition\";\nimport { wirePropertyV2ToSdkPropertyDefinition } from \"./wirePropertyV2ToSdkPropertyDefinition\";\nexport function wireObjectTypeFullMetadataToSdkObjectTypeDefinition(objectTypeWithLink, v2) {\n if (objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey] === undefined) {\n throw new Error(`Primary key ${objectTypeWithLink.objectType.primaryKey} not found in ${objectTypeWithLink.objectType.apiName}`);\n }\n return {\n type: \"object\",\n apiName: objectTypeWithLink.objectType.apiName,\n description: objectTypeWithLink.objectType.description,\n primaryKeyApiName: objectTypeWithLink.objectType.primaryKey,\n primaryKeyType: wirePropertyV2ToSdkPrimaryKeyTypeDefinition(objectTypeWithLink.objectType.properties[objectTypeWithLink.objectType.primaryKey]),\n links: Object.fromEntries(objectTypeWithLink.linkTypes.map(linkType => {\n return [linkType.apiName, {\n multiplicity: linkType.cardinality === \"MANY\",\n targetType: linkType.objectTypeApiName\n }];\n })),\n properties: Object.fromEntries(Object.entries(objectTypeWithLink.objectType.properties).map(([key, value]) => [key, wirePropertyV2ToSdkPropertyDefinition(value, !(v2 && objectTypeWithLink.objectType.primaryKey === key))]))\n };\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ObjectTypeDefinition } from "@osdk/api";
|
|
2
|
+
import type { ObjectTypeFullMetadata } from "@osdk/gateway/types";
|
|
3
|
+
export declare function wireObjectTypeFullMetadataToSdkObjectTypeDefinition(objectTypeWithLink: ObjectTypeFullMetadata, v2: boolean): ObjectTypeDefinition<any>;
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osdk/generator-converters",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"access": "public",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/palantir/osdk-ts.git"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./build/types/index.d.ts",
|
|
14
|
+
"import": "./build/js/index.mjs",
|
|
15
|
+
"require": "./build/js/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./*": {
|
|
18
|
+
"types": "./build/types/public/*.d.ts",
|
|
19
|
+
"import": "./build/js/public/*.mjs",
|
|
20
|
+
"require": "./build/js/public/*.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@osdk/api": "1.2.0",
|
|
25
|
+
"@osdk/gateway": "1.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"ts-expect": "^1.3.0",
|
|
29
|
+
"typescript": "^5.2.2",
|
|
30
|
+
"vitest": "^1.2.2"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [],
|
|
36
|
+
"files": [
|
|
37
|
+
"build/types",
|
|
38
|
+
"build/js",
|
|
39
|
+
"changelog",
|
|
40
|
+
"CHANGELOG_OLD.md",
|
|
41
|
+
"package.json",
|
|
42
|
+
"templates",
|
|
43
|
+
"*.d.ts"
|
|
44
|
+
],
|
|
45
|
+
"main": "./build/js/index.cjs",
|
|
46
|
+
"module": "./build/js/index.mjs",
|
|
47
|
+
"types": "./build/types/index.d.ts",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
|
|
50
|
+
"dev:transpile": "tsup --watch",
|
|
51
|
+
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
|
|
52
|
+
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"transpile": "tsup",
|
|
56
|
+
"transpileWatch": "tsup --watch",
|
|
57
|
+
"typecheck": "tsc-absolute --build"
|
|
58
|
+
}
|
|
59
|
+
}
|