@osdk/maker 0.15.0-beta.8 → 0.15.0-beta.9
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 +8 -0
- package/build/browser/api/action/ActionParameterConditionalOverride.js.map +1 -1
- package/build/browser/api/defineValueType.js +8 -3
- package/build/browser/api/defineValueType.js.map +1 -1
- package/build/browser/api/test/actions.test.js +8 -5
- package/build/browser/api/test/actions.test.js.map +1 -1
- package/build/browser/api/test/misc.test.js +4 -2
- package/build/browser/api/test/misc.test.js.map +1 -1
- package/build/browser/api/test/objects.test.js +3 -2
- package/build/browser/api/test/objects.test.js.map +1 -1
- package/build/browser/api/test/valueTypes.test.js +82 -0
- package/build/browser/api/test/valueTypes.test.js.map +1 -1
- package/build/browser/cli/main.js +1 -1
- package/build/browser/conversion/toMarketplace/convertActionParameterConditionalOverride.js +15 -7
- package/build/browser/conversion/toMarketplace/convertActionParameterConditionalOverride.js.map +1 -1
- package/build/browser/conversion/toMarketplace/convertObject.js +6 -5
- package/build/browser/conversion/toMarketplace/convertObject.js.map +1 -1
- package/build/cjs/index.cjs +28 -14
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +3 -0
- package/build/esm/api/action/ActionParameterConditionalOverride.js.map +1 -1
- package/build/esm/api/defineValueType.js +8 -3
- package/build/esm/api/defineValueType.js.map +1 -1
- package/build/esm/api/test/actions.test.js +8 -5
- package/build/esm/api/test/actions.test.js.map +1 -1
- package/build/esm/api/test/misc.test.js +4 -2
- package/build/esm/api/test/misc.test.js.map +1 -1
- package/build/esm/api/test/objects.test.js +3 -2
- package/build/esm/api/test/objects.test.js.map +1 -1
- package/build/esm/api/test/valueTypes.test.js +82 -0
- package/build/esm/api/test/valueTypes.test.js.map +1 -1
- package/build/esm/cli/main.js +1 -1
- package/build/esm/conversion/toMarketplace/convertActionParameterConditionalOverride.js +15 -7
- package/build/esm/conversion/toMarketplace/convertActionParameterConditionalOverride.js.map +1 -1
- package/build/esm/conversion/toMarketplace/convertObject.js +6 -5
- package/build/esm/conversion/toMarketplace/convertObject.js.map +1 -1
- package/build/types/api/action/ActionParameterConditionalOverride.d.ts +2 -0
- package/build/types/api/action/ActionParameterConditionalOverride.d.ts.map +1 -1
- package/build/types/api/defineValueType.d.ts +1 -0
- package/build/types/api/defineValueType.d.ts.map +1 -1
- package/build/types/conversion/toMarketplace/convertObject.d.ts.map +1 -1
- package/package.json +3 -3
package/build/cjs/index.d.cts
CHANGED
|
@@ -90,10 +90,12 @@ type ActionParameterConditionalOverride = VisibilityOverride | DisabledOverride
|
|
|
90
90
|
type VisibilityOverride = {
|
|
91
91
|
type: "visibility";
|
|
92
92
|
condition: ConditionDefinition;
|
|
93
|
+
then?: "editable" | "disabled" | "hidden";
|
|
93
94
|
};
|
|
94
95
|
type DisabledOverride = {
|
|
95
96
|
type: "disabled";
|
|
96
97
|
condition: ConditionDefinition;
|
|
98
|
+
then?: "editable" | "disabled" | "hidden";
|
|
97
99
|
};
|
|
98
100
|
type RequiredOverride = {
|
|
99
101
|
type: "required";
|
|
@@ -904,6 +906,7 @@ type ValueTypeDefinition = {
|
|
|
904
906
|
type: NewValueTypeDefinition;
|
|
905
907
|
version: string;
|
|
906
908
|
status?: UserValueTypeStatus;
|
|
909
|
+
namespacePrefix?: boolean;
|
|
907
910
|
};
|
|
908
911
|
type UserValueTypeStatus = "active" | {
|
|
909
912
|
type: "deprecated";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionParameterConditionalOverride.js","names":[],"sources":["ActionParameterConditionalOverride.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 { OntologyIrParameterPrefill } from \"@osdk/client.unstable\";\nimport type { ActionParameterAllowedValues } from \"./ActionParameterAllowedValues.js\";\nimport type { ConditionDefinition } from \"./ConditionDefinition.js\";\n\nexport type ActionParameterConditionalOverride =\n | VisibilityOverride\n | DisabledOverride\n | RequiredOverride\n | DefaultValueOverride\n | ConstraintOverride;\n\nexport type VisibilityOverride = {\n type: \"visibility\";\n condition: ConditionDefinition;\n};\n\nexport type DisabledOverride = {\n type: \"disabled\";\n condition: ConditionDefinition;\n};\n\nexport type RequiredOverride = {\n type: \"required\";\n condition: ConditionDefinition;\n};\n\nexport type DefaultValueOverride = {\n type: \"defaultValue\";\n condition: ConditionDefinition;\n defaultValue: OntologyIrParameterPrefill;\n};\n\nexport type ConstraintOverride = {\n type: \"constraint\";\n condition: ConditionDefinition;\n constraint: ActionParameterAllowedValues;\n};\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ActionParameterConditionalOverride.js","names":[],"sources":["ActionParameterConditionalOverride.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 { OntologyIrParameterPrefill } from \"@osdk/client.unstable\";\nimport type { ActionParameterAllowedValues } from \"./ActionParameterAllowedValues.js\";\nimport type { ConditionDefinition } from \"./ConditionDefinition.js\";\n\nexport type ActionParameterConditionalOverride =\n | VisibilityOverride\n | DisabledOverride\n | RequiredOverride\n | DefaultValueOverride\n | ConstraintOverride;\n\nexport type VisibilityOverride = {\n type: \"visibility\";\n condition: ConditionDefinition;\n then?:\n | \"editable\"\n | \"disabled\"\n | \"hidden\";\n};\n\nexport type DisabledOverride = {\n type: \"disabled\";\n condition: ConditionDefinition;\n then?:\n | \"editable\"\n | \"disabled\"\n | \"hidden\";\n};\n\nexport type RequiredOverride = {\n type: \"required\";\n condition: ConditionDefinition;\n};\n\nexport type DefaultValueOverride = {\n type: \"defaultValue\";\n condition: ConditionDefinition;\n defaultValue: OntologyIrParameterPrefill;\n};\n\nexport type ConstraintOverride = {\n type: \"constraint\";\n condition: ConditionDefinition;\n constraint: ActionParameterAllowedValues;\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import invariant from "tiny-invariant";
|
|
18
18
|
import { OntologyEntityTypeEnum } from "./common/OntologyEntityTypeEnum.js";
|
|
19
|
-
import { namespace, updateOntology } from "./defineOntology.js";
|
|
19
|
+
import { namespace, ontologyDefinition, updateOntology } from "./defineOntology.js";
|
|
20
20
|
function convertValueTypeTypeToBaseType(valueType) {
|
|
21
21
|
if (typeof valueType === "string") {}
|
|
22
22
|
switch (true) {
|
|
@@ -63,13 +63,18 @@ function convertValueTypeTypeToBaseType(valueType) {
|
|
|
63
63
|
}
|
|
64
64
|
export function defineValueType(valueTypeDef) {
|
|
65
65
|
const {
|
|
66
|
-
apiName,
|
|
66
|
+
apiName: inputApiName,
|
|
67
67
|
displayName,
|
|
68
68
|
description,
|
|
69
69
|
type,
|
|
70
|
-
version
|
|
70
|
+
version,
|
|
71
|
+
namespacePrefix
|
|
71
72
|
} = valueTypeDef;
|
|
73
|
+
const apiName = namespacePrefix ? namespace + inputApiName : inputApiName;
|
|
72
74
|
!/^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/.test(version) ? process.env.NODE_ENV !== "production" ? invariant(false, "Version is not a valid semver") : invariant(false) : void 0;
|
|
75
|
+
const existingVersions = ontologyDefinition[OntologyEntityTypeEnum.VALUE_TYPE][apiName] ?? [];
|
|
76
|
+
const duplicateVersion = existingVersions.find(vt => vt.version === version);
|
|
77
|
+
!(duplicateVersion === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Value type with apiName ${apiName} and version ${version} is already defined`) : invariant(false) : void 0;
|
|
73
78
|
const typeName = typeof type.type === "string" ? type.type : type.type.type === "struct" ? "structV2" : type.type.type;
|
|
74
79
|
// These suck but TS doesn't understand the relationship from the key of the base type to the type string
|
|
75
80
|
const constraints = type.constraints ? type.constraints.map(constraint => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineValueType.js","names":["invariant","OntologyEntityTypeEnum","namespace","updateOntology","convertValueTypeTypeToBaseType","valueType","type","array","elementType","structV2","fields","map","field","identifier","baseType","keyType","optional","wrappedType","Error","defineValueType","valueTypeDef","apiName","displayName","description","version","test","process","env","NODE_ENV","typeName","constraints","constraint","output","failureMessage","vt","packageNamespace","substring","length","displayMetadata","status","convertUserValueTypeStatusToValueTypeStatus","exampleValues","__type","VALUE_TYPE","deprecated","message","deadline","replacedBy","active"],"sources":["defineValueType.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 {\n BaseType,\n DataConstraint,\n DataConstraintWrapper,\n FailureMessage,\n ValueTypeDataConstraint,\n ValueTypeRid,\n ValueTypeStatus,\n} from \"@osdk/client.unstable\";\nimport invariant from \"tiny-invariant\";\nimport { OntologyEntityTypeEnum } from \"./common/OntologyEntityTypeEnum.js\";\nimport { namespace, updateOntology } from \"./defineOntology.js\";\nimport { type ValueTypeDefinitionVersion } from \"./values/ValueTypeDefinitionVersion.js\";\nimport { type ValueTypeType } from \"./values/ValueTypeType.js\";\n\ntype ZipBaseAndConstraint<Base, Constraint> = {\n [PropertyType in (BaseType[\"type\"] & DataConstraint[\"type\"])]: Base extends\n { type: PropertyType } ? {\n baseType: Omit<Base, \"type\">;\n constraints?: Constraint extends { type: PropertyType } ? {\n constraint: Omit<Constraint, \"type\">;\n failureMessage?: FailureMessage;\n }[]\n : undefined;\n }\n : never;\n};\n\ntype MappedZip = ZipBaseAndConstraint<BaseType, DataConstraint>;\n\ntype TypeNames = ValueTypeType[\"type\"];\n\ntype ValueTypeDefinitionBacking = {\n [Type in ValueTypeType[\"type\"] & DataConstraint[\"type\"]]: {\n baseType: { \"type\": Extract<ValueTypeType, { type: Type }>[\"value\"] } & {\n constraints: {\n constraint: Extract<\n DataConstraint,\n { type: Type }\n >[keyof Omit<Extract<DataConstraint, { type: Type }>, \"type\">];\n failureMessage?: FailureMessage;\n }[];\n };\n };\n};\n\ntype NewValueTypeDefinitionBacking = {\n [Type in ValueTypeType as Type[\"type\"]]: {\n type: Type[\"value\"];\n constraints?: Type[\"constraints\"];\n };\n};\ntype NewValueTypeDefinition =\n NewValueTypeDefinitionBacking[keyof NewValueTypeDefinitionBacking];\n\nfunction convertValueTypeTypeToBaseType(\n valueType: ValueTypeType[\"value\"],\n): BaseType {\n if (typeof valueType === \"string\") {\n }\n switch (true) {\n case (typeof valueType === \"object\" && valueType.type === \"array\"):\n return {\n type: \"array\",\n array: {\n elementType: convertValueTypeTypeToBaseType(valueType.elementType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"struct\"):\n return {\n type: \"structV2\",\n structV2: {\n fields: valueType.fields.map(field => ({\n identifier: field.identifier,\n baseType: convertValueTypeTypeToBaseType(field.baseType),\n })),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"map\"):\n return {\n type: \"map\",\n map: {\n keyType: convertValueTypeTypeToBaseType(valueType.keyType),\n valueType: convertValueTypeTypeToBaseType(valueType.valueType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"optional\"):\n return {\n type: \"optional\",\n optional: {\n wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType),\n },\n };\n case (typeof valueType === \"string\"):\n return { type: valueType, [valueType]: {} } as any;\n default:\n throw new Error(\"Invalid ValueTypeType\");\n }\n}\n\nexport type ValueTypeDefinition = {\n apiName: string;\n displayName: string;\n description?: string;\n type: NewValueTypeDefinition;\n version: string;\n status?: UserValueTypeStatus;\n};\n\nexport type UserValueTypeStatus = \"active\" | {\n type: \"deprecated\";\n message: string;\n deadline: string;\n replacedBy?: ValueTypeRid;\n};\n\nexport function defineValueType(\n valueTypeDef: ValueTypeDefinition,\n): ValueTypeDefinitionVersion {\n const { apiName, displayName, description, type, version } = valueTypeDef;\n const semverValidation =\n /^((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)$/;\n invariant(semverValidation.test(version), \"Version is not a valid semver\");\n\n const typeName: TypeNames = typeof type.type === \"string\"\n ? type.type\n : type.type.type === \"struct\"\n ? \"structV2\"\n : type.type.type;\n // These suck but TS doesn't understand the relationship from the key of the base type to the type string\n const constraints = type.constraints\n ? type.constraints.map<ValueTypeDataConstraint>(constraint => {\n const output: any = {\n constraint: { type: typeName, [typeName]: constraint.constraint },\n failureMessage: constraint.failureMessage,\n };\n return { constraint: output as DataConstraintWrapper };\n })\n : [];\n\n const baseType: BaseType = convertValueTypeTypeToBaseType(type.type);\n\n const vt: ValueTypeDefinitionVersion = {\n apiName,\n packageNamespace: namespace.substring(0, namespace.length - 1),\n displayMetadata: {\n displayName: displayName,\n description: description ?? \"\",\n },\n status: convertUserValueTypeStatusToValueTypeStatus(valueTypeDef.status),\n version: version,\n baseType: baseType,\n constraints: constraints,\n exampleValues: [],\n __type: OntologyEntityTypeEnum.VALUE_TYPE,\n };\n updateOntology(vt);\n return vt;\n}\n\nexport function convertUserValueTypeStatusToValueTypeStatus(\n status: UserValueTypeStatus | undefined,\n): ValueTypeStatus {\n if (typeof status === \"object\" && status.type === \"deprecated\") {\n return {\n type: \"deprecated\",\n deprecated: {\n message: status.message,\n deadline: status.deadline,\n replacedBy: status.replacedBy,\n },\n };\n }\n return { type: \"active\", active: {} };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SAASC,SAAS,EAAEC,cAAc,QAAQ,qBAAqB;AA4C/D,SAASC,8BAA8BA,CACrCC,SAAiC,EACvB;EACV,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE,CACnC;EACA,QAAQ,IAAI;IACV,KAAM,OAAOA,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,OAAO;MAC/D,OAAO;QACLA,IAAI,EAAE,OAAO;QACbC,KAAK,EAAE;UACLC,WAAW,EAAEJ,8BAA8B,CAACC,SAAS,CAACG,WAAW;QACnE;MACF,CAAC;IACH,KAAM,OAAOH,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,QAAQ;MAChE,OAAO;QACLA,IAAI,EAAE,UAAU;QAChBG,QAAQ,EAAE;UACRC,MAAM,EAAEL,SAAS,CAACK,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;YACrCC,UAAU,EAAED,KAAK,CAACC,UAAU;YAC5BC,QAAQ,EAAEV,8BAA8B,CAACQ,KAAK,CAACE,QAAQ;UACzD,CAAC,CAAC;QACJ;MACF,CAA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C","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineValueType.js","names":["invariant","OntologyEntityTypeEnum","namespace","ontologyDefinition","updateOntology","convertValueTypeTypeToBaseType","valueType","type","array","elementType","structV2","fields","map","field","identifier","baseType","keyType","optional","wrappedType","Error","defineValueType","valueTypeDef","apiName","inputApiName","displayName","description","version","namespacePrefix","test","process","env","NODE_ENV","existingVersions","VALUE_TYPE","duplicateVersion","find","vt","undefined","typeName","constraints","constraint","output","failureMessage","packageNamespace","substring","length","displayMetadata","status","convertUserValueTypeStatusToValueTypeStatus","exampleValues","__type","deprecated","message","deadline","replacedBy","active"],"sources":["defineValueType.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 {\n BaseType,\n DataConstraint,\n DataConstraintWrapper,\n FailureMessage,\n ValueTypeDataConstraint,\n ValueTypeRid,\n ValueTypeStatus,\n} from \"@osdk/client.unstable\";\nimport invariant from \"tiny-invariant\";\nimport { OntologyEntityTypeEnum } from \"./common/OntologyEntityTypeEnum.js\";\nimport {\n namespace,\n ontologyDefinition,\n updateOntology,\n} from \"./defineOntology.js\";\nimport { type ValueTypeDefinitionVersion } from \"./values/ValueTypeDefinitionVersion.js\";\nimport { type ValueTypeType } from \"./values/ValueTypeType.js\";\n\ntype ZipBaseAndConstraint<Base, Constraint> = {\n [PropertyType in (BaseType[\"type\"] & DataConstraint[\"type\"])]: Base extends\n { type: PropertyType } ? {\n baseType: Omit<Base, \"type\">;\n constraints?: Constraint extends { type: PropertyType } ? {\n constraint: Omit<Constraint, \"type\">;\n failureMessage?: FailureMessage;\n }[]\n : undefined;\n }\n : never;\n};\n\ntype MappedZip = ZipBaseAndConstraint<BaseType, DataConstraint>;\n\ntype TypeNames = ValueTypeType[\"type\"];\n\ntype ValueTypeDefinitionBacking = {\n [Type in ValueTypeType[\"type\"] & DataConstraint[\"type\"]]: {\n baseType: { \"type\": Extract<ValueTypeType, { type: Type }>[\"value\"] } & {\n constraints: {\n constraint: Extract<\n DataConstraint,\n { type: Type }\n >[keyof Omit<Extract<DataConstraint, { type: Type }>, \"type\">];\n failureMessage?: FailureMessage;\n }[];\n };\n };\n};\n\ntype NewValueTypeDefinitionBacking = {\n [Type in ValueTypeType as Type[\"type\"]]: {\n type: Type[\"value\"];\n constraints?: Type[\"constraints\"];\n };\n};\ntype NewValueTypeDefinition =\n NewValueTypeDefinitionBacking[keyof NewValueTypeDefinitionBacking];\n\nfunction convertValueTypeTypeToBaseType(\n valueType: ValueTypeType[\"value\"],\n): BaseType {\n if (typeof valueType === \"string\") {\n }\n switch (true) {\n case (typeof valueType === \"object\" && valueType.type === \"array\"):\n return {\n type: \"array\",\n array: {\n elementType: convertValueTypeTypeToBaseType(valueType.elementType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"struct\"):\n return {\n type: \"structV2\",\n structV2: {\n fields: valueType.fields.map(field => ({\n identifier: field.identifier,\n baseType: convertValueTypeTypeToBaseType(field.baseType),\n })),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"map\"):\n return {\n type: \"map\",\n map: {\n keyType: convertValueTypeTypeToBaseType(valueType.keyType),\n valueType: convertValueTypeTypeToBaseType(valueType.valueType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"optional\"):\n return {\n type: \"optional\",\n optional: {\n wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType),\n },\n };\n case (typeof valueType === \"string\"):\n return { type: valueType, [valueType]: {} } as any;\n default:\n throw new Error(\"Invalid ValueTypeType\");\n }\n}\n\nexport type ValueTypeDefinition = {\n apiName: string;\n displayName: string;\n description?: string;\n type: NewValueTypeDefinition;\n version: string;\n status?: UserValueTypeStatus;\n namespacePrefix?: boolean;\n};\n\nexport type UserValueTypeStatus = \"active\" | {\n type: \"deprecated\";\n message: string;\n deadline: string;\n replacedBy?: ValueTypeRid;\n};\n\nexport function defineValueType(\n valueTypeDef: ValueTypeDefinition,\n): ValueTypeDefinitionVersion {\n const {\n apiName: inputApiName,\n displayName,\n description,\n type,\n version,\n namespacePrefix,\n } = valueTypeDef;\n const apiName = namespacePrefix ? namespace + inputApiName : inputApiName;\n const semverValidation =\n /^((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)$/;\n invariant(semverValidation.test(version), \"Version is not a valid semver\");\n\n const existingVersions =\n ontologyDefinition[OntologyEntityTypeEnum.VALUE_TYPE][apiName] ?? [];\n const duplicateVersion = existingVersions.find(vt => vt.version === version);\n invariant(\n duplicateVersion === undefined,\n `Value type with apiName ${apiName} and version ${version} is already defined`,\n );\n\n const typeName: TypeNames = typeof type.type === \"string\"\n ? type.type\n : type.type.type === \"struct\"\n ? \"structV2\"\n : type.type.type;\n // These suck but TS doesn't understand the relationship from the key of the base type to the type string\n const constraints = type.constraints\n ? type.constraints.map<ValueTypeDataConstraint>(constraint => {\n const output: any = {\n constraint: { type: typeName, [typeName]: constraint.constraint },\n failureMessage: constraint.failureMessage,\n };\n return { constraint: output as DataConstraintWrapper };\n })\n : [];\n\n const baseType: BaseType = convertValueTypeTypeToBaseType(type.type);\n\n const vt: ValueTypeDefinitionVersion = {\n apiName,\n packageNamespace: namespace.substring(0, namespace.length - 1),\n displayMetadata: {\n displayName: displayName,\n description: description ?? \"\",\n },\n status: convertUserValueTypeStatusToValueTypeStatus(valueTypeDef.status),\n version: version,\n baseType: baseType,\n constraints: constraints,\n exampleValues: [],\n __type: OntologyEntityTypeEnum.VALUE_TYPE,\n };\n updateOntology(vt);\n return vt;\n}\n\nexport function convertUserValueTypeStatusToValueTypeStatus(\n status: UserValueTypeStatus | undefined,\n): ValueTypeStatus {\n if (typeof status === \"object\" && status.type === \"deprecated\") {\n return {\n type: \"deprecated\",\n deprecated: {\n message: status.message,\n deadline: status.deadline,\n replacedBy: status.replacedBy,\n },\n };\n }\n return { type: \"active\", active: {} };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SACEC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,QACT,qBAAqB;AA4C5B,SAASC,8BAA8BA,CACrCC,SAAiC,EACvB;EACV,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE,CACnC;EACA,QAAQ,IAAI;IACV,KAAM,OAAOA,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,OAAO;MAC/D,OAAO;QACLA,IAAI,EAAE,OAAO;QACbC,KAAK,EAAE;UACLC,WAAW,EAAEJ,8BAA8B,CAACC,SAAS,CAACG,WAAW;QACnE;MACF,CAAC;IACH,KAAM,OAAOH,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,QAAQ;MAChE,OAAO;QACLA,IAAI,EAAE,UAAU;QAChBG,QAAQ,EAAE;UACRC,MAAM,EAAEL,SAAS,CAACK,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;YACrCC,UAAU,EAAED,KAAK,CAACC,UAAU;YAC5BC,QAAQ,EAAEV,8BAA8B,CAACQ,KAAK,CAACE,QAAQ;UACzD,CAAC,CAAC;QACJ;MACF,CAAC;IACH,KAAM,OAAOT,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,KAAK;MAC7D,OAAO;QACLA,IAAI,EAAE,KAAK;QACX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AAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,CAACxC,IAAI,KAAK,YAAY,EAAE;IAC9D,OAAO;MACLA,IAAI,EAAE,YAAY;MAClB4C,UAAU,EAAE;QACVC,OAAO,EAAEL,MAAM,CAACK,OAAO;QACvBC,QAAQ,EAAEN,MAAM,CAACM,QAAQ;QACzBC,UAAU,EAAEP,MAAM,CAACO;MACrB;IACF,CAAC;EACH;EACA,OAAO;IAAE/C,IAAI,EAAE,QAAQ;IAAEgD,MAAM,EAAE,CAAC;EAAE,CAAC;AACvC","ignoreList":[]}
|
|
@@ -1170,18 +1170,21 @@
|
|
|
1170
1170
|
{
|
|
1171
1171
|
"interfaceTypeApiName": "com.palantir.exampleInterface",
|
|
1172
1172
|
"linksV2": {},
|
|
1173
|
-
"properties": {
|
|
1173
|
+
"properties": {},
|
|
1174
|
+
"propertiesV2": {
|
|
1174
1175
|
"com.palantir.mySpt": {
|
|
1175
1176
|
"propertyTypeRid": "bar",
|
|
1176
|
-
|
|
1177
|
-
"com.palantir.property1": {
|
|
1178
|
-
"propertyTypeRid": "property1",
|
|
1177
|
+
"type": "propertyTypeRid",
|
|
1179
1178
|
},
|
|
1180
1179
|
"com.palantir.property2": {
|
|
1181
1180
|
"propertyTypeRid": "property2",
|
|
1181
|
+
"type": "propertyTypeRid",
|
|
1182
|
+
},
|
|
1183
|
+
"property1": {
|
|
1184
|
+
"propertyTypeRid": "property1",
|
|
1185
|
+
"type": "propertyTypeRid",
|
|
1182
1186
|
},
|
|
1183
1187
|
},
|
|
1184
|
-
"propertiesV2": {},
|
|
1185
1188
|
},
|
|
1186
1189
|
],
|
|
1187
1190
|
"primaryKeys": [
|