@osdk/maker 0.9.0-beta.14 → 0.9.0-beta.16

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,23 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.9.0-beta.16
4
+
5
+ ### Minor Changes
6
+
7
+ - 0a4f131: Fix value types so they actually serialize correctly.
8
+ - 8e5e49a: Add optional link constraints
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [e5fe7c0]
13
+ - @osdk/api@2.1.0-beta.16
14
+
15
+ ## 0.9.0-beta.15
16
+
17
+ ### Patch Changes
18
+
19
+ - @osdk/api@2.1.0-beta.15
20
+
3
21
  ## 0.9.0-beta.14
4
22
 
5
23
  ### Minor Changes
@@ -7,6 +7,7 @@ type Many = {
7
7
  toOne?: never;
8
8
  displayName?: string;
9
9
  description?: string;
10
+ required?: boolean;
10
11
  };
11
12
  type One = {
12
13
  apiName: string;
@@ -15,6 +16,7 @@ type One = {
15
16
  toMany?: never;
16
17
  displayName?: string;
17
18
  description?: string;
19
+ required?: boolean;
18
20
  };
19
21
  export declare function defineInterfaceLinkConstraint(linkDef: One | Many): void;
20
22
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,sBAAsB,GAAG,MAAM,GAAG,aAAa,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,GAAG,GAAG,IAAI,QAgBpB"}
1
+ {"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,sBAAsB,GAAG,MAAM,GAAG,aAAa,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,GAAG,GAAG,IAAI,QAgBpB"}
@@ -22,7 +22,7 @@ export function defineInterfaceLinkConstraint(linkDef) {
22
22
  cardinality: linkDef.toMany ? "MANY" : "SINGLE",
23
23
  linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
24
24
  metadata: fromLinkMeta,
25
- required: true // TODO: expose this?
25
+ required: linkDef.required ?? true
26
26
  });
27
27
  }
28
28
  function getLinkedType(t) {
@@ -1 +1 @@
1
- {"version":3,"file":"defineInterfaceLinkConstraint.js","names":["invariant","namespace","defineInterfaceLinkConstraint","linkDef","fromLinkMeta","getLinkMeta","from","links","find","a","metadata","apiName","process","env","NODE_ENV","push","cardinality","toMany","linkedEntityTypeId","getLinkedType","toOne","required","t","type","interfaceType","meta","withDefaults","description","displayName"],"sources":["defineInterfaceLinkConstraint.js"],"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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace } from \"./defineOntology.js\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n invariant(linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName)\n == null, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`);\n linkDef.from.links.push({\n cardinality: linkDef.toMany ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),\n metadata: fromLinkMeta,\n required: true, // TODO: expose this?\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: typeof t === \"string\" ? t : t.apiName,\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\"\n ? withDefaults({ apiName: namespace + meta })\n : withDefaults(meta);\n}\nfunction withDefaults({ apiName, description, displayName }) {\n return {\n apiName: namespace + apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,OAAO,SAASC,6BAA6BA,CAACC,OAAO,EAAE;EACnD,MAAMC,YAAY,GAAGC,WAAW,CAACF,OAAO,CAAC;EACzC,EAAUA,OAAO,CAACG,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAACC,OAAO,KAAKP,YAAY,CAACO,OAAO,CAAC,IAC5E,IAAI,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADXd,SAAS,QACI,qBAAqBI,YAAY,CAACO,OAAO,sBAAsBR,OAAO,CAACQ,OAAO,EAAE,IAD7FX,SAAS;EAETG,OAAO,CAACG,IAAI,CAACC,KAAK,CAACQ,IAAI,CAAC;IACpBC,WAAW,EAAEb,OAAO,CAACc,MAAM,GAAG,MAAM,GAAG,QAAQ;IAC/CC,kBAAkB,EAAEC,aAAa,CAAChB,OAAO,CAACc,MAAM,IAAId,OAAO,CAACiB,KAAK,CAAC;IAClEV,QAAQ,EAAEN,YAAY;IACtBiB,QAAQ,EAAE,IAAI,CAAE;EACpB,CAAC,CAAC;AACN;AACA,SAASF,aAAaA,CAACG,CAAC,EAAE;EACtB,OAAO;IACHC,IAAI,EAAE,eAAe;IACrBC,aAAa,EAAE,OAAOF,CAAC,KAAK,QAAQ,GAAGA,CAAC,GAAGA,CAAC,CAACX;EACjD,CAAC;AACL;AACA,SAASN,WAAWA,CAACoB,IAAI,EAAE;EACvB,OAAO,OAAOA,IAAI,KAAK,QAAQ,GACzBC,YAAY,CAAC;IAAEf,OAAO,EAAEV,SAAS,GAAGwB;EAAK,CAAC,CAAC,GAC3CC,YAAY,CAACD,IAAI,CAAC;AAC5B;AACA,SAASC,YAAYA,CAAC;EAAEf,OAAO;EAAEgB,WAAW;EAAEC;AAAY,CAAC,EAAE;EACzD,OAAO;IACHjB,OAAO,EAAEV,SAAS,GAAGU,OAAO;IAC5BiB,WAAW,EAAEA,WAAW,IAAIjB,OAAO;IACnCgB,WAAW,EAAEA,WAAW,IAAIC,WAAW,IAAIjB;EAC/C,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"defineInterfaceLinkConstraint.js","names":["invariant","namespace","defineInterfaceLinkConstraint","linkDef","fromLinkMeta","getLinkMeta","from","links","find","a","metadata","apiName","process","env","NODE_ENV","push","cardinality","toMany","linkedEntityTypeId","getLinkedType","toOne","required","t","type","interfaceType","meta","withDefaults","description","displayName"],"sources":["defineInterfaceLinkConstraint.js"],"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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace } from \"./defineOntology.js\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n invariant(linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName)\n == null, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`);\n linkDef.from.links.push({\n cardinality: linkDef.toMany ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),\n metadata: fromLinkMeta,\n required: linkDef.required ?? true,\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: typeof t === \"string\" ? t : t.apiName,\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\"\n ? withDefaults({ apiName: namespace + meta })\n : withDefaults(meta);\n}\nfunction withDefaults({ apiName, description, displayName }) {\n return {\n apiName: namespace + apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,OAAO,SAASC,6BAA6BA,CAACC,OAAO,EAAE;EACnD,MAAMC,YAAY,GAAGC,WAAW,CAACF,OAAO,CAAC;EACzC,EAAUA,OAAO,CAACG,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAACC,OAAO,KAAKP,YAAY,CAACO,OAAO,CAAC,IAC5E,IAAI,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADXd,SAAS,QACI,qBAAqBI,YAAY,CAACO,OAAO,sBAAsBR,OAAO,CAACQ,OAAO,EAAE,IAD7FX,SAAS;EAETG,OAAO,CAACG,IAAI,CAACC,KAAK,CAACQ,IAAI,CAAC;IACpBC,WAAW,EAAEb,OAAO,CAACc,MAAM,GAAG,MAAM,GAAG,QAAQ;IAC/CC,kBAAkB,EAAEC,aAAa,CAAChB,OAAO,CAACc,MAAM,IAAId,OAAO,CAACiB,KAAK,CAAC;IAClEV,QAAQ,EAAEN,YAAY;IACtBiB,QAAQ,EAAElB,OAAO,CAACkB,QAAQ,IAAI;EAClC,CAAC,CAAC;AACN;AACA,SAASF,aAAaA,CAACG,CAAC,EAAE;EACtB,OAAO;IACHC,IAAI,EAAE,eAAe;IACrBC,aAAa,EAAE,OAAOF,CAAC,KAAK,QAAQ,GAAGA,CAAC,GAAGA,CAAC,CAACX;EACjD,CAAC;AACL;AACA,SAASN,WAAWA,CAACoB,IAAI,EAAE;EACvB,OAAO,OAAOA,IAAI,KAAK,QAAQ,GACzBC,YAAY,CAAC;IAAEf,OAAO,EAAEV,SAAS,GAAGwB;EAAK,CAAC,CAAC,GAC3CC,YAAY,CAACD,IAAI,CAAC;AAC5B;AACA,SAASC,YAAYA,CAAC;EAAEf,OAAO;EAAEgB,WAAW;EAAEC;AAAY,CAAC,EAAE;EACzD,OAAO;IACHjB,OAAO,EAAEV,SAAS,GAAGU,OAAO;IAC5BiB,WAAW,EAAEA,WAAW,IAAIjB,OAAO;IACnCgB,WAAW,EAAEA,WAAW,IAAIC,WAAW,IAAIjB;EAC/C,CAAC;AACL","ignoreList":[]}
@@ -1,25 +1,16 @@
1
- import type { BaseType, DataConstraint, FailureMessage } from "@osdk/client.unstable";
2
- import type { ValueTypeDefinitionVersion } from "./types.js";
3
- type ZipBaseAndConstraint<Base, Constraint> = {
4
- [PropertyType in (BaseType["type"] & DataConstraint["type"])]: Base extends {
5
- type: PropertyType;
6
- } ? {
7
- baseType: Omit<Base, "type">;
8
- constraints?: Constraint extends {
9
- type: PropertyType;
10
- } ? {
11
- constraint: Omit<Constraint, "type">;
12
- failureMessage?: FailureMessage;
13
- }[] : undefined;
14
- } : never;
1
+ import type { ValueTypeDefinitionVersion, ValueTypeType } from "./types.js";
2
+ type NewValueTypeDefinitionBacking = {
3
+ [Type in ValueTypeType as Type["type"]]: {
4
+ type: Type["value"];
5
+ constraints?: Type["constraints"];
6
+ };
15
7
  };
16
- type MappedZip = ZipBaseAndConstraint<BaseType, DataConstraint>;
17
- type TypeAndConstraints = MappedZip[keyof MappedZip];
8
+ type NewValueTypeDefinition = NewValueTypeDefinitionBacking[keyof NewValueTypeDefinitionBacking];
18
9
  export declare function defineValueType(opts: {
19
10
  apiName: string;
20
11
  displayName: string;
21
12
  description?: string;
22
- typeAndConstraints: TypeAndConstraints;
13
+ type: NewValueTypeDefinition;
23
14
  version: string;
24
15
  }): ValueTypeDefinitionVersion;
25
16
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"defineValueType.d.ts","sourceRoot":"","sources":["../../../src/api/defineValueType.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE7D,KAAK,oBAAoB,CAAC,IAAI,EAAE,UAAU,IAAI;KAC3C,YAAY,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,SACjE;QAAE,IAAI,EAAE,YAAY,CAAA;KAAE,GAAG;QACvB,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7B,WAAW,CAAC,EAAE,UAAU,SAAS;YAAE,IAAI,EAAE,YAAY,CAAA;SAAE,GAAG;YACtD,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACrC,cAAc,CAAC,EAAE,cAAc,CAAC;SACjC,EAAE,GACD,SAAS,CAAC;KACf,GACC,KAAK;CACV,CAAC;AAEF,KAAK,SAAS,GAAG,oBAAoB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAEhE,KAAK,kBAAkB,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC;AACrD,wBAAgB,eAAe,CAC7B,IAAI,EAAE;IACJ,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB,GACA,0BAA0B,CA2C5B"}
1
+ {"version":3,"file":"defineValueType.d.ts","sourceRoot":"","sources":["../../../src/api/defineValueType.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,aAAa,EACd,MAAM,YAAY,CAAC;AAiCpB,KAAK,6BAA6B,GAAG;KAClC,IAAI,IAAI,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG;QACvC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KACnC;CACF,CAAC;AACF,KAAK,sBAAsB,GACzB,6BAA6B,CAAC,MAAM,6BAA6B,CAAC,CAAC;AA+CrE,wBAAgB,eAAe,CAC7B,IAAI,EAAE;IACJ,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB,GACA,0BAA0B,CAyC5B"}
@@ -15,28 +15,74 @@
15
15
  */
16
16
  import invariant from "tiny-invariant";
17
17
  import { ontologyDefinition } from "./defineOntology.js";
18
+ function convertValueTypeTypeToBaseType(valueType) {
19
+ if (typeof valueType === "string") {}
20
+ switch (true) {
21
+ case typeof valueType === "object" && valueType.type === "array":
22
+ return {
23
+ type: "array",
24
+ array: {
25
+ elementType: convertValueTypeTypeToBaseType(valueType.elementType)
26
+ }
27
+ };
28
+ case typeof valueType === "object" && valueType.type === "struct":
29
+ return {
30
+ type: "structV2",
31
+ structV2: {
32
+ fields: valueType.fields.map(field => ({
33
+ identifier: field.identifier,
34
+ baseType: convertValueTypeTypeToBaseType(field.baseType)
35
+ }))
36
+ }
37
+ };
38
+ case typeof valueType === "object" && valueType.type === "map":
39
+ return {
40
+ type: "map",
41
+ map: {
42
+ keyType: convertValueTypeTypeToBaseType(valueType.keyType),
43
+ valueType: convertValueTypeTypeToBaseType(valueType.valueType)
44
+ }
45
+ };
46
+ case typeof valueType === "object" && valueType.type === "optional":
47
+ return {
48
+ type: "optional",
49
+ optional: {
50
+ wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType)
51
+ }
52
+ };
53
+ case typeof valueType === "string":
54
+ return {
55
+ type: valueType,
56
+ [valueType]: {}
57
+ };
58
+ default:
59
+ throw new Error("Invalid ValueTypeType");
60
+ }
61
+ }
18
62
  export function defineValueType(opts) {
19
63
  const {
20
64
  apiName,
21
65
  displayName,
22
66
  description,
23
- typeAndConstraints,
67
+ type,
24
68
  version
25
69
  } = opts;
26
70
  !/^((([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;
71
+ const typeName = typeof type.type === "string" ? type.type : type.type.type === "struct" ? "structV2" : type.type.type;
27
72
  // These suck but TS doesn't understand the relationship from the key of the base type to the type string
28
- const constraints = typeAndConstraints.constraints ? typeAndConstraints.constraints.map(constraint => {
29
- return {
73
+ const constraints = type.constraints ? type.constraints.map(constraint => {
74
+ const output = {
30
75
  constraint: {
31
- [Object.keys(constraint["constraint"])[0]]: Object.keys(constraint["constraint"])[0],
32
- ...constraint
33
- }
76
+ type: typeName,
77
+ [typeName]: constraint.constraint
78
+ },
79
+ failureMessage: constraint.failureMessage
80
+ };
81
+ return {
82
+ constraint: output
34
83
  };
35
84
  }) : [];
36
- const baseType = {
37
- [Object.keys(typeAndConstraints.baseType)[0]]: Object.keys(typeAndConstraints.baseType)[0],
38
- ...typeAndConstraints.baseType
39
- };
85
+ const baseType = convertValueTypeTypeToBaseType(type.type);
40
86
  const vt = {
41
87
  apiName,
42
88
  displayMetadata: {
@@ -1 +1 @@
1
- {"version":3,"file":"defineValueType.js","names":["invariant","ontologyDefinition","defineValueType","opts","apiName","displayName","description","typeAndConstraints","version","test","process","env","NODE_ENV","constraints","map","constraint","Object","keys","baseType","vt","displayMetadata","status","type","active","exampleValues","valueTypes","undefined","push"],"sources":["defineValueType.js"],"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 */\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineValueType(opts) {\n const { apiName, displayName, description, typeAndConstraints, version } = opts;\n const semverValidation = /^((([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 // These suck but TS doesn't understand the relationship from the key of the base type to the type string\n const constraints = typeAndConstraints.constraints\n ? typeAndConstraints.constraints.map(constraint => {\n return {\n constraint: {\n [Object.keys(constraint[\"constraint\"])[0]]: Object.keys(constraint[\"constraint\"])[0],\n ...constraint,\n },\n };\n })\n : [];\n const baseType = {\n [Object.keys(typeAndConstraints.baseType)[0]]: Object.keys(typeAndConstraints.baseType)[0],\n ...typeAndConstraints.baseType,\n };\n const vt = {\n apiName,\n displayMetadata: {\n displayName: displayName,\n description: description ?? \"\",\n },\n status: { type: \"active\", active: {} },\n version: version,\n baseType: baseType,\n constraints: constraints,\n exampleValues: [],\n };\n if (ontologyDefinition.valueTypes[apiName] === undefined) {\n ontologyDefinition.valueTypes[apiName] = [];\n }\n ontologyDefinition.valueTypes[apiName].push(vt);\n return vt;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kB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,CAACwB,UAAU,CAACrB,OAAO,CAAC,KAAKsB,SAAS,EAAE;IACtDzB,kBAAkB,CAACwB,UAAU,CAACrB,OAAO,CAAC,GAAG,EAAE;EAC/C;EACAH,kBAAkB,CAACwB,UAAU,CAACrB,OAAO,CAAC,CAACuB,IAAI,CAACR,EAAE,CAAC;EAC/C,OAAOA,EAAE;AACb","ignoreList":[]}
1
+ {"version":3,"file":"defineValueType.js","names":["invariant","ontologyDefinition","convertValueTypeTypeToBaseType","valueType","type","array","elementType","structV2","fields","map","field","identifier","baseType","keyType","optional","wrappedType","Error","defineValueType","opts","apiName","displayName","description","version","test","process","env","NODE_ENV","typeName","constraints","constraint","output","failureMessage","vt","displayMetadata","status","active","exampleValues","valueTypes","undefined","push"],"sources":["defineValueType.js"],"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 */\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nfunction convertValueTypeTypeToBaseType(valueType) {\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]: {} };\n default:\n throw new Error(\"Invalid ValueTypeType\");\n }\n}\nexport function defineValueType(opts) {\n const { apiName, displayName, description, type, version } = opts;\n const semverValidation = /^((([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 const typeName = 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(constraint => {\n const output = {\n constraint: { type: typeName, [typeName]: constraint.constraint },\n failureMessage: constraint.failureMessage,\n };\n return { constraint: output };\n })\n : [];\n const baseType = convertValueTypeTypeToBaseType(type.type);\n const vt = {\n apiName,\n displayMetadata: {\n displayName: displayName,\n description: description ?? \"\",\n },\n status: { type: \"active\", active: {} },\n version: version,\n baseType: baseType,\n constraints: constraints,\n exampleValues: [],\n };\n if (ontologyDefinition.valueTypes[apiName] === undefined) {\n ontologyDefinition.valueTypes[apiName] = [];\n }\n ontologyDefinition.valueTypes[apiName].push(vt);\n return vt;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,8BAA8BA,CAACC,SAAS,EAAE;EAC/C,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE,CACnC;E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AC,KAAKmB,SAAS,EAAE;IACtDrC,kBAAkB,CAACoC,UAAU,CAAClB,OAAO,CAAC,GAAG,EAAE;EAC/C;EACAlB,kBAAkB,CAACoC,UAAU,CAAClB,OAAO,CAAC,CAACoB,IAAI,CAACP,EAAE,CAAC;EAC/C,OAAOA,EAAE;AACb","ignoreList":[]}
@@ -29,15 +29,11 @@ describe("Ontology Defining", () => {
29
29
  expect(() => defineValueType({
30
30
  apiName: "apiName",
31
31
  displayName: "displayName",
32
- typeAndConstraints: {
33
- baseType: {
34
- boolean: {}
35
- },
32
+ type: {
33
+ "type": "boolean",
36
34
  constraints: [{
37
35
  constraint: {
38
- boolean: {
39
- allowedValues: ["TRUE_VALUE"]
40
- }
36
+ "allowedValues": ["TRUE_VALUE"]
41
37
  }
42
38
  }]
43
39
  },
@@ -48,61 +44,59 @@ describe("Ontology Defining", () => {
48
44
  defineValueType({
49
45
  apiName: "apiName",
50
46
  displayName: "displayName",
51
- typeAndConstraints: {
52
- baseType: {
53
- boolean: {}
54
- },
47
+ type: {
48
+ "type": "boolean",
55
49
  constraints: [{
56
50
  constraint: {
57
- boolean: {
58
- allowedValues: ["TRUE_VALUE"]
59
- }
51
+ "allowedValues": ["TRUE_VALUE"]
60
52
  }
61
53
  }]
62
54
  },
63
55
  version: "0.1.0"
64
56
  });
65
57
  expect(dumpValueTypeWireType()).toMatchInlineSnapshot(`
58
+ {
59
+ "valueTypes": [
60
+ {
61
+ "metadata": {
62
+ "apiName": "apiName",
63
+ "displayMetadata": {
64
+ "description": "",
65
+ "displayName": "displayName",
66
+ },
67
+ "status": {
68
+ "active": {},
69
+ "type": "active",
70
+ },
71
+ },
72
+ "versions": [
66
73
  {
67
- "valueTypes": [
68
- {
69
- "metadata": {
70
- "apiName": "apiName",
71
- "displayMetadata": {
72
- "description": "",
73
- "displayName": "displayName",
74
- },
75
- "status": {
76
- "active": {},
77
- "type": "active",
78
- },
79
- },
80
- "versions": [
81
- {
82
- "baseType": {
83
- "boolean": {},
84
- },
85
- "constraints": [
86
- {
87
- "constraint": {
88
- "boolean": "boolean",
89
- "constraint": {
90
- "boolean": {
91
- "allowedValues": [
92
- "TRUE_VALUE",
93
- ],
94
- },
95
- },
96
- },
97
- },
98
- ],
99
- "exampleValues": [],
100
- "version": "0.1.0",
101
- },
102
- ],
103
- },
104
- ],
105
- }
74
+ "baseType": {
75
+ "boolean": {},
76
+ "type": "boolean",
77
+ },
78
+ "constraints": [
79
+ {
80
+ "constraint": {
81
+ "constraint": {
82
+ "boolean": {
83
+ "allowedValues": [
84
+ "TRUE_VALUE",
85
+ ],
86
+ },
87
+ "type": "boolean",
88
+ },
89
+ "failureMessage": undefined,
90
+ },
91
+ },
92
+ ],
93
+ "exampleValues": [],
94
+ "version": "0.1.0",
95
+ },
96
+ ],
97
+ },
98
+ ],
99
+ }
106
100
  `);
107
101
  });
108
102
  defineOntology("com.palantir.", () => {});