attlaz-client 1.4.20 → 1.4.23

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.
@@ -1,11 +1,10 @@
1
+ import { DataValueCollection } from '../DataValueCollection';
1
2
  export declare class AdapterConnection {
2
3
  id: number;
3
4
  key: string;
4
5
  adapter: string;
5
6
  name: string;
6
- configuration: {
7
- key: string;
8
- value: string;
9
- }[];
7
+ configuration: DataValueCollection;
8
+ constructor();
10
9
  static parse(rawAdapterConnection: any): AdapterConnection;
11
10
  }
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AdapterConnection = void 0;
4
+ const DataValueCollection_1 = require("../DataValueCollection");
4
5
  class AdapterConnection {
6
+ constructor() {
7
+ this.configuration = new DataValueCollection_1.DataValueCollection();
8
+ }
5
9
  static parse(rawAdapterConnection) {
6
10
  let adapterConnection = new AdapterConnection();
7
11
  adapterConnection.id = rawAdapterConnection.id;
8
12
  adapterConnection.key = rawAdapterConnection.key;
9
13
  adapterConnection.adapter = rawAdapterConnection.adapter;
10
14
  adapterConnection.name = rawAdapterConnection.name;
11
- adapterConnection.configuration = rawAdapterConnection.configuration;
15
+ adapterConnection.configuration = DataValueCollection_1.DataValueCollection.fromObject(rawAdapterConnection.configuration);
12
16
  return adapterConnection;
13
17
  // adapter.id = rawAdapter.id;
14
18
  // adapter.name = rawAdapter.name;
@@ -1,5 +1,6 @@
1
1
  export declare class DataValue {
2
2
  key: string;
3
3
  value: DataValueValue;
4
+ constructor(key: string, value: DataValueValue);
4
5
  }
5
6
  export declare type DataValueValue = string | number | boolean;
@@ -2,5 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataValue = void 0;
4
4
  class DataValue {
5
+ constructor(key, value) {
6
+ this.key = key;
7
+ this.value = value;
8
+ }
5
9
  }
6
10
  exports.DataValue = DataValue;
@@ -0,0 +1,13 @@
1
+ import { DataValueValue } from './DataValue';
2
+ export declare class DataValueCollection {
3
+ private values;
4
+ get length(): number;
5
+ static fromObject(rawTags: {
6
+ key: string;
7
+ value: DataValueValue;
8
+ }[]): DataValueCollection;
9
+ set(key: string, value: DataValueValue): void;
10
+ get(key: string): DataValueValue | null;
11
+ unset(key: string): void;
12
+ serialize(): string | null;
13
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataValueCollection = void 0;
4
+ const DataValue_1 = require("./DataValue");
5
+ const Utils_1 = require("../Utils");
6
+ class DataValueCollection {
7
+ constructor() {
8
+ this.values = [];
9
+ }
10
+ get length() {
11
+ return this.values.length;
12
+ }
13
+ static fromObject(rawTags) {
14
+ if (Utils_1.Utils.isNullOrUndefined(rawTags)) {
15
+ return new DataValueCollection();
16
+ }
17
+ const result = new DataValueCollection();
18
+ for (const rawTag of rawTags) {
19
+ // TODO: validate rawTag
20
+ result.set(rawTag.key, rawTag.value);
21
+ }
22
+ return result;
23
+ }
24
+ set(key, value) {
25
+ const existingIndex = this.values.findIndex((tag) => {
26
+ return tag.key === key;
27
+ });
28
+ if (existingIndex !== -1) {
29
+ this.values.splice(existingIndex);
30
+ }
31
+ this.values.push(new DataValue_1.DataValue(key, value));
32
+ }
33
+ get(key) {
34
+ for (const tag of this.values) {
35
+ if (tag.key === key) {
36
+ return tag.value;
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+ unset(key) {
42
+ this.values = this.values.filter((tag) => {
43
+ return tag.key !== key;
44
+ });
45
+ }
46
+ serialize() {
47
+ if (this.values.length === 0) {
48
+ return null;
49
+ }
50
+ return JSON.stringify(this.values);
51
+ }
52
+ }
53
+ exports.DataValueCollection = DataValueCollection;
@@ -1,7 +1,7 @@
1
1
  import { LogLevel } from "./LogLevel";
2
2
  import { LogStreamId } from './LogStreamId';
3
- import { DataValue, DataValueValue } from '../DataValue';
4
3
  import { LogStatus } from './LogStatus';
4
+ import { DataValueCollection } from '../DataValueCollection';
5
5
  export declare class Log {
6
6
  id: string;
7
7
  readonly logStream: LogStreamId;
@@ -10,10 +10,8 @@ export declare class Log {
10
10
  message: string;
11
11
  context: object;
12
12
  status: LogStatus;
13
- tags: DataValue[];
13
+ tags: DataValueCollection;
14
14
  _version: string;
15
15
  constructor(logStream: LogStreamId, level: LogLevel, date: Date);
16
16
  static parse(rawLog: any): Log;
17
- setTag(key: string, value: DataValueValue): void;
18
- getTagValue(key: string): DataValueValue | null;
19
17
  }
@@ -4,13 +4,14 @@ exports.Log = void 0;
4
4
  const LogLevel_1 = require("./LogLevel");
5
5
  const LogStreamId_1 = require("./LogStreamId");
6
6
  const LogStatus_1 = require("./LogStatus");
7
+ const DataValueCollection_1 = require("../DataValueCollection");
7
8
  class Log {
8
9
  constructor(logStream, level, date) {
9
10
  this.status = LogStatus_1.LogStatus.Normal;
10
- this.tags = [];
11
11
  this.logStream = logStream;
12
12
  this.level = level;
13
13
  this.date = date;
14
+ this.tags = new DataValueCollection_1.DataValueCollection();
14
15
  }
15
16
  static parse(rawLog) {
16
17
  const date = new Date(rawLog.date);
@@ -23,20 +24,9 @@ class Log {
23
24
  if (rawLog.status !== null && rawLog.status !== undefined && rawLog.status !== '') {
24
25
  log.status = LogStatus_1.LogStatus.fromString(rawLog.status);
25
26
  }
26
- log.tags = rawLog.tags;
27
+ log.tags = DataValueCollection_1.DataValueCollection.fromObject(rawLog.tags);
27
28
  log._version = rawLog._version;
28
29
  return log;
29
30
  }
30
- setTag(key, value) {
31
- this.tags.push({ key, value });
32
- }
33
- getTagValue(key) {
34
- for (const tag of this.tags) {
35
- if (tag.key === key) {
36
- return tag.value;
37
- }
38
- }
39
- return null;
40
- }
41
31
  }
42
32
  exports.Log = Log;
@@ -2,7 +2,7 @@ export declare enum StorageType {
2
2
  Cache = "cache",
3
3
  Persistent = "persistent",
4
4
  Vault = "vault",
5
- Workers = "workers"
5
+ Infrastructure = "infrastructure"
6
6
  }
7
7
  export declare namespace StorageType {
8
8
  function fromString(input: string): StorageType;
@@ -7,7 +7,7 @@ var StorageType;
7
7
  StorageType["Cache"] = "cache";
8
8
  StorageType["Persistent"] = "persistent";
9
9
  StorageType["Vault"] = "vault";
10
- StorageType["Workers"] = "workers";
10
+ StorageType["Infrastructure"] = "infrastructure";
11
11
  })(StorageType = exports.StorageType || (exports.StorageType = {}));
12
12
  (function (StorageType) {
13
13
  function fromString(input) {
@@ -9,4 +9,5 @@ export declare class AdapterEndpoint extends Endpoint {
9
9
  getAdapterConfiguration(adapterId: string): Promise<DataResult<AdapterConfiguration[]>>;
10
10
  getConnections(projectId: string): Promise<DataResult<AdapterConnection[]>>;
11
11
  getConnectionByKey(connectionKey: string): Promise<DataResult<AdapterConnection>>;
12
+ saveConnection(projectId: string, adapter: AdapterConnection): Promise<DataResult<AdapterConnection>>;
12
13
  }
@@ -76,5 +76,21 @@ class AdapterEndpoint extends Endpoint_1.Endpoint {
76
76
  throw error;
77
77
  }
78
78
  }
79
+ async saveConnection(projectId, adapter) {
80
+ try {
81
+ let url = '/connections';
82
+ const data = adapter;
83
+ data.projectId = projectId;
84
+ const result = await this.request(url, data, 'POST');
85
+ result.setData(AdapterConnection_1.AdapterConnection.parse(result.getData()));
86
+ return result;
87
+ }
88
+ catch (error) {
89
+ if (this.httpClient.isDebugEnabled()) {
90
+ console.error('Failed to save connection: ', error);
91
+ }
92
+ throw error;
93
+ }
94
+ }
79
95
  }
80
96
  exports.AdapterEndpoint = AdapterEndpoint;
@@ -55,7 +55,7 @@ class LogEndpoint extends Endpoint_1.Endpoint {
55
55
  return new Promise((resolve, reject) => {
56
56
  let cmd = '/logstreams/' + Utils_1.Utils.base64encode(log.logStream.id) + '/logs';
57
57
  this.httpClient.request(cmd, log, 'POST').then((rawSavedLog) => {
58
- resolve(Log_1.Log.parse(rawSavedLog));
58
+ resolve(Log_1.Log.parse(rawSavedLog.getData()));
59
59
  }).catch((reason) => {
60
60
  if (this.httpClient.isDebugEnabled()) {
61
61
  console.error('Failed to save log: ', reason);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.4.20",
3
+ "version": "1.4.23",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",