@osdk/maker 0.15.0-beta.4 → 0.15.0-beta.6

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.
@@ -24,7 +24,7 @@ import { defineOntology } from "../api/defineOntology.js";
24
24
  const apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
25
25
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
26
26
  export default async function main(args = process.argv) {
27
- const commandLineOpts = await yargs(hideBin(args)).version("0.15.0-beta.4" ?? "").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
27
+ const commandLineOpts = await yargs(hideBin(args)).version("0.15.0-beta.6" ?? "").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
28
28
  input: {
29
29
  alias: "i",
30
30
  describe: "Input file",
@@ -405,16 +405,38 @@ function validateDerivedDatasource(objectDef, datasource) {
405
405
  });
406
406
  const isLinkedProperties = typeof Object.values(datasource.propertyMapping)[0] === "string";
407
407
  if (isLinkedProperties) {
408
- validateLinkedProperties(datasource);
408
+ validateLinkedProperties(datasource, objectDef);
409
409
  } else {
410
410
  validateAggregations(datasource, objectDef);
411
411
  }
412
412
  }
413
+ function getPropertiesForValidation(linkObject, objectDef) {
414
+ const targetApiName = typeof linkObject === "string" ? linkObject : linkObject.apiName;
415
+ const selfApiName = namespace + objectDef.apiName;
416
+ if (targetApiName === selfApiName) {
417
+ return {
418
+ apiName: selfApiName,
419
+ hasProperty: (propName) => objectDef.properties?.[propName] !== void 0
420
+ };
421
+ }
422
+ const {
423
+ apiName,
424
+ object
425
+ } = getObject(linkObject);
426
+ return {
427
+ apiName,
428
+ hasProperty: (propName) => object.properties?.find((p) => p.apiName === propName) !== void 0
429
+ };
430
+ }
413
431
  function validateLinkedProperties(datasource, objectDef) {
414
432
  const foreignProperties = Object.values(datasource.propertyMapping);
415
- const finalObject = getObject(datasource.linkDefinition.at(-1).linkType.toMany.object).object;
433
+ const targetObject = datasource.linkDefinition.at(-1).linkType.toMany.object;
434
+ const {
435
+ apiName,
436
+ hasProperty
437
+ } = getPropertiesForValidation(targetObject, objectDef);
416
438
  foreignProperties.forEach((prop) => {
417
- !(finalObject.properties?.find((p) => p.apiName === prop) !== void 0) ? process.env.NODE_ENV !== "production" ? invariant7__default.default(false, `Property '${prop}' on object '${finalObject.apiName}' is not defined`) : invariant7__default.default(false) : void 0;
439
+ !hasProperty(prop) ? process.env.NODE_ENV !== "production" ? invariant7__default.default(false, `Property '${prop}' on object '${apiName}' is not defined`) : invariant7__default.default(false) : void 0;
418
440
  });
419
441
  }
420
442
  function validateAggregations(datasource, objectDef) {
@@ -440,8 +462,12 @@ function validateAggregations(datasource, objectDef) {
440
462
  }
441
463
  if (agg.type !== "count") {
442
464
  const foreignProperty = agg.property;
443
- const finalObject = getObject(datasource.linkDefinition.at(-1).linkType.toMany.object).object;
444
- !(finalObject.properties?.find((p) => p.apiName === foreignProperty) !== void 0) ? process.env.NODE_ENV !== "production" ? invariant7__default.default(false, `Property '${foreignProperty}' on object '${finalObject.apiName}' is not defined`) : invariant7__default.default(false) : void 0;
465
+ const targetObject = datasource.linkDefinition.at(-1).linkType.toMany.object;
466
+ const {
467
+ apiName,
468
+ hasProperty
469
+ } = getPropertiesForValidation(targetObject, objectDef);
470
+ !hasProperty(foreignProperty) ? process.env.NODE_ENV !== "production" ? invariant7__default.default(false, `Property '${foreignProperty}' on object '${apiName}' is not defined`) : invariant7__default.default(false) : void 0;
445
471
  }
446
472
  });
447
473
  }
@@ -2081,7 +2107,7 @@ function addNamespaceIfNone(apiName) {
2081
2107
  var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
2082
2108
  var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
2083
2109
  async function main(args = process.argv) {
2084
- const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.15.0-beta.4").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
2110
+ const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.15.0-beta.6").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
2085
2111
  input: {
2086
2112
  alias: "i",
2087
2113
  describe: "Input file",
@@ -3045,7 +3071,7 @@ function defineCreateOrModifyObjectAction(def) {
3045
3071
  }
3046
3072
  const parameters = createParameters(def, def.objectType.properties ?? {}, parameterNames);
3047
3073
  parameters.forEach((p) => {
3048
- if (p.id !== CREATE_OR_MODIFY_OBJECT_PARAMETER && p.defaultValue === void 0) {
3074
+ if (def.objectType.properties?.[p.id] && p.defaultValue === void 0) {
3049
3075
  p.defaultValue = {
3050
3076
  type: "objectParameterPropertyValue",
3051
3077
  objectParameterPropertyValue: {
@@ -3468,7 +3494,7 @@ function defineModifyObjectAction(def) {
3468
3494
  }
3469
3495
  const parameters = createParameters(def, def.objectType.properties ?? {}, parameterNames);
3470
3496
  parameters.forEach((p) => {
3471
- if (p.id !== MODIFY_OBJECT_PARAMETER && p.defaultValue === void 0) {
3497
+ if (def.objectType.properties?.[p.id] && p.defaultValue === void 0) {
3472
3498
  p.defaultValue = {
3473
3499
  type: "objectParameterPropertyValue",
3474
3500
  objectParameterPropertyValue: {