rest-client-sdk 7.2.0 → 7.2.1
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/{index.js → index.cjs} +1 -1
- package/dist/index.cjs.map +1 -0
- package/dist/{index.es.js → index.mjs} +1 -1
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -14
- package/dist/index.es.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/AsyncStorageInterface.ts +0 -7
- package/src/ErrorFactory.ts +0 -258
- package/src/Mapping/Attribute.ts +0 -33
- package/src/Mapping/ClassMetadata.ts +0 -125
- package/src/Mapping/Relation.ts +0 -68
- package/src/Mapping.ts +0 -120
- package/src/RestClientSdk.ts +0 -127
- package/src/RestClientSdkInterface.ts +0 -27
- package/src/TokenGenerator/AbstractTokenGenerator.ts +0 -86
- package/src/TokenGenerator/AuthorizationCodeFlowTokenGenerator.ts +0 -146
- package/src/TokenGenerator/ClientCredentialsGenerator.ts +0 -97
- package/src/TokenGenerator/PasswordGenerator.ts +0 -140
- package/src/TokenGenerator/ProvidedTokenGenerator.ts +0 -44
- package/src/TokenGenerator/TokenGeneratorInterface.ts +0 -27
- package/src/TokenGenerator/types.ts +0 -33
- package/src/TokenStorage.ts +0 -256
- package/src/TokenStorageInterface.ts +0 -14
- package/src/UnitOfWork.ts +0 -354
- package/src/client/AbstractClient.ts +0 -545
- package/src/client/headerUtils.ts +0 -53
- package/src/decorator.ts +0 -53
- package/src/index.ts +0 -86
- package/src/isImmutable.ts +0 -52
- package/src/serializer/JsSerializer.ts +0 -30
- package/src/serializer/Serializer.ts +0 -138
- package/src/serializer/SerializerInterface.ts +0 -89
- package/src/utils/levenshtein.ts +0 -53
- package/src/utils/logging.ts +0 -96
- package/src/utils/repositoryGenerator.ts +0 -16
package/src/index.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type AsyncStorageInterface from './AsyncStorageInterface';
|
|
2
|
-
import {
|
|
3
|
-
BadRequestError,
|
|
4
|
-
ConflictError,
|
|
5
|
-
ForbiddenError,
|
|
6
|
-
HttpError,
|
|
7
|
-
InternalServerError,
|
|
8
|
-
ResourceNotFoundError,
|
|
9
|
-
UnauthorizedError,
|
|
10
|
-
InvalidScopeError,
|
|
11
|
-
OauthError,
|
|
12
|
-
InvalidGrantError,
|
|
13
|
-
} from './ErrorFactory';
|
|
14
|
-
import Mapping from './Mapping';
|
|
15
|
-
import Attribute from './Mapping/Attribute';
|
|
16
|
-
import ClassMetadata from './Mapping/ClassMetadata';
|
|
17
|
-
import Relation from './Mapping/Relation';
|
|
18
|
-
import RestClientSdk from './RestClientSdk';
|
|
19
|
-
import type { SdkMetadata, MetadataDefinition } from './RestClientSdk';
|
|
20
|
-
// eslint-disable-next-line import/no-duplicates
|
|
21
|
-
import type RestClientSdkInterface from './RestClientSdkInterface';
|
|
22
|
-
// eslint-disable-next-line import/no-duplicates
|
|
23
|
-
import type { Config } from './RestClientSdkInterface';
|
|
24
|
-
import AbstractTokenGenerator from './TokenGenerator/AbstractTokenGenerator';
|
|
25
|
-
import AuthorizationCodeFlowTokenGenerator from './TokenGenerator/AuthorizationCodeFlowTokenGenerator';
|
|
26
|
-
import ClientCredentialsGenerator from './TokenGenerator/ClientCredentialsGenerator';
|
|
27
|
-
import PasswordGenerator from './TokenGenerator/PasswordGenerator';
|
|
28
|
-
import ProvidedTokenGenerator from './TokenGenerator/ProvidedTokenGenerator';
|
|
29
|
-
import type TokenGeneratorInterface from './TokenGenerator/TokenGeneratorInterface';
|
|
30
|
-
import type {
|
|
31
|
-
Token,
|
|
32
|
-
ErrorBody,
|
|
33
|
-
TokenBody,
|
|
34
|
-
TokenResponse,
|
|
35
|
-
} from './TokenGenerator/types';
|
|
36
|
-
import TokenStorage from './TokenStorage';
|
|
37
|
-
import TokenStorageInterface from './TokenStorageInterface';
|
|
38
|
-
import type { HasExpiresAt } from './TokenStorageInterface';
|
|
39
|
-
import AbstractClient from './client/AbstractClient';
|
|
40
|
-
import Serializer from './serializer/Serializer';
|
|
41
|
-
import type SerializerInterface from './serializer/SerializerInterface';
|
|
42
|
-
import { Logger, Log, LoggerHistory } from './utils/logging';
|
|
43
|
-
|
|
44
|
-
export default RestClientSdk;
|
|
45
|
-
export {
|
|
46
|
-
AbstractClient,
|
|
47
|
-
AbstractTokenGenerator,
|
|
48
|
-
AuthorizationCodeFlowTokenGenerator,
|
|
49
|
-
ClientCredentialsGenerator,
|
|
50
|
-
PasswordGenerator,
|
|
51
|
-
ProvidedTokenGenerator,
|
|
52
|
-
Serializer,
|
|
53
|
-
TokenStorage,
|
|
54
|
-
UnauthorizedError,
|
|
55
|
-
BadRequestError,
|
|
56
|
-
ConflictError,
|
|
57
|
-
ForbiddenError,
|
|
58
|
-
OauthError,
|
|
59
|
-
InvalidGrantError,
|
|
60
|
-
InvalidScopeError,
|
|
61
|
-
HttpError,
|
|
62
|
-
InternalServerError,
|
|
63
|
-
ResourceNotFoundError,
|
|
64
|
-
Mapping,
|
|
65
|
-
ClassMetadata,
|
|
66
|
-
Attribute,
|
|
67
|
-
Relation,
|
|
68
|
-
Logger,
|
|
69
|
-
};
|
|
70
|
-
export type {
|
|
71
|
-
SerializerInterface,
|
|
72
|
-
Token,
|
|
73
|
-
ErrorBody,
|
|
74
|
-
TokenResponse,
|
|
75
|
-
TokenBody,
|
|
76
|
-
HasExpiresAt,
|
|
77
|
-
Config,
|
|
78
|
-
SdkMetadata,
|
|
79
|
-
RestClientSdkInterface,
|
|
80
|
-
TokenStorageInterface,
|
|
81
|
-
TokenGeneratorInterface,
|
|
82
|
-
AsyncStorageInterface,
|
|
83
|
-
MetadataDefinition,
|
|
84
|
-
LoggerHistory,
|
|
85
|
-
Log,
|
|
86
|
-
};
|
package/src/isImmutable.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// "fork" of https://github.com/facebook/immutable-js/blob/v4.0.0-rc.9/src/Predicates.js
|
|
3
|
-
// because tree-shaking does not seems to work as expected
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
|
|
13
|
-
export const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
|
|
14
|
-
export const IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
|
|
15
|
-
export const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
|
|
16
|
-
export const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@';
|
|
17
|
-
|
|
18
|
-
export function isImmutable(maybeImmutable: unknown): boolean {
|
|
19
|
-
return isCollection(maybeImmutable) || isRecord(maybeImmutable);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function isCollection(maybeCollection: any): boolean {
|
|
23
|
-
return !!(maybeCollection && maybeCollection[IS_ITERABLE_SENTINEL]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isKeyed(maybeKeyed: any): boolean {
|
|
27
|
-
return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function isIndexed(maybeIndexed: any): boolean {
|
|
31
|
-
return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function isAssociative(maybeAssociative: any): boolean {
|
|
35
|
-
return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isOrdered(maybeOrdered: any): boolean {
|
|
39
|
-
return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isRecord(maybeRecord: any): boolean {
|
|
43
|
-
return !!(maybeRecord && maybeRecord[IS_RECORD_SENTINEL]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function isValueObject(maybeValue: any): boolean {
|
|
47
|
-
return !!(
|
|
48
|
-
maybeValue &&
|
|
49
|
-
typeof maybeValue.equals === 'function' &&
|
|
50
|
-
typeof maybeValue.hashCode === 'function'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import ClassMetadata from '../Mapping/ClassMetadata';
|
|
3
|
-
import Serializer from './Serializer';
|
|
4
|
-
|
|
5
|
-
class JsSerializer extends Serializer {
|
|
6
|
-
encodeItem(
|
|
7
|
-
object: Record<string, unknown>,
|
|
8
|
-
classMetadata: ClassMetadata
|
|
9
|
-
): string {
|
|
10
|
-
return JSON.stringify(object);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
decodeItem(
|
|
14
|
-
rawData: string,
|
|
15
|
-
classMetadata: ClassMetadata,
|
|
16
|
-
response: Response
|
|
17
|
-
): Record<string, unknown> {
|
|
18
|
-
return JSON.parse(rawData);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
decodeList(
|
|
22
|
-
rawListData: string,
|
|
23
|
-
classMetadata: ClassMetadata,
|
|
24
|
-
response: Response
|
|
25
|
-
): Iterable<Record<string, unknown>> {
|
|
26
|
-
return JSON.parse(rawListData);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default JsSerializer;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import ClassMetadata from '../Mapping/ClassMetadata';
|
|
3
|
-
import SerializerInterface, {
|
|
4
|
-
Entity,
|
|
5
|
-
NormalizedObject,
|
|
6
|
-
NormalizedList,
|
|
7
|
-
EntityList,
|
|
8
|
-
} from './SerializerInterface';
|
|
9
|
-
|
|
10
|
-
class Serializer implements SerializerInterface {
|
|
11
|
-
/**
|
|
12
|
-
* convert an entity to a plain javascript object
|
|
13
|
-
* @param {object} entity - The entity to convert
|
|
14
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
15
|
-
* @return {object} the object to serialize
|
|
16
|
-
*/
|
|
17
|
-
normalizeItem(
|
|
18
|
-
entity: Entity,
|
|
19
|
-
classMetadata: ClassMetadata
|
|
20
|
-
): NormalizedObject {
|
|
21
|
-
return entity;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* convert a plain javascript object to string
|
|
26
|
-
* @param {object} object - The object to convert to convert
|
|
27
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
28
|
-
* @return {string} the content of the request
|
|
29
|
-
*/
|
|
30
|
-
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string {
|
|
31
|
-
throw new TypeError('`encodeItem` method must be implemented');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* convert an entity to string that will be sent as the request content
|
|
36
|
-
* @param {any} entity - The entity to convert
|
|
37
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
38
|
-
* @return {string} the content of the request
|
|
39
|
-
*/
|
|
40
|
-
serializeItem(object: Entity, classMetadata: ClassMetadata): string {
|
|
41
|
-
const noralizedData = this.normalizeItem(object, classMetadata);
|
|
42
|
-
return this.encodeItem(noralizedData, classMetadata);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* convert a plain object to an entity
|
|
47
|
-
* @param {object} object - The plain javascript object
|
|
48
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
49
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
50
|
-
* @return {object} an entity
|
|
51
|
-
*/
|
|
52
|
-
denormalizeItem(
|
|
53
|
-
object: NormalizedObject,
|
|
54
|
-
classMetadata: ClassMetadata,
|
|
55
|
-
response: Response
|
|
56
|
-
): Entity {
|
|
57
|
-
return object;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* convert a string containing an object to a plain javascript object
|
|
62
|
-
* @param {string} rawData - The string fetched from the response
|
|
63
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
64
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
65
|
-
* @return {object} the normalized object
|
|
66
|
-
*/
|
|
67
|
-
decodeItem(
|
|
68
|
-
rawData: string,
|
|
69
|
-
classMetadata: ClassMetadata,
|
|
70
|
-
response: Response
|
|
71
|
-
): NormalizedObject {
|
|
72
|
-
throw new TypeError('`decodeItem` method must be implemented');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* convert a string containing an object to an entity
|
|
77
|
-
* @param {string} rawData - The string fetched from the response
|
|
78
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
79
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
80
|
-
* @return {object} the entity
|
|
81
|
-
*/
|
|
82
|
-
deserializeItem(
|
|
83
|
-
rawData: string,
|
|
84
|
-
classMetadata: ClassMetadata,
|
|
85
|
-
response: Response
|
|
86
|
-
): Entity {
|
|
87
|
-
const object = this.decodeItem(rawData, classMetadata, response);
|
|
88
|
-
return this.denormalizeItem(object, classMetadata, response);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* convert a plain object list to an entity list
|
|
93
|
-
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object)
|
|
94
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
95
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
96
|
-
* @return {Iterable<object>} a list of entities
|
|
97
|
-
*/
|
|
98
|
-
denormalizeList(
|
|
99
|
-
objectList: NormalizedList,
|
|
100
|
-
classMetadata: ClassMetadata,
|
|
101
|
-
response: Response
|
|
102
|
-
): EntityList {
|
|
103
|
-
return objectList; // weird conversion as the declaration of list type is fuzzy
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* convert a string containing a list of objects to a list of plain javascript objects
|
|
108
|
-
* @param {string} rawListData - The string fetched from the response
|
|
109
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
110
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
111
|
-
* @return {Iterable<object>} a list of normalized objects
|
|
112
|
-
*/
|
|
113
|
-
decodeList(
|
|
114
|
-
rawListData: string,
|
|
115
|
-
classMetadata: ClassMetadata,
|
|
116
|
-
response: Response
|
|
117
|
-
): NormalizedList {
|
|
118
|
-
throw new TypeError('`deserializeList` method must be implemented');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* convert a string containing a list of objects to a list of entities
|
|
123
|
-
* @param {string} rawListData - The string fetched from the response
|
|
124
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
125
|
-
* @param {Record<string, unknown>} response - the HTTP response
|
|
126
|
-
* @return {Iterable<object>} a list of entities
|
|
127
|
-
*/
|
|
128
|
-
deserializeList(
|
|
129
|
-
rawListData: string,
|
|
130
|
-
classMetadata: ClassMetadata,
|
|
131
|
-
response: Response
|
|
132
|
-
): EntityList {
|
|
133
|
-
const objectList = this.decodeList(rawListData, classMetadata, response);
|
|
134
|
-
return this.denormalizeList(objectList, classMetadata, response);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export default Serializer;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import ClassMetadata from '../Mapping/ClassMetadata';
|
|
2
|
-
|
|
3
|
-
export type Entity = Record<string, unknown>;
|
|
4
|
-
export type NormalizedObject = Record<string, unknown>;
|
|
5
|
-
export type NormalizedList = Iterable<Record<string, unknown>>;
|
|
6
|
-
export type EntityList = Iterable<Entity>;
|
|
7
|
-
|
|
8
|
-
export default interface SerializerInterface {
|
|
9
|
-
/**
|
|
10
|
-
* convert an entity to a plain javascript object
|
|
11
|
-
* @param {object} entity - The entity to convert
|
|
12
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
13
|
-
* @return {object} the object to serialize
|
|
14
|
-
*/
|
|
15
|
-
normalizeItem(entity: Entity, classMetadata: ClassMetadata): NormalizedObject;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* convert a plain javascript object to string
|
|
19
|
-
* @param {object} object - The object to convert to convert
|
|
20
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
21
|
-
* @return {string} the content of the request
|
|
22
|
-
*/
|
|
23
|
-
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* convert a plain object to an entity
|
|
27
|
-
* @param {object} object - The plain javascript object
|
|
28
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
29
|
-
* @param {object} response - the HTTP response
|
|
30
|
-
* @return {object} an entity
|
|
31
|
-
*/
|
|
32
|
-
denormalizeItem(
|
|
33
|
-
object: NormalizedObject,
|
|
34
|
-
classMetadata: ClassMetadata,
|
|
35
|
-
response: Response
|
|
36
|
-
): Entity;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* convert a string containing an object to a plain javascript object
|
|
40
|
-
* @param {string} rawData - The string fetched from the response
|
|
41
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
42
|
-
* @param {object} response - the HTTP response
|
|
43
|
-
* @return {object} the normalized object
|
|
44
|
-
*/
|
|
45
|
-
decodeItem(
|
|
46
|
-
rawData: string,
|
|
47
|
-
classMetadata: ClassMetadata,
|
|
48
|
-
response: Response
|
|
49
|
-
): NormalizedObject;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* convert a plain object list to an entity list
|
|
53
|
-
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object)
|
|
54
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
55
|
-
* @param {object} response - the HTTP response
|
|
56
|
-
* @return {Iterable<object>} a list of entities
|
|
57
|
-
*/
|
|
58
|
-
denormalizeList(
|
|
59
|
-
objectList: NormalizedList,
|
|
60
|
-
classMetadata: ClassMetadata,
|
|
61
|
-
response: Response
|
|
62
|
-
): EntityList;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* convert a string containing a list of objects to a list of plain javascript objects
|
|
66
|
-
* @param {string} rawListData - The string fetched from the response
|
|
67
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
68
|
-
* @param {object} response - the HTTP response
|
|
69
|
-
* @return {Iterable<object>} a list of normalized objects or an iterable object containint the list
|
|
70
|
-
*/
|
|
71
|
-
decodeList(
|
|
72
|
-
rawListData: string,
|
|
73
|
-
classMetadata: ClassMetadata,
|
|
74
|
-
response: Response
|
|
75
|
-
): NormalizedList;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* convert a string containing a list of objects to a list of entities
|
|
79
|
-
* @param {string} rawListData - The string fetched from the response
|
|
80
|
-
* @param {ClassMetadata} classMetadata - the class metadata
|
|
81
|
-
* @param {object} response - the HTTP response
|
|
82
|
-
* @return {Iterable<object>} a list of entities
|
|
83
|
-
*/
|
|
84
|
-
deserializeList(
|
|
85
|
-
rawListData: string,
|
|
86
|
-
classMetadata: ClassMetadata,
|
|
87
|
-
response: Response
|
|
88
|
-
): EntityList;
|
|
89
|
-
}
|
package/src/utils/levenshtein.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
function levenshteinDistance(a: string, b: string): number {
|
|
2
|
-
const matrix: number[][] = [];
|
|
3
|
-
|
|
4
|
-
// Increment along the first column of each row
|
|
5
|
-
for (let i = 0; i <= b.length; i += 1) {
|
|
6
|
-
matrix[i] = [i];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Increment each column in the first row
|
|
10
|
-
for (let j = 0; j <= a.length; j += 1) {
|
|
11
|
-
matrix[0][j] = j;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Fill in the rest of the matrix
|
|
15
|
-
for (let i = 1; i <= b.length; i += 1) {
|
|
16
|
-
for (let j = 1; j <= a.length; j += 1) {
|
|
17
|
-
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
18
|
-
matrix[i][j] = matrix[i - 1][j - 1];
|
|
19
|
-
} else {
|
|
20
|
-
matrix[i][j] = Math.min(
|
|
21
|
-
matrix[i - 1][j - 1] + 1, // substitution
|
|
22
|
-
matrix[i][j - 1] + 1, // insertion
|
|
23
|
-
matrix[i - 1][j] + 1 // deletion
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return matrix[b.length][a.length];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
33
|
-
export function findClosestWord(
|
|
34
|
-
word: string,
|
|
35
|
-
list: string[],
|
|
36
|
-
maxDistance = Infinity
|
|
37
|
-
): string | null {
|
|
38
|
-
let closestWord: string | null = null;
|
|
39
|
-
let minDistance = Infinity;
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line no-plusplus
|
|
42
|
-
for (let i = 0; i < list.length; i += 1) {
|
|
43
|
-
const candidate = list[i];
|
|
44
|
-
const distance = levenshteinDistance(word, candidate);
|
|
45
|
-
|
|
46
|
-
if (distance < minDistance && distance <= maxDistance) {
|
|
47
|
-
minDistance = distance;
|
|
48
|
-
closestWord = candidate;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return closestWord;
|
|
53
|
-
}
|
package/src/utils/logging.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { convertToRecord } from '../client/headerUtils';
|
|
2
|
-
|
|
3
|
-
type SdkRequest = RequestInit & { url: string };
|
|
4
|
-
|
|
5
|
-
// type SdkResponse = Partial<Response>;
|
|
6
|
-
type SdkResponse = {
|
|
7
|
-
status: number;
|
|
8
|
-
headers: Record<string, string>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const generateId = () =>
|
|
12
|
-
`rest-client-sdk|${Date.now()}-${
|
|
13
|
-
Math.floor(Math.random() * (9e12 - 1)) + 1e12
|
|
14
|
-
}`;
|
|
15
|
-
|
|
16
|
-
export type SerializableRequest = {
|
|
17
|
-
url: string;
|
|
18
|
-
method?: string;
|
|
19
|
-
headers?: Record<string, string>;
|
|
20
|
-
body?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type Log = {
|
|
24
|
-
id: string;
|
|
25
|
-
request?: SerializableRequest;
|
|
26
|
-
response?: SdkResponse;
|
|
27
|
-
logTimes: {
|
|
28
|
-
request?: number;
|
|
29
|
-
response?: number;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type LoggerHistory = Array<Log>;
|
|
34
|
-
|
|
35
|
-
function serializeRequest(req: SdkRequest): SerializableRequest {
|
|
36
|
-
const request = { ...req }; // Make a clone, useful for doing destructive things
|
|
37
|
-
return {
|
|
38
|
-
method: request.method, // The Request Method, e.g. GET, POST, DELETE
|
|
39
|
-
url: request.url, // The URL
|
|
40
|
-
headers: request.headers ? convertToRecord(request.headers) : undefined,
|
|
41
|
-
body: typeof request.body === 'string' ? request.body : undefined,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
46
|
-
export class Logger {
|
|
47
|
-
#history: LoggerHistory;
|
|
48
|
-
|
|
49
|
-
get history(): LoggerHistory {
|
|
50
|
-
return this.#history;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
constructor() {
|
|
54
|
-
this.#history = [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
logRequest(params: SdkRequest): string {
|
|
58
|
-
const log: Log = {
|
|
59
|
-
id: generateId(),
|
|
60
|
-
request: serializeRequest(params),
|
|
61
|
-
logTimes: { request: Date.now() },
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this.#history.push(log);
|
|
65
|
-
|
|
66
|
-
return log.id;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
logResponse(response: Response, requestId?: undefined | string): string {
|
|
70
|
-
const id = requestId || generateId();
|
|
71
|
-
|
|
72
|
-
// console.log('clone');
|
|
73
|
-
// const clonedResponse = response.clone(); // THIS IS THE LINE THAT CAUSES THE PROBLEM
|
|
74
|
-
// console.log('after clone', clonedResponse.status);
|
|
75
|
-
|
|
76
|
-
const logContent: SdkResponse = {
|
|
77
|
-
status: response.status, // clonedResponse.status,
|
|
78
|
-
headers: Object.fromEntries(response.headers),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const foundLogIndex = this.#history.findIndex((log) => log.id === id);
|
|
82
|
-
|
|
83
|
-
if (foundLogIndex > -1) {
|
|
84
|
-
this.#history[foundLogIndex].response = logContent;
|
|
85
|
-
this.#history[foundLogIndex].logTimes.response = Date.now();
|
|
86
|
-
} else {
|
|
87
|
-
this.#history.push({
|
|
88
|
-
id,
|
|
89
|
-
response: logContent,
|
|
90
|
-
logTimes: { response: Date.now() },
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return id;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import type ClassMetadata from '../Mapping/ClassMetadata';
|
|
3
|
-
// eslint-disable-next-line import/no-duplicates
|
|
4
|
-
import type RestClientSdk from '../RestClientSdk';
|
|
5
|
-
// eslint-disable-next-line import/no-duplicates
|
|
6
|
-
import type { MetadataDefinition, SdkMetadata } from '../RestClientSdk';
|
|
7
|
-
import type AbstractClient from '../client/AbstractClient';
|
|
8
|
-
|
|
9
|
-
export function generateRepository<D extends MetadataDefinition>(
|
|
10
|
-
sdk: RestClientSdk<SdkMetadata>,
|
|
11
|
-
metadata: ClassMetadata,
|
|
12
|
-
isUnitOfWorkEnabled = true
|
|
13
|
-
): AbstractClient<D> {
|
|
14
|
-
// eslint-disable-next-line new-cap
|
|
15
|
-
return new metadata.repositoryClass(sdk, metadata, isUnitOfWorkEnabled);
|
|
16
|
-
}
|