industrial-model 0.9.0 → 0.10.0
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/README.md +1 -1
- package/dist/cli/index.cjs +39 -12
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cognite-core/index.cjs +12 -4
- package/dist/cognite-core/index.cjs.map +1 -1
- package/dist/cognite-core/index.js +12 -4
- package/dist/cognite-core/index.js.map +1 -1
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -503,7 +503,7 @@ do {
|
|
|
503
503
|
} while (cursor !== null);
|
|
504
504
|
```
|
|
505
505
|
|
|
506
|
-
Pass `limit: -1` when you want the SDK to follow all root cursors automatically. The SDK issues multiple `instances.query` calls, using
|
|
506
|
+
Pass `limit: -1` when you want the SDK to follow all root cursors automatically. The SDK issues multiple `instances.query` calls, using 10000 root items per page, and returns `cursor: null`.
|
|
507
507
|
|
|
508
508
|
```ts
|
|
509
509
|
const { items } = await model.query<CogniteAsset>()({
|
package/dist/cli/index.cjs
CHANGED
|
@@ -3964,6 +3964,7 @@ function processMappedProperty(propertyName, fieldName, prop) {
|
|
|
3964
3964
|
const isList = prop.type.list === true;
|
|
3965
3965
|
const isRelation = cogniteType === "direct";
|
|
3966
3966
|
const relationSource = getDirectRelationSource(prop);
|
|
3967
|
+
const enumValues = cogniteType === "enum" && prop.type.values ? Object.keys(prop.type.values) : null;
|
|
3967
3968
|
let relationTarget = null;
|
|
3968
3969
|
let relationTargetSpace = null;
|
|
3969
3970
|
let relationTargetExternalId = null;
|
|
@@ -3986,7 +3987,8 @@ function processMappedProperty(propertyName, fieldName, prop) {
|
|
|
3986
3987
|
isListDirectRelation: isRelation && isList,
|
|
3987
3988
|
relationTarget,
|
|
3988
3989
|
relationTargetSpace,
|
|
3989
|
-
relationTargetExternalId
|
|
3990
|
+
relationTargetExternalId,
|
|
3991
|
+
enumValues
|
|
3990
3992
|
};
|
|
3991
3993
|
}
|
|
3992
3994
|
function processEdgeProperty(propertyName, fieldName, prop) {
|
|
@@ -4003,7 +4005,8 @@ function processEdgeProperty(propertyName, fieldName, prop) {
|
|
|
4003
4005
|
isListDirectRelation: false,
|
|
4004
4006
|
relationTarget: toPascal(prop.source.externalId),
|
|
4005
4007
|
relationTargetSpace: prop.source.space,
|
|
4006
|
-
relationTargetExternalId: prop.source.externalId
|
|
4008
|
+
relationTargetExternalId: prop.source.externalId,
|
|
4009
|
+
enumValues: null
|
|
4007
4010
|
};
|
|
4008
4011
|
}
|
|
4009
4012
|
function processReverseProperty(propertyName, fieldName, prop) {
|
|
@@ -4021,7 +4024,8 @@ function processReverseProperty(propertyName, fieldName, prop) {
|
|
|
4021
4024
|
isListDirectRelation: false,
|
|
4022
4025
|
relationTarget: toPascal(prop.source.externalId),
|
|
4023
4026
|
relationTargetSpace: prop.source.space,
|
|
4024
|
-
relationTargetExternalId: prop.source.externalId
|
|
4027
|
+
relationTargetExternalId: prop.source.externalId,
|
|
4028
|
+
enumValues: null
|
|
4025
4029
|
};
|
|
4026
4030
|
}
|
|
4027
4031
|
|
|
@@ -4034,11 +4038,16 @@ function getRelationTypeFields(view) {
|
|
|
4034
4038
|
(f) => (f.isRelation || f.isEdge || f.isReverseRelation) && f.relationTarget
|
|
4035
4039
|
);
|
|
4036
4040
|
}
|
|
4037
|
-
function getInterfaceType(field) {
|
|
4041
|
+
function getInterfaceType(field, viewName) {
|
|
4038
4042
|
if (field.isRelation && !field.isList) return "NodeId";
|
|
4039
4043
|
if (field.isEdge || field.isRelation && field.isList) return "NodeId[]";
|
|
4040
|
-
|
|
4041
|
-
|
|
4044
|
+
const baseType = field.enumValues && viewName ? getEnumTypeName(viewName, field) : field.mappedType;
|
|
4045
|
+
if (field.isList) return `${baseType}[]`;
|
|
4046
|
+
return baseType;
|
|
4047
|
+
}
|
|
4048
|
+
function getEnumTypeName(viewName, field) {
|
|
4049
|
+
const capitalized = field.fieldName.charAt(0).toUpperCase() + field.fieldName.slice(1);
|
|
4050
|
+
return `${viewName}${capitalized}`;
|
|
4042
4051
|
}
|
|
4043
4052
|
function getRelationResolvedType(field) {
|
|
4044
4053
|
const target = field.relationTarget ?? "unknown";
|
|
@@ -4187,9 +4196,14 @@ function renderTypes(views, config) {
|
|
|
4187
4196
|
" UpsertOptions,",
|
|
4188
4197
|
" UpsertResult,",
|
|
4189
4198
|
'} from "industrial-model";',
|
|
4190
|
-
""
|
|
4191
|
-
renderViewExternalIdUnion(views, config)
|
|
4199
|
+
""
|
|
4192
4200
|
];
|
|
4201
|
+
const enumAliases = renderEnumTypeAliases(views);
|
|
4202
|
+
if (enumAliases) {
|
|
4203
|
+
lines.push(enumAliases);
|
|
4204
|
+
lines.push("");
|
|
4205
|
+
}
|
|
4206
|
+
lines.push(renderViewExternalIdUnion(views, config));
|
|
4193
4207
|
for (const view of views) {
|
|
4194
4208
|
lines.push("");
|
|
4195
4209
|
lines.push(renderView(view));
|
|
@@ -4205,19 +4219,32 @@ function renderViewExternalIdUnion(views, config) {
|
|
|
4205
4219
|
return `export type ${config.clientName}ViewExternalId =
|
|
4206
4220
|
${views.map((view) => ` | "${view.viewExternalId}"`).join("\n")};`;
|
|
4207
4221
|
}
|
|
4222
|
+
function renderEnumTypeAliases(views) {
|
|
4223
|
+
const aliases = [];
|
|
4224
|
+
for (const view of views) {
|
|
4225
|
+
for (const field of view.fields) {
|
|
4226
|
+
if (field.enumValues && field.enumValues.length > 0) {
|
|
4227
|
+
const typeName = getEnumTypeName(view.viewName, field);
|
|
4228
|
+
const union = field.enumValues.map((v) => `"${v}"`).join(" | ");
|
|
4229
|
+
aliases.push(`export type ${typeName} = ${union};`);
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
return aliases.join("\n");
|
|
4234
|
+
}
|
|
4208
4235
|
function renderView(view) {
|
|
4209
4236
|
const propsFields = getPropsFields(view);
|
|
4210
4237
|
const relationFields = getRelationTypeFields(view);
|
|
4211
4238
|
if (relationFields.length === 0) {
|
|
4212
4239
|
const propsLines2 = propsFields.map(
|
|
4213
|
-
(f) => ` ${f.fieldName}${f.isNullable ? "?" : ""}: ${getInterfaceType(f)};`
|
|
4240
|
+
(f) => ` ${f.fieldName}${f.isNullable ? "?" : ""}: ${getInterfaceType(f, view.viewName)};`
|
|
4214
4241
|
);
|
|
4215
4242
|
return `export type ${view.viewName} = IndustrialModel<{
|
|
4216
4243
|
${propsLines2.join("\n")}
|
|
4217
4244
|
}>;`;
|
|
4218
4245
|
}
|
|
4219
4246
|
const propsLines = propsFields.map(
|
|
4220
|
-
(f) => ` ${f.fieldName}${f.isNullable ? "?" : ""}: ${getInterfaceType(f)};`
|
|
4247
|
+
(f) => ` ${f.fieldName}${f.isNullable ? "?" : ""}: ${getInterfaceType(f, view.viewName)};`
|
|
4221
4248
|
);
|
|
4222
4249
|
const relLines = relationFields.map(
|
|
4223
4250
|
(f) => ` ${f.fieldName}${f.isNullable ? "?" : ""}: ${getRelationResolvedType(f)};`
|
|
@@ -6771,7 +6798,7 @@ var generateCommand = new Command("generate").description("Generate TypeScript t
|
|
|
6771
6798
|
dataModelVersion: dataModel.version,
|
|
6772
6799
|
clientName: options.clientName,
|
|
6773
6800
|
outputPath: options.outputPath,
|
|
6774
|
-
packageVersion: "0.
|
|
6801
|
+
packageVersion: "0.10.0"
|
|
6775
6802
|
});
|
|
6776
6803
|
console.log(
|
|
6777
6804
|
`
|
|
@@ -6791,7 +6818,7 @@ Generating types for ${dataModel.space}/${dataModel.externalId}/${dataModel.vers
|
|
|
6791
6818
|
});
|
|
6792
6819
|
|
|
6793
6820
|
// src/cli/index.ts
|
|
6794
|
-
var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.
|
|
6821
|
+
var program2 = new Command().name("industrial-model").description("Code generator for Cognite Data Fusion data models").version("0.10.0");
|
|
6795
6822
|
program2.addCommand(generateCommand);
|
|
6796
6823
|
program2.parse();
|
|
6797
6824
|
//# sourceMappingURL=index.cjs.map
|