@osdk/maker 0.11.0-beta.7 → 0.11.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.11.0-beta.9
4
+
5
+ ### Minor Changes
6
+
7
+ - 508ecd6: Improve defineLink syntax
8
+
9
+ ## 0.11.0-beta.8
10
+
11
+ ### Minor Changes
12
+
13
+ - f8db93d: improve media upload (beta)
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [f8db93d]
18
+ - @osdk/api@2.3.0-beta.7
19
+
3
20
  ## 0.11.0-beta.7
4
21
 
5
22
  ### Minor Changes
package/README.md CHANGED
@@ -568,29 +568,22 @@ const departmentToEmployeesLink = defineLink({
568
568
  one: {
569
569
  object: departmentObject, // The "one" side of the relationship
570
570
  metadata: {
571
- displayMetadata: {
572
- displayName: "Department",
573
- pluralDisplayName: "Departments",
574
- visibility: "NORMAL",
575
- },
576
571
  apiName: "department",
577
- typeClasses: [],
572
+ displayName: "Department",
573
+ pluralDisplayName: "Departments",
574
+ visibility: "NORMAL",
578
575
  },
579
576
  },
580
577
  toMany: {
581
578
  object: employeeObject, // The "many" side of the relationship
582
579
  metadata: {
583
- displayMetadata: {
584
- displayName: "Employee",
585
- pluralDisplayName: "Employees",
586
- visibility: "NORMAL",
587
- },
588
580
  apiName: "employees",
589
- typeClasses: [],
581
+ displayName: "Employee",
582
+ pluralDisplayName: "Employees",
583
+ visibility: "NORMAL",
590
584
  },
591
585
  },
592
586
  manyForeignKeyProperty: "departmentId", // Property on employeeObject that refers to departmentObject
593
- cardinality: "OneToMany",
594
587
  });
595
588
  ```
596
589
 
@@ -603,25 +596,19 @@ const productToCategoriesLink = defineLink({
603
596
  many: {
604
597
  object: productObject, // One side of the many-to-many relationship
605
598
  metadata: {
606
- displayMetadata: {
607
- displayName: "Product",
608
- pluralDisplayName: "Products",
609
- visibility: "NORMAL",
610
- },
611
599
  apiName: "products",
612
- typeClasses: [],
600
+ displayName: "Product",
601
+ pluralDisplayName: "Products",
602
+ visibility: "NORMAL",
613
603
  },
614
604
  },
615
605
  toMany: {
616
606
  object: categoryObject, // Other side of the many-to-many relationship
617
607
  metadata: {
618
- displayMetadata: {
619
- displayName: "Category",
620
- pluralDisplayName: "Categories",
621
- visibility: "NORMAL",
622
- },
623
608
  apiName: "categories",
624
- typeClasses: [],
609
+ displayName: "Category",
610
+ pluralDisplayName: "Categories",
611
+ visibility: "NORMAL",
625
612
  },
626
613
  },
627
614
  });
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import invariant from "tiny-invariant";
18
+ import { convertToDisplayName, convertToPluralDisplayName } from "./defineObject.js";
18
19
  import { updateOntology } from "./defineOntology.js";
19
20
  import { OntologyEntityTypeEnum } from "./types.js";
20
21
  const typeIdPattern = /([a-z][a-z0-9\\-]*)/;
@@ -26,11 +27,45 @@ export function defineLink(linkDefinition) {
26
27
  const typesMatch = foreignKey.type === linkDefinition.one.object.properties?.find(prop => prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName)?.type;
27
28
  !typesMatch ? process.env.NODE_ENV !== "production" ? invariant(false, `Link ${linkDefinition.apiName} has type mismatch between the one side's primary key and the foreign key on the many side`) : invariant(false) : void 0;
28
29
  }
29
- const linkType = {
30
+ const fullLinkDefinition = "one" in linkDefinition ? {
31
+ ...linkDefinition,
32
+ one: convertUserOneToManyLinkDefinition(linkDefinition.one),
33
+ toMany: convertUserOneToManyLinkDefinition(linkDefinition.toMany)
34
+ } : {
30
35
  ...linkDefinition,
36
+ many: convertUserManyToManyLinkDefinition(linkDefinition.many),
37
+ toMany: convertUserManyToManyLinkDefinition(linkDefinition.toMany)
38
+ };
39
+ const linkType = {
40
+ cardinality: "one" in linkDefinition ? "OneToMany" : undefined,
41
+ ...fullLinkDefinition,
31
42
  __type: OntologyEntityTypeEnum.LINK_TYPE
32
43
  };
33
44
  updateOntology(linkType);
34
45
  return linkType;
35
46
  }
47
+ function convertUserOneToManyLinkDefinition(oneToMany) {
48
+ return {
49
+ ...oneToMany,
50
+ metadata: convertLinkTypeMetadata(oneToMany.metadata)
51
+ };
52
+ }
53
+ function convertUserManyToManyLinkDefinition(manyToMany) {
54
+ return {
55
+ ...manyToMany,
56
+ metadata: convertLinkTypeMetadata(manyToMany.metadata)
57
+ };
58
+ }
59
+ function convertLinkTypeMetadata(metadata) {
60
+ return {
61
+ apiName: metadata.apiName,
62
+ displayMetadata: {
63
+ displayName: metadata.displayName ?? convertToDisplayName(metadata.apiName),
64
+ pluralDisplayName: metadata.pluralDisplayName ?? convertToPluralDisplayName(metadata.apiName),
65
+ visibility: metadata.visibility ?? "NORMAL",
66
+ groupDisplayName: metadata.groupDisplayName ?? ""
67
+ },
68
+ typeClasses: []
69
+ };
70
+ }
36
71
  //# sourceMappingURL=defineLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineLink.js","names":["invariant","updateOntology","OntologyEntityTypeEnum","typeIdPattern","defineLink","linkDefinition","foreignKey","toMany","object","properties","find","prop","apiName","manyForeignKeyProperty","undefined","process","env","NODE_ENV","test","typesMatch","type","one","primaryKeyPropertyApiName","linkType","__type","LINK_TYPE"],"sources":["defineLink.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 invariant from \"tiny-invariant\";\nimport { updateOntology } from \"./defineOntology.js\";\nimport type { LinkType, LinkTypeDefinition } from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\nconst typeIdPattern = /([a-z][a-z0-9\\\\-]*)/;\n\nexport function defineLink(\n linkDefinition: LinkTypeDefinition,\n): LinkType {\n if (\"one\" in linkDefinition) {\n const foreignKey = linkDefinition.toMany.object.properties?.find(prop =>\n prop.apiName === linkDefinition.manyForeignKeyProperty\n );\n invariant(\n foreignKey !== undefined,\n `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.apiName} does not exist on object ${linkDefinition.toMany.object.apiName}}`,\n );\n\n invariant(\n typeIdPattern.test(linkDefinition.apiName),\n `Top level link api names are expected to match the regex pattern ([a-z][a-z0-9\\\\-]*) ${linkDefinition.apiName} does not match`,\n );\n\n const typesMatch =\n foreignKey.type === linkDefinition.one.object.properties?.find(prop =>\n prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName\n )?.type;\n invariant(\n typesMatch,\n `Link ${linkDefinition.apiName} has type mismatch between the one side's primary key and the foreign key on the many side`,\n );\n }\n const linkType: LinkType = {\n ...linkDefinition,\n __type: OntologyEntityTypeEnum.LINK_TYPE,\n };\n updateOntology(linkType);\n return linkType;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,cAAc,QAAQ,qBAAqB;AAEpD,SAASC,sBAAsB,QAAQ,YAAY;AAEnD,MAAMC,aAAa,GAAG,qBAAqB;AAE3C,OAAO,SAASC,UAAUA,CACxBC,cAAkC,EACxB;EACV,IAAI,KAAK,IAAIA,cAAc,EAAE;IAC3B,MAAMC,UAAU,GAAGD,cAAc,CAACE,MAAM,CAACC,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACnEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACQ,sBAClC,CAAC;IACD,EACEP,UAAU,KAAKQ,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1BjB,SAAS,QAEP,eAAeK,cAAc,CAACQ,sBAAsB,YAAYR,cAAc,CAACO,OAAO,6BAA6BP,cAAc,CAACE,MAAM,CAACC,MAAM,CAACI,OAAO,GAAG,IAF5JZ,SAAS;IAKT,CACEG,aAAa,CAACe,IAAI,CAACb,cAAc,CAACO,OAAO,CAAC,GAAAG,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD5CjB,SAAS,QAEP,wFAAwFK,cAAc,CAACO,OAAO,iBAAiB,IAFjIZ,SAAS;IAKT,MAAMmB,UAAU,GACdb,UAAU,CAACc,IAAI,KAAKf,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACjEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACc,yBAC7C,CAAC,EAAEF,IAAI;IACT,CACED,UAAU,GAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADZjB,SAAS,QAEP,QAAQK,cAAc,CAACO,OAAO,4FAA4F,IAF5HZ,SAAS;EAIX;EACA,MAAMuB,QAAkB,GAAG;IACzB,GAAGlB,cAAc;IACjBmB,MAAM,EAAEtB,sBAAsB,CAACuB;EACjC,CAAC;EACDxB,cAAc,CAACsB,QAAQ,CAAC;EACxB,OAAOA,QAAQ;AACjB","ignoreList":[]}
1
+ {"version":3,"file":"defineLink.js","names":["invariant","convertToDisplayName","convertToPluralDisplayName","updateOntology","OntologyEntityTypeEnum","typeIdPattern","defineLink","linkDefinition","foreignKey","toMany","object","properties","find","prop","apiName","manyForeignKeyProperty","undefined","process","env","NODE_ENV","test","typesMatch","type","one","primaryKeyPropertyApiName","fullLinkDefinition","convertUserOneToManyLinkDefinition","many","convertUserManyToManyLinkDefinition","linkType","cardinality","__type","LINK_TYPE","oneToMany","metadata","convertLinkTypeMetadata","manyToMany","displayMetadata","displayName","pluralDisplayName","visibility","groupDisplayName","typeClasses"],"sources":["defineLink.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 { LinkTypeMetadata } from \"@osdk/client.unstable\";\nimport invariant from \"tiny-invariant\";\nimport {\n convertToDisplayName,\n convertToPluralDisplayName,\n} from \"./defineObject.js\";\nimport { updateOntology } from \"./defineOntology.js\";\nimport type {\n LinkType,\n LinkTypeDefinition,\n LinkTypeMetadataUserDefinition,\n ManyToManyObjectLinkReference,\n ManyToManyObjectLinkReferenceUserDefinition,\n OneToManyObjectLinkReference,\n OneToManyObjectLinkReferenceUserDefinition,\n} from \"./types.js\";\nimport { OntologyEntityTypeEnum } from \"./types.js\";\n\nconst typeIdPattern = /([a-z][a-z0-9\\\\-]*)/;\n\nexport function defineLink(\n linkDefinition: LinkTypeDefinition,\n): LinkType {\n if (\"one\" in linkDefinition) {\n const foreignKey = linkDefinition.toMany.object.properties?.find(prop =>\n prop.apiName === linkDefinition.manyForeignKeyProperty\n );\n invariant(\n foreignKey !== undefined,\n `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.apiName} does not exist on object ${linkDefinition.toMany.object.apiName}}`,\n );\n\n invariant(\n typeIdPattern.test(linkDefinition.apiName),\n `Top level link api names are expected to match the regex pattern ([a-z][a-z0-9\\\\-]*) ${linkDefinition.apiName} does not match`,\n );\n\n const typesMatch =\n foreignKey.type === linkDefinition.one.object.properties?.find(prop =>\n prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName\n )?.type;\n invariant(\n typesMatch,\n `Link ${linkDefinition.apiName} has type mismatch between the one side's primary key and the foreign key on the many side`,\n );\n }\n const fullLinkDefinition = \"one\" in linkDefinition\n ? {\n ...linkDefinition,\n one: convertUserOneToManyLinkDefinition(linkDefinition.one),\n toMany: convertUserOneToManyLinkDefinition(linkDefinition.toMany),\n }\n : {\n ...linkDefinition,\n many: convertUserManyToManyLinkDefinition(linkDefinition.many),\n toMany: convertUserManyToManyLinkDefinition(linkDefinition.toMany),\n };\n const linkType: LinkType = {\n cardinality: \"one\" in linkDefinition ? \"OneToMany\" : undefined,\n ...fullLinkDefinition,\n __type: OntologyEntityTypeEnum.LINK_TYPE,\n };\n updateOntology(linkType);\n return linkType;\n}\n\nfunction convertUserOneToManyLinkDefinition(\n oneToMany: OneToManyObjectLinkReferenceUserDefinition,\n): OneToManyObjectLinkReference {\n return {\n ...oneToMany,\n metadata: convertLinkTypeMetadata(oneToMany.metadata),\n };\n}\n\nfunction convertUserManyToManyLinkDefinition(\n manyToMany: ManyToManyObjectLinkReferenceUserDefinition,\n): ManyToManyObjectLinkReference {\n return {\n ...manyToMany,\n metadata: convertLinkTypeMetadata(manyToMany.metadata),\n };\n}\n\nfunction convertLinkTypeMetadata(\n metadata: LinkTypeMetadataUserDefinition,\n): LinkTypeMetadata {\n return {\n apiName: metadata.apiName,\n displayMetadata: {\n displayName: metadata.displayName\n ?? convertToDisplayName(metadata.apiName),\n pluralDisplayName: metadata.pluralDisplayName\n ?? convertToPluralDisplayName(metadata.apiName),\n visibility: metadata.visibility ?? \"NORMAL\",\n groupDisplayName: metadata.groupDisplayName ?? \"\",\n },\n typeClasses: [],\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SACEC,oBAAoB,EACpBC,0BAA0B,QACrB,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,qBAAqB;AAUpD,SAASC,sBAAsB,QAAQ,YAAY;AAEnD,MAAMC,aAAa,GAAG,qBAAqB;AAE3C,OAAO,SAASC,UAAUA,C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IAAI,CAAC;IAC9DlB,MAAM,EAAEmB,mCAAmC,CAACrB,cAAc,CAACE,MAAM;EACnE,CAAC;EACH,MAAMoB,QAAkB,GAAG;IACzBC,WAAW,EAAE,KAAK,IAAIvB,cAAc,GAAG,WAAW,GAAGS,SAAS;IAC9D,GAAGS,kBAAkB;IACrBM,MAAM,EAAE3B,sBAAsB,CAAC4B;EACjC,CAAC;EACD7B,cAAc,CAAC0B,QAAQ,CAAC;EACxB,OAAOA,QAAQ;AACjB;AAEA,SAASH,kCAAkCA,CACzCO,SAAqD,EACvB;EAC9B,OAAO;IACL,GAAGA,SAAS;IACZC,QAAQ,EAAEC,uBAAuB,CAACF,SAAS,CAACC,QAAQ;EACtD,CAAC;AACH;AAEA,SAASN,mCAAmCA,CAC1CQ,UAAuD,EACxB;EAC/B,OAAO;IACL,GAAGA,UAAU;IACbF,QAAQ,EAAEC,uBAAuB,CAACC,UAAU,CAACF,QAAQ;EACvD,CAAC;AACH;AAEA,SAASC,uBAAuBA,CAC9BD,QAAwC,EACtB;EAClB,OAAO;IACLpB,OAAO,EAAEoB,QAAQ,CAACpB,OAAO;IACzBuB,eAAe,EAAE;MACfC,WAAW,EAAEJ,QAAQ,CAACI,WAAW,IAC5BrC,oBAAoB,CAACiC,QAAQ,CAACpB,OAAO,CAAC;MAC3CyB,iBAAiB,EAAEL,QAAQ,CAACK,iBAAiB,IACxCrC,0BAA0B,CAACgC,QAAQ,CAACpB,OAAO,CAAC;MACjD0B,UAAU,EAAEN,QAAQ,CAACM,UAAU,IAAI,QAAQ;MAC3CC,gBAAgB,EAAEP,QAAQ,CAACO,gBAAgB,IAAI;IACjD,CAAC;IACDC,WAAW,EAAE;EACf,CAAC;AACH","ignoreList":[]}
@@ -111,4 +111,12 @@ function validateInterfaceImplProperty(spt, mappedObjectProp, object) {
111
111
  type: "valid"
112
112
  };
113
113
  }
114
+ export function convertToDisplayName(s) {
115
+ return s === undefined || s == null ? "" : s.charAt(0).toUpperCase() + s.slice(1);
116
+ }
117
+
118
+ // TODO: edge cases
119
+ export function convertToPluralDisplayName(s) {
120
+ return s === undefined || s == null ? "" : s.endsWith("s") ? convertToDisplayName(s) : convertToDisplayName(s) + "s";
121
+ }
114
122
  //# 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"],"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"],"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,QACT,qBAAqB;AAS5B,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,GAAGR,SAAS,GAAGO,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC;EAC7E,IACEP,kBAAkB,CAACE,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,oBAD3DtB,SAAS,QAEP,kBAAkBS,SAAS,CAACU,oBAAoB,6BAA6BV,SAAS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nD,OAAOA,IAAI,CAACA,IAAI,KAAK,SAAS,IAAIA,IAAI,CAACA,IAAI,KAAK,QAAQ;EAC1D;EACA,OAAO,KAAK;AACd;AAIA,SAAS8B,sBAAsBA,CAC7BG,KAA0C,EAClC;EACR,OAAO,8BAA8BA,KAAK,CAACrB,MAAM,IAAI;AACvD;;AAEA;AACA,SAASS,6BAA6BA,CACpCa,GAAuB,EACvBC,gBAAwB,EACxBC,MAA4B,EACV;EAClB,MAAMC,OAAO,GAAGD,MAAM,CAAC5D,UAAU,EAAE8D,IAAI,CAACC,IAAI,IAC1CA,IAAI,CAACjE,OAAO,KAAK6D,gBACnB,CAAC;EACD,IAAIE,OAAO,KAAKzD,SAAS,EAAE;IACzB,OAAO;MACLoB,IAAI,EAAE,SAAS;MACfY,MAAM,EACJ,+EAA+EuB,gBAAgB;IACnG,CAAC;EACH;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","ignoreList":[]}
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 : convertToD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