@bett3r-dev/pv3-types 1.0.0 → 1.4.0
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/CHANGELOG.md +305 -0
- package/build/adminPlugin.d.ts +24 -0
- package/build/adminPlugin.d.ts.map +1 -0
- package/build/{eventsourcing/utils.js → adminPlugin.js} +1 -1
- package/build/adminPlugin.js.map +1 -0
- package/build/aggregateSchema.d.ts +94 -0
- package/build/aggregateSchema.d.ts.map +1 -0
- package/build/aggregateSchema.js +287 -0
- package/build/aggregateSchema.js.map +1 -0
- package/build/authentication.d.ts +179 -78
- package/build/authentication.d.ts.map +1 -1
- package/build/authentication.js +62 -19
- package/build/authentication.js.map +1 -1
- package/build/cache.d.ts +50 -4
- package/build/cache.d.ts.map +1 -1
- package/build/clusterAdministration.d.ts +712 -225
- package/build/clusterAdministration.d.ts.map +1 -1
- package/build/clusterAdministration.js +175 -52
- package/build/clusterAdministration.js.map +1 -1
- package/build/configuration.d.ts +26 -5
- package/build/configuration.d.ts.map +1 -1
- package/build/database.d.ts +240 -56
- package/build/database.d.ts.map +1 -1
- package/build/database.js +102 -20
- package/build/database.js.map +1 -1
- package/build/endpoints.d.ts +141 -41
- package/build/endpoints.d.ts.map +1 -1
- package/build/endpoints.js +50 -26
- package/build/endpoints.js.map +1 -1
- package/build/errors.d.ts +166 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +276 -0
- package/build/errors.js.map +1 -0
- package/build/evenstore.d.ts +47 -7
- package/build/evenstore.d.ts.map +1 -1
- package/build/eventsourcing/aggregateBuilder.d.ts +17 -8
- package/build/eventsourcing/aggregateBuilder.d.ts.map +1 -1
- package/build/eventsourcing/commandBuilder.d.ts +20 -13
- package/build/eventsourcing/commandBuilder.d.ts.map +1 -1
- package/build/eventsourcing/commandHandlers.d.ts +155 -33
- package/build/eventsourcing/commandHandlers.d.ts.map +1 -1
- package/build/eventsourcing/commandHandlers.js +62 -14
- package/build/eventsourcing/commandHandlers.js.map +1 -1
- package/build/eventsourcing/eventHandlers.d.ts +173 -44
- package/build/eventsourcing/eventHandlers.d.ts.map +1 -1
- package/build/eventsourcing/eventHandlers.js +29 -21
- package/build/eventsourcing/eventHandlers.js.map +1 -1
- package/build/eventsourcing/eventHandlersBuilder.d.ts +18 -12
- package/build/eventsourcing/eventHandlersBuilder.d.ts.map +1 -1
- package/build/eventsourcing/eventHandlersBuilder.js.map +1 -1
- package/build/eventsourcing/eventsourcing.types.d.ts +322 -0
- package/build/eventsourcing/eventsourcing.types.d.ts.map +1 -0
- package/build/eventsourcing/eventsourcing.types.js +26 -0
- package/build/eventsourcing/eventsourcing.types.js.map +1 -0
- package/build/eventsourcing/externalSystemBuilder.d.ts +8 -7
- package/build/eventsourcing/externalSystemBuilder.d.ts.map +1 -1
- package/build/eventsourcing/index.d.ts +2 -378
- package/build/eventsourcing/index.d.ts.map +1 -1
- package/build/eventsourcing/index.js +2 -23
- package/build/eventsourcing/index.js.map +1 -1
- package/build/eventsourcing/invariants.d.ts +34 -10
- package/build/eventsourcing/invariants.d.ts.map +1 -1
- package/build/eventsourcing/shapeChangeForSubscriber.d.ts +33 -0
- package/build/eventsourcing/shapeChangeForSubscriber.d.ts.map +1 -0
- package/build/eventsourcing/shapeChangeForSubscriber.js +47 -0
- package/build/eventsourcing/shapeChangeForSubscriber.js.map +1 -0
- package/build/index.d.ts +6 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -1
- package/build/index.js.map +1 -1
- package/build/infrastructure.d.ts +9 -1
- package/build/infrastructure.d.ts.map +1 -1
- package/build/infrastructure.js +33 -1
- package/build/infrastructure.js.map +1 -1
- package/build/livenessWatchdog.d.ts +28 -0
- package/build/livenessWatchdog.d.ts.map +1 -0
- package/build/livenessWatchdog.js +43 -0
- package/build/livenessWatchdog.js.map +1 -0
- package/build/logger.d.ts +8 -9
- package/build/logger.d.ts.map +1 -1
- package/build/logger.js +18 -6
- package/build/logger.js.map +1 -1
- package/build/outboxManager.d.ts +858 -14
- package/build/outboxManager.d.ts.map +1 -1
- package/build/outboxManager.js +173 -15
- package/build/outboxManager.js.map +1 -1
- package/build/permissions.d.ts +47 -0
- package/build/permissions.d.ts.map +1 -0
- package/build/permissions.js +3 -0
- package/build/permissions.js.map +1 -0
- package/build/ports.d.ts +10 -10
- package/build/ports.d.ts.map +1 -1
- package/build/routesAuth.d.ts +17 -25
- package/build/routesAuth.d.ts.map +1 -1
- package/build/routesAuth.js +4 -14
- package/build/routesAuth.js.map +1 -1
- package/build/typedEventEmitter.d.ts +7 -13
- package/build/typedEventEmitter.d.ts.map +1 -1
- package/build/typedEventEmitter.js +2 -2
- package/build/typedEventEmitter.js.map +1 -1
- package/build/userSession.d.ts +8 -0
- package/build/userSession.d.ts.map +1 -0
- package/build/userSession.js +3 -0
- package/build/userSession.js.map +1 -0
- package/package.json +22 -7
- package/build/eventsourcing/utils.d.ts +0 -4
- package/build/eventsourcing/utils.d.ts.map +0 -1
- package/build/eventsourcing/utils.js.map +0 -1
- package/build/validation.d.ts +0 -64
- package/build/validation.d.ts.map +0 -1
- package/build/validation.js +0 -57
- package/build/validation.js.map +0 -1
- package/src/authentication.ts +0 -273
- package/src/cache.ts +0 -109
- package/src/clusterAdministration.ts +0 -216
- package/src/configuration.ts +0 -71
- package/src/database.ts +0 -157
- package/src/endpoints.ts +0 -198
- package/src/evenstore.ts +0 -27
- package/src/eventsourcing/aggregateBuilder.ts +0 -11
- package/src/eventsourcing/commandBuilder.ts +0 -64
- package/src/eventsourcing/commandHandlers.ts +0 -137
- package/src/eventsourcing/eventHandlers.ts +0 -118
- package/src/eventsourcing/eventHandlersBuilder.ts +0 -42
- package/src/eventsourcing/externalSystemBuilder.ts +0 -20
- package/src/eventsourcing/index.ts +0 -111
- package/src/eventsourcing/invariants.ts +0 -27
- package/src/eventsourcing/utils.ts +0 -4
- package/src/index.ts +0 -15
- package/src/infrastructure.ts +0 -41
- package/src/logger.ts +0 -45
- package/src/outboxManager.ts +0 -36
- package/src/ports.ts +0 -42
- package/src/routesAuth.ts +0 -58
- package/src/typedEventEmitter.ts +0 -73
- package/src/validation.ts +0 -89
- package/tsconfig.json +0 -15
package/src/ports.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AuthenticationPort } from './authentication';
|
|
2
|
-
import { CachePort } from './cache';
|
|
3
|
-
import { ConfigurationPort } from './configuration';
|
|
4
|
-
import { DatabasePort } from './database';
|
|
5
|
-
import { EndpointsPort } from './endpoints';
|
|
6
|
-
import { EventStorePort } from './evenstore';
|
|
7
|
-
import { EventSourcingPort } from './eventsourcing';
|
|
8
|
-
import { InfrastructurePortType } from './infrastructure';
|
|
9
|
-
import { LoggerPort } from './logger';
|
|
10
|
-
import { TypedEventEmitter } from './typedEventEmitter';
|
|
11
|
-
|
|
12
|
-
export type PortEmitterEvents = {
|
|
13
|
-
started: void,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Base type for Porst that exposes an EventEmitter interface for handling the 'started' event.
|
|
18
|
-
*/
|
|
19
|
-
export type PortEmitter = {
|
|
20
|
-
isStarted: boolean,
|
|
21
|
-
emitter: TypedEventEmitter<PortEmitterEvents>,
|
|
22
|
-
onStarted: ( fn: () => void ) => void
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type AdapterBase<T = any> = {
|
|
26
|
-
name: string,
|
|
27
|
-
_adapter: () => T,
|
|
28
|
-
start: () => Promise<void>,
|
|
29
|
-
stop: () => Promise<void>,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type Ports = {
|
|
33
|
-
configuration: ConfigurationPort,
|
|
34
|
-
logger: LoggerPort,
|
|
35
|
-
cache: CachePort,
|
|
36
|
-
endpoints: EndpointsPort,
|
|
37
|
-
database: DatabasePort,
|
|
38
|
-
eventstore: EventStorePort,
|
|
39
|
-
eventsourcing: EventSourcingPort,
|
|
40
|
-
authentication: AuthenticationPort,
|
|
41
|
-
infrastructure: InfrastructurePortType
|
|
42
|
-
}
|
package/src/routesAuth.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import S from '@bett3r-dev/jsonschema-definer';
|
|
2
|
-
import { METHODS } from 'http';
|
|
3
|
-
import { Event } from './eventsourcing';
|
|
4
|
-
import { Ports } from './ports';
|
|
5
|
-
import { ClusterRoutesConfigType } from './clusterAdministration';
|
|
6
|
-
|
|
7
|
-
export const ClusterRoutesAggregateSchema = S.shape({
|
|
8
|
-
method: S.string().enum( ...METHODS.map( m=>m.toLocaleLowerCase())),
|
|
9
|
-
id: S.string(),
|
|
10
|
-
isPublic: S.boolean().optional(),
|
|
11
|
-
roles: S.array().items( S.string()).optional(),
|
|
12
|
-
});
|
|
13
|
-
export type ClusterRoutesAggregateType = typeof ClusterRoutesAggregateSchema.type;
|
|
14
|
-
|
|
15
|
-
export type RouteManagerEndpointAuth = ClusterRoutesAggregateType;
|
|
16
|
-
|
|
17
|
-
export const UpsertRouteCommandSchema = S.shape({}).additionalProperties( ClusterRoutesAggregateSchema );
|
|
18
|
-
export const DeleteRouteCommandSchema = S.array().items( S.string());
|
|
19
|
-
|
|
20
|
-
export const ClusterManagerEvents = {
|
|
21
|
-
RoutesUpserted: () => Event({
|
|
22
|
-
schema: UpsertRouteCommandSchema
|
|
23
|
-
}),
|
|
24
|
-
RouteDeleted: () => Event({
|
|
25
|
-
schema: DeleteRouteCommandSchema
|
|
26
|
-
})
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Represents the place where the routes are stored and consumed by an authorization server.
|
|
32
|
-
* Usually this store will live in a Cache and holds all the endpoints of the application
|
|
33
|
-
* and their access requirements. That means if the resource is public, or what roles can have access.
|
|
34
|
-
*/
|
|
35
|
-
export type RoutesAuthManagerType = {
|
|
36
|
-
getAllRoutes: () => Promise<RouteManagerEndpointAuth[]>;
|
|
37
|
-
getRoute: ( method:string, route: string ) => Promise<Pick<RouteManagerEndpointAuth, 'isPublic'|'roles'> | false>
|
|
38
|
-
upsertRoute: ( endpoint: RouteManagerEndpointAuth ) => Promise<RouteManagerEndpointAuth>;
|
|
39
|
-
subscribeToRoutesAuthChanges: ( onStructureChanges: ( change: ClusterRoutesAggregateType ) => void ) => Promise<{ unsubscribe: () => void }>;
|
|
40
|
-
stop: () => Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type RouteAuthManagerFactory = ( ports: Pick<Ports, 'database'|'eventstore'>, config: ClusterRoutesConfigType, eventstore?: Ports['eventstore']) => RoutesAuthManagerType
|
|
44
|
-
|
|
45
|
-
// Endpoints Schemas
|
|
46
|
-
export const EndpointMarkedAsPublicSchema = S.shape({
|
|
47
|
-
method: S.string().enum( ...METHODS.map( m=>m.toLocaleLowerCase())),
|
|
48
|
-
id: S.string(),
|
|
49
|
-
isPublic: S.boolean().optional()
|
|
50
|
-
});
|
|
51
|
-
export type EndpointMarkedAsPublic = typeof EndpointMarkedAsPublicSchema.type
|
|
52
|
-
|
|
53
|
-
export const EndpointRolesUpsertedSchema = S.shape({
|
|
54
|
-
method: S.string().enum( ...METHODS.map( m=>m.toLocaleLowerCase())),
|
|
55
|
-
id: S.string(),
|
|
56
|
-
roles: S.array().items( S.string()),
|
|
57
|
-
});
|
|
58
|
-
export type EndpointRolesUpserted = typeof EndpointRolesUpsertedSchema.type
|
package/src/typedEventEmitter.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { EventEmitter as NativeEventEmitter } from 'events';
|
|
2
|
-
|
|
3
|
-
declare module 'events' {
|
|
4
|
-
interface EventEmitter {
|
|
5
|
-
on<K extends keyof any>( event: K, listener: ( ...args: any[]) => void ): this;
|
|
6
|
-
emit<K extends keyof any>( event: K, ...args: any[]): boolean;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class TypedEventEmitter<T> {
|
|
11
|
-
|
|
12
|
-
private emitter = new NativeEventEmitter();
|
|
13
|
-
|
|
14
|
-
on<K extends keyof T>( event: K, listener: ( arg: T[K]) => void ): this {
|
|
15
|
-
this.emitter.on( event as string, listener );
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
emit<K extends keyof T>( event: K, arg?: T[K]): boolean {
|
|
20
|
-
return this.emitter.emit( event as string, arg );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
off<K extends keyof T>( event: K, listener: ( arg: T[K]) => void ): this {
|
|
24
|
-
this.emitter.off( event as string, listener );
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
once<K extends keyof T>( event: K, listener: ( arg: T[K]) => void ): this {
|
|
29
|
-
this.emitter.once( event as string, listener );
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
removeAllListeners<K extends keyof T>( event?: K ): this {
|
|
34
|
-
this.emitter.removeAllListeners( event as string );
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
listeners<K extends keyof T>( event: K ): Function[] {
|
|
39
|
-
return this.emitter.listeners( event as string );
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
rawListeners<K extends keyof T>( event: K ): Function[] {
|
|
43
|
-
return this.emitter.rawListeners( event as string );
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
listenerCount<K extends keyof T>( event: K ): number {
|
|
47
|
-
return this.emitter.listenerCount( event as string );
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
prependListener<K extends keyof T>( event: K, listener: ( arg: T[K]) => void ): this {
|
|
51
|
-
this.emitter.prependListener( event as string, listener );
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
prependOnceListener<K extends keyof T>( event: K, listener: ( arg: T[K]) => void ): this {
|
|
56
|
-
this.emitter.prependOnceListener( event as string, listener );
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
eventNames(): ( keyof T )[] {
|
|
61
|
-
return this.emitter.eventNames() as ( keyof T )[];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getMaxListeners(): number {
|
|
65
|
-
return this.emitter.getMaxListeners();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
setMaxListeners( n: number ): this {
|
|
69
|
-
this.emitter.setMaxListeners( n );
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
package/src/validation.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import S, { BaseSchema } from '@bett3r-dev/jsonschema-definer';
|
|
2
|
-
|
|
3
|
-
export type AppErrorInstance<ErrorPayload = unknown> = Error & AppErrorData<ErrorPayload>
|
|
4
|
-
export type AppErrorData<ErrorPayload = unknown> = {
|
|
5
|
-
error?: string,
|
|
6
|
-
description?: string,
|
|
7
|
-
type: ErrorTypes,
|
|
8
|
-
details?: ErrorPayload,
|
|
9
|
-
status?:number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type AppErrorType<ErrorPayload = any> = AppErrorData<ErrorPayload> & {schema?: BaseSchema<ErrorPayload>}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @hidden
|
|
16
|
-
*/
|
|
17
|
-
export const errorStatusCodeMap = {
|
|
18
|
-
BadRequestError: 400,
|
|
19
|
-
UnauthorizedError: 401,
|
|
20
|
-
PaymentRequiredError: 402,
|
|
21
|
-
ForbiddenError: 403,
|
|
22
|
-
NotFoundError: 404,
|
|
23
|
-
MethodNotAllowedError: 405,
|
|
24
|
-
NotAcceptableError: 406,
|
|
25
|
-
ProxyAuthenticationRequiredError: 407,
|
|
26
|
-
RequestTimeoutError: 408,
|
|
27
|
-
ConflictError: 409,
|
|
28
|
-
ConcurrencyError: 409,
|
|
29
|
-
GoneError: 410,
|
|
30
|
-
LengthRequiredError: 411,
|
|
31
|
-
PreconditionFailedError: 412,
|
|
32
|
-
PayloadTooLargeError: 413,
|
|
33
|
-
TooManyRequestsError: 429,
|
|
34
|
-
InternalServerError: 500,
|
|
35
|
-
NotImplementedError: 501,
|
|
36
|
-
BadGatewayError: 502,
|
|
37
|
-
ServiceUnavailableError: 503,
|
|
38
|
-
GatewayTimeoutError: 504,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const statusCodeErrorMap = {
|
|
42
|
-
400: 'BadRequestError',
|
|
43
|
-
401: 'UnauthorizedError',
|
|
44
|
-
402: 'PaymentRequiredError',
|
|
45
|
-
403: 'ForbiddenError',
|
|
46
|
-
404: 'NotFoundError',
|
|
47
|
-
405: 'MethodNotAllowedError',
|
|
48
|
-
406: 'NotAcceptableError',
|
|
49
|
-
407: 'ProxyAuthenticationRequiredError',
|
|
50
|
-
408: 'RequestTimeoutError',
|
|
51
|
-
409: 'ConcurrencyError',
|
|
52
|
-
410: 'GoneError',
|
|
53
|
-
411: 'LengthRequiredError',
|
|
54
|
-
412: 'PreconditionFailedError',
|
|
55
|
-
413: 'PayloadTooLargeError',
|
|
56
|
-
429: 'TooManyRequestsError',
|
|
57
|
-
500: 'InternalServerError',
|
|
58
|
-
501: 'NotImplementedError',
|
|
59
|
-
502: 'BadGatewayError',
|
|
60
|
-
503: 'ServiceUnavailableError',
|
|
61
|
-
504: 'GatewayTimeoutError',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const ErrorTypesSchema = S.string().enum(
|
|
66
|
-
'BadRequestError',
|
|
67
|
-
'UnauthorizedError',
|
|
68
|
-
'PaymentRequiredError',
|
|
69
|
-
'ForbiddenError',
|
|
70
|
-
'NotFoundError',
|
|
71
|
-
'MethodNotAllowedError',
|
|
72
|
-
'NotAcceptableError',
|
|
73
|
-
'ProxyAuthenticationRequiredError',
|
|
74
|
-
'RequestTimeoutError',
|
|
75
|
-
'ConflictError',
|
|
76
|
-
'ConcurrencyError',
|
|
77
|
-
'GoneError',
|
|
78
|
-
'LengthRequiredError',
|
|
79
|
-
'PreconditionFailedError',
|
|
80
|
-
'PayloadTooLargeError',
|
|
81
|
-
'TooManyRequestsError',
|
|
82
|
-
'InternalServerError',
|
|
83
|
-
'NotImplementedError',
|
|
84
|
-
'BadGatewayError',
|
|
85
|
-
'ServiceUnavailableError',
|
|
86
|
-
'GatewayTimeoutError'
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
export type ErrorTypes = typeof ErrorTypesSchema.type;
|
package/tsconfig.json
DELETED