industrial-model 0.11.1 → 0.11.3

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.
@@ -216434,6 +216434,11 @@ var CogniteSdkAdapter = class {
216434
216434
  }))
216435
216435
  };
216436
216436
  }
216437
+ async retrieveViews(ids) {
216438
+ const cleanIds = ids.map(({ space, externalId, version }) => ({ space, externalId, version }));
216439
+ const response = await this.client.views.retrieve(cleanIds);
216440
+ return { items: response.items };
216441
+ }
216437
216442
  async queryInstances(request) {
216438
216443
  const response = await this.client.instances.query(
216439
216444
  request
@@ -216552,6 +216557,22 @@ function mapDatapointResult(item) {
216552
216557
  };
216553
216558
  }
216554
216559
 
216560
+ // src/utils/view.ts
216561
+ function isViewPropertyDefinition(p) {
216562
+ return "container" in p;
216563
+ }
216564
+ function isReverseDirectRelation(p) {
216565
+ return "through" in p;
216566
+ }
216567
+ function isEdgeConnection(p) {
216568
+ return !isViewPropertyDefinition(p) && !isReverseDirectRelation(p) && "source" in p;
216569
+ }
216570
+ function getDirectRelationSource(p) {
216571
+ const type = p.type;
216572
+ if (type.type === "direct" && type.source) return type.source;
216573
+ return void 0;
216574
+ }
216575
+
216555
216576
  // src/mappers/view-mapper.ts
216556
216577
  var ViewMapper = class {
216557
216578
  constructor(cognite, dataModelId) {
@@ -216598,9 +216619,44 @@ var ViewMapper = class {
216598
216619
  for (const view of dm.views ?? []) {
216599
216620
  views.set(view.externalId, view);
216600
216621
  }
216622
+ await this.loadDependencyViews(views);
216601
216623
  return views;
216602
216624
  }
216625
+ async loadDependencyViews(views) {
216626
+ const pending = /* @__PURE__ */ new Map();
216627
+ for (const view of views.values()) {
216628
+ for (const property of Object.values(view.properties)) {
216629
+ for (const ref of collectPropertyRefs(property)) {
216630
+ if (!views.has(ref.externalId) && !pending.has(ref.externalId)) {
216631
+ pending.set(ref.externalId, ref);
216632
+ }
216633
+ }
216634
+ }
216635
+ }
216636
+ if (pending.size === 0) return;
216637
+ const sizeBefore = views.size;
216638
+ const fetched = await this.cognite.retrieveViews(Array.from(pending.values()));
216639
+ for (const view of fetched.items) {
216640
+ views.set(view.externalId, view);
216641
+ }
216642
+ if (views.size > sizeBefore) {
216643
+ await this.loadDependencyViews(views);
216644
+ }
216645
+ }
216603
216646
  };
216647
+ function collectPropertyRefs(property) {
216648
+ if (isViewPropertyDefinition(property)) {
216649
+ const source = getDirectRelationSource(property);
216650
+ return source ? [source] : [];
216651
+ }
216652
+ if (isReverseDirectRelation(property)) {
216653
+ return [property.source, property.through.source];
216654
+ }
216655
+ if (isEdgeConnection(property)) {
216656
+ return [property.source];
216657
+ }
216658
+ return [];
216659
+ }
216604
216660
 
216605
216661
  // src/cli/generator/json-types-parser.ts
216606
216662
  var fs = __toESM(require("fs"), 1);
@@ -216700,22 +216756,6 @@ function toCamel(str) {
216700
216756
  return pascal.charAt(0).toLowerCase() + pascal.slice(1);
216701
216757
  }
216702
216758
 
216703
- // src/utils/view.ts
216704
- function isViewPropertyDefinition(p) {
216705
- return "container" in p;
216706
- }
216707
- function isReverseDirectRelation(p) {
216708
- return "through" in p;
216709
- }
216710
- function isEdgeConnection(p) {
216711
- return !isViewPropertyDefinition(p) && !isReverseDirectRelation(p) && "source" in p;
216712
- }
216713
- function getDirectRelationSource(p) {
216714
- const type = p.type;
216715
- if (type.type === "direct" && type.source) return type.source;
216716
- return void 0;
216717
- }
216718
-
216719
216759
  // src/cli/generator/constants.ts
216720
216760
  var typeMappings = {
216721
216761
  text: "string",
@@ -216733,58 +216773,26 @@ var typeMappings = {
216733
216773
  direct: "NodeId",
216734
216774
  enum: "string"
216735
216775
  };
216736
- var reservedWords = /* @__PURE__ */ new Set([
216737
- "break",
216738
- "case",
216739
- "catch",
216740
- "class",
216741
- "const",
216742
- "continue",
216743
- "debugger",
216744
- "default",
216745
- "delete",
216746
- "do",
216747
- "else",
216748
- "enum",
216749
- "export",
216750
- "extends",
216751
- "false",
216752
- "finally",
216753
- "for",
216754
- "function",
216755
- "if",
216756
- "import",
216757
- "in",
216758
- "instanceof",
216759
- "new",
216760
- "null",
216761
- "return",
216762
- "super",
216763
- "switch",
216764
- "this",
216765
- "throw",
216766
- "true",
216767
- "try",
216768
- "typeof",
216769
- "undefined",
216770
- "var",
216771
- "void",
216772
- "while",
216773
- "with",
216774
- "yield"
216775
- ]);
216776
216776
 
216777
216777
  // src/cli/generator/parser.ts
216778
- function parseViews(views) {
216779
- return views.sort((a, b) => a.externalId.localeCompare(b.externalId)).map(parseView);
216778
+ function parseViews(views, knownExternalIds) {
216779
+ const available = knownExternalIds ?? new Set(views.map((v) => v.externalId));
216780
+ const parsed = views.sort((a, b) => a.externalId.localeCompare(b.externalId)).map(parseView);
216781
+ for (const view of parsed) {
216782
+ for (const field of view.fields) {
216783
+ if (field.relationTargetExternalId && !available.has(field.relationTargetExternalId)) {
216784
+ field.relationTarget = null;
216785
+ field.relationTargetSpace = null;
216786
+ field.relationTargetExternalId = null;
216787
+ }
216788
+ }
216789
+ }
216790
+ return parsed;
216780
216791
  }
216781
216792
  function parseView(view) {
216782
216793
  const fields = [];
216783
216794
  for (const [propertyName, prop] of Object.entries(view.properties)) {
216784
- let fieldName = toCamel(propertyName);
216785
- if (reservedWords.has(fieldName)) {
216786
- fieldName = `${fieldName}_`;
216787
- }
216795
+ const fieldName = toCamel(propertyName);
216788
216796
  if (isViewPropertyDefinition(prop)) {
216789
216797
  fields.push(processMappedProperty(propertyName, fieldName, prop));
216790
216798
  } else if (isEdgeConnection(prop)) {
@@ -216889,7 +216897,7 @@ function getInterfaceType(field, viewName) {
216889
216897
  }
216890
216898
  function getEnumTypeName(viewName, field) {
216891
216899
  const capitalized = field.fieldName.charAt(0).toUpperCase() + field.fieldName.slice(1);
216892
- return `${viewName}${capitalized}`;
216900
+ return `${viewName}_${capitalized}`;
216893
216901
  }
216894
216902
  function getRelationResolvedType(field) {
216895
216903
  const target = field.relationTarget ?? "unknown";
@@ -217546,7 +217554,7 @@ async function promptAuth(flags) {
217546
217554
  });
217547
217555
  const baseUrl = flags.baseUrl || await dist_default4({
217548
217556
  message: "CDF base URL:",
217549
- default: extracted.baseUrl || "https://az-eastus-1.cognitedata.com"
217557
+ default: extracted.baseUrl || "https://az-phx-001.cognitedata.com"
217550
217558
  });
217551
217559
  return { token, project, baseUrl };
217552
217560
  }
@@ -217664,7 +217672,7 @@ var generateCommand = new Command("generate").description("Generate TypeScript t
217664
217672
  dataModelVersion: dataModel.version,
217665
217673
  clientName: options.clientName,
217666
217674
  outputPath: options.outputPath,
217667
- packageVersion: "0.11.1"
217675
+ packageVersion: "0.11.3"
217668
217676
  });
217669
217677
  console.log(
217670
217678
  `
@@ -217705,7 +217713,7 @@ Error loading JSON types file: ${error instanceof Error ? error.message : error}
217705
217713
  });
217706
217714
 
217707
217715
  // src/cli/index.ts
217708
- var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.11.1");
217716
+ var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.11.3");
217709
217717
  program2.addCommand(generateCommand);
217710
217718
  program2.parse();
217711
217719
  /*! Bundled license information: