attlaz-client 1.4.24 → 1.4.25

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpClientRequest = void 0;
4
4
  const Utils_1 = require("../Utils");
5
+ const JsonSerializable_1 = require("../Model/JsonSerializable");
5
6
  class HttpClientRequest {
6
7
  constructor(url, method = HttpClientRequest.GET) {
7
8
  this.headers = {};
@@ -23,7 +24,7 @@ class HttpClientRequest {
23
24
  }
24
25
  setJsonBody(data) {
25
26
  this.setJsonHeader();
26
- this.body = JSON.stringify(data);
27
+ this.body = JsonSerializable_1.JsonSerializable.stringify(data);
27
28
  }
28
29
  getFullUrl() {
29
30
  let result = this.urlObj.href;
@@ -6,6 +6,7 @@ const HttpClient_1 = require("./HttpClient");
6
6
  const HttpClientRequest_1 = require("./HttpClientRequest");
7
7
  const Utils_1 = require("../Utils");
8
8
  const ClientOAuth2 = require("client-oauth2");
9
+ const JsonSerializable_1 = require("../Model/JsonSerializable");
9
10
  class OAuthClient {
10
11
  constructor(options) {
11
12
  this.debug = false;
@@ -139,7 +140,7 @@ class OAuthClient {
139
140
  let requestData = new HttpClientRequest_1.HttpClientRequest(url, method);
140
141
  if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
141
142
  if (typeof parameters === 'object') {
142
- parameters = JSON.stringify(parameters);
143
+ parameters = JsonSerializable_1.JsonSerializable.stringify(parameters);
143
144
  }
144
145
  else if (typeof parameters === 'string') {
145
146
  }
@@ -1,8 +1,9 @@
1
1
  import { DataValue, DataValueValue } from './DataValue';
2
- export declare class DataValueCollection implements Iterable<DataValue> {
2
+ import { JsonSerializable } from './JsonSerializable';
3
+ export declare class DataValueCollection extends JsonSerializable implements Iterable<DataValue> {
3
4
  private values;
4
5
  get length(): number;
5
- static fromObject(rawTags: {
6
+ static fromObject(rawValues: {
6
7
  key: string;
7
8
  value: DataValueValue;
8
9
  }[]): DataValueCollection;
@@ -11,4 +12,5 @@ export declare class DataValueCollection implements Iterable<DataValue> {
11
12
  unset(key: string): void;
12
13
  serialize(): string | null;
13
14
  [Symbol.iterator](): Iterator<DataValue>;
15
+ jsonSerialize(): any;
14
16
  }
@@ -3,21 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataValueCollection = void 0;
4
4
  const DataValue_1 = require("./DataValue");
5
5
  const Utils_1 = require("../Utils");
6
- class DataValueCollection {
6
+ const JsonSerializable_1 = require("./JsonSerializable");
7
+ class DataValueCollection extends JsonSerializable_1.JsonSerializable {
7
8
  constructor() {
9
+ super(...arguments);
8
10
  this.values = [];
9
11
  }
10
12
  get length() {
11
13
  return this.values.length;
12
14
  }
13
- static fromObject(rawTags) {
14
- if (Utils_1.Utils.isNullOrUndefined(rawTags)) {
15
+ static fromObject(rawValues) {
16
+ if (Utils_1.Utils.isNullOrUndefined(rawValues)) {
15
17
  return new DataValueCollection();
16
18
  }
17
19
  const result = new DataValueCollection();
18
- for (const rawTag of rawTags) {
20
+ for (const rawValue of rawValues) {
19
21
  // TODO: validate rawTag
20
- result.set(rawTag.key, rawTag.value);
22
+ result.set(rawValue.key, rawValue.value);
21
23
  }
22
24
  return result;
23
25
  }
@@ -52,5 +54,8 @@ class DataValueCollection {
52
54
  [Symbol.iterator]() {
53
55
  return this.values.values();
54
56
  }
57
+ jsonSerialize() {
58
+ return this.values;
59
+ }
55
60
  }
56
61
  exports.DataValueCollection = DataValueCollection;
@@ -0,0 +1,4 @@
1
+ export declare abstract class JsonSerializable {
2
+ static stringify(object: any): string;
3
+ abstract jsonSerialize(): any;
4
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonSerializable = void 0;
4
+ class JsonSerializable {
5
+ static stringify(object) {
6
+ const replacer = (key, value) => {
7
+ // Filtering out properties
8
+ if (value instanceof JsonSerializable && 'jsonSerialize' in value) {
9
+ return value.jsonSerialize();
10
+ }
11
+ return value;
12
+ };
13
+ return JSON.stringify(object, replacer);
14
+ }
15
+ }
16
+ exports.JsonSerializable = JsonSerializable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.4.24",
3
+ "version": "1.4.25",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",