@mayhem93/nexxus-core-lib 0.0.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/LICENSE +373 -0
- package/README.md +384 -0
- package/dist-cjs/common/BuiltinSchemas.js +26 -0
- package/dist-cjs/common/BuiltinSchemas.js.map +1 -0
- package/dist-cjs/common/FilterQuery.js +252 -0
- package/dist-cjs/common/FilterQuery.js.map +1 -0
- package/dist-cjs/common/JsonPatch.js +392 -0
- package/dist-cjs/common/JsonPatch.js.map +1 -0
- package/dist-cjs/common/ModelTypes.js +3 -0
- package/dist-cjs/common/ModelTypes.js.map +1 -0
- package/dist-cjs/common/QueuePayloads.js +3 -0
- package/dist-cjs/common/QueuePayloads.js.map +1 -0
- package/dist-cjs/common/SchemaValidator.js +41 -0
- package/dist-cjs/common/SchemaValidator.js.map +1 -0
- package/dist-cjs/index.js +20 -0
- package/dist-cjs/index.js.map +1 -0
- package/dist-cjs/lib/BaseService.js +83 -0
- package/dist-cjs/lib/BaseService.js.map +1 -0
- package/dist-cjs/lib/ConfigManager.js +138 -0
- package/dist-cjs/lib/ConfigManager.js.map +1 -0
- package/dist-cjs/lib/ConfigProvider.js +65 -0
- package/dist-cjs/lib/ConfigProvider.js.map +1 -0
- package/dist-cjs/lib/Exceptions.js +64 -0
- package/dist-cjs/lib/Exceptions.js.map +1 -0
- package/dist-cjs/lib/GlobalServices.js +29 -0
- package/dist-cjs/lib/GlobalServices.js.map +1 -0
- package/dist-cjs/lib/Logger.js +131 -0
- package/dist-cjs/lib/Logger.js.map +1 -0
- package/dist-cjs/models/AppModel.js +14 -0
- package/dist-cjs/models/AppModel.js.map +1 -0
- package/dist-cjs/models/Application.js +79 -0
- package/dist-cjs/models/Application.js.map +1 -0
- package/dist-cjs/models/BaseModel.js +33 -0
- package/dist-cjs/models/BaseModel.js.map +1 -0
- package/dist-cjs/models/User.js +39 -0
- package/dist-cjs/models/User.js.map +1 -0
- package/dist-cjs/types/QueuePayloads.js +3 -0
- package/dist-cjs/types/QueuePayloads.js.map +1 -0
- package/dist-esm/common/BuiltinSchemas.js +22 -0
- package/dist-esm/common/BuiltinSchemas.js.map +1 -0
- package/dist-esm/common/FilterQuery.js +247 -0
- package/dist-esm/common/FilterQuery.js.map +1 -0
- package/dist-esm/common/JsonPatch.js +387 -0
- package/dist-esm/common/JsonPatch.js.map +1 -0
- package/dist-esm/common/ModelTypes.js +2 -0
- package/dist-esm/common/ModelTypes.js.map +1 -0
- package/dist-esm/common/QueuePayloads.js +2 -0
- package/dist-esm/common/QueuePayloads.js.map +1 -0
- package/dist-esm/common/SchemaValidator.js +37 -0
- package/dist-esm/common/SchemaValidator.js.map +1 -0
- package/dist-esm/index.js +16 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/lib/BaseService.js +79 -0
- package/dist-esm/lib/BaseService.js.map +1 -0
- package/dist-esm/lib/ConfigManager.js +133 -0
- package/dist-esm/lib/ConfigManager.js.map +1 -0
- package/dist-esm/lib/ConfigProvider.js +56 -0
- package/dist-esm/lib/ConfigProvider.js.map +1 -0
- package/dist-esm/lib/Exceptions.js +53 -0
- package/dist-esm/lib/Exceptions.js.map +1 -0
- package/dist-esm/lib/GlobalServices.js +25 -0
- package/dist-esm/lib/GlobalServices.js.map +1 -0
- package/dist-esm/lib/Logger.js +125 -0
- package/dist-esm/lib/Logger.js.map +1 -0
- package/dist-esm/models/AppModel.js +10 -0
- package/dist-esm/models/AppModel.js.map +1 -0
- package/dist-esm/models/Application.js +74 -0
- package/dist-esm/models/Application.js.map +1 -0
- package/dist-esm/models/BaseModel.js +29 -0
- package/dist-esm/models/BaseModel.js.map +1 -0
- package/dist-esm/models/User.js +35 -0
- package/dist-esm/models/User.js.map +1 -0
- package/dist-esm/types/QueuePayloads.js +2 -0
- package/dist-esm/types/QueuePayloads.js.map +1 -0
- package/dist-types/common/BuiltinSchemas.d.ts +69 -0
- package/dist-types/common/FilterQuery.d.ts +58 -0
- package/dist-types/common/JsonPatch.d.ts +78 -0
- package/dist-types/common/ModelTypes.d.ts +24 -0
- package/dist-types/common/QueuePayloads.d.ts +78 -0
- package/dist-types/common/SchemaValidator.d.ts +4 -0
- package/dist-types/index.d.ts +15 -0
- package/dist-types/lib/BaseService.d.ts +28 -0
- package/dist-types/lib/ConfigManager.d.ts +48 -0
- package/dist-types/lib/ConfigProvider.d.ts +27 -0
- package/dist-types/lib/Exceptions.d.ts +33 -0
- package/dist-types/lib/GlobalServices.d.ts +19 -0
- package/dist-types/lib/Logger.d.ts +48 -0
- package/dist-types/models/AppModel.d.ts +9 -0
- package/dist-types/models/Application.d.ts +29 -0
- package/dist-types/models/BaseModel.d.ts +23 -0
- package/dist-types/models/User.d.ts +17 -0
- package/dist-types/types/QueuePayloads.d.ts +57 -0
- package/package.json +46 -0
- package/src/schemas/root.schema.json +8 -0
- package/src/schemas/winston-logger.schema.json +24 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal fields present in all models
|
|
3
|
+
* Note: 'type' and 'appId' are excluded as they are handled separately in queries
|
|
4
|
+
*/
|
|
5
|
+
export declare const NEXXUS_UNIVERSAL_FIELDS: {
|
|
6
|
+
readonly id: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly required: true;
|
|
9
|
+
};
|
|
10
|
+
readonly createdAt: {
|
|
11
|
+
readonly type: "date";
|
|
12
|
+
readonly required: true;
|
|
13
|
+
};
|
|
14
|
+
readonly updatedAt: {
|
|
15
|
+
readonly type: "date";
|
|
16
|
+
readonly required: true;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Schema definitions for built-in (reserved) models. Only used for
|
|
21
|
+
*/
|
|
22
|
+
export declare const NEXXUS_BUILTIN_MODEL_SCHEMAS: {
|
|
23
|
+
readonly user: {
|
|
24
|
+
readonly userType: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
readonly required: false;
|
|
27
|
+
readonly filterable: true;
|
|
28
|
+
};
|
|
29
|
+
readonly username: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
readonly required: true;
|
|
32
|
+
readonly filterable: true;
|
|
33
|
+
};
|
|
34
|
+
readonly password: {
|
|
35
|
+
readonly type: "string";
|
|
36
|
+
readonly required: false;
|
|
37
|
+
};
|
|
38
|
+
readonly authProviders: {
|
|
39
|
+
readonly type: "array";
|
|
40
|
+
readonly required: true;
|
|
41
|
+
readonly arrayType: "string";
|
|
42
|
+
};
|
|
43
|
+
readonly devices: {
|
|
44
|
+
readonly type: "array";
|
|
45
|
+
readonly required: true;
|
|
46
|
+
readonly arrayType: "string";
|
|
47
|
+
};
|
|
48
|
+
readonly details: {
|
|
49
|
+
readonly type: "object";
|
|
50
|
+
readonly required: false;
|
|
51
|
+
readonly properties: {};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
readonly application: {
|
|
55
|
+
readonly name: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly required: true;
|
|
58
|
+
readonly filterable: true;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Type helper to get valid built-in model types
|
|
64
|
+
*/
|
|
65
|
+
export type NexxusBuiltinModelType = keyof typeof NEXXUS_BUILTIN_MODEL_SCHEMAS;
|
|
66
|
+
/**
|
|
67
|
+
* Helper to check if a model type is built-in
|
|
68
|
+
*/
|
|
69
|
+
export declare function isBuiltinModel(modelType: string): modelType is NexxusBuiltinModelType;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { NexxusModelDef } from '../common/ModelTypes';
|
|
2
|
+
import { type NexxusBuiltinModelType } from './BuiltinSchemas';
|
|
3
|
+
import type { NexxusAppModelType } from '../models/AppModel';
|
|
4
|
+
import type { NexxusUserDetailSchema } from '../models/User';
|
|
5
|
+
export type NexxusComparisonOperator = 'gte' | 'lte' | 'gt' | 'lt' | 'ne' | 'in';
|
|
6
|
+
export type NexxusLogicalOperator = '$and' | '$or';
|
|
7
|
+
export type NexxusFieldValue = string | number | boolean;
|
|
8
|
+
export type NexxusFieldCondition = NexxusFieldValue | Partial<Record<NexxusComparisonOperator, NexxusFieldValue | NexxusFieldValue[]>>;
|
|
9
|
+
export type NexxusFilterQueryType = {
|
|
10
|
+
[field: string]: NexxusFieldCondition;
|
|
11
|
+
} | {
|
|
12
|
+
[op in NexxusLogicalOperator]?: NexxusFilterQueryType[];
|
|
13
|
+
};
|
|
14
|
+
export type FilterNode = {
|
|
15
|
+
type: 'field';
|
|
16
|
+
field: string;
|
|
17
|
+
operator: 'eq';
|
|
18
|
+
value: NexxusFieldValue;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'field';
|
|
21
|
+
field: string;
|
|
22
|
+
operator: NexxusComparisonOperator;
|
|
23
|
+
value: NexxusFieldValue | NexxusFieldValue[];
|
|
24
|
+
} | {
|
|
25
|
+
type: 'logical';
|
|
26
|
+
operator: NexxusLogicalOperator;
|
|
27
|
+
conditions: FilterNode[];
|
|
28
|
+
};
|
|
29
|
+
type FilterNodeWithContext = FilterNode & {
|
|
30
|
+
depth: number;
|
|
31
|
+
parentOperator?: NexxusLogicalOperator;
|
|
32
|
+
};
|
|
33
|
+
export type NexxusFilterQueryConfig = {
|
|
34
|
+
appModelDef: NexxusModelDef;
|
|
35
|
+
} | {
|
|
36
|
+
modelType: NexxusBuiltinModelType;
|
|
37
|
+
userDetailsSchema?: NexxusUserDetailSchema;
|
|
38
|
+
};
|
|
39
|
+
export declare class NexxusFilterQuery {
|
|
40
|
+
private query;
|
|
41
|
+
private nodes;
|
|
42
|
+
private modelDef;
|
|
43
|
+
constructor(query: NexxusFilterQueryType, config: NexxusFilterQueryConfig);
|
|
44
|
+
getNodes(): FilterNode[];
|
|
45
|
+
getNormalizedQuery(): NexxusFilterQueryType;
|
|
46
|
+
[Symbol.iterator](): Generator<FilterNodeWithContext>;
|
|
47
|
+
test(object: Partial<NexxusAppModelType>): boolean;
|
|
48
|
+
private testNode;
|
|
49
|
+
private validateAndParse;
|
|
50
|
+
private parseQuery;
|
|
51
|
+
private testFieldCondition;
|
|
52
|
+
private parseFieldCondition;
|
|
53
|
+
private getFieldFromPath;
|
|
54
|
+
private validateOperator;
|
|
55
|
+
private validateValueType;
|
|
56
|
+
private traverseNodes;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NexxusApplicationSchema } from '../models/Application';
|
|
2
|
+
import type { NexxusModelFieldType } from '../common/ModelTypes';
|
|
3
|
+
import { NexxusAppModelType } from '../models/AppModel';
|
|
4
|
+
import { NexxusBuiltinModelType } from './BuiltinSchemas';
|
|
5
|
+
import type { NexxusUserDetailSchema } from '../models/User';
|
|
6
|
+
declare const JSON_OPS: readonly ["replace", "append", "prepend", "incr", "decr"];
|
|
7
|
+
export type NexxusJsonPatchConstructor = {
|
|
8
|
+
op: typeof JSON_OPS[number];
|
|
9
|
+
path: string[];
|
|
10
|
+
value: any[];
|
|
11
|
+
metadata: NexxusJsonPatchMetadata;
|
|
12
|
+
};
|
|
13
|
+
export type NexxusJsonPatchMetadata = {
|
|
14
|
+
appId: string;
|
|
15
|
+
id: string;
|
|
16
|
+
type: string;
|
|
17
|
+
userId?: string;
|
|
18
|
+
};
|
|
19
|
+
export type NexxusJsonPatchInternal = {
|
|
20
|
+
op: typeof JSON_OPS[number];
|
|
21
|
+
path: string[];
|
|
22
|
+
value: any[];
|
|
23
|
+
metadata: NexxusJsonPatchMetadataInternal;
|
|
24
|
+
};
|
|
25
|
+
type NexxusJsonPatchMetadataInternal = NexxusJsonPatchMetadata & {
|
|
26
|
+
pathFieldTypes?: NexxusModelFieldType[];
|
|
27
|
+
};
|
|
28
|
+
export type NexxusJsonPatchMetadataConstructor = Omit<NexxusJsonPatchMetadata, 'pathFieldTypes'>;
|
|
29
|
+
export type NexxusJsonPatchValidationConfig = {
|
|
30
|
+
appSchema: NexxusApplicationSchema;
|
|
31
|
+
} | {
|
|
32
|
+
modelType: NexxusBuiltinModelType;
|
|
33
|
+
userDetailsSchema?: NexxusUserDetailSchema;
|
|
34
|
+
};
|
|
35
|
+
export declare class NexxusJsonPatch {
|
|
36
|
+
private valid;
|
|
37
|
+
private fullPatch;
|
|
38
|
+
private static readonly OPERATION_RULES;
|
|
39
|
+
constructor(fullPatch: NexxusJsonPatchConstructor | NexxusJsonPatchInternal);
|
|
40
|
+
get(): NexxusJsonPatchInternal;
|
|
41
|
+
isValid(): boolean;
|
|
42
|
+
getPartialModel(): Partial<NexxusAppModelType>;
|
|
43
|
+
validate(config: NexxusJsonPatchValidationConfig): void;
|
|
44
|
+
private static validateAgainstType;
|
|
45
|
+
private static traverseSchema;
|
|
46
|
+
private static validateValueType;
|
|
47
|
+
/**
|
|
48
|
+
* Validate string type
|
|
49
|
+
*/
|
|
50
|
+
private static validateString;
|
|
51
|
+
/**
|
|
52
|
+
* Validate number type
|
|
53
|
+
*/
|
|
54
|
+
private static validateNumber;
|
|
55
|
+
/**
|
|
56
|
+
* Validate boolean type
|
|
57
|
+
*/
|
|
58
|
+
private static validateBoolean;
|
|
59
|
+
/**
|
|
60
|
+
* Validate date type
|
|
61
|
+
*/
|
|
62
|
+
private static validateDate;
|
|
63
|
+
/**
|
|
64
|
+
* Validate object type (recursively validates properties)
|
|
65
|
+
*/
|
|
66
|
+
private static validateObject;
|
|
67
|
+
/**
|
|
68
|
+
* Validate array type (recursively validates elements)
|
|
69
|
+
*/
|
|
70
|
+
private static validateArray;
|
|
71
|
+
/**
|
|
72
|
+
* Helper to validate primitive types (reusable for arrays)
|
|
73
|
+
*/
|
|
74
|
+
private static validatePrimitiveType;
|
|
75
|
+
private static isObjectFieldDef;
|
|
76
|
+
private static isArrayFieldDef;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type NexxusModelPrimitiveType = 'string' | 'number' | 'boolean' | 'date';
|
|
2
|
+
export type NexxusModelFieldType = NexxusModelPrimitiveType | 'array' | 'object';
|
|
3
|
+
interface BaseFieldDef {
|
|
4
|
+
type: NexxusModelFieldType;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PrimitiveFieldDef extends BaseFieldDef {
|
|
8
|
+
type: NexxusModelPrimitiveType;
|
|
9
|
+
filterable?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface NexxusArrayFieldDef extends BaseFieldDef {
|
|
12
|
+
type: 'array';
|
|
13
|
+
arrayType: NexxusModelPrimitiveType | 'object';
|
|
14
|
+
properties?: Record<string, NexxusFieldDef>;
|
|
15
|
+
}
|
|
16
|
+
export interface NexxusObjectFieldDef extends BaseFieldDef {
|
|
17
|
+
type: 'object';
|
|
18
|
+
properties: Record<string, NexxusFieldDef>;
|
|
19
|
+
}
|
|
20
|
+
export type NexxusFieldDef = PrimitiveFieldDef | NexxusArrayFieldDef | NexxusObjectFieldDef;
|
|
21
|
+
export interface NexxusModelDef {
|
|
22
|
+
[fieldName: string]: NexxusFieldDef;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NexxusAppModelType } from '../models/AppModel';
|
|
2
|
+
import { NexxusJsonPatchInternal, NexxusJsonPatchMetadata } from '../common/JsonPatch';
|
|
3
|
+
export interface NexxusBaseQueuePayload {
|
|
4
|
+
event: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export type NexxusModelCreatedPayload = {
|
|
8
|
+
event: 'model_created';
|
|
9
|
+
data: NexxusAppModelType;
|
|
10
|
+
};
|
|
11
|
+
export type NexxusModelUpdatedPayload = {
|
|
12
|
+
event: 'model_updated';
|
|
13
|
+
data: Array<NexxusJsonPatchInternal>;
|
|
14
|
+
};
|
|
15
|
+
export type NexxusModelDeletedData = Pick<NexxusAppModelType, 'id' | 'type' | 'appId' | 'userId'>;
|
|
16
|
+
export type NexxusModelDeletedPayload = {
|
|
17
|
+
event: 'model_deleted';
|
|
18
|
+
data: NexxusModelDeletedData;
|
|
19
|
+
};
|
|
20
|
+
export type NexxusWriterPayload = NexxusModelCreatedPayload | NexxusModelUpdatedPayload | NexxusModelDeletedPayload;
|
|
21
|
+
export type NexxusTransportManagetJsonPatch = Omit<NexxusJsonPatchInternal, 'metadata'> & {
|
|
22
|
+
metadata: NexxusJsonPatchMetadata & {
|
|
23
|
+
partialModel: Partial<NexxusAppModelType>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type NexxusTransportManagerModelUpdatedPayload = {
|
|
27
|
+
event: 'model_updated';
|
|
28
|
+
data: Array<NexxusTransportManagetJsonPatch>;
|
|
29
|
+
};
|
|
30
|
+
export type NexxusTransportManagerPayload = NexxusModelCreatedPayload | NexxusTransportManagerModelUpdatedPayload | NexxusModelDeletedPayload;
|
|
31
|
+
export interface NexxusWebSocketJsonPatchMetadata {
|
|
32
|
+
id: string;
|
|
33
|
+
channels: Array<string>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* JsonPatch type for WebSocket transport workers
|
|
37
|
+
*/
|
|
38
|
+
export type NexxusWebSocketJsonPatch = Omit<NexxusJsonPatchInternal, 'metadata'> & {
|
|
39
|
+
metadata: NexxusWebSocketJsonPatchMetadata;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Payload for WebSocket Transport - slim metadata with just channel
|
|
43
|
+
*/
|
|
44
|
+
export type NexxusWebSocketModelUpdatedPayload = {
|
|
45
|
+
event: 'model_updated';
|
|
46
|
+
data: Array<NexxusWebSocketJsonPatch>;
|
|
47
|
+
};
|
|
48
|
+
export type NexxusWebsocketPayload = {
|
|
49
|
+
event: 'device_message';
|
|
50
|
+
deviceIds: Array<string>;
|
|
51
|
+
data: NexxusModelCreatedPayload | NexxusWebSocketModelUpdatedPayload | NexxusModelDeletedPayload;
|
|
52
|
+
};
|
|
53
|
+
export type NexxusMqttPayload = {
|
|
54
|
+
event: 'mqtt_publish';
|
|
55
|
+
topic: string;
|
|
56
|
+
payload: Buffer;
|
|
57
|
+
} | {
|
|
58
|
+
event: 'mqtt_subscribe';
|
|
59
|
+
topic: string;
|
|
60
|
+
};
|
|
61
|
+
export interface NexxusBuiltInQueuePayloadMap {
|
|
62
|
+
'writer': NexxusWriterPayload;
|
|
63
|
+
'transport-manager': NexxusTransportManagerPayload;
|
|
64
|
+
}
|
|
65
|
+
export interface NexxusDynamicQueuePayloadMap {
|
|
66
|
+
'websockets-transport': NexxusWebsocketPayload;
|
|
67
|
+
'mqtt-transport': NexxusMqttPayload;
|
|
68
|
+
}
|
|
69
|
+
export type NexxusBuiltInQueueName = keyof NexxusBuiltInQueuePayloadMap;
|
|
70
|
+
export type NexxusDynamicQueueType = keyof NexxusDynamicQueuePayloadMap;
|
|
71
|
+
export type NexxusDynamicQueuePattern = keyof NexxusDynamicQueuePayloadMap;
|
|
72
|
+
export type NexxusDynamicQueueName<T extends NexxusDynamicQueuePattern = NexxusDynamicQueuePattern> = `${T}_${number}`;
|
|
73
|
+
export type NexxusKnownQueueName = NexxusBuiltInQueueName | NexxusDynamicQueueName;
|
|
74
|
+
export type NexxusQueueName = NexxusKnownQueueName | (string & {});
|
|
75
|
+
type ExtractQueuePattern<Q extends string> = Q extends `${infer Pattern}_${number}` ? Pattern extends NexxusDynamicQueuePattern ? Pattern : never : never;
|
|
76
|
+
export type ExtractQueueType<Q extends string> = Q extends `${infer Type}_${number}` ? Type extends NexxusDynamicQueueType ? Type : never : never;
|
|
77
|
+
export type NexxusQueuePayload<Q extends NexxusQueueName> = Q extends NexxusBuiltInQueueName ? NexxusBuiltInQueuePayloadMap[Q] : Q extends NexxusDynamicQueueName ? ExtractQueuePattern<Q> extends NexxusDynamicQueuePattern ? NexxusDynamicQueuePayloadMap[ExtractQueuePattern<Q>] : NexxusBaseQueuePayload : NexxusBaseQueuePayload;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./lib/Exceptions";
|
|
2
|
+
export * from "./lib/ConfigProvider";
|
|
3
|
+
export * from "./lib/ConfigManager";
|
|
4
|
+
export * from "./lib/BaseService";
|
|
5
|
+
export * from "./lib/Logger";
|
|
6
|
+
export * from "./common/QueuePayloads";
|
|
7
|
+
export * from "./common/JsonPatch";
|
|
8
|
+
export * from "./common/FilterQuery";
|
|
9
|
+
export * from "./models/BaseModel";
|
|
10
|
+
export * from './common/BuiltinSchemas';
|
|
11
|
+
export * from "./models/AppModel";
|
|
12
|
+
export * from "./models/Application";
|
|
13
|
+
export * from "./models/User";
|
|
14
|
+
export declare const NEXXUS_PREFIX_LC = "nxx";
|
|
15
|
+
export declare const NEXXUS_PREFIX_UC = "NXX";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ConfigEnvVars, ConfigCliArgs, AddJsonSchemaDefFuncArg, NexxusConfigManager } from './ConfigManager';
|
|
2
|
+
import type { NexxusBaseLogger } from "./Logger";
|
|
3
|
+
import { NexxusConfig } from './ConfigProvider';
|
|
4
|
+
export type EventMap = Record<string | symbol, any[]>;
|
|
5
|
+
export interface INexxusBaseServices {
|
|
6
|
+
configManager: NexxusConfigManager;
|
|
7
|
+
logger: NexxusBaseLogger<NexxusConfig>;
|
|
8
|
+
}
|
|
9
|
+
declare class TypedEventEmitter<E> {
|
|
10
|
+
private emitter;
|
|
11
|
+
constructor();
|
|
12
|
+
on<K extends keyof E>(event: K, listener: (...payload: E[K] extends any[] ? E[K] : never) => void): this;
|
|
13
|
+
once<K extends keyof E>(event: K, listener: (...payload: E[K] extends any[] ? E[K] : never) => void): this;
|
|
14
|
+
off<K extends keyof E>(event: K, listener: (...payload: E[K] extends any[] ? E[K] : never) => void): this;
|
|
15
|
+
emit<K extends keyof E>(event: K, ...payload: E[K] extends any[] ? E[K] : never): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class NexxusBaseService<T extends NexxusConfig, Ev extends EventMap = {}> extends TypedEventEmitter<Ev> {
|
|
18
|
+
protected config: Readonly<T>;
|
|
19
|
+
protected static envVars: ConfigEnvVars;
|
|
20
|
+
protected static cliArgs: ConfigCliArgs;
|
|
21
|
+
protected static schemaPath: string;
|
|
22
|
+
private static schemaContents;
|
|
23
|
+
constructor(config: Readonly<T>);
|
|
24
|
+
static envVarConfig(): ConfigEnvVars;
|
|
25
|
+
static cliArgConfig(): ConfigCliArgs;
|
|
26
|
+
static schema(): AddJsonSchemaDefFuncArg;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NexxusBaseService } from './BaseService';
|
|
2
|
+
import { CliArgType, NexxusConfig, INexxusConfigProvider } from "./ConfigProvider";
|
|
3
|
+
import type { JSONSchema7Definition } from "json-schema";
|
|
4
|
+
export type AddJsonSchemaDefFuncArg = {
|
|
5
|
+
name: string;
|
|
6
|
+
where: string;
|
|
7
|
+
definition: JSONSchema7Definition;
|
|
8
|
+
required: boolean;
|
|
9
|
+
};
|
|
10
|
+
type EnvVarsSpec = {
|
|
11
|
+
name: string;
|
|
12
|
+
location: string;
|
|
13
|
+
};
|
|
14
|
+
export type ConfigEnvVars = {
|
|
15
|
+
source: string;
|
|
16
|
+
specs: Array<EnvVarsSpec>;
|
|
17
|
+
};
|
|
18
|
+
type CliArgsSpec = {
|
|
19
|
+
name: string;
|
|
20
|
+
location: string;
|
|
21
|
+
type: CliArgType;
|
|
22
|
+
};
|
|
23
|
+
export type ConfigCliArgs = {
|
|
24
|
+
source: string;
|
|
25
|
+
specs: Array<CliArgsSpec>;
|
|
26
|
+
};
|
|
27
|
+
export declare class NexxusConfigManager {
|
|
28
|
+
private static CONF_FILE_NAME;
|
|
29
|
+
private jsonSchema;
|
|
30
|
+
private envVarsSpecs;
|
|
31
|
+
private cliArgsSpecs;
|
|
32
|
+
private data;
|
|
33
|
+
private configProviders;
|
|
34
|
+
private customProviders;
|
|
35
|
+
constructor(confFile?: string);
|
|
36
|
+
addCustomProvider(provider: INexxusConfigProvider): void;
|
|
37
|
+
private addJsonSchemaDef;
|
|
38
|
+
validateServices(svcs: Array<typeof NexxusBaseService>): void;
|
|
39
|
+
private addCliArgsToSpec;
|
|
40
|
+
private addEnvVarsToSpec;
|
|
41
|
+
private populateFromCliArgs;
|
|
42
|
+
private populateFromEnvVars;
|
|
43
|
+
private populateFromCustomProviders;
|
|
44
|
+
private formatAjvErrors;
|
|
45
|
+
private validate;
|
|
46
|
+
getConfig(field?: string): NexxusConfig;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type NexxusConfig = Record<string, any>;
|
|
2
|
+
export type CliArgType = "int" | "str" | "boolean" | "float";
|
|
3
|
+
export interface INexxusConfigProvider {
|
|
4
|
+
getConfig(): NexxusConfig | Promise<NexxusConfig>;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class NexxusConfigProvider implements INexxusConfigProvider {
|
|
7
|
+
abstract getConfig(): NexxusConfig;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class NexxusAsyncConfigProvider implements INexxusConfigProvider {
|
|
10
|
+
abstract getConfig(): Promise<NexxusConfig>;
|
|
11
|
+
}
|
|
12
|
+
export declare class NexxusFileConfigProvider extends NexxusConfigProvider {
|
|
13
|
+
private filePath;
|
|
14
|
+
constructor(filePath: string);
|
|
15
|
+
getConfig(): NexxusConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare class NexxusEnvVarsConfigProvider extends NexxusConfigProvider {
|
|
18
|
+
static ENV_VAR_PREFIX: Readonly<string>;
|
|
19
|
+
getConfig(): NexxusConfig;
|
|
20
|
+
}
|
|
21
|
+
export declare class NexxusCliArgConfigProvider extends NexxusConfigProvider {
|
|
22
|
+
private argParser;
|
|
23
|
+
private originalExit;
|
|
24
|
+
constructor();
|
|
25
|
+
addArgument(name: string, type: CliArgType): void;
|
|
26
|
+
getConfig(): NexxusConfig;
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare enum NexxusExceptions {
|
|
2
|
+
FATAL_ERROR = "FatalErrorException",
|
|
3
|
+
BAD_REQUEST = "BadRequestException",
|
|
4
|
+
CONNECTION_ERROR = "ConnectionErrorException",
|
|
5
|
+
INVALID_CONFIG = "InvalidConfigException",
|
|
6
|
+
INVALID_JSON_PATCH = "InvalidJsonPatchException",
|
|
7
|
+
INVALID_QUERY_FILTER = "InvalidQueryFilterException",
|
|
8
|
+
INVALID_USER_MODEL = "InvalidUserModelException"
|
|
9
|
+
}
|
|
10
|
+
export declare class NexxusException extends Error {
|
|
11
|
+
constructor(type: string, message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class FatalErrorException extends NexxusException {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class BadRequestException extends NexxusException {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class ConnectionException extends NexxusException {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class InvalidConfigException extends NexxusException {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class InvalidJsonPatchException extends NexxusException {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class InvalidQueryFilterException extends NexxusException {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class InvalidUserModelException extends NexxusException {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NexxusBaseLogger } from "./Logger";
|
|
2
|
+
import { NexxusConfig } from "./ConfigProvider";
|
|
3
|
+
import { NexxusConfigManager } from "./ConfigManager";
|
|
4
|
+
type GlobalServicesInitParams = {
|
|
5
|
+
logger?: NexxusBaseLogger<NexxusConfig>;
|
|
6
|
+
configManager?: NexxusConfigManager;
|
|
7
|
+
database?: unknown;
|
|
8
|
+
messageQueue?: unknown;
|
|
9
|
+
redis?: unknown;
|
|
10
|
+
};
|
|
11
|
+
export declare class NexxusGlobalServices {
|
|
12
|
+
static logger: Readonly<NexxusBaseLogger<NexxusConfig>>;
|
|
13
|
+
static configManager: Readonly<NexxusConfigManager>;
|
|
14
|
+
static database: unknown;
|
|
15
|
+
static messageQueue: unknown;
|
|
16
|
+
static redis: unknown;
|
|
17
|
+
static init(params: GlobalServicesInitParams): void;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ConfigEnvVars, ConfigCliArgs } from './ConfigManager';
|
|
2
|
+
import { NexxusBaseService, INexxusBaseServices } from './BaseService';
|
|
3
|
+
import { NexxusConfig } from './ConfigProvider';
|
|
4
|
+
type LoggableType = string | object | number | boolean | null | undefined;
|
|
5
|
+
export declare const enum NexxusLoggerLevels {
|
|
6
|
+
EMERGENCY = "emerg",
|
|
7
|
+
ALERT = "alert",
|
|
8
|
+
CRITICAL = "crit",
|
|
9
|
+
ERROR = "error",
|
|
10
|
+
WARNING = "warn",
|
|
11
|
+
NOTICE = "notice",
|
|
12
|
+
INFO = "info",
|
|
13
|
+
DEBUG = "debug"
|
|
14
|
+
}
|
|
15
|
+
type WinstonNexxusLoggerConfig = {
|
|
16
|
+
level: NexxusLoggerLevels;
|
|
17
|
+
logType: "json" | "text";
|
|
18
|
+
timestamps: boolean;
|
|
19
|
+
colors: boolean;
|
|
20
|
+
} & NexxusConfig;
|
|
21
|
+
export interface INexxusLogger {
|
|
22
|
+
log(level: NexxusLoggerLevels, message: LoggableType, label?: string): void;
|
|
23
|
+
}
|
|
24
|
+
export interface INexxusAsyncLogger extends INexxusLogger {
|
|
25
|
+
log(level: NexxusLoggerLevels, message: LoggableType, label?: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
interface NexxusLoggerServices extends Omit<INexxusBaseServices, 'logger'> {
|
|
28
|
+
}
|
|
29
|
+
export declare abstract class NexxusBaseLogger<T extends NexxusConfig> extends NexxusBaseService<T> implements INexxusLogger {
|
|
30
|
+
constructor(services: NexxusLoggerServices);
|
|
31
|
+
abstract log(level: NexxusLoggerLevels, message: LoggableType, label?: string): void;
|
|
32
|
+
debug(message: LoggableType, label?: string): void;
|
|
33
|
+
info(message: LoggableType, label?: string): void;
|
|
34
|
+
warn(message: LoggableType, label?: string): void;
|
|
35
|
+
error(message: LoggableType, label?: string): void;
|
|
36
|
+
critical(message: LoggableType, label?: string): void;
|
|
37
|
+
alert(message: LoggableType, label?: string): void;
|
|
38
|
+
emerg(message: LoggableType, label?: string): void;
|
|
39
|
+
}
|
|
40
|
+
export declare class WinstonNexxusLogger extends NexxusBaseLogger<WinstonNexxusLoggerConfig> {
|
|
41
|
+
private winston;
|
|
42
|
+
protected static schemaPath: string;
|
|
43
|
+
protected static envVars: ConfigEnvVars;
|
|
44
|
+
protected static cliArgs: ConfigCliArgs;
|
|
45
|
+
constructor(services: NexxusLoggerServices);
|
|
46
|
+
log(level: NexxusLoggerLevels, message: LoggableType, label?: string): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NexxusBaseModel, INexxusBaseModel } from "./BaseModel";
|
|
2
|
+
export type NexxusAppModelType = INexxusBaseModel & {
|
|
3
|
+
appId: string;
|
|
4
|
+
userId?: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare class NexxusAppModel extends NexxusBaseModel<NexxusAppModelType> {
|
|
8
|
+
constructor(props: NexxusAppModelType);
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NexxusBaseModel, INexxusBaseModel } from "./BaseModel";
|
|
2
|
+
import { NexxusModelDef } from "../common/ModelTypes";
|
|
3
|
+
import { NexxusUserDetailSchema } from "./User";
|
|
4
|
+
export interface NexxusApplicationSchema {
|
|
5
|
+
[modelName: string]: NexxusModelDef;
|
|
6
|
+
}
|
|
7
|
+
export interface NexxusUserTypeConfig {
|
|
8
|
+
private?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type NexxusApplicationModelType = INexxusBaseModel<'application'> & {
|
|
11
|
+
name: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
schema: NexxusApplicationSchema;
|
|
14
|
+
authEnabled: boolean;
|
|
15
|
+
allowMultipleLogin: boolean | null;
|
|
16
|
+
userTypes?: {
|
|
17
|
+
[userType: string]: NexxusUserTypeConfig;
|
|
18
|
+
};
|
|
19
|
+
userDetailSchema?: {
|
|
20
|
+
[userType: string]: NexxusUserDetailSchema;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare class NexxusApplication extends NexxusBaseModel<NexxusApplicationModelType> {
|
|
24
|
+
constructor(data: NexxusApplicationModelType);
|
|
25
|
+
getSchema(): NexxusApplicationSchema;
|
|
26
|
+
getUserDetailSchema(userType?: string): NexxusUserDetailSchema | null;
|
|
27
|
+
getAppModelFieldType(modelType: string, fieldPath: string): string | undefined;
|
|
28
|
+
getModelFilterableFields(modelType: string): Set<string>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NexxusApplication, NexxusApplicationModelType } from "./Application";
|
|
2
|
+
import { NexxusApplicationUser, NexxusUserModelType } from "./User";
|
|
3
|
+
import { NexxusAppModel, NexxusAppModelType } from "./AppModel";
|
|
4
|
+
export type AnyNexxusModel = NexxusApplication | NexxusApplicationUser | NexxusAppModel;
|
|
5
|
+
export type AnyNexxusModelType = NexxusApplicationModelType | NexxusUserModelType | NexxusAppModelType;
|
|
6
|
+
export interface INexxusBaseModel<TType extends string = string> {
|
|
7
|
+
id?: string;
|
|
8
|
+
createdAt?: number;
|
|
9
|
+
updatedAt?: number;
|
|
10
|
+
type: TType;
|
|
11
|
+
}
|
|
12
|
+
export declare const MODEL_REGISTRY: {
|
|
13
|
+
readonly application: "application";
|
|
14
|
+
readonly user: "user";
|
|
15
|
+
};
|
|
16
|
+
export type NexxusBuiltinModelTypeName = typeof MODEL_REGISTRY[keyof typeof MODEL_REGISTRY];
|
|
17
|
+
export type NexxusModelTypeName = NexxusBuiltinModelTypeName | string;
|
|
18
|
+
export declare abstract class NexxusBaseModel<T extends INexxusBaseModel = INexxusBaseModel> {
|
|
19
|
+
protected data: T;
|
|
20
|
+
static readonly modelType: string | undefined;
|
|
21
|
+
constructor(data: T);
|
|
22
|
+
getData(): T;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NexxusBaseModel, INexxusBaseModel } from "./BaseModel";
|
|
2
|
+
import { NexxusFieldDef } from "../common/ModelTypes";
|
|
3
|
+
export type NexxusUserModelType = INexxusBaseModel<'user'> & {
|
|
4
|
+
appId: string;
|
|
5
|
+
userType: string;
|
|
6
|
+
username: string;
|
|
7
|
+
password: string | null;
|
|
8
|
+
authProviders: Array<string>;
|
|
9
|
+
devices: Array<string>;
|
|
10
|
+
details?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export interface NexxusUserDetailSchema {
|
|
13
|
+
[field: string]: NexxusFieldDef;
|
|
14
|
+
}
|
|
15
|
+
export declare class NexxusApplicationUser extends NexxusBaseModel<NexxusUserModelType> {
|
|
16
|
+
constructor(data: NexxusUserModelType);
|
|
17
|
+
}
|