industrial-model 0.11.2 → 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.
- package/dist/cli/index.cjs +72 -21
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cognite-core/index.cjs +40 -0
- package/dist/cognite-core/index.cjs.map +1 -1
- package/dist/cognite-core/index.js +40 -0
- package/dist/cognite-core/index.js.map +1 -1
- package/dist/index.cjs +40 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -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",
|
|
@@ -216735,8 +216775,19 @@ var typeMappings = {
|
|
|
216735
216775
|
};
|
|
216736
216776
|
|
|
216737
216777
|
// src/cli/generator/parser.ts
|
|
216738
|
-
function parseViews(views) {
|
|
216739
|
-
|
|
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;
|
|
216740
216791
|
}
|
|
216741
216792
|
function parseView(view) {
|
|
216742
216793
|
const fields = [];
|
|
@@ -217503,7 +217554,7 @@ async function promptAuth(flags) {
|
|
|
217503
217554
|
});
|
|
217504
217555
|
const baseUrl = flags.baseUrl || await dist_default4({
|
|
217505
217556
|
message: "CDF base URL:",
|
|
217506
|
-
default: extracted.baseUrl || "https://az-
|
|
217557
|
+
default: extracted.baseUrl || "https://az-phx-001.cognitedata.com"
|
|
217507
217558
|
});
|
|
217508
217559
|
return { token, project, baseUrl };
|
|
217509
217560
|
}
|
|
@@ -217621,7 +217672,7 @@ var generateCommand = new Command("generate").description("Generate TypeScript t
|
|
|
217621
217672
|
dataModelVersion: dataModel.version,
|
|
217622
217673
|
clientName: options.clientName,
|
|
217623
217674
|
outputPath: options.outputPath,
|
|
217624
|
-
packageVersion: "0.11.
|
|
217675
|
+
packageVersion: "0.11.3"
|
|
217625
217676
|
});
|
|
217626
217677
|
console.log(
|
|
217627
217678
|
`
|
|
@@ -217662,7 +217713,7 @@ Error loading JSON types file: ${error instanceof Error ? error.message : error}
|
|
|
217662
217713
|
});
|
|
217663
217714
|
|
|
217664
217715
|
// src/cli/index.ts
|
|
217665
|
-
var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.11.
|
|
217716
|
+
var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.11.3");
|
|
217666
217717
|
program2.addCommand(generateCommand);
|
|
217667
217718
|
program2.parse();
|
|
217668
217719
|
/*! Bundled license information:
|