@cognite/cli 0.5.2 → 0.6.0-alpha.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.
@@ -0,0 +1,12 @@
1
+ import {
2
+ buildPullArgs,
3
+ execSkillsCli,
4
+ pullAllArgs,
5
+ registerSkillsCommand
6
+ } from "./chunk-SUXS6HCW.js";
7
+ export {
8
+ buildPullArgs,
9
+ execSkillsCli,
10
+ pullAllArgs,
11
+ registerSkillsCommand
12
+ };
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
1
  {
2
2
  "name": "@cognite/cli",
3
+ "version": "0.6.0-alpha.6",
4
+ "description": "CLI for Cognite Data Fusion",
5
+ "license": "Apache-2.0",
6
+ "author": "Cognite",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/cognitedata/dune.git",
10
+ "directory": "packages/cli"
11
+ },
12
+ "type": "module",
3
13
  "bin": {
4
- "cdf": "index.js"
14
+ "dune": "./dist/cli/cli.js"
5
15
  },
6
16
  "files": [
7
- "index.js",
8
- "operations.js"
17
+ "dist"
9
18
  ],
10
- "version": "0.5.2",
11
- "description": "a cli for cognite data fusion",
12
- "main": "index.js",
13
19
  "scripts": {
14
- "test": "echo \"Error: no test specified, continuing anyway\" && exit 0"
15
- },
16
- "author": "You",
17
- "license": "MIT",
18
- "dependencies": {
19
- "@cognite/sdk": "^2.16.1",
20
- "js-yaml": "^3.13.1",
21
- "pipe-args": "^1.3.0",
22
- "yargs": "^13.3.0"
20
+ "build": "tsup",
21
+ "prepublishOnly": "pnpm run build"
23
22
  },
24
- "prettier": {
25
- "singleQuote": true,
26
- "trailingComma": "es5"
23
+ "devDependencies": {
24
+ "@types/node": "^24.10.1",
25
+ "tsup": "^8.4.0",
26
+ "typescript": "^5.0.0"
27
27
  },
28
- "devDependencies": {}
28
+ "engines": {
29
+ "node": ">=20"
30
+ }
29
31
  }
package/README.md DELETED
@@ -1,61 +0,0 @@
1
- # cdf cli
2
-
3
- This is in super alpha!
4
-
5
- ## Install
6
-
7
- $ npm i -g @cognite/cli
8
-
9
- ## Screencast example
10
-
11
- ![This is how it works](https://media.giphy.com/media/TgymOB5RrXunSANV3P/giphy.gif)
12
-
13
- ## Usage
14
-
15
- The project and api-key is specified through the two _required_ environment variables
16
-
17
- $ export COGNITE_PROJECT=publicdata
18
- $ export COGNITE_CREDENTIALS=<api-key>
19
-
20
- and the optional environment variable
21
-
22
- $ export COGNITE_BASE_URL=<cluster-specific-url>
23
-
24
- ## Examples
25
-
26
- `cdf assets list`
27
-
28
- `cdf assets list --limit=5`
29
-
30
- `cdf assets list --filter.root=true --limit=5`
31
-
32
- `cdf assets retrieve --externalIds=test1,test2`
33
-
34
- `cdf assets retrieve --ids=123,234`
35
-
36
- `cdf assets search --filter.root=true --search.name=name --limit=10`
37
-
38
- `cdf assets create --externalId=test1 --name=somename`
39
-
40
- `cdf assets update --externalId=test1 --update.name.set=somenewname`
41
-
42
- You can also pipe JSON input to create/delete to create multiple assets at once. Assuming assets.json contains
43
-
44
- ```
45
- [
46
- {"externalId": "test.1"},
47
- {"externalId": "test.2"}
48
- ]
49
- ```
50
-
51
- then;
52
- `cat assets.json | cdf assets create`
53
- `cat assets.json | cdf assets delete`
54
-
55
- ## Settings
56
-
57
- ## Contribution
58
-
59
- Yes, please. Issues and PRs are highly welcome.
60
-
61
- This package is automatically released using [semantic release](https://github.com/semantic-release/semantic-release). Please write commit messages that follows the angular commit message conventions (feat:, fix: etc).
package/index.js DELETED
@@ -1,116 +0,0 @@
1
- #!/usr/bin/env node
2
- require('pipe-args').load();
3
- const yargs = require('yargs');
4
- const { CogniteClient } = require('@cognite/sdk');
5
- const yaml = require('js-yaml');
6
- const getOperation = require('./operations');
7
-
8
- if (!(process.env.COGNITE_CREDENTIALS && process.env.COGNITE_PROJECT)) {
9
- console.error(`Both COGNITE_CREDENTIALS and COGNITE_PROJECT needs to be set`);
10
- process.exit(1);
11
- }
12
-
13
- const sdk = new CogniteClient({
14
- appId: 'cdf-cli',
15
- baseUrl: process.env.COGNITE_BASE_URL || 'https://api.cognitedata.com',
16
- });
17
-
18
- sdk.loginWithApiKey({
19
- apiKey: process.env.COGNITE_CREDENTIALS,
20
- project: process.env.COGNITE_PROJECT,
21
- });
22
-
23
- // Supported resource types
24
- const resourceTypes = [
25
- 'timeseries',
26
- 'sequences',
27
- 'assets',
28
- 'events',
29
- 'files',
30
- 'datapoints',
31
- 'apiKeys',
32
- 'securityCategories',
33
- 'serviceAccounts',
34
- 'groups',
35
- 'raw',
36
- 'models3D',
37
- 'revisions3D',
38
- ];
39
-
40
- // Remove these nonsense properties from the resourceTypes
41
- // and assume the rest is the actual operations
42
- const BLACKLIST = [
43
- 'transformTo',
44
- 'client',
45
- 'resourcePath',
46
- 'map',
47
- 'callListEndpointWithGet',
48
- 'callListEndpointWithPost',
49
- 'sequenceRowsAPI',
50
- 'rawTablesApi',
51
- 'rawRowsApi',
52
- ].map(i => new RegExp(i, 'gi'));
53
-
54
- function cleanArguments(args) {
55
- const cp = {
56
- ...args,
57
- };
58
- // Remove the ones that will not get passed on to the SDK
59
- delete cp['$0'];
60
- delete cp['_'];
61
- delete cp['o'];
62
- return cp;
63
- }
64
-
65
- const mainHandler = (resourceType, operation) => async yargz => {
66
- const func = getOperation(
67
- resourceType,
68
- operation,
69
- sdk,
70
- cleanArguments(yargz)
71
- );
72
- if (!func) {
73
- console.error(
74
- `Sorry, ${resourceType} ${operation} is not implemented yet :-(`
75
- );
76
- process.exit(1);
77
- }
78
-
79
- // Handle result
80
- try {
81
- let extraArguments = [];
82
- if (yargz['_'].length > 2) {
83
- // Some arguments should go to the sdk
84
- // this would be all non-options after cdf revisions3D list
85
- extraArguments = yargz['_'].slice(2);
86
- }
87
- let result = await func(...extraArguments);
88
- if (result.map) {
89
- // This is an array, remove nonsense objects
90
- result = result.map(r => JSON.parse(JSON.stringify(r)));
91
- }
92
- const YAML_OUTPUT = /yaml|yml/.test(yargz.o);
93
- if (YAML_OUTPUT) {
94
- console.log(yaml.safeDump(result));
95
- } else {
96
- console.log(JSON.stringify(result, null, 2));
97
- }
98
- } catch (ex) {
99
- console.error(ex);
100
- }
101
- };
102
-
103
- for (const resourceType of resourceTypes) {
104
- const validOperations = Object.keys(sdk[resourceType]).filter(
105
- key => !BLACKLIST.some(regEx => regEx.test(key))
106
- );
107
-
108
- yargs.command(`${resourceType} <operation>`, '', yargz => {
109
- // Create the subcommands
110
- for (const operation of validOperations) {
111
- yargz.command(operation, '', {}, mainHandler(resourceType, operation));
112
- }
113
- });
114
- }
115
-
116
- yargs.help().argv;
package/operations.js DELETED
@@ -1,113 +0,0 @@
1
- function getOperation(resourceType, operation, sdk, args) {
2
- // Generic function that can read a single entity from options
3
- // e.g `cdf timeseries create --externalId=my.extid --name=my.name`
4
- // or it reads a piped/buffered input and assumes an array
5
- // e.g `cat timeseries.json | cdf timeseries create`
6
- const argsOrPipedOperation = operation => {
7
- return () => {
8
- // Check if any normal arguments are sent
9
- let arrayArgs;
10
- if (Object.keys(args).length > 0) {
11
- arrayArgs = [{ ...args }];
12
- } else {
13
- // Assume that stuff is piped
14
- const buffer = process.argv[process.argv.length - 1];
15
- arrayArgs = JSON.parse(buffer);
16
- }
17
- return sdk[resourceType][operation](arrayArgs);
18
- };
19
- };
20
-
21
- const operationMap = {
22
- list: function() {
23
- let assetIds = args.assetIds;
24
- switch (typeof assetIds) {
25
- case 'number':
26
- assetIds = [assetIds];
27
- break;
28
- case 'string':
29
- if (assetIds.startsWith('[')) {
30
- assetIds = assetIds.slice(1);
31
- }
32
- if (assetIds.endsWith(']')) {
33
- assetIds = assetIds.slice(0, assetIds.length - 1);
34
- }
35
- const splitted = assetIds.split(',');
36
- if (splitted.length > 1) {
37
- assetIds = splitted.map(Number);
38
- } else {
39
- assetIds = [Number(assetIds)];
40
- }
41
- break;
42
- default:
43
- assetIds = undefined;
44
- }
45
- // Some list operations take more just one object
46
- // Check if this function was called with any direct objects and pass them on
47
- // ex. cdf revisions3D list 123123 --filter
48
- // To make the code worse, make sure there's nothing undefined #javascript
49
- const sdkArguments = [
50
- ...arguments,
51
- {
52
- ...args,
53
- assetIds,
54
- limit: undefined,
55
- },
56
- ].filter(a => a !== undefined);
57
- const promise = sdk[resourceType].list(...sdkArguments);
58
- if (promise.autoPagingToArray) {
59
- return promise.autoPagingToArray({ limit: args.limit });
60
- }
61
- return promise;
62
- },
63
-
64
- list3DNodes: function() {
65
- const sdkArguments = [
66
- ...arguments,
67
- {
68
- ...args,
69
- },
70
- ].filter(a => a !== undefined);
71
-
72
- return sdk[resourceType].list3DNodes(...sdkArguments);
73
- },
74
-
75
- retrieve: () => {
76
- const externalIds =
77
- (args.externalIds && String(args.externalIds).split(',')) || [];
78
- const ids = (args.ids && String(args.ids).split(',')) || [];
79
- const allIds = [
80
- ...ids.map(i => ({ id: i })),
81
- ...externalIds.map(i => ({ externalId: i })),
82
- ];
83
-
84
- if (resourceType === 'datapoints') {
85
- // This has to be handled separately.
86
- const clonedArgs = {
87
- ...args,
88
- ids: undefined,
89
- externalIds: undefined,
90
- };
91
- return sdk.datapoints.retrieve({ ...clonedArgs, items: allIds });
92
- }
93
- return sdk[resourceType].retrieve(allIds);
94
- },
95
-
96
- retrieveLatest: argsOrPipedOperation('retrieveLatest'),
97
-
98
- search: () => sdk[resourceType].search(args),
99
-
100
- create: argsOrPipedOperation('create'),
101
-
102
- delete: argsOrPipedOperation('delete'),
103
-
104
- update: argsOrPipedOperation('update'),
105
- };
106
- const func = operationMap[operation];
107
- if (func) {
108
- return func;
109
- }
110
- throw new Error(`${resourceType}.${operation} isn't implemented yet :-(`);
111
- }
112
-
113
- module.exports = getOperation;