@api-client/core 0.6.27 → 0.6.30
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/build/src/events/BaseEvents.d.ts +30 -28
- package/build/src/events/BaseEvents.js +15 -15
- package/build/src/events/BaseEvents.js.map +1 -1
- package/build/src/events/models/ClientCertificateEvents.d.ts +4 -4
- package/build/src/events/models/ClientCertificateEvents.js +6 -6
- package/build/src/events/models/ClientCertificateEvents.js.map +1 -1
- package/build/src/events/transport/TransportEvents.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +6 -0
- package/build/src/mocking/ProjectMock.js +9 -0
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/Arc.d.ts +10 -0
- package/build/src/mocking/lib/Arc.js +31 -0
- package/build/src/mocking/lib/Arc.js.map +1 -0
- package/build/src/mocking/lib/Certificates.d.ts +24 -0
- package/build/src/mocking/lib/Certificates.js +52 -0
- package/build/src/mocking/lib/Certificates.js.map +1 -0
- package/build/src/mocking/lib/HostRules.d.ts +19 -0
- package/build/src/mocking/lib/HostRules.js +38 -0
- package/build/src/mocking/lib/HostRules.js.map +1 -0
- package/build/src/mocking/lib/Request.js +5 -2
- package/build/src/mocking/lib/Request.js.map +1 -1
- package/build/src/mocking/lib/Url.d.ts +11 -5
- package/build/src/mocking/lib/Url.js +17 -10
- package/build/src/mocking/lib/Url.js.map +1 -1
- package/build/src/models/ClientCertificate.d.ts +2 -2
- package/build/src/models/ClientCertificate.js +10 -7
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/arc/ArcHttpRequest.d.ts +1 -0
- package/build/src/models/arc/ArcHttpRequest.js +20 -12
- package/build/src/models/arc/ArcHttpRequest.js.map +1 -1
- package/build/src/models/arc/ArcProject.js +5 -0
- package/build/src/models/arc/ArcProject.js.map +1 -1
- package/build/src/runtime/http-engine/HttpEngine.js +7 -5
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/events/BaseEvents.ts +33 -33
- package/src/events/models/ClientCertificateEvents.ts +6 -6
- package/src/events/transport/TransportEvents.ts +2 -0
- package/src/mocking/ProjectMock.ts +9 -0
- package/src/mocking/lib/Arc.ts +34 -0
- package/src/mocking/lib/Certificates.ts +60 -0
- package/src/mocking/lib/HostRules.ts +42 -0
- package/src/mocking/lib/Request.ts +6 -3
- package/src/mocking/lib/Url.ts +20 -13
- package/src/models/ClientCertificate.ts +12 -9
- package/src/models/arc/ArcHttpRequest.ts +20 -12
- package/src/models/arc/ArcProject.ts +5 -0
- package/src/runtime/http-engine/HttpEngine.ts +8 -6
package/src/events/BaseEvents.ts
CHANGED
|
@@ -35,9 +35,9 @@ export class ContextEvent<S extends object, R> extends CustomEvent<S & ContextEv
|
|
|
35
35
|
|
|
36
36
|
export interface ContextReadEventDetail {
|
|
37
37
|
/**
|
|
38
|
-
* The
|
|
38
|
+
* The key of the state object to read.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
key: string;
|
|
41
41
|
/**
|
|
42
42
|
* Optional parent, when needed.
|
|
43
43
|
*/
|
|
@@ -50,19 +50,19 @@ export interface ContextReadEventDetail {
|
|
|
50
50
|
export class ContextReadEvent<T> extends ContextEvent<ContextReadEventDetail, T> {
|
|
51
51
|
/**
|
|
52
52
|
* @param type The type of the event
|
|
53
|
-
* @param
|
|
53
|
+
* @param key The domain key of the object to read
|
|
54
54
|
* @param parent Optional parent, when needed.
|
|
55
55
|
*/
|
|
56
|
-
constructor(type: string,
|
|
57
|
-
super(type, {
|
|
56
|
+
constructor(type: string, key: string, parent?: string) {
|
|
57
|
+
super(type, { key, parent });
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export interface ContextReadBulkEventDetail {
|
|
62
62
|
/**
|
|
63
|
-
* The list of
|
|
63
|
+
* The list of keys to read.
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
keys: string[];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -71,10 +71,10 @@ export interface ContextReadBulkEventDetail {
|
|
|
71
71
|
export class ContextReadBulkEvent<T> extends ContextEvent<ContextReadBulkEventDetail, T[]> {
|
|
72
72
|
/**
|
|
73
73
|
* @param type The type of the event
|
|
74
|
-
* @param
|
|
74
|
+
* @param keys The list of domain keys to read. These must be of the same domain type.
|
|
75
75
|
*/
|
|
76
|
-
constructor(type: string,
|
|
77
|
-
super(type, {
|
|
76
|
+
constructor(type: string, keys: string[]) {
|
|
77
|
+
super(type, { keys });
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -89,7 +89,7 @@ export interface ContextChangeRecord<T> {
|
|
|
89
89
|
*/
|
|
90
90
|
kind?: string;
|
|
91
91
|
/**
|
|
92
|
-
* The
|
|
92
|
+
* The key of the changed context state object.
|
|
93
93
|
*/
|
|
94
94
|
key: string;
|
|
95
95
|
/**
|
|
@@ -97,29 +97,29 @@ export interface ContextChangeRecord<T> {
|
|
|
97
97
|
*/
|
|
98
98
|
item?: T;
|
|
99
99
|
/**
|
|
100
|
-
* Optionally, when relevant, the
|
|
100
|
+
* Optionally, when relevant, the key of the parent of the changed object.
|
|
101
101
|
*/
|
|
102
102
|
parent?: string;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export interface ContextDeleteEventDetail {
|
|
106
106
|
/**
|
|
107
|
-
* The
|
|
107
|
+
* The key of the domain object to remove.
|
|
108
108
|
*/
|
|
109
|
-
|
|
109
|
+
key: string;
|
|
110
110
|
/**
|
|
111
|
-
* The
|
|
111
|
+
* The key of the parent object, if applicable.
|
|
112
112
|
*/
|
|
113
113
|
parent?: string;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
export interface ContextDeleteBulkEventDetail {
|
|
117
117
|
/**
|
|
118
|
-
* The list of
|
|
118
|
+
* The list of keys of the domain object to remove.
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
keys: string[];
|
|
121
121
|
/**
|
|
122
|
-
* The
|
|
122
|
+
* The key of the parent object, if applicable.
|
|
123
123
|
*/
|
|
124
124
|
parent?: string;
|
|
125
125
|
}
|
|
@@ -131,11 +131,11 @@ export class ContextDeleteEvent extends ContextEvent<ContextDeleteEventDetail, C
|
|
|
131
131
|
/**
|
|
132
132
|
* An event to be used to delete a state in the context provider.
|
|
133
133
|
* @param type The type of the event to dispatch.
|
|
134
|
-
* @param
|
|
135
|
-
* @param parent The
|
|
134
|
+
* @param key The key of the object to delete
|
|
135
|
+
* @param parent The key of the parent object, if applicable.
|
|
136
136
|
*/
|
|
137
|
-
constructor(type: string,
|
|
138
|
-
super(type, {
|
|
137
|
+
constructor(type: string, key: string, parent?: string) {
|
|
138
|
+
super(type, { key, parent });
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -146,11 +146,11 @@ export class ContextDeleteBulkEvent extends ContextEvent<ContextDeleteBulkEventD
|
|
|
146
146
|
/**
|
|
147
147
|
* An event to be used to delete a number of entities in the context provider.
|
|
148
148
|
* @param type The type of the event to dispatch.
|
|
149
|
-
* @param
|
|
150
|
-
* @param parent The
|
|
149
|
+
* @param keys The list of ids of the domain object to remove.
|
|
150
|
+
* @param parent The key of the parent object, if applicable.
|
|
151
151
|
*/
|
|
152
|
-
constructor(type: string,
|
|
153
|
-
super(type, {
|
|
152
|
+
constructor(type: string, keys: string[], parent?: string) {
|
|
153
|
+
super(type, { keys, parent });
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -161,11 +161,11 @@ export interface ContextDeleteRecord {
|
|
|
161
161
|
*/
|
|
162
162
|
kind?: string;
|
|
163
163
|
/**
|
|
164
|
-
* The
|
|
164
|
+
* The key of the removed object.
|
|
165
165
|
*/
|
|
166
|
-
|
|
166
|
+
key: string;
|
|
167
167
|
/**
|
|
168
|
-
* The
|
|
168
|
+
* The key of the parent object, if applicable.
|
|
169
169
|
*/
|
|
170
170
|
parent?: string;
|
|
171
171
|
}
|
|
@@ -173,7 +173,7 @@ export interface ContextDeleteRecord {
|
|
|
173
173
|
/**
|
|
174
174
|
* An event dispatched to the context store to restore previously deleted items.
|
|
175
175
|
*/
|
|
176
|
-
export class ContextRestoreEvent<T> extends ContextEvent<ContextDeleteRecord[], ContextChangeRecord<T>[]> {
|
|
176
|
+
export class ContextRestoreEvent<T> extends ContextEvent<{ records: ContextDeleteRecord[] }, (ContextChangeRecord<T> | undefined)[]> {
|
|
177
177
|
/**
|
|
178
178
|
* An event dispatched to the context store to restore previously deleted items.
|
|
179
179
|
*
|
|
@@ -183,7 +183,7 @@ export class ContextRestoreEvent<T> extends ContextEvent<ContextDeleteRecord[],
|
|
|
183
183
|
* @param records The records of previously deleted items.
|
|
184
184
|
*/
|
|
185
185
|
constructor(type: string, records: ContextDeleteRecord[]) {
|
|
186
|
-
super(type, records);
|
|
186
|
+
super(type, { records });
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
@@ -232,7 +232,7 @@ export interface ContextUpdateEventDetail<T> {
|
|
|
232
232
|
*/
|
|
233
233
|
item: T;
|
|
234
234
|
/**
|
|
235
|
-
* The
|
|
235
|
+
* The key of the parent object, if applicable.
|
|
236
236
|
*/
|
|
237
237
|
parent?: string;
|
|
238
238
|
}
|
|
@@ -243,7 +243,7 @@ export interface ContextUpdateBulkEventDetail<T> {
|
|
|
243
243
|
*/
|
|
244
244
|
items: T[];
|
|
245
245
|
/**
|
|
246
|
-
* The
|
|
246
|
+
* The key of the parent object, if applicable.
|
|
247
247
|
*/
|
|
248
248
|
parent?: string;
|
|
249
249
|
}
|
|
@@ -6,12 +6,12 @@ export class ClientCertificateEvents {
|
|
|
6
6
|
/**
|
|
7
7
|
* Dispatches an event handled by the data store to read the client certificate.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param key The key of the client certificate
|
|
10
10
|
* @param target A node on which to dispatch the event.
|
|
11
11
|
* @returns Promise resolved to a client certificate model.
|
|
12
12
|
*/
|
|
13
|
-
static async read(
|
|
14
|
-
const e = new ContextReadEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.read,
|
|
13
|
+
static async read(key: string, target: EventTarget = window): Promise<HttpCertificate | undefined> {
|
|
14
|
+
const e = new ContextReadEvent<HttpCertificate>(ModelEventTypes.ClientCertificate.read, key);
|
|
15
15
|
target.dispatchEvent(e);
|
|
16
16
|
return e.detail.result;
|
|
17
17
|
}
|
|
@@ -32,12 +32,12 @@ export class ClientCertificateEvents {
|
|
|
32
32
|
/**
|
|
33
33
|
* Dispatches an event handled by the data store to delete a client certificate
|
|
34
34
|
*
|
|
35
|
-
* @param
|
|
35
|
+
* @param key The key of the project to delete.
|
|
36
36
|
* @param target A node on which to dispatch the event.
|
|
37
37
|
* @returns Promise resolved to a new revision after delete.
|
|
38
38
|
*/
|
|
39
|
-
static async delete(
|
|
40
|
-
const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete,
|
|
39
|
+
static async delete(key: string, target: EventTarget = window): Promise<ContextDeleteRecord | undefined> {
|
|
40
|
+
const e = new ContextDeleteEvent(ModelEventTypes.ClientCertificate.delete, key, undefined);
|
|
41
41
|
target.dispatchEvent(e);
|
|
42
42
|
return e.detail.result;
|
|
43
43
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
3
|
import { IRequestAuthorization } from "../../models/RequestAuthorization.js";
|
|
2
4
|
import { IHttpRequest } from "../../models/HttpRequest.js";
|
|
3
5
|
import { IRequestBaseConfig } from "../../models/RequestConfig.js";
|
|
@@ -4,6 +4,9 @@ import { Response } from './lib/Response.js';
|
|
|
4
4
|
import { User } from './lib/User.js';
|
|
5
5
|
import { History } from './lib/History.js';
|
|
6
6
|
import { Url } from './lib/Url.js';
|
|
7
|
+
import { Certificates } from './lib/Certificates.js';
|
|
8
|
+
import { HostRules } from './lib/HostRules.js';
|
|
9
|
+
import { Arc } from './lib/Arc.js';
|
|
7
10
|
|
|
8
11
|
export { IRequestLogInit } from './lib/Request.js';
|
|
9
12
|
export { IResponseInit } from './lib/Response.js';
|
|
@@ -16,6 +19,9 @@ export class ProjectMock extends DataMock {
|
|
|
16
19
|
user: User;
|
|
17
20
|
history: History;
|
|
18
21
|
url: Url;
|
|
22
|
+
certificates: Certificates;
|
|
23
|
+
hostRules: HostRules;
|
|
24
|
+
arc: Arc;
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* @param init The library init options.
|
|
@@ -27,5 +33,8 @@ export class ProjectMock extends DataMock {
|
|
|
27
33
|
this.user = new User(init);
|
|
28
34
|
this.history = new History(init);
|
|
29
35
|
this.url = new Url(init);
|
|
36
|
+
this.certificates = new Certificates(init);
|
|
37
|
+
this.hostRules = new HostRules(init);
|
|
38
|
+
this.arc = new Arc(init);
|
|
30
39
|
}
|
|
31
40
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Types, IDataMockInit, IHttpRequestInit } from '@pawel-up/data-mock';
|
|
2
|
+
import { IArcHttpRequest, Kind as ArcHttpRequestKind } from '../../models/arc/ArcHttpRequest.js';
|
|
3
|
+
import { Request } from './Request.js';
|
|
4
|
+
|
|
5
|
+
export class Arc {
|
|
6
|
+
protected request: Request;
|
|
7
|
+
protected types: Types;
|
|
8
|
+
|
|
9
|
+
constructor(init: IDataMockInit={}) {
|
|
10
|
+
this.request = new Request(init);
|
|
11
|
+
this.types = new Types(init.seed);
|
|
12
|
+
// this.lorem = new Lorem(init);
|
|
13
|
+
// this.time = new Time(init);
|
|
14
|
+
// this.http = new Http(init);
|
|
15
|
+
// this.response = new Response(init);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
arcRequest(init?: IHttpRequestInit): IArcHttpRequest {
|
|
19
|
+
const request = this.request.request(init);
|
|
20
|
+
return {
|
|
21
|
+
key: this.types.uuid(),
|
|
22
|
+
...request,
|
|
23
|
+
kind: ArcHttpRequestKind,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
arcRequests(size = 25, init?: IHttpRequestInit): IArcHttpRequest[] {
|
|
28
|
+
const result: IArcHttpRequest[] = [];
|
|
29
|
+
for (let i = 0; i < size; i++) {
|
|
30
|
+
result.push(this.arcRequest(init));
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IDataMockInit, Lorem, Random, Types, Utils } from '@pawel-up/data-mock';
|
|
2
|
+
import { HttpCertificate, Certificate, ICertificateData } from '../../models/ClientCertificate.js';
|
|
3
|
+
|
|
4
|
+
export declare interface CertificateCreateInit {
|
|
5
|
+
binary?: boolean;
|
|
6
|
+
noPassphrase?: boolean;
|
|
7
|
+
type?: 'p12' | 'pem';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Certificates {
|
|
11
|
+
lorem: Lorem;
|
|
12
|
+
types: Types;
|
|
13
|
+
random: Random;
|
|
14
|
+
|
|
15
|
+
constructor(init: IDataMockInit={}) {
|
|
16
|
+
this.lorem = new Lorem(init);
|
|
17
|
+
this.types = new Types(init.seed);
|
|
18
|
+
this.random = new Random(init.seed);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a certificate definition.
|
|
23
|
+
*/
|
|
24
|
+
certificate(opts: CertificateCreateInit = {}): HttpCertificate {
|
|
25
|
+
const type = opts.type ? opts.type : this.random.pickOne(['p12', 'pem']);
|
|
26
|
+
const data = this.lorem.paragraph();
|
|
27
|
+
const cert = opts.binary ? Utils.strToBuffer(data) : data;
|
|
28
|
+
let instance: Certificate;
|
|
29
|
+
if (type === 'p12') {
|
|
30
|
+
instance = Certificate.fromP12(cert, this.lorem.word());
|
|
31
|
+
} else if (type === 'pem') {
|
|
32
|
+
instance = Certificate.fromPem(cert, cert, this.lorem.word());
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error(`Invalid certificate type.`);
|
|
35
|
+
}
|
|
36
|
+
if (!opts.noPassphrase) {
|
|
37
|
+
instance.cert.passphrase = this.lorem.word();
|
|
38
|
+
if (type === 'pem') {
|
|
39
|
+
const key = instance.certKey as ICertificateData;
|
|
40
|
+
key.passphrase = this.lorem.word();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return instance.toJSON();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a list of ClientCertificate objects that are used to create a new certificates.
|
|
49
|
+
*
|
|
50
|
+
* @param size The number of certificates to generate.
|
|
51
|
+
* @param opts Create options
|
|
52
|
+
*/
|
|
53
|
+
certificates(size = 15, opts: CertificateCreateInit = {}): HttpCertificate[] {
|
|
54
|
+
const result: HttpCertificate[] = [];
|
|
55
|
+
for (let i = 0; i < size; i++) {
|
|
56
|
+
result[result.length] = this.certificate(opts);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Lorem, Types, Internet, IDataMockInit } from '@pawel-up/data-mock';
|
|
2
|
+
import { IHostRule } from '../../models/HostRule.js';
|
|
3
|
+
|
|
4
|
+
export class HostRules {
|
|
5
|
+
types: Types;
|
|
6
|
+
lorem: Lorem;
|
|
7
|
+
internet: Internet;
|
|
8
|
+
|
|
9
|
+
constructor(init: IDataMockInit = {}) {
|
|
10
|
+
this.types = new Types(init.seed);
|
|
11
|
+
this.lorem = new Lorem(init);
|
|
12
|
+
this.internet = new Internet(init);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generates random host rule data object.
|
|
17
|
+
*/
|
|
18
|
+
rule(): IHostRule {
|
|
19
|
+
const result: IHostRule = {
|
|
20
|
+
key: this.types.uuid(),
|
|
21
|
+
from: this.internet.uri(),
|
|
22
|
+
to: this.internet.uri(),
|
|
23
|
+
enabled: this.types.boolean(),
|
|
24
|
+
comment: this.lorem.paragraph(),
|
|
25
|
+
};
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generates a list of host rules.
|
|
31
|
+
*
|
|
32
|
+
* @param size Number of items to generate. Default to 25.
|
|
33
|
+
* @return List of datastore entries.
|
|
34
|
+
*/
|
|
35
|
+
rules(size = 25): IHostRule[] {
|
|
36
|
+
const result = [];
|
|
37
|
+
for (let i = 0; i < size; i++) {
|
|
38
|
+
result.push(this.rule());
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Http, Types, Lorem, Time, IDataMockInit, IHttpRequestInit } from '@pawel-up/data-mock';
|
|
2
2
|
// import { randomValue } from '@pawel-up/data-mock/src/lib/Http.js';
|
|
3
3
|
import { IHttpRequest, Kind as HttpRequestKind } from '../../models/HttpRequest.js';
|
|
4
|
-
import { IRequest, Kind as RequestKind } from '../../models/Request.js';
|
|
4
|
+
import { IRequest, Kind as RequestKind, Request as RequestModel } from '../../models/Request.js';
|
|
5
5
|
import { ISentRequest } from '../../models/SentRequest.js';
|
|
6
6
|
import { IRequestLog, Kind as RequestLogKind } from '../../models/RequestLog.js';
|
|
7
7
|
import { IResponseInit, Response } from './Response.js';
|
|
@@ -45,14 +45,17 @@ export class Request {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
request(init?: IHttpRequestInit): IRequest {
|
|
48
|
-
|
|
48
|
+
const schema = {
|
|
49
49
|
kind: RequestKind,
|
|
50
50
|
expects: this.httpRequest(init),
|
|
51
51
|
info: {
|
|
52
52
|
name: this.lorem.words(2),
|
|
53
53
|
description: this.lorem.paragraph(),
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
created: this.time.timestamp(),
|
|
56
|
+
};
|
|
57
|
+
const instance = new RequestModel(schema);
|
|
58
|
+
return instance.toJSON();
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
httpRequest(init?: IHttpRequestInit): IHttpRequest {
|
package/src/mocking/lib/Url.ts
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IUrl } from
|
|
1
|
+
import { Internet, Types, Time, IDataMockInit } from '@pawel-up/data-mock';
|
|
2
|
+
import { IUrl } from '../../models/Url.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Mocks the URL data.
|
|
6
|
-
*/
|
|
7
4
|
export class Url {
|
|
8
5
|
types: Types;
|
|
9
6
|
internet: Internet;
|
|
10
|
-
|
|
7
|
+
time: Time;
|
|
8
|
+
|
|
11
9
|
constructor(init: IDataMockInit={}) {
|
|
12
10
|
this.types = new Types(init.seed);
|
|
13
11
|
this.internet = new Internet(init);
|
|
12
|
+
this.time = new Time(init);
|
|
14
13
|
}
|
|
15
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Generates a single ARC URL model item.
|
|
17
|
+
*/
|
|
16
18
|
url(): IUrl {
|
|
17
|
-
const
|
|
19
|
+
const url = this.internet.uri();
|
|
20
|
+
const time = this.types.datetime().getTime();
|
|
18
21
|
const result: IUrl = {
|
|
19
|
-
|
|
20
|
-
cnt: this.types.number({ min:
|
|
21
|
-
|
|
22
|
+
time,
|
|
23
|
+
cnt: this.types.number({ min: 100, max: 1000 }),
|
|
24
|
+
key: url,
|
|
25
|
+
midnight: this.time.midnight(time),
|
|
22
26
|
};
|
|
23
|
-
date.setHours(0, 0, 0, 0);
|
|
24
|
-
result.midnight = date.getTime();
|
|
25
27
|
return result;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Generates list of ARC URL models.
|
|
32
|
+
*
|
|
33
|
+
* @returns List of datastore entries.
|
|
34
|
+
*/
|
|
35
|
+
urls(size = 25): IUrl[] {
|
|
29
36
|
const result: IUrl[] = [];
|
|
30
37
|
for (let i = 0; i < size; i++) {
|
|
31
38
|
result.push(this.url());
|
|
@@ -71,7 +71,7 @@ export interface IPemCertificate extends ICertificate {
|
|
|
71
71
|
certKey: ICertificateData;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export type HttpCertificate = IP12Certificate | IPemCertificate;
|
|
74
|
+
export type HttpCertificate = IP12Certificate | IPemCertificate | ICertificate;
|
|
75
75
|
|
|
76
76
|
export interface IPemCreateOptions {
|
|
77
77
|
type: 'p12';
|
|
@@ -128,7 +128,7 @@ export class Certificate {
|
|
|
128
128
|
* Timestamp when the certificate was inserted into the data store.
|
|
129
129
|
* Required when returning a result. Auto-generated when inserting, if missing.
|
|
130
130
|
*/
|
|
131
|
-
created
|
|
131
|
+
created = 0;
|
|
132
132
|
/**
|
|
133
133
|
* Certificate type. Either `p12` or `pem`.
|
|
134
134
|
*/
|
|
@@ -162,6 +162,7 @@ export class Certificate {
|
|
|
162
162
|
key: v4(),
|
|
163
163
|
name,
|
|
164
164
|
type: 'pem',
|
|
165
|
+
created: Date.now(),
|
|
165
166
|
};
|
|
166
167
|
if (keyPassphrase) {
|
|
167
168
|
init.certKey.passphrase = keyPassphrase;
|
|
@@ -185,6 +186,7 @@ export class Certificate {
|
|
|
185
186
|
key: v4(),
|
|
186
187
|
name,
|
|
187
188
|
type: 'p12',
|
|
189
|
+
created: Date.now(),
|
|
188
190
|
};
|
|
189
191
|
if (passphrase) {
|
|
190
192
|
init.cert.passphrase = passphrase;
|
|
@@ -224,6 +226,7 @@ export class Certificate {
|
|
|
224
226
|
key: _id,
|
|
225
227
|
name,
|
|
226
228
|
type: 'p12',
|
|
229
|
+
created,
|
|
227
230
|
};
|
|
228
231
|
return new Certificate(init);
|
|
229
232
|
}
|
|
@@ -231,16 +234,15 @@ export class Certificate {
|
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
constructor(certificate: HttpCertificate) {
|
|
234
|
-
const { type, cert, key = v4(), name = '', created } = certificate;
|
|
237
|
+
const { type, cert, key = v4(), name = '', created = Date.now() } = certificate;
|
|
235
238
|
this.key = key;
|
|
236
239
|
this.name = name;
|
|
237
240
|
this.type = type;
|
|
238
241
|
this.cert = Certificate.fromStore(cert);
|
|
239
|
-
|
|
240
|
-
this.created = created;
|
|
241
|
-
}
|
|
242
|
+
this.created = created;
|
|
242
243
|
if (type === 'pem') {
|
|
243
|
-
|
|
244
|
+
const typed = certificate as IPemCertificate;
|
|
245
|
+
this.certKey = Certificate.fromStore(typed.certKey);
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
|
|
@@ -288,12 +290,13 @@ export class Certificate {
|
|
|
288
290
|
}
|
|
289
291
|
|
|
290
292
|
toJSON(): HttpCertificate {
|
|
291
|
-
const result:
|
|
293
|
+
const result: HttpCertificate = {
|
|
292
294
|
kind: Kind,
|
|
293
295
|
key: this.key,
|
|
294
296
|
cert: Certificate.toStore(this.cert),
|
|
295
297
|
name: this.name,
|
|
296
|
-
type:
|
|
298
|
+
type: this.type,
|
|
299
|
+
created: this.created,
|
|
297
300
|
};
|
|
298
301
|
|
|
299
302
|
if (this.type === 'pem' && this.certKey) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IRequest, Request } from "../Request.js";
|
|
2
|
-
import v4 from "../../lib/uuid.js";
|
|
3
2
|
import { HttpRequest, IHttpRequest } from "../HttpRequest.js";
|
|
4
3
|
import { Thing } from "../Thing.js";
|
|
5
4
|
|
|
@@ -15,6 +14,7 @@ export class ArcHttpRequest extends Request {
|
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* The identifier of the request.
|
|
17
|
+
* The key is related to the `created` property. It is the `new Date(created).toJSON()` value.
|
|
18
18
|
*/
|
|
19
19
|
key = '';
|
|
20
20
|
|
|
@@ -24,9 +24,10 @@ export class ArcHttpRequest extends Request {
|
|
|
24
24
|
* @param url The Request URL. This is required.
|
|
25
25
|
*/
|
|
26
26
|
static fromUrl(url: string): ArcHttpRequest {
|
|
27
|
-
const
|
|
27
|
+
const d = new Date();
|
|
28
|
+
const now: number = d.getTime();
|
|
28
29
|
const request = new ArcHttpRequest({
|
|
29
|
-
key:
|
|
30
|
+
key: d.toJSON(),
|
|
30
31
|
kind: Kind,
|
|
31
32
|
created: now,
|
|
32
33
|
updated: now,
|
|
@@ -42,9 +43,10 @@ export class ArcHttpRequest extends Request {
|
|
|
42
43
|
* @param name The Request name.
|
|
43
44
|
*/
|
|
44
45
|
static fromName(name: string): ArcHttpRequest {
|
|
45
|
-
const
|
|
46
|
+
const d = new Date();
|
|
47
|
+
const now: number = d.getTime();
|
|
46
48
|
const request = new ArcHttpRequest({
|
|
47
|
-
key:
|
|
49
|
+
key: d.toJSON(),
|
|
48
50
|
kind: Kind,
|
|
49
51
|
created: now,
|
|
50
52
|
updated: now,
|
|
@@ -60,9 +62,10 @@ export class ArcHttpRequest extends Request {
|
|
|
60
62
|
* @param info The request data.
|
|
61
63
|
*/
|
|
62
64
|
static fromHttpRequest(info: IHttpRequest): ArcHttpRequest {
|
|
63
|
-
const
|
|
65
|
+
const d = new Date();
|
|
66
|
+
const now: number = d.getTime();
|
|
64
67
|
const request = new ArcHttpRequest({
|
|
65
|
-
key:
|
|
68
|
+
key: d.toJSON(),
|
|
66
69
|
kind: Kind,
|
|
67
70
|
created: now,
|
|
68
71
|
updated: now,
|
|
@@ -76,11 +79,13 @@ export class ArcHttpRequest extends Request {
|
|
|
76
79
|
* Creates a request for a schema of a Request.
|
|
77
80
|
*/
|
|
78
81
|
static fromRequest(request: IArcHttpRequest): ArcHttpRequest {
|
|
79
|
-
const
|
|
82
|
+
const d = new Date(request.created || Date.now());
|
|
83
|
+
const now: number = d.getTime();
|
|
80
84
|
const init: IArcHttpRequest = {
|
|
81
85
|
...request,
|
|
82
|
-
key,
|
|
83
|
-
kind: Kind
|
|
86
|
+
key: d.toJSON(),
|
|
87
|
+
kind: Kind,
|
|
88
|
+
created: now,
|
|
84
89
|
};
|
|
85
90
|
const result = new ArcHttpRequest(init);
|
|
86
91
|
return result;
|
|
@@ -96,7 +101,10 @@ export class ArcHttpRequest extends Request {
|
|
|
96
101
|
init = input;
|
|
97
102
|
}
|
|
98
103
|
if (init) {
|
|
99
|
-
this.key = init.key
|
|
104
|
+
this.key = init.key;
|
|
105
|
+
}
|
|
106
|
+
if (!this.key) {
|
|
107
|
+
this.key = new Date(this.created || Date.now()).toJSON();
|
|
100
108
|
}
|
|
101
109
|
this.kind = Kind;
|
|
102
110
|
}
|
|
@@ -105,7 +113,7 @@ export class ArcHttpRequest extends Request {
|
|
|
105
113
|
super.new(init);
|
|
106
114
|
|
|
107
115
|
const { key } = init;
|
|
108
|
-
this.key = key ||
|
|
116
|
+
this.key = key || new Date(init.created || Date.now()).toJSON();
|
|
109
117
|
this.kind = Kind;
|
|
110
118
|
}
|
|
111
119
|
|
|
@@ -951,12 +951,15 @@ export class ArcProject extends ArcProjectParent {
|
|
|
951
951
|
init.kind = ArcProjectKind;
|
|
952
952
|
}
|
|
953
953
|
} else {
|
|
954
|
+
const now = Date.now();
|
|
954
955
|
init = {
|
|
955
956
|
kind: ArcProjectKind,
|
|
956
957
|
key: v4(),
|
|
957
958
|
definitions: {},
|
|
958
959
|
items: [],
|
|
959
960
|
info: Thing.fromName('').toJSON(),
|
|
961
|
+
created: now,
|
|
962
|
+
updated: now,
|
|
960
963
|
}
|
|
961
964
|
}
|
|
962
965
|
this.new(init);
|
|
@@ -1001,6 +1004,8 @@ export class ArcProject extends ArcProjectParent {
|
|
|
1001
1004
|
definitions: {},
|
|
1002
1005
|
items: [],
|
|
1003
1006
|
info: this.info.toJSON(),
|
|
1007
|
+
created: this.created,
|
|
1008
|
+
updated: this.updated,
|
|
1004
1009
|
};
|
|
1005
1010
|
if (Array.isArray(this.definitions.requests) && this.definitions.requests.length) {
|
|
1006
1011
|
result.definitions.requests = this.definitions.requests.map(i => i.toJSON());
|