@osdk/maker 0.11.0-beta.11 → 0.11.0-beta.12
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 +14 -0
- package/build/browser/api/addDependency.js +2 -2
- package/build/browser/api/addDependency.js.map +1 -1
- package/build/browser/api/defineInterface.js +1 -0
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineObject.js +10 -2
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +11 -5
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/overall.test.js +575 -1
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +1 -1
- package/build/cjs/index.cjs +24 -9
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +3 -2
- package/build/esm/api/addDependency.js +2 -2
- package/build/esm/api/addDependency.js.map +1 -1
- package/build/esm/api/defineInterface.js +1 -0
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineObject.js +10 -2
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +11 -5
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/overall.test.js +575 -1
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +1 -1
- package/build/types/api/addDependency.d.ts +1 -1
- package/build/types/api/addDependency.d.ts.map +1 -1
- package/build/types/api/defineInterface.d.ts +1 -0
- package/build/types/api/defineInterface.d.ts.map +1 -1
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/build/types/api/defineOntology.d.ts.map +1 -1
- package/build/types/api/types.d.ts +1 -1
- package/build/types/api/types.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @osdk/maker
|
|
2
2
|
|
|
3
|
+
## 0.11.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1847bcb: Support arrays in OT props
|
|
8
|
+
- 3ae0cfd: Remove import/dep from codegen
|
|
9
|
+
- 7d232fb: Added searchable field to interface definitions
|
|
10
|
+
- 60b0029: Check extended interfaces when validating object property mapping
|
|
11
|
+
- 0abeec3: Make codegen prettier
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @osdk/api@2.3.0-beta.9
|
|
16
|
+
|
|
3
17
|
## 0.11.0-beta.11
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -18,7 +18,7 @@ import * as fs from "fs";
|
|
|
18
18
|
import * as path from "path";
|
|
19
19
|
import { dependencies } from "./defineOntology.js";
|
|
20
20
|
const MAX_SEARCH_DEPTH = 5;
|
|
21
|
-
export function addDependency(
|
|
21
|
+
export function addDependency(namespaceNoDot, fileInPackage) {
|
|
22
22
|
let dir = path.dirname(fileInPackage);
|
|
23
23
|
let packageJsonPath = null;
|
|
24
24
|
for (let i = 0; i < MAX_SEARCH_DEPTH; i++) {
|
|
@@ -35,6 +35,6 @@ export function addDependency(namespace, fileInPackage) {
|
|
|
35
35
|
throw new Error(`Could not find a package.json within ${MAX_SEARCH_DEPTH} parent directories of ${fileInPackage}`);
|
|
36
36
|
}
|
|
37
37
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
38
|
-
dependencies[
|
|
38
|
+
dependencies[namespaceNoDot] = packageJson.version ?? "";
|
|
39
39
|
}
|
|
40
40
|
//# sourceMappingURL=addDependency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addDependency.js","names":["fs","path","dependencies","MAX_SEARCH_DEPTH","addDependency","
|
|
1
|
+
{"version":3,"file":"addDependency.js","names":["fs","path","dependencies","MAX_SEARCH_DEPTH","addDependency","namespaceNoDot","fileInPackage","dir","dirname","packageJsonPath","i","candidate","join","existsSync","parentDir","Error","packageJson","JSON","parse","readFileSync","version"],"sources":["addDependency.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 * as fs from \"fs\";\nimport * as path from \"path\";\nimport { dependencies } from \"./defineOntology.js\";\n\nconst MAX_SEARCH_DEPTH = 5;\n\nexport function addDependency(\n namespaceNoDot: string,\n fileInPackage: string,\n): void {\n let dir = path.dirname(fileInPackage);\n let packageJsonPath = null;\n\n for (let i = 0; i < MAX_SEARCH_DEPTH; i++) {\n const candidate = path.join(dir, \"package.json\");\n if (fs.existsSync(candidate)) {\n packageJsonPath = candidate;\n break;\n }\n const parentDir = path.dirname(dir);\n if (parentDir === dir) break;\n dir = parentDir;\n }\n\n if (!packageJsonPath) {\n throw new Error(\n `Could not find a package.json within ${MAX_SEARCH_DEPTH} parent directories of ${fileInPackage}`,\n );\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n dependencies[namespaceNoDot] = packageJson.version ?? \"\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,EAAE,MAAM,IAAI;AACxB,OAAO,KAAKC,IAAI,MAAM,MAAM;AAC5B,SAASC,YAAY,QAAQ,qBAAqB;AAElD,MAAMC,gBAAgB,GAAG,CAAC;AAE1B,OAAO,SAASC,aAAaA,CAC3BC,cAAsB,EACtBC,aAAqB,EACf;EACN,IAAIC,GAAG,GAAGN,IAAI,CAACO,OAAO,CAACF,aAAa,CAAC;EACrC,IAAIG,eAAe,GAAG,IAAI;EAE1B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,gBAAgB,EAAEO,CAAC,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGV,IAAI,CAACW,IAAI,CAACL,GAAG,EAAE,cAAc,CAAC;IAChD,IAAIP,EAAE,CAACa,UAAU,CAACF,SAAS,CAAC,EAAE;MAC5BF,eAAe,GAAGE,SAAS;MAC3B;IACF;IACA,MAAMG,SAAS,GAAGb,IAAI,CAACO,OAAO,CAACD,GAAG,CAAC;IACnC,IAAIO,SAAS,KAAKP,GAAG,EAAE;IACvBA,GAAG,GAAGO,SAAS;EACjB;EAEA,IAAI,CAACL,eAAe,EAAE;IACpB,MAAM,IAAIM,KAAK,CACb,wCAAwCZ,gBAAgB,0BAA0BG,aAAa,EACjG,CAAC;EACH;EAEA,MAAMU,WAAW,GAAGC,IAAI,CAACC,KAAK,CAAClB,EAAE,CAACmB,YAAY,CAACV,eAAe,EAAE,OAAO,CAAC,CAAC;EACzEP,YAAY,CAACG,cAAc,CAAC,GAAGW,WAAW,CAACI,OAAO,IAAI,EAAE;AAC1D","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineInterface.js","names":["invariant","namespace","ontologyDefinition","updateOntology","withoutNamespace","defineSharedPropertyType","OntologyEntityTypeEnum","defineInterface","interfaceDef","apiName","INTERFACE_TYPE","undefined","process","env","NODE_ENV","properties","Object","fromEntries","entries","map","type","required","sharedPropertyType","unifyBasePropertyDefinition","propertyDefinition","extendsInterfaces","extends","Array","isArray","status","mapSimplifiedStatusToInterfaceTypeStatus","deprecated","message","deadline","fullInterface","displayMetadata","displayName","description","icon","blueprint","color","locator","links","propertiesV2","__type","isPropertyTypeType","v","replacedBy","active","experimental","Error","JSON","stringify","spt","array","unNamespacedTypeApiName","key"],"sources":["defineInterface.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 invariant from \"tiny-invariant\";\nimport {\n namespace,\n ontologyDefinition,\n updateOntology,\n withoutNamespace,\n} from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nimport type { BlueprintIcon } from \"./iconNames.js\";\nimport {\n type InterfaceType,\n type InterfaceTypeStatus,\n OntologyEntityTypeEnum,\n type PropertyTypeType,\n type SharedPropertyType,\n} from \"./types.js\";\n\ntype SimplifiedInterfaceTypeStatus =\n | { type: \"deprecated\"; message: string; deadline: string }\n | { type: \"active\" }\n | { type: \"experimental\" };\n\ntype PropertyBase = SharedPropertyType | PropertyTypeType;\ntype PropertyWithOptional = {\n required: boolean;\n propertyDefinition: PropertyBase;\n};\n\nexport type InterfaceTypeDefinition = {\n apiName: string;\n displayName?: string;\n description?: string;\n icon?: { locator: BlueprintIcon; color: string };\n status?: SimplifiedInterfaceTypeStatus;\n properties?: Record<\n string,\n PropertyBase | PropertyWithOptional\n >;\n extends?: InterfaceType | InterfaceType[];\n};\n\nexport function defineInterface(\n interfaceDef: InterfaceTypeDefinition,\n): InterfaceType {\n const apiName = namespace + interfaceDef.apiName;\n invariant(\n ontologyDefinition[OntologyEntityTypeEnum.INTERFACE_TYPE][apiName]\n === undefined,\n `Interface ${apiName} already exists`,\n );\n\n const properties = Object.fromEntries(\n Object.entries(interfaceDef.properties ?? {}).map<\n [string, { required: boolean; sharedPropertyType: SharedPropertyType }]\n >(\n ([apiName, type]) => {\n if (typeof type === \"object\" && \"propertyDefinition\" in type) {\n return [apiName, {\n required: type.required,\n sharedPropertyType: unifyBasePropertyDefinition(\n namespace,\n apiName,\n type.propertyDefinition,\n ),\n }];\n }\n\n return [apiName, {\n required: true,\n sharedPropertyType: unifyBasePropertyDefinition(\n namespace,\n apiName,\n type,\n ),\n }];\n },\n ),\n );\n\n const extendsInterfaces = interfaceDef.extends\n ? (Array.isArray(interfaceDef.extends)\n ? interfaceDef.extends\n : [interfaceDef.extends])\n : [];\n\n const status: InterfaceTypeStatus = mapSimplifiedStatusToInterfaceTypeStatus(\n interfaceDef.status ?? { type: \"active\" },\n );\n\n invariant(\n status.type !== \"deprecated\"\n || (status.deprecated.message && status.deprecated.deadline),\n `Deprecated status must include message and deadline properties.`,\n );\n\n const fullInterface: InterfaceType = {\n apiName,\n displayMetadata: {\n displayName: interfaceDef.displayName ?? interfaceDef.apiName,\n description: interfaceDef.description ?? interfaceDef.displayName\n ?? interfaceDef.apiName,\n icon: interfaceDef.icon !== undefined\n ? {\n type: \"blueprint\",\n blueprint: {\n color: interfaceDef.icon.color,\n locator: interfaceDef.icon.locator,\n },\n }\n : undefined,\n },\n extendsInterfaces,\n links: [],\n status,\n propertiesV2: properties,\n __type: OntologyEntityTypeEnum.INTERFACE_TYPE,\n };\n\n updateOntology(fullInterface);\n return fullInterface;\n}\n\nfunction isPropertyTypeType(\n v: PropertyTypeType,\n): v is PropertyTypeType {\n return v === \"boolean\" || v === \"byte\"\n || v === \"date\" || v === \"decimal\" || v === \"double\"\n || v === \"float\" || v === \"geopoint\" || v === \"geoshape\"\n || v === \"integer\" || v === \"long\"\n || (typeof v === \"object\" && v.type === \"marking\")\n || v === \"short\" || v === \"string\"\n || v === \"timestamp\";\n}\n\nfunction mapSimplifiedStatusToInterfaceTypeStatus(\n status: SimplifiedInterfaceTypeStatus,\n): InterfaceTypeStatus {\n switch (status.type) {\n case \"deprecated\":\n return {\n type: \"deprecated\",\n deprecated: {\n message: status.message,\n deadline: status.deadline,\n replacedBy: undefined,\n },\n };\n case \"active\":\n return {\n type: \"active\",\n active: {},\n };\n case \"experimental\":\n return {\n type: \"experimental\",\n experimental: {},\n };\n default:\n throw new Error(`Invalid status type: ${(status as any).type}`);\n }\n}\n\nfunction unifyBasePropertyDefinition(\n namespace: string,\n apiName: string,\n type: PropertyBase,\n): SharedPropertyType {\n if (\n typeof type === \"string\"\n || (typeof type === \"object\" && !(\"apiName\" in type))\n ) {\n invariant(\n isPropertyTypeType(type),\n `Invalid data type ${\n JSON.stringify(type)\n } for property ${apiName} on InterfaceType ${apiName}`,\n );\n\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false,\n });\n return spt;\n } else {\n const unNamespacedTypeApiName = withoutNamespace(type.apiName);\n invariant(\n namespace + apiName === type.apiName\n || apiName === unNamespacedTypeApiName,\n `property key and it's apiName must be identical. ${\n JSON.stringify({ key: apiName, apiName: type.apiName })\n }`,\n );\n return type;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,QACX,qBAAqB;AAC5B,SAASC,wBAAwB,QAAQ,gBAAgB;AAEzD,SAGEC,sBAAsB,QAGjB,YAAY;AA0BnB,OAAO,SAASC,eAAeA,CAC7BC,YAAqC,EACtB;EACf,MAAMC,OAAO,GAAGR,SAAS,GAAGO,YAAY,CAACC,OAAO;EAChD,EACEP,kBAAkB,CAACI,sBAAsB,CAACI,cAAc,CAAC,CAACD,OAAO,CAAC,KAC5DE,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAFjBd,SAAS,QAGP,aAAaS,OAAO,iBAAiB,IAHvCT,SAAS;EAMT,MAAMe,UAAU,GAAGC,MAAM,CAACC,WAAW,CACnCD,MAAM,CAACE,OAAO,CAACV,YAAY,CAACO,UAAU,IAAI,CAAC,CAAC,CAAC,CAACI,GAAG,CAG/C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IAAI,EAAE,cAAc;QACpB6B,YAAY,EAAE,CAAC;MACjB,CAAC;IACH;MACE,MAAM,IAAIC,KAAK,CAAC,wBAAyBrB,MAAM,CAAST,IAAI,EAAE,CAAC;EACnE;AACF;AAEA,SAASG,2BAA2BA,CAClCtB,SAAiB,EACjBQ,OAAe,EACfW,IAAkB,EACE;EACpB,IACE,OAAOA,IAAI,KAAK,QAAQ,IACpB,OAAOA,IAAI,KAAK,QAAQ,IAAI,EAAE,SAAS,IAAIA,IAAI,CAAE,EACrD;IACA,CACEyB,kBAAkB,CAACzB,IAAI,CAAC,GAAAR,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1Bd,SAAS,QAEP,qBACEmD,IAAI,CAACC,SAAS,CAAChC,IAAI,CAAC,iBACLX,OAAO,qBAAqBA,OAAO,EAAE,IAJxDT,SAAS;IAOT,MAAMqD,GAAG,GAAGhD,wBAAwB,CAAC;MACnCI,OAAO;MACP2B,WAAW,EAAE3B,OAAO;MACpBW,IAAI;MACJkC,KAAK,EAAE;IACT,CAAC,CAAC;IACF,OAAOD,GAAG;EACZ,CAAC,MAAM;IACL,MAAME,uBAAuB,GAAGnD,gBAAgB,CAACgB,IAAI,CAACX,OAAO,CAAC;IAC9D,EACER,SAAS,GAAGQ,OAAO,KAAKW,IAAI,CAACX,OAAO,IAC/BA,OAAO,KAAK8C,uBAAuB,IAAA3C,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAF1Cd,SAAS,QAGP,oDACEmD,IAAI,CAACC,SAAS,CAAC;MAAEI,GAAG,EAAE/C,OAAO;MAAEA,OAAO,EAAEW,IAAI,CAACX;IAAQ,CAAC,CAAC,EACvD,IALJT,SAAS;IAOT,OAAOoB,IAAI;EACb;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineInterface.js","names":["invariant","namespace","ontologyDefinition","updateOntology","withoutNamespace","defineSharedPropertyType","OntologyEntityTypeEnum","defineInterface","interfaceDef","apiName","INTERFACE_TYPE","undefined","process","env","NODE_ENV","properties","Object","fromEntries","entries","map","type","required","sharedPropertyType","unifyBasePropertyDefinition","propertyDefinition","extendsInterfaces","extends","Array","isArray","status","mapSimplifiedStatusToInterfaceTypeStatus","deprecated","message","deadline","fullInterface","displayMetadata","displayName","description","icon","blueprint","color","locator","links","propertiesV2","searchable","__type","isPropertyTypeType","v","replacedBy","active","experimental","Error","JSON","stringify","spt","array","unNamespacedTypeApiName","key"],"sources":["defineInterface.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 invariant from \"tiny-invariant\";\nimport {\n namespace,\n ontologyDefinition,\n updateOntology,\n withoutNamespace,\n} from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nimport type { BlueprintIcon } from \"./iconNames.js\";\nimport {\n type InterfaceType,\n type InterfaceTypeStatus,\n OntologyEntityTypeEnum,\n type PropertyTypeType,\n type SharedPropertyType,\n} from \"./types.js\";\n\ntype SimplifiedInterfaceTypeStatus =\n | { type: \"deprecated\"; message: string; deadline: string }\n | { type: \"active\" }\n | { type: \"experimental\" };\n\ntype PropertyBase = SharedPropertyType | PropertyTypeType;\ntype PropertyWithOptional = {\n required: boolean;\n propertyDefinition: PropertyBase;\n};\n\nexport type InterfaceTypeDefinition = {\n apiName: string;\n displayName?: string;\n description?: string;\n icon?: { locator: BlueprintIcon; color: string };\n status?: SimplifiedInterfaceTypeStatus;\n properties?: Record<\n string,\n PropertyBase | PropertyWithOptional\n >;\n extends?: InterfaceType | InterfaceType[];\n searchable?: boolean;\n};\n\nexport function defineInterface(\n interfaceDef: InterfaceTypeDefinition,\n): InterfaceType {\n const apiName = namespace + interfaceDef.apiName;\n invariant(\n ontologyDefinition[OntologyEntityTypeEnum.INTERFACE_TYPE][apiName]\n === undefined,\n `Interface ${apiName} already exists`,\n );\n\n const properties = Object.fromEntries(\n Object.entries(interfaceDef.properties ?? {}).map<\n [string, { required: boolean; sharedPropertyType: SharedPropertyType }]\n >(\n ([apiName, type]) => {\n if (typeof type === \"object\" && \"propertyDefinition\" in type) {\n return [apiName, {\n required: type.required,\n sharedPropertyType: unifyBasePropertyDefinition(\n namespace,\n apiName,\n type.propertyDefinition,\n ),\n }];\n }\n\n return [apiName, {\n required: true,\n sharedPropertyType: unifyBasePropertyDefinition(\n namespace,\n apiName,\n type,\n ),\n }];\n },\n ),\n );\n\n const extendsInterfaces = interfaceDef.extends\n ? (Array.isArray(interfaceDef.extends)\n ? interfaceDef.extends\n : [interfaceDef.extends])\n : [];\n\n const status: InterfaceTypeStatus = mapSimplifiedStatusToInterfaceTypeStatus(\n interfaceDef.status ?? { type: \"active\" },\n );\n\n invariant(\n status.type !== \"deprecated\"\n || (status.deprecated.message && status.deprecated.deadline),\n `Deprecated status must include message and deadline properties.`,\n );\n\n const fullInterface: InterfaceType = {\n apiName,\n displayMetadata: {\n displayName: interfaceDef.displayName ?? interfaceDef.apiName,\n description: interfaceDef.description ?? interfaceDef.displayName\n ?? interfaceDef.apiName,\n icon: interfaceDef.icon !== undefined\n ? {\n type: \"blueprint\",\n blueprint: {\n color: interfaceDef.icon.color,\n locator: interfaceDef.icon.locator,\n },\n }\n : undefined,\n },\n extendsInterfaces,\n links: [],\n status,\n propertiesV2: properties,\n searchable: interfaceDef.searchable ?? true,\n __type: OntologyEntityTypeEnum.INTERFACE_TYPE,\n };\n\n updateOntology(fullInterface);\n return fullInterface;\n}\n\nfunction isPropertyTypeType(\n v: PropertyTypeType,\n): v is PropertyTypeType {\n return v === \"boolean\" || v === \"byte\"\n || v === \"date\" || v === \"decimal\" || v === \"double\"\n || v === \"float\" || v === \"geopoint\" || v === \"geoshape\"\n || v === \"integer\" || v === \"long\"\n || (typeof v === \"object\" && v.type === \"marking\")\n || v === \"short\" || v === \"string\"\n || v === \"timestamp\";\n}\n\nfunction mapSimplifiedStatusToInterfaceTypeStatus(\n status: SimplifiedInterfaceTypeStatus,\n): InterfaceTypeStatus {\n switch (status.type) {\n case \"deprecated\":\n return {\n type: \"deprecated\",\n deprecated: {\n message: status.message,\n deadline: status.deadline,\n replacedBy: undefined,\n },\n };\n case \"active\":\n return {\n type: \"active\",\n active: {},\n };\n case \"experimental\":\n return {\n type: \"experimental\",\n experimental: {},\n };\n default:\n throw new Error(`Invalid status type: ${(status as any).type}`);\n }\n}\n\nfunction unifyBasePropertyDefinition(\n namespace: string,\n apiName: string,\n type: PropertyBase,\n): SharedPropertyType {\n if (\n typeof type === \"string\"\n || (typeof type === \"object\" && !(\"apiName\" in type))\n ) {\n invariant(\n isPropertyTypeType(type),\n `Invalid data type ${\n JSON.stringify(type)\n } for property ${apiName} on InterfaceType ${apiName}`,\n );\n\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false,\n });\n return spt;\n } else {\n const unNamespacedTypeApiName = withoutNamespace(type.apiName);\n invariant(\n namespace + apiName === type.apiName\n || apiName === unNamespacedTypeApiName,\n `property key and it's apiName must be identical. ${\n JSON.stringify({ key: apiName, apiName: type.apiName })\n }`,\n );\n return type;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,QACX,qBAAqB;AAC5B,SAASC,wBAAwB,QAAQ,gBAAgB;AAEzD,SAGEC,sBAAsB,QAGjB,YAAY;AA2BnB,OAAO,SAASC,eAAeA,CAC7BC,YAAqC,EACtB;EACf,MAAMC,OAA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IAC/BA,OAAO,KAAK+C,uBAAuB,IAAA5C,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAF1Cd,SAAS,QAGP,oDACEoD,IAAI,CAACC,SAAS,CAAC;MAAEI,GAAG,EAAEhD,OAAO;MAAEA,OAAO,EAAEW,IAAI,CAACX;IAAQ,CAAC,CAAC,EACvD,IALJT,SAAS;IAOT,OAAOoB,IAAI;EACb;AACF","ignoreList":[]}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import invariant from "tiny-invariant";
|
|
18
|
-
import { extractNamespace, namespace, ontologyDefinition, updateOntology } from "./defineOntology.js";
|
|
18
|
+
import { extractNamespace, namespace, ontologyDefinition, updateOntology, withoutNamespace } from "./defineOntology.js";
|
|
19
19
|
import { OntologyEntityTypeEnum } from "./types.js";
|
|
20
20
|
|
|
21
21
|
// From https://stackoverflow.com/a/79288714
|
|
@@ -49,7 +49,8 @@ export function defineObject(objectDef) {
|
|
|
49
49
|
!(objectDef.properties ?? []).filter(p => p.apiName === objectDef.titlePropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} must be a primitive type`) : invariant(false) : void 0;
|
|
50
50
|
!(objectDef.properties ?? []).filter(p => p.apiName === objectDef.primaryKeyPropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`) : invariant(false) : void 0;
|
|
51
51
|
objectDef.implementsInterfaces?.forEach(interfaceImpl => {
|
|
52
|
-
const
|
|
52
|
+
const allInterfaceProperties = getAllInterfacePropertiesNoNamespace(interfaceImpl.implements);
|
|
53
|
+
const nonExistentInterfaceProperties = interfaceImpl.propertyMapping.map(val => val.interfaceProperty).filter(interfaceProperty => allInterfaceProperties[interfaceProperty] === undefined).map(interfaceProp => ({
|
|
53
54
|
type: "invalid",
|
|
54
55
|
reason: `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`
|
|
55
56
|
}));
|
|
@@ -119,4 +120,11 @@ export function convertToDisplayName(s) {
|
|
|
119
120
|
export function convertToPluralDisplayName(s) {
|
|
120
121
|
return s === undefined || s == null ? "" : s.endsWith("s") ? convertToDisplayName(s) : convertToDisplayName(s) + "s";
|
|
121
122
|
}
|
|
123
|
+
function getAllInterfacePropertiesNoNamespace(interfaceType) {
|
|
124
|
+
const localProperties = Object.fromEntries(Object.entries(interfaceType.propertiesV2).map(([apiName, property]) => [withoutNamespace(apiName), property]));
|
|
125
|
+
return interfaceType.extendsInterfaces.reduce((acc, ext) => ({
|
|
126
|
+
...getAllInterfacePropertiesNoNamespace(ext),
|
|
127
|
+
...acc
|
|
128
|
+
}), localProperties);
|
|
129
|
+
}
|
|
122
130
|
//# sourceMappingURL=defineObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineObject.js","names":["invariant","extractNamespace","namespace","ontologyDefinition","updateOntology","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","OBJECT_TYPE","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","filter","p","every","editOnly","retentionPeriod","datasource","test","status","activeProperties","property","length","join","type","deadline","isExotic","implementsInterfaces","forEach","interfaceImpl","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","implements","propertiesV2","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","extendsValidations","extendsInterfaces","flatMap","interfaceType","allFailedValidations","concat","formatValidationErrors","finalObject","__type","error","spt","mappedObjectProp","object","objProp","find","prop","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith"],"sources":["defineObject.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 invariant from \"tiny-invariant\";\nimport {\n extractNamespace,\n namespace,\n ontologyDefinition,\n updateOntology,\n} from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n ObjectType,\n ObjectTypeDefinition,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\n// ISO 8601 date and time format (YYYY-MM-DDThh:mm:ss.sssZ)\nconst ISO_8601_DATETIME =\n /^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\n\nexport function defineObject(\n objectDef: ObjectTypeDefinition,\n): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (\n ontologyDefinition[OntologyEntityTypeEnum.OBJECT_TYPE][apiName]\n !== undefined\n ) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n propertyApiNames.includes(objectDef.primaryKeyPropertyApiName),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`,\n );\n\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !p.editOnly),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`,\n );\n\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n\n // Validate that if object status is experimental, no property can have a status of active\n if (objectDef.status === \"experimental\") {\n const activeProperties = (objectDef.properties ?? [])\n .filter(property => property.status === \"active\")\n .map(property => property.apiName);\n\n invariant(\n activeProperties.length === 0,\n `When object \"${objectDef.apiName}\" has experimental status, no properties can have \"active\" status, but found active properties: ${\n activeProperties.join(\", \")\n }`,\n );\n }\n\n // Validate deprecated status deadline is in ISO 8601 format\n if (\n objectDef.status && typeof objectDef.status === \"object\"\n && objectDef.status.type === \"deprecated\"\n ) {\n const deadline = objectDef.status.deadline;\n invariant(\n deadline !== undefined && ISO_8601_DATETIME.test(deadline),\n `Deprecated status deadline \"${deadline}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 datetime string`,\n );\n }\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n interfaceImpl.implements.propertiesV2[interfaceProperty]\n === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(\n interfaceImpl.implements.propertiesV2,\n )\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceType =>\n Object.entries(interfaceType.propertiesV2).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n\n interfaceImpl.propertyMapping = interfaceImpl.propertyMapping.map((\n mapping,\n ) => ({\n interfaceProperty: extractNamespace(interfaceImpl.implements.apiName)\n + mapping.interfaceProperty,\n mapsTo: mapping.mapsTo,\n }));\n });\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n };\n updateOntology(finalObject);\n return finalObject;\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectTypeDefinition,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n\nexport function convertToDisplayName(s: string | undefined | null): string {\n return s === undefined || s == null\n ? \"\"\n : s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n// TODO: edge cases\nexport function convertToPluralDisplayName(\n s: string | undefined | null,\n): string {\n return s === undefined || s == null\n ? \"\"\n : s.endsWith(\"s\")\n ? convertToDisplayName(s)\n : convertToDisplayName(s) + \"s\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,gBAAgB,EAChBC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,Q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H;EACA,IAAID,GAAG,CAAClC,IAAI,KAAKqC,OAAO,EAAErC,IAAI,EAAE;IAC9B,OAAO;MACLA,IAAI,EAAE,SAAS;MACfY,MAAM,EACJ,mGAAmGsB,GAAG,CAAC5D,OAAO,qBAAqB6D,gBAAgB;IACvJ,CAAC;EACH;EAEA,OAAO;IAAEnC,IAAI,EAAE;EAAQ,CAAC;AAC1B;AAEA,OAAO,SAASwC,oBAAoBA,CAACC,CAA4B,EAAU;EACzE,OAAOA,CAAC,KAAK7D,SAAS,IAAI6D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,CAAC,CAACG,KAAK,CAAC,CAAC,CAAC;AAC5C;;AAEA;AACA,OAAO,SAASC,0BAA0BA,CACxCJ,CAA4B,EACpB;EACR,OAAOA,CAAC,KAAK7D,SAAS,IAAI6D,CAAC,IAAI,IAAI,GAC/B,EAAE,GACFA,CAAC,CAACK,QAAQ,CAAC,GAAG,CAAC,GACfN,oBAAoB,CAACC,CAAC,CAAC,GACvBD,oBAAoB,CAACC,CAAC,CAAC,GAAG,GAAG;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineObject.js","names":["invariant","extractNamespace","namespace","ontologyDefinition","updateOntology","withoutNamespace","OntologyEntityTypeEnum","ISO_8601_DURATION","ISO_8601_DATETIME","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","OBJECT_TYPE","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","filter","p","every","editOnly","retentionPeriod","datasource","test","status","activeProperties","property","length","join","type","deadline","isExotic","implementsInterfaces","forEach","interfaceImpl","allInterfaceProperties","getAllInterfacePropertiesNoNamespace","implements","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","propertiesV2","extendsValidations","extendsInterfaces","flatMap","interfaceType","allFailedValidations","concat","formatValidationErrors","finalObject","__type","error","spt","mappedObjectProp","object","objProp","find","prop","convertToDisplayName","s","charAt","toUpperCase","slice","convertToPluralDisplayName","endsWith","localProperties","reduce","acc","ext"],"sources":["defineObject.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 invariant from \"tiny-invariant\";\nimport {\n extractNamespace,\n namespace,\n ontologyDefinition,\n updateOntology,\n withoutNamespace,\n} from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n InterfaceType,\n ObjectType,\n ObjectTypeDefinition,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\n// ISO 8601 date and time format (YYYY-MM-DDThh:mm:ss.sssZ)\nconst ISO_8601_DATETIME =\n /^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?)?$/;\n\nexport function defineObject(\n objectDef: ObjectTypeDefinition,\n): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (\n ontologyDefinition[OntologyEntityTypeEnum.OBJECT_TYPE][apiName]\n !== undefined\n ) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n propertyApiNames.includes(objectDef.primaryKeyPropertyApiName),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`,\n );\n\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !p.editOnly),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`,\n );\n\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n\n // Validate that if object status is experimental, no property can have a status of active\n if (objectDef.status === \"experimental\") {\n const activeProperties = (objectDef.properties ?? [])\n .filter(property => property.status === \"active\")\n .map(property => property.apiName);\n\n invariant(\n activeProperties.length === 0,\n `When object \"${objectDef.apiName}\" has experimental status, no properties can have \"active\" status, but found active properties: ${\n activeProperties.join(\", \")\n }`,\n );\n }\n\n // Validate deprecated status deadline is in ISO 8601 format\n if (\n objectDef.status && typeof objectDef.status === \"object\"\n && objectDef.status.type === \"deprecated\"\n ) {\n const deadline = objectDef.status.deadline;\n invariant(\n deadline !== undefined && ISO_8601_DATETIME.test(deadline),\n `Deprecated status deadline \"${deadline}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 datetime string`,\n );\n }\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const allInterfaceProperties = getAllInterfacePropertiesNoNamespace(\n interfaceImpl.implements,\n );\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n allInterfaceProperties[interfaceProperty] === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(\n interfaceImpl.implements.propertiesV2,\n )\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceType =>\n Object.entries(interfaceType.propertiesV2).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n\n interfaceImpl.propertyMapping = interfaceImpl.propertyMapping.map((\n mapping,\n ) => ({\n interfaceProperty: extractNamespace(interfaceImpl.implements.apiName)\n + mapping.interfaceProperty,\n mapsTo: mapping.mapsTo,\n }));\n });\n\n const finalObject: ObjectType = {\n ...objectDef,\n apiName: apiName,\n __type: OntologyEntityTypeEnum.OBJECT_TYPE,\n };\n updateOntology(finalObject);\n return finalObject;\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectTypeDefinition,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n\nexport function convertToDisplayName(s: string | undefined | null): string {\n return s === undefined || s == null\n ? \"\"\n : s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n// TODO: edge cases\nexport function convertToPluralDisplayName(\n s: string | undefined | null,\n): string {\n return s === undefined || s == null\n ? \"\"\n : s.endsWith(\"s\")\n ? convertToDisplayName(s)\n : convertToDisplayName(s) + \"s\";\n}\n\nfunction getAllInterfacePropertiesNoNamespace(\n interfaceType: InterfaceType,\n): Record<string, InterfacePropertyType> {\n const localProperties = Object.fromEntries(\n Object.entries(interfaceType.propertiesV2).map(([apiName, property]) => [\n withoutNamespace(apiName),\n property,\n ]),\n );\n\n return interfaceType.extendsInterfaces.reduce(\n (acc, ext) => ({ ...getAllInterfacePropertiesNoNamespace(ext), ...acc }),\n localProperties,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,gBAAgB,EAChBC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,QACX,qBAAqB;AAU5B,SAASC,sBAAsB,QAAQ,YAAY;;AAEnD;AACA,MAAMC,iBAAiB,GACrB,+OAA+O;;AAEjP;AACA,MAAMC,iBAAiB,GACrB,sEAAsE;AAExE,OAAO,SAASC,YAAYA,CAC1BC,SAA+B,EACnB;EACZ,MAAMC,OAAO,GAAGT,SAAS,GAAGQ,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC;EAC7E,IACER,kBAAkB,CAACG,sBAAsB,CAACU,WAAW,CAAC,CAACL,OAAO,CAAC,KACzDM,SAAS,EACf;IACA,MAAM,IAAIC,KAAK,CACb,4BAA4BR,SAAS,CAACC,OAAO,qBAC/C,CAAC;EACH;EACA,CACEC,gBAAgB,CAACO,QAAQ,CAACT,SAAS,CAACU,oBAAoB,CAAC,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD3DvB,SAAS,QAEP,kB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ACFA,CAAC,CAACK,QAAQ,CAAC,GAAG,CAAC,GACfN,oBAAoB,CAACC,CAAC,CAAC,GACvBD,oBAAoB,CAACC,CAAC,CAAC,GAAG,GAAG;AACnC;AAEA,SAASpC,oCAAoCA,CAC3CsB,aAA4B,EACW;EACvC,MAAMoB,eAAe,GAAGlC,MAAM,CAACC,WAAW,CACxCD,MAAM,CAACS,OAAO,CAACK,aAAa,CAACJ,YAAY,CAAC,CAAChD,GAAG,CAAC,CAAC,CAACH,OAAO,EAAEuB,QAAQ,CAAC,KAAK,CACtE7B,gBAAgB,CAACM,OAAO,CAAC,EACzBuB,QAAQ,CACT,CACH,CAAC;EAED,OAAOgC,aAAa,CAACF,iBAAiB,CAACuB,MAAM,CAC3C,CAACC,GAAG,EAAEC,GAAG,MAAM;IAAE,GAAG7C,oCAAoC,CAAC6C,GAAG,CAAC;IAAE,GAAGD;EAAI,CAAC,CAAC,EACxEF,eACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -445,7 +445,12 @@ function convertProperty(property) {
|
|
|
445
445
|
indexedForSearch: property.indexedForSearch ?? true,
|
|
446
446
|
ruleSetBinding: undefined,
|
|
447
447
|
baseFormatter: property.baseFormatter,
|
|
448
|
-
type:
|
|
448
|
+
type: property.array ? {
|
|
449
|
+
type: "array",
|
|
450
|
+
array: {
|
|
451
|
+
subtype: convertType(property.type)
|
|
452
|
+
}
|
|
453
|
+
} : convertType(property.type),
|
|
449
454
|
typeClasses: property.typeClasses ?? (shouldNotHaveRenderHints(property.type) ? [] : defaultTypeClasses),
|
|
450
455
|
status: convertObjectStatus(property.status),
|
|
451
456
|
inlineAction: undefined,
|
|
@@ -584,6 +589,9 @@ function convertInterface(interfaceType) {
|
|
|
584
589
|
allLinks: [],
|
|
585
590
|
allProperties: [],
|
|
586
591
|
allPropertiesV2: {},
|
|
592
|
+
// TODO(mwalther): Support propertiesV3
|
|
593
|
+
propertiesV3: {},
|
|
594
|
+
allPropertiesV3: {},
|
|
587
595
|
properties: []
|
|
588
596
|
};
|
|
589
597
|
}
|
|
@@ -1038,11 +1046,9 @@ function writeDependencyFile(dependencyFile) {
|
|
|
1038
1046
|
}
|
|
1039
1047
|
function dependencyInjectionString() {
|
|
1040
1048
|
const namespaceNoDot = namespace.endsWith(".") ? namespace.slice(0, -1) : namespace;
|
|
1041
|
-
return `
|
|
1042
|
-
import { fileURLToPath } from "url";
|
|
1043
|
-
import { addDependency } from '@osdk/maker';
|
|
1049
|
+
return `import { addDependency } from "@osdk/maker";
|
|
1044
1050
|
|
|
1045
|
-
addDependency("${namespaceNoDot}",
|
|
1051
|
+
addDependency("${namespaceNoDot}", new URL(import.meta.url).pathname);
|
|
1046
1052
|
`;
|
|
1047
1053
|
}
|
|
1048
1054
|
//# sourceMappingURL=defineOntology.js.map
|