@polygonlabs/servercore 1.0.0-dev.42 → 1.0.0-dev.44
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/README.md +106 -6
- package/dist/index.d.ts +1 -1
- package/dist/storage/db_interface.d.ts +7 -7
- package/dist/types/database.d.ts +37 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
@@ -1,15 +1,115 @@
|
|
1
|
-
# servercore
|
1
|
+
# @polygonlabs/servercore
|
2
2
|
|
3
|
-
|
3
|
+
Core server framework for building scalable TypeScript applications with built-in logging, error handling, API utilities, and event processing.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **API Framework**: Health checks, response handlers, and Zod validation utilities
|
8
|
+
- **Event Consumers**: Abstract base classes for REST API and cron job consumers
|
9
|
+
- **Error Handling**: Comprehensive error system with custom error types
|
10
|
+
- **Logging**: Winston-based logging with Sentry integration
|
11
|
+
- **Storage Interfaces**: Abstract interfaces for databases and queues
|
12
|
+
- **Utilities**: ULID generation, data decoders, and type utilities
|
13
|
+
|
14
|
+
## Installation
|
4
15
|
|
5
16
|
```bash
|
6
|
-
|
17
|
+
npm install @polygonlabs/servercore
|
18
|
+
# or
|
19
|
+
bun add @polygonlabs/servercore
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### API Framework
|
25
|
+
|
26
|
+
```typescript
|
27
|
+
import { healthCheck, handleResponse } from '@polygonlabs/servercore/api';
|
28
|
+
import { validateInput } from '@polygonlabs/servercore/api';
|
29
|
+
import { z } from 'zod';
|
30
|
+
|
31
|
+
// Health check endpoint
|
32
|
+
const health = healthCheck();
|
33
|
+
|
34
|
+
// Response handling
|
35
|
+
const response = handleResponse(data, 200);
|
36
|
+
|
37
|
+
// Input validation
|
38
|
+
const schema = z.object({ name: z.string() });
|
39
|
+
const validatedData = validateInput(schema, input);
|
40
|
+
```
|
41
|
+
|
42
|
+
### Event Consumers
|
43
|
+
|
44
|
+
```typescript
|
45
|
+
import { RestApiConsumer, CronEventConsumer } from '@polygonlabs/servercore/consumers';
|
46
|
+
|
47
|
+
class MyApiConsumer extends RestApiConsumer {
|
48
|
+
async processEvent(event: any) {
|
49
|
+
// Process API event
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
class MyCronConsumer extends CronEventConsumer {
|
54
|
+
async processEvent() {
|
55
|
+
// Process scheduled event
|
56
|
+
}
|
57
|
+
}
|
7
58
|
```
|
8
59
|
|
9
|
-
|
60
|
+
### Logging
|
61
|
+
|
62
|
+
```typescript
|
63
|
+
import { createLogger } from '@polygonlabs/servercore/logger';
|
64
|
+
|
65
|
+
const logger = createLogger({
|
66
|
+
level: 'info',
|
67
|
+
service: 'my-service'
|
68
|
+
});
|
69
|
+
|
70
|
+
logger.info('Application started');
|
71
|
+
logger.error('Something went wrong', { error });
|
72
|
+
```
|
73
|
+
|
74
|
+
### Error Handling
|
75
|
+
|
76
|
+
```typescript
|
77
|
+
import {
|
78
|
+
ApiError,
|
79
|
+
DatabaseError,
|
80
|
+
ExternalDependencyError
|
81
|
+
} from '@polygonlabs/servercore/errors';
|
82
|
+
|
83
|
+
// Throw specific errors
|
84
|
+
throw new ApiError('Invalid request', 'INVALID_REQUEST');
|
85
|
+
throw new DatabaseError('Connection failed');
|
86
|
+
throw new ExternalDependencyError('Service unavailable');
|
87
|
+
```
|
88
|
+
|
89
|
+
## Development
|
10
90
|
|
11
91
|
```bash
|
12
|
-
|
92
|
+
# Install dependencies
|
93
|
+
bun install
|
94
|
+
|
95
|
+
# Build the package
|
96
|
+
bun run build
|
97
|
+
|
98
|
+
# Run type checking
|
99
|
+
bun run typecheck
|
100
|
+
|
101
|
+
# Run tests
|
102
|
+
bun run tests
|
13
103
|
```
|
14
104
|
|
15
|
-
|
105
|
+
## Dependencies
|
106
|
+
|
107
|
+
- **croner**: Cron job scheduling
|
108
|
+
- **ulid**: Unique identifier generation
|
109
|
+
- **viem**: Ethereum utilities
|
110
|
+
- **winston**: Logging framework
|
111
|
+
- **zod**: Schema validation
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
MIT
|
package/dist/index.d.ts
CHANGED
@@ -5,7 +5,7 @@ export { Logger } from './logger/logger.js';
|
|
5
5
|
export { errorCodes } from './constants/error_codes.js';
|
6
6
|
export { httpResposneCodes } from './constants/http_success_codes.js';
|
7
7
|
export { ILoggerConfig } from './types/logger_config.js';
|
8
|
-
export { IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, WhereFilterOp } from './types/database.js';
|
8
|
+
export { AddDocumentsParams, ConditionalUpdateDocumentsParams, GetCollectionGroupParams, GetDocumentParams, GetDocumentsParams, IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, UpdateDocumentsParams, WhereFilterOp } from './types/database.js';
|
9
9
|
export { IObserver } from './types/observer.js';
|
10
10
|
export { ChainNativeCurrency, IEventConsumerConfig } from './types/event_consumer_config.js';
|
11
11
|
export { ResponseContext } from './types/response_context.js';
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import { AddDocumentsParams, UpdateDocumentsParams, ConditionalUpdateDocumentsParams, GetDocumentsParams, GetDocumentParams, GetCollectionGroupParams } from '../types/database.js';
|
2
2
|
|
3
3
|
interface Database {
|
4
4
|
connect(): Promise<void>;
|
5
5
|
disconnect(): Promise<void>;
|
6
|
-
addDocuments(
|
7
|
-
updateDocuments(
|
8
|
-
conditionalUpdateDocuments(
|
9
|
-
getDocuments(
|
10
|
-
getDocument(
|
11
|
-
getCollectionGroup(
|
6
|
+
addDocuments(params: AddDocumentsParams): Promise<void>;
|
7
|
+
updateDocuments(params: UpdateDocumentsParams): Promise<void>;
|
8
|
+
conditionalUpdateDocuments(params: ConditionalUpdateDocumentsParams): Promise<void>;
|
9
|
+
getDocuments(params: GetDocumentsParams): Promise<any[]>;
|
10
|
+
getDocument(params: GetDocumentParams): Promise<any | null>;
|
11
|
+
getCollectionGroup(params: GetCollectionGroupParams): Promise<any | null>;
|
12
12
|
}
|
13
13
|
|
14
14
|
export type { Database };
|
package/dist/types/database.d.ts
CHANGED
@@ -17,5 +17,41 @@ interface IDocumentConditionalModifications {
|
|
17
17
|
interface IQueryOrFilterParams {
|
18
18
|
or: IQueryFilterOperationParams[];
|
19
19
|
}
|
20
|
+
interface AddDocumentsParams {
|
21
|
+
collectionPaths: string[] | string;
|
22
|
+
docDatas: any[];
|
23
|
+
docIds?: string[];
|
24
|
+
}
|
25
|
+
interface UpdateDocumentsParams {
|
26
|
+
collectionPaths: string[] | string;
|
27
|
+
docDatas: any[];
|
28
|
+
docIds: string[];
|
29
|
+
}
|
30
|
+
interface ConditionalUpdateDocumentsParams {
|
31
|
+
collectionPaths: string[] | string;
|
32
|
+
docDatas: any[];
|
33
|
+
docIds: string[];
|
34
|
+
conditions: IQueryFilterOperationParams[];
|
35
|
+
conditionModifications: IDocumentConditionalModifications[];
|
36
|
+
}
|
37
|
+
interface GetDocumentsParams {
|
38
|
+
collectionPath: string;
|
39
|
+
filter?: IQueryFilterOperationParams[];
|
40
|
+
limit?: number;
|
41
|
+
order?: IQueryOrderOperationParams[];
|
42
|
+
startAfterCursor?: string | number;
|
43
|
+
selectFields?: string[];
|
44
|
+
orFilters?: IQueryOrFilterParams[];
|
45
|
+
offset?: number;
|
46
|
+
}
|
47
|
+
interface GetDocumentParams {
|
48
|
+
collectionId: string;
|
49
|
+
docId: string;
|
50
|
+
}
|
51
|
+
interface GetCollectionGroupParams {
|
52
|
+
groupId: string;
|
53
|
+
filter?: IQueryFilterOperationParams[];
|
54
|
+
orFilters?: IQueryOrFilterParams[];
|
55
|
+
}
|
20
56
|
|
21
|
-
export type { IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, WhereFilterOp };
|
57
|
+
export type { AddDocumentsParams, ConditionalUpdateDocumentsParams, GetCollectionGroupParams, GetDocumentParams, GetDocumentsParams, IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, UpdateDocumentsParams, WhereFilterOp };
|
package/dist/types/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export { ILoggerConfig } from './logger_config.js';
|
2
|
-
export { IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, WhereFilterOp } from './database.js';
|
2
|
+
export { AddDocumentsParams, ConditionalUpdateDocumentsParams, GetCollectionGroupParams, GetDocumentParams, GetDocumentsParams, IDocumentConditionalModifications, IQueryFilterOperationParams, IQueryOrFilterParams, IQueryOrderOperationParams, OrderByDirection, UpdateDocumentsParams, WhereFilterOp } from './database.js';
|
3
3
|
export { IObserver } from './observer.js';
|
4
4
|
export { ChainNativeCurrency, IEventConsumerConfig } from './event_consumer_config.js';
|
5
5
|
export { ResponseContext } from './response_context.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@polygonlabs/servercore",
|
3
|
-
"version": "1.0.0-dev.
|
3
|
+
"version": "1.0.0-dev.44",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
@@ -16,7 +16,8 @@
|
|
16
16
|
"scripts": {
|
17
17
|
"tests": "echo 'Hello unit tests'",
|
18
18
|
"tests:integration": "echo 'Hello integration tests'",
|
19
|
-
"build": "tsup"
|
19
|
+
"build": "tsup",
|
20
|
+
"typecheck": "tsc --noEmit"
|
20
21
|
},
|
21
22
|
"files": [
|
22
23
|
"./dist/**",
|
@@ -35,5 +36,5 @@
|
|
35
36
|
"winston-transport-sentry-node": "^3.0.0",
|
36
37
|
"zod": "^3.24.2"
|
37
38
|
},
|
38
|
-
"gitHead": "
|
39
|
+
"gitHead": "c446ec91faa1603fb2a326dea481dc60e1ac07d4"
|
39
40
|
}
|