@azure-net/kit 0.7.0 → 0.8.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/core/classMirror/ClassMirror.d.ts +3 -0
- package/dist/core/{application/ProxyResourceService.js → classMirror/ClassMirror.js} +4 -6
- package/dist/core/classMirror/index.d.ts +1 -0
- package/dist/core/classMirror/index.js +1 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/infra/resource/BaseResource.d.ts +6 -6
- package/dist/core/infra/resource/BaseResource.js +1 -1
- package/dist/core/infra/response/BaseResponse.d.ts +5 -1
- package/dist/core/infra/response/BaseResponse.js +13 -1
- package/dist/lib/eventModifiers/EventModifiers.d.ts +16 -5
- package/dist/lib/eventModifiers/EventModifiers.js +29 -20
- package/package.json +1 -1
- package/dist/core/application/ProxyResourceService.d.ts +0 -4
- package/dist/core/application/index.d.ts +0 -1
- package/dist/core/application/index.js +0 -1
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
this.repository = repo;
|
|
5
|
-
const proto = Object.getPrototypeOf(repo);
|
|
1
|
+
export class ClassMirror {
|
|
2
|
+
constructor(target) {
|
|
3
|
+
const proto = Object.getPrototypeOf(target);
|
|
6
4
|
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
7
5
|
if (name === 'constructor')
|
|
8
6
|
continue;
|
|
@@ -12,7 +10,7 @@ export class ProxyResourceService {
|
|
|
12
10
|
if (name in this)
|
|
13
11
|
continue;
|
|
14
12
|
Object.defineProperty(this, name, {
|
|
15
|
-
value: descriptor.value.bind(
|
|
13
|
+
value: descriptor.value.bind(target),
|
|
16
14
|
configurable: true,
|
|
17
15
|
writable: true
|
|
18
16
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ClassMirror.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ClassMirror.js';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export * from './infra/resource/index.js';
|
|
|
3
3
|
export * from './infra/httpService/index.js';
|
|
4
4
|
export * from './infra/datasource/index.js';
|
|
5
5
|
export * from './infra/query/index.js';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './classMirror/index.js';
|
|
7
7
|
export * from './request/index.js';
|
|
8
8
|
export * from './boundaryProvider/index.js';
|
package/dist/core/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export * from './infra/resource/index.js';
|
|
|
3
3
|
export * from './infra/httpService/index.js';
|
|
4
4
|
export * from './infra/datasource/index.js';
|
|
5
5
|
export * from './infra/query/index.js';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './classMirror/index.js';
|
|
7
7
|
export * from './request/index.js';
|
|
8
8
|
export * from './boundaryProvider/index.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type
|
|
1
|
+
export type PlainObject<T> = {
|
|
2
2
|
[K in keyof T as K extends string ? (T[K] extends (...args: unknown[]) => unknown ? never : K) : never]: T[K];
|
|
3
3
|
};
|
|
4
|
-
export interface
|
|
5
|
-
toPlainObject():
|
|
4
|
+
export interface IDTOMapper<TOutput = never> {
|
|
5
|
+
toPlainObject(): [TOutput] extends [never] ? PlainObject<this> : TOutput;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
export type Collection<T> = T[];
|
|
8
|
+
export declare class DTOMapper<TOutput = never> implements IDTOMapper<TOutput> {
|
|
9
|
+
toPlainObject(): [TOutput] extends [never] ? PlainObject<this> : TOutput;
|
|
9
10
|
}
|
|
10
|
-
export {};
|
|
@@ -7,14 +7,18 @@ type ResponseBuilderState<TData, TMeta = unknown> = {
|
|
|
7
7
|
data: TData;
|
|
8
8
|
meta: TMeta;
|
|
9
9
|
};
|
|
10
|
+
type ArrayElement<T> = T extends readonly (infer E)[] ? E : never;
|
|
10
11
|
export declare class ResponseBuilder<TData = unknown, TMeta = object, TWrapper = TData> {
|
|
11
12
|
protected readonly response: HttpServiceResponse<TWrapper>;
|
|
12
13
|
protected state: ResponseBuilderState<TData, TMeta>;
|
|
13
14
|
constructor(response: HttpServiceResponse<TWrapper>);
|
|
14
15
|
protected unwrapData(data: TWrapper): TData;
|
|
15
|
-
|
|
16
|
+
mapUsing<TResource>(ResourceClass: new (data: TData) => {
|
|
16
17
|
toPlainObject(): TResource;
|
|
17
18
|
}): ResponseBuilder<TResource, TMeta, TWrapper>;
|
|
19
|
+
mapCollectionUsing<TResource>(ResourceClass: new (data: ArrayElement<TData>) => {
|
|
20
|
+
toPlainObject(): TResource;
|
|
21
|
+
}): ResponseBuilder<TResource[], TMeta, TWrapper>;
|
|
18
22
|
extract<TPath extends DeepKeys<TData>>(path: TPath): ResponseBuilder<DeepValue<TData, TPath>, TMeta, TWrapper>;
|
|
19
23
|
addMeta<TNewMeta extends Record<string, unknown>>(metaData: TNewMeta | ((current: TMeta) => TNewMeta)): ResponseBuilder<TData, TMeta & TNewMeta, TWrapper>;
|
|
20
24
|
getData(): TData;
|
|
@@ -12,7 +12,7 @@ export class ResponseBuilder {
|
|
|
12
12
|
unwrapData(data) {
|
|
13
13
|
return data;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
mapUsing(ResourceClass) {
|
|
16
16
|
const resource = new ResourceClass(this.state.data);
|
|
17
17
|
const newResponse = new ResponseBuilder(this.response);
|
|
18
18
|
newResponse.state = {
|
|
@@ -21,6 +21,18 @@ export class ResponseBuilder {
|
|
|
21
21
|
};
|
|
22
22
|
return newResponse;
|
|
23
23
|
}
|
|
24
|
+
mapCollectionUsing(ResourceClass) {
|
|
25
|
+
if (!Array.isArray(this.state.data)) {
|
|
26
|
+
throw new Error('toCollection can only be used when data is an array');
|
|
27
|
+
}
|
|
28
|
+
const collection = this.state.data.map((dataElement) => new ResourceClass(dataElement).toPlainObject());
|
|
29
|
+
const newResponse = new ResponseBuilder(this.response);
|
|
30
|
+
newResponse.state = {
|
|
31
|
+
...this.state,
|
|
32
|
+
data: collection
|
|
33
|
+
};
|
|
34
|
+
return newResponse;
|
|
35
|
+
}
|
|
24
36
|
extract(path) {
|
|
25
37
|
const keys = path.split('.');
|
|
26
38
|
let result = this.state.data;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
export type EventHandler<E = Event> = (event: E) => void;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
interface EventModifier<E extends Event = Event> {
|
|
3
|
+
(fn: () => void): EventHandler<E>;
|
|
4
|
+
prevent: EventModifier<E>;
|
|
5
|
+
stop: EventModifier<E>;
|
|
6
|
+
immediate: EventModifier<E>;
|
|
7
|
+
once: EventModifier<E>;
|
|
8
|
+
preventDefault: EventModifier<E>;
|
|
9
|
+
stopPropagation: EventModifier<E>;
|
|
10
|
+
stopImmediatePropagation: EventModifier<E>;
|
|
11
|
+
}
|
|
12
|
+
export declare const prevent: EventModifier<Event>;
|
|
13
|
+
export declare const stop: EventModifier<Event>;
|
|
14
|
+
export declare const immediate: EventModifier<Event>;
|
|
15
|
+
export declare const once: EventModifier<Event>;
|
|
16
|
+
export declare const event: EventModifier<Event>;
|
|
17
|
+
export {};
|
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
const createEventModifier = (modifiers = new Set()) => {
|
|
2
|
+
return new Proxy(() => { }, {
|
|
3
|
+
get(_, prop) {
|
|
4
|
+
return createEventModifier(new Set([...modifiers, prop]));
|
|
5
|
+
},
|
|
6
|
+
apply(_, __, [fn]) {
|
|
7
|
+
let executed = false;
|
|
8
|
+
return (event) => {
|
|
9
|
+
if (modifiers.has('once') && executed)
|
|
10
|
+
return;
|
|
11
|
+
if (modifiers.has('prevent') || modifiers.has('preventDefault')) {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
}
|
|
14
|
+
if (modifiers.has('stop') || modifiers.has('stopPropagation')) {
|
|
15
|
+
event.stopPropagation();
|
|
16
|
+
}
|
|
17
|
+
if (modifiers.has('immediate') || modifiers.has('stopImmediatePropagation')) {
|
|
18
|
+
event.stopImmediatePropagation();
|
|
19
|
+
}
|
|
20
|
+
if (modifiers.has('once'))
|
|
21
|
+
executed = true;
|
|
22
|
+
fn();
|
|
23
|
+
};
|
|
19
24
|
}
|
|
20
|
-
};
|
|
25
|
+
});
|
|
21
26
|
};
|
|
22
|
-
export const
|
|
27
|
+
export const prevent = createEventModifier(new Set(['prevent']));
|
|
28
|
+
export const stop = createEventModifier(new Set(['stop']));
|
|
29
|
+
export const immediate = createEventModifier(new Set(['immediate']));
|
|
30
|
+
export const once = createEventModifier(new Set(['once']));
|
|
31
|
+
export const event = createEventModifier();
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ProxyResourceService.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ProxyResourceService.js';
|