onecore 0.6.5 → 0.6.6
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 +78 -114
- package/package.json +1 -1
- package/src/index.ts +6 -2
- package/src/io.ts +5 -0
- package/src/mq.ts +7 -7
package/README.md
CHANGED
|
@@ -16,14 +16,19 @@ npm install onecore
|
|
|
16
16
|
|
|
17
17
|
Large applications commonly depend on many infrastructure libraries:
|
|
18
18
|
|
|
19
|
-
* Database
|
|
20
|
-
* Validation
|
|
21
19
|
* Cache
|
|
22
|
-
* Message Queue
|
|
23
20
|
* Logging
|
|
24
21
|
* Health Check
|
|
25
|
-
*
|
|
22
|
+
* Validation
|
|
23
|
+
* Database
|
|
24
|
+
* DB
|
|
25
|
+
* Transaction
|
|
26
|
+
* Statement
|
|
27
|
+
* Repository
|
|
28
|
+
* Service
|
|
29
|
+
* Message Queue
|
|
26
30
|
* Import / Export
|
|
31
|
+
* HTTP clients
|
|
27
32
|
* Localization
|
|
28
33
|
|
|
29
34
|
Without a shared foundation, each library tends to define its own interfaces and metadata.
|
|
@@ -38,11 +43,11 @@ Without a shared foundation, each library tends to define its own interfaces and
|
|
|
38
43
|
┌─────────┴─────────┐
|
|
39
44
|
│ onecore │
|
|
40
45
|
│ │
|
|
41
|
-
│
|
|
42
|
-
│
|
|
43
|
-
│
|
|
44
|
-
│
|
|
45
|
-
│
|
|
46
|
+
│ Interfaces │
|
|
47
|
+
│ Attribute │
|
|
48
|
+
│ Transaction │
|
|
49
|
+
│ Repository │
|
|
50
|
+
│ Use Cases │
|
|
46
51
|
└─────────┬─────────┘
|
|
47
52
|
│
|
|
48
53
|
┌──────────┬──────────┼──────────┬──────────┐
|
|
@@ -55,17 +60,18 @@ The implementation packages depend on these contracts, while application code ca
|
|
|
55
60
|
## Features
|
|
56
61
|
|
|
57
62
|
* Shared TypeScript interfaces for the Core TS ecosystem
|
|
58
|
-
* Unified `Attribute` metadata model
|
|
63
|
+
* Unified `Attribute` metadata model
|
|
64
|
+
* `ErrorMessage` for data validation
|
|
65
|
+
* Generic `Filter` and `SearchResult` models
|
|
59
66
|
* Database executor and transaction abstractions
|
|
60
|
-
*
|
|
67
|
+
* Type-safe database parameter abstraction
|
|
68
|
+
* Repository abstractions for CRUD and search
|
|
61
69
|
* Reusable CRUD and Search use-case classes
|
|
62
|
-
* Generic filtering and search result models
|
|
63
|
-
* Type-safe database parameter abstraction
|
|
64
|
-
* No framework dependency
|
|
65
|
-
* Interfaces with no runtime representation after TypeScript compilation
|
|
66
|
-
* Suitable for both backend and frontend projects
|
|
67
|
-
* Tree-shakeable runtime code
|
|
68
70
|
|
|
71
|
+
* Interfaces with no runtime representation after TypeScript compilation
|
|
72
|
+
* No framework dependency
|
|
73
|
+
* Suitable for both backend and frontend projects
|
|
74
|
+
* Tree-shakeable runtime code
|
|
69
75
|
## Unified metadata
|
|
70
76
|
|
|
71
77
|
The central concept in `onecore` is `Attribute`.
|
|
@@ -124,13 +130,13 @@ Individual libraries consume only the properties relevant to them.
|
|
|
124
130
|
│
|
|
125
131
|
┌───────────────┼────────────────┐
|
|
126
132
|
│ │ │
|
|
127
|
-
|
|
133
|
+
Validation Database Import/Export
|
|
128
134
|
│ │ │
|
|
129
|
-
validation-core sql-core
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
validation-core sql-core import-service
|
|
136
|
+
postgres-kit export-kit
|
|
137
|
+
mysql2-core
|
|
132
138
|
oracle-core
|
|
133
|
-
|
|
139
|
+
mssql-core
|
|
134
140
|
cassandra-core
|
|
135
141
|
mongodb-kit
|
|
136
142
|
```
|
|
@@ -222,9 +228,9 @@ export type FormatType =
|
|
|
222
228
|
export interface Executor {
|
|
223
229
|
driver: string
|
|
224
230
|
param(i: number): string
|
|
231
|
+
query<T>(sql: string, args?: any[], m?: StringMap, bools?: Attribute[]): Promise<T[]>
|
|
225
232
|
execute(sql: string, args?: any[]): Promise<number>
|
|
226
233
|
executeBatch(statements: Statement[], requireFirstAffected?: boolean): Promise<number>
|
|
227
|
-
query<T>(sql: string, args?: any[], m?: StringMap, bools?: Attribute[]): Promise<T[]>
|
|
228
234
|
}
|
|
229
235
|
```
|
|
230
236
|
|
|
@@ -301,7 +307,7 @@ The transaction abstraction is particularly useful when several repositories par
|
|
|
301
307
|
|
|
302
308
|
`onecore` defines generic repository contracts for CRUD and search operations.
|
|
303
309
|
|
|
304
|
-
###
|
|
310
|
+
### CRUDRepository
|
|
305
311
|
|
|
306
312
|
```ts
|
|
307
313
|
export interface CRUDRepository<T, ID> {
|
|
@@ -327,12 +333,12 @@ Transactional operation:
|
|
|
327
333
|
await repository.create(user, tx)
|
|
328
334
|
```
|
|
329
335
|
|
|
330
|
-
###
|
|
336
|
+
### SearchRepository
|
|
331
337
|
|
|
332
338
|
```ts
|
|
333
339
|
export interface SearchRepository<T, F extends Filter> {
|
|
334
340
|
search(
|
|
335
|
-
|
|
341
|
+
filter: F,
|
|
336
342
|
limit: number,
|
|
337
343
|
offset?: number | string,
|
|
338
344
|
fields?: string[],
|
|
@@ -365,7 +371,7 @@ export interface SearchResult<T> {
|
|
|
365
371
|
|
|
366
372
|
This allows implementations to support result counts as well as cursor-style pagination.
|
|
367
373
|
|
|
368
|
-
##
|
|
374
|
+
## Repository
|
|
369
375
|
|
|
370
376
|
CRUD and search repositories can be combined:
|
|
371
377
|
|
|
@@ -429,7 +435,7 @@ export class CRUDUseCase<T, ID> {
|
|
|
429
435
|
}
|
|
430
436
|
```
|
|
431
437
|
|
|
432
|
-
###
|
|
438
|
+
### UseCase
|
|
433
439
|
|
|
434
440
|
For applications that need both CRUD and search operations:
|
|
435
441
|
|
|
@@ -503,10 +509,7 @@ export interface ErrorMessage {
|
|
|
503
509
|
with:
|
|
504
510
|
|
|
505
511
|
```ts
|
|
506
|
-
export type Result<T> =
|
|
507
|
-
| number
|
|
508
|
-
| T
|
|
509
|
-
| ErrorMessage[]
|
|
512
|
+
export type Result<T> = number | T | ErrorMessage[]
|
|
510
513
|
```
|
|
511
514
|
|
|
512
515
|
This allows an application layer to return structured field-level errors without coupling the service interface to a particular validation library.
|
|
@@ -520,10 +523,11 @@ Examples include:
|
|
|
520
523
|
```text
|
|
521
524
|
Database
|
|
522
525
|
├── sql-core
|
|
523
|
-
├── mysql2-core
|
|
524
526
|
├── postgres-kit
|
|
527
|
+
├── mysql2-core
|
|
525
528
|
├── oracle-core
|
|
526
529
|
├── mssql-core
|
|
530
|
+
├── cassandra-core
|
|
527
531
|
└── mongodb-kit
|
|
528
532
|
|
|
529
533
|
Validation
|
|
@@ -535,6 +539,7 @@ Messaging
|
|
|
535
539
|
├── redis-messaging
|
|
536
540
|
├── rabbitmq-transport
|
|
537
541
|
├── activemq
|
|
542
|
+
├── kafka-plus
|
|
538
543
|
└── ibmmq-plus
|
|
539
544
|
|
|
540
545
|
Cache
|
|
@@ -542,12 +547,12 @@ Cache
|
|
|
542
547
|
└── redis-plus
|
|
543
548
|
|
|
544
549
|
Other
|
|
550
|
+
├── import-service
|
|
551
|
+
├── export-kit
|
|
545
552
|
├── logger-core
|
|
546
553
|
├── health-service
|
|
547
|
-
├── web-clients
|
|
548
554
|
├── locale-service
|
|
549
|
-
|
|
550
|
-
└── export-kit
|
|
555
|
+
└── web-clients
|
|
551
556
|
```
|
|
552
557
|
|
|
553
558
|
These packages can share the same contracts and metadata model while remaining independently implemented.
|
|
@@ -558,12 +563,12 @@ These packages can share the same contracts and metadata model while remaining i
|
|
|
558
563
|
`onecore` defines the common contracts used by the ecosystem.
|
|
559
564
|
|
|
560
565
|
### Database
|
|
566
|
+
* Statement
|
|
567
|
+
* DB
|
|
568
|
+
* Transaction
|
|
561
569
|
* SearchRepository
|
|
562
570
|
* CRUDRepository
|
|
563
571
|
* Repository
|
|
564
|
-
* Transaction
|
|
565
|
-
* Statement
|
|
566
|
-
* QueryBuilder
|
|
567
572
|
|
|
568
573
|
Implemented by
|
|
569
574
|
|
|
@@ -575,8 +580,6 @@ Implemented by
|
|
|
575
580
|
* cassandra-core
|
|
576
581
|
* mongodb-kit
|
|
577
582
|
|
|
578
|
-
---
|
|
579
|
-
|
|
580
583
|
### Validation
|
|
581
584
|
|
|
582
585
|
* Validator<T>
|
|
@@ -585,8 +588,6 @@ Implemented by
|
|
|
585
588
|
|
|
586
589
|
* validation-core
|
|
587
590
|
|
|
588
|
-
---
|
|
589
|
-
|
|
590
591
|
### Cache
|
|
591
592
|
|
|
592
593
|
* CachePort
|
|
@@ -596,8 +597,6 @@ Implemented by
|
|
|
596
597
|
* cache-plus
|
|
597
598
|
* redis-plus
|
|
598
599
|
|
|
599
|
-
---
|
|
600
|
-
|
|
601
600
|
### Message Queue
|
|
602
601
|
|
|
603
602
|
* Producer
|
|
@@ -611,9 +610,9 @@ Implemented by
|
|
|
611
610
|
* redis-messaging
|
|
612
611
|
* nats-plus
|
|
613
612
|
* rabbitmq-transport
|
|
614
|
-
*
|
|
615
|
-
|
|
616
|
-
|
|
613
|
+
* activemq
|
|
614
|
+
* kafka-plus
|
|
615
|
+
* ibmmq-plus
|
|
617
616
|
|
|
618
617
|
### Logging
|
|
619
618
|
|
|
@@ -623,8 +622,6 @@ Implemented by
|
|
|
623
622
|
|
|
624
623
|
* logger-core
|
|
625
624
|
|
|
626
|
-
---
|
|
627
|
-
|
|
628
625
|
### Health Check
|
|
629
626
|
|
|
630
627
|
* HealthChecker
|
|
@@ -633,8 +630,6 @@ Implemented by
|
|
|
633
630
|
|
|
634
631
|
* health-service
|
|
635
632
|
|
|
636
|
-
---
|
|
637
|
-
|
|
638
633
|
### HTTP
|
|
639
634
|
|
|
640
635
|
* HttpRequest
|
|
@@ -644,8 +639,6 @@ Implemented by
|
|
|
644
639
|
|
|
645
640
|
* web-clients
|
|
646
641
|
|
|
647
|
-
---
|
|
648
|
-
|
|
649
642
|
### Localization
|
|
650
643
|
|
|
651
644
|
* Locale
|
|
@@ -674,17 +667,34 @@ Reusable classes such as `UseCase` are only included when they are actually impo
|
|
|
674
667
|
|
|
675
668
|
This makes the package suitable for both backend and frontend projects.
|
|
676
669
|
|
|
677
|
-
## Backend
|
|
670
|
+
## Backend Support
|
|
678
671
|
|
|
679
|
-
|
|
672
|
+
Infrastructure services often depend only on interfaces.
|
|
673
|
+
|
|
674
|
+
Examples include
|
|
680
675
|
|
|
681
|
-
* Repository contracts
|
|
682
|
-
* Database transactions
|
|
683
676
|
* Shared metadata
|
|
677
|
+
* Database transactions
|
|
678
|
+
* Repository contracts
|
|
684
679
|
* Application use cases
|
|
685
|
-
*
|
|
680
|
+
* Message Queue services
|
|
681
|
+
* Import services / Export services
|
|
682
|
+
* Infrastructure interfaces: Logging, Cache, Validation...
|
|
683
|
+
|
|
684
|
+
Since these projects do not use application-layer base classes, the generated JavaScript contains virtually no runtime code from `onecore`.
|
|
685
|
+
|
|
686
|
+
## Frontend Support
|
|
687
|
+
|
|
688
|
+
`onecore` works in frontend applications.
|
|
686
689
|
|
|
687
|
-
|
|
690
|
+
React applications commonly use
|
|
691
|
+
|
|
692
|
+
* Attribute
|
|
693
|
+
* Locale
|
|
694
|
+
* Currency
|
|
695
|
+
* Validator interfaces
|
|
696
|
+
|
|
697
|
+
without importing any backend service classes.
|
|
688
698
|
|
|
689
699
|
For example:
|
|
690
700
|
|
|
@@ -698,6 +708,8 @@ import type {
|
|
|
698
708
|
|
|
699
709
|
This allows a frontend and backend to share the same domain metadata and contracts.
|
|
700
710
|
|
|
711
|
+
The final JavaScript bundle remains minimal because interfaces are removed during compilation and unused code is tree-shaken.
|
|
712
|
+
|
|
701
713
|
## Design principles
|
|
702
714
|
|
|
703
715
|
### One common contract
|
|
@@ -720,51 +732,16 @@ Transactions are passed explicitly to repository operations when multiple operat
|
|
|
720
732
|
|
|
721
733
|
Keep shared contracts in TypeScript interfaces and keep runtime implementations small and reusable.
|
|
722
734
|
|
|
723
|
-
## License
|
|
724
|
-
|
|
725
|
-
MIT
|
|
726
|
-
|
|
727
|
-
# Frontend Support
|
|
728
735
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
React applications commonly use
|
|
732
|
-
|
|
733
|
-
* Attribute
|
|
734
|
-
* Locale
|
|
735
|
-
* Currency
|
|
736
|
-
* Validator interfaces
|
|
737
|
-
|
|
738
|
-
without importing any backend service classes.
|
|
739
|
-
|
|
740
|
-
The final JavaScript bundle remains minimal because interfaces are removed during compilation and unused code is tree-shaken.
|
|
741
|
-
|
|
742
|
-
---
|
|
743
|
-
|
|
744
|
-
# Backend Support
|
|
745
|
-
|
|
746
|
-
Infrastructure services often depend only on interfaces.
|
|
747
|
-
|
|
748
|
-
Examples include
|
|
749
|
-
|
|
750
|
-
* Message Queue services
|
|
751
|
-
* Import services
|
|
752
|
-
* Export services
|
|
753
|
-
* Background workers
|
|
754
|
-
|
|
755
|
-
Since these projects do not use application-layer base classes, the generated JavaScript contains virtually no runtime code from `onecore`.
|
|
756
|
-
|
|
757
|
-
---
|
|
758
|
-
|
|
759
|
-
# Sample Projects
|
|
736
|
+
## Sample Projects
|
|
760
737
|
|
|
761
738
|
The following sample applications demonstrate different ways of using `onecore`.
|
|
762
739
|
|
|
763
740
|
### CRUD Applications
|
|
764
741
|
|
|
765
|
-
* [
|
|
766
|
-
* [
|
|
767
|
-
* [
|
|
742
|
+
* [sql-modular-sample](https://github.com/source-code-template/sql-modular-sample) — SQL modular microservice using MySQL
|
|
743
|
+
* [sql-simple-modular-sample](https://github.com/source-code-template/sql-simple-modular-sample) — SQL modular microservice using PosgreSQL
|
|
744
|
+
* [mongo-simple-modular-sample](https://github.com/source-code-template/mongo-simple-modular-sample) — MongoDB modular microservice
|
|
768
745
|
|
|
769
746
|
These projects extend the reusable CRUD and Search use-case classes.
|
|
770
747
|
|
|
@@ -794,21 +771,8 @@ These projects depend only on interfaces and the shared `Attribute` metadata mod
|
|
|
794
771
|
|
|
795
772
|
These projects depend only on interfaces and the shared `Attribute` metadata model.
|
|
796
773
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
# Design Principles
|
|
800
|
-
|
|
801
|
-
* Interface-first architecture
|
|
802
|
-
* Dependency inversion
|
|
803
|
-
* Clean Architecture
|
|
804
|
-
* Hexagonal Architecture
|
|
805
|
-
* Tree-shakeable design
|
|
806
|
-
* Shared metadata model
|
|
807
|
-
* Framework independent
|
|
808
|
-
* Enterprise ready
|
|
774
|
+
## License
|
|
809
775
|
|
|
810
|
-
|
|
776
|
+
MIT
|
|
811
777
|
|
|
812
|
-
# License
|
|
813
778
|
|
|
814
|
-
MIT
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -118,11 +118,15 @@ export interface Parser<T> {
|
|
|
118
118
|
export interface Transformer<T> {
|
|
119
119
|
transform: (data: string) => Promise<T>;
|
|
120
120
|
}
|
|
121
|
+
export interface ExportResult {
|
|
122
|
+
total: number
|
|
123
|
+
success: number
|
|
124
|
+
}
|
|
121
125
|
export interface ExportService {
|
|
122
|
-
export(ctx?: any): Promise<
|
|
126
|
+
export(ctx?: any): Promise<ExportResult>;
|
|
123
127
|
}
|
|
124
128
|
export interface Exporter {
|
|
125
|
-
export(ctx?: any): Promise<
|
|
129
|
+
export(ctx?: any): Promise<ExportResult>;
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
// tslint:disable-next-line:max-classes-per-file
|
package/src/io.ts
CHANGED
package/src/mq.ts
CHANGED
|
@@ -56,27 +56,27 @@ export interface Writer<T, R, ID> {
|
|
|
56
56
|
}
|
|
57
57
|
*/
|
|
58
58
|
export interface SimpleConsumer<T, R> {
|
|
59
|
-
consume(
|
|
59
|
+
consume(process: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
|
|
60
60
|
}
|
|
61
61
|
export interface SimpleSubscriber<T, R> {
|
|
62
|
-
subscribe(
|
|
62
|
+
subscribe(process: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
|
|
63
63
|
}
|
|
64
64
|
export interface SimpleReceiver<T, R> {
|
|
65
|
-
receive(
|
|
65
|
+
receive(process: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
|
|
66
66
|
}
|
|
67
67
|
export interface SimpleReader<T, R> {
|
|
68
|
-
read(
|
|
68
|
+
read(process: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export interface MessageConsumer<T, ID, R> {
|
|
72
72
|
consume(data: Message<T, ID, R>): void;
|
|
73
73
|
}
|
|
74
74
|
export interface MessageSubscriber<T, ID, R> {
|
|
75
|
-
subscribe(
|
|
75
|
+
subscribe(process: (data: Message<T, ID, R>) => Promise<number>): void;
|
|
76
76
|
}
|
|
77
77
|
export interface MessageReceiver<T, ID, R> {
|
|
78
|
-
receive(
|
|
78
|
+
receive(process: (data: Message<T, ID, R>) => Promise<number>): void;
|
|
79
79
|
}
|
|
80
80
|
export interface MessageReader<T, ID, R> {
|
|
81
|
-
read(
|
|
81
|
+
read(process: (data: Message<T, ID, R>) => Promise<number>): void;
|
|
82
82
|
}
|