onecore 0.5.17 → 0.6.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/README.md CHANGED
@@ -1 +1,400 @@
1
- # onecore
1
+ # onecore
2
+
3
+ > The shared foundation for the Core TS ecosystem.
4
+
5
+ `onecore` provides the common contracts, metadata model, and reusable application-layer base classes used throughout the Core TS ecosystem.
6
+
7
+ It allows libraries such as **sql-core**, **mysql2-core**, **postgres-kit**, **mongodb-kit**, **validation-core**, **cache-plus**, **redis-plus**, **message-processing**, **nats-plus**, **redis-messaging**, **rabbitmq-transport**, **logger-core**, and **health-service** to work together through a unified API.
8
+
9
+ ## Features
10
+
11
+ * Common interfaces for enterprise applications
12
+ * Unified metadata model (`Attribute`)
13
+ * Reusable CRUD and Search use-case base classes
14
+ * Zero-cost abstractions through TypeScript interfaces
15
+ * Tree-shakeable architecture
16
+ * Works in both backend and frontend applications
17
+ * No framework dependency
18
+ * Fully written in TypeScript
19
+
20
+ ---
21
+
22
+ # Installation
23
+
24
+ ```bash
25
+ npm install onecore
26
+ ```
27
+
28
+ ---
29
+
30
+ # Why onecore?
31
+
32
+ Enterprise applications often use many infrastructure libraries.
33
+
34
+ For example:
35
+
36
+ * Database
37
+ * Validation
38
+ * Cache
39
+ * Message Queue
40
+ * Logging
41
+ * Health Check
42
+ * Import/Export
43
+
44
+ Without a shared foundation, every library exposes its own interfaces and metadata.
45
+
46
+ ```text
47
+ Repository (sql)
48
+ Validator (validation)
49
+ Producer (mq)
50
+ Logger (logger)
51
+ Cache (cache)
52
+ ```
53
+
54
+ `onecore` provides a single common language for the entire ecosystem.
55
+
56
+ ```ts
57
+ import {
58
+ Repository,
59
+ Validator,
60
+ Producer,
61
+ CachePort,
62
+ Logger,
63
+ HealthChecker
64
+ } from "onecore";
65
+ ```
66
+
67
+ Applications only depend on **onecore**, while implementation libraries implement these contracts.
68
+
69
+ ---
70
+
71
+ # Ecosystem
72
+
73
+ ```
74
+ Applications
75
+ ┌───────────────────────────────────────────────────────────────┐
76
+ │ │
77
+ │ React Apps • REST APIs • Microservices • Workers • CLI │
78
+ │ │
79
+ └───────────────────────────────────────────────────────────────┘
80
+ ▲
81
+ │
82
+ Reusable Use Cases (Optional)
83
+ CRUD • Search • View • Generic Services
84
+ ▲
85
+ │
86
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
87
+ │ onecore │
88
+ │ │
89
+ │ • Common Interfaces │
90
+ │ • Unified Attribute Metadata │
91
+ │ • Locale & Currency │
92
+ │ • Shared Models │
93
+ │ • Reusable Service Layer │
94
+ └─────────────────────────────────────────────────────────────────────────────────┘
95
+ ▲ ▲ ▲ ▲ ▲
96
+ │ │ │ │ │
97
+ │ │ │ │ │
98
+ ┌────────────────┐ ┌────────────────┐ ┌──────────────────┐ ┌────────────────┐ ┌────────────────┐
99
+ │ Database │ │ Validation │ │ Messaging │ │ Import / Export│ │ Cache │
100
+ ├────────────────┤ ├────────────────┤ ├──────────────────┤ ├────────────────┤ ├────────────────┤
101
+ │ sql-core │ │validation-core │ │message-processing│ │import-service │ │ cache-plus │
102
+ │ mysql2-core │ │ │ │nats-plus │ │export-kit │ │ redis-plus │
103
+ │ postgres-kit │ │ │ │redis-messaging │ │ │ │ │
104
+ │ oracle-core │ │ │ │rabbitmq-transport│ │ │ │ │
105
+ │ mssql-core │ │ │ │activemq │ │ │ │ │
106
+ │ mongodb-kit │ │ │ │ibmmq-plus │ │ │ │ │
107
+ └────────────────┘ └────────────────┘ └──────────────────┘ └────────────────┘ └────────────────┘
108
+
109
+ ```
110
+
111
+ All libraries share the same interfaces defined by `onecore`.
112
+
113
+ ---
114
+
115
+ # Zero-Cost Abstractions
116
+
117
+ One of the goals of `onecore` is to provide a common API **without adding runtime overhead**.
118
+
119
+ ## Interfaces
120
+
121
+ Interfaces disappear after TypeScript compilation.
122
+
123
+ ```ts
124
+ import { Repository, Validator } from "onecore";
125
+ ```
126
+
127
+ The generated JavaScript contains no implementation from `onecore`.
128
+
129
+ ## Base Classes
130
+
131
+ If an application extends one of the reusable CRUD or Search use-case classes, only those classes are included in the final bundle.
132
+
133
+ Modern bundlers such as Webpack, Rollup, Vite, and esbuild tree-shake unused code automatically.
134
+
135
+ This allows frontend and backend projects to share the same package while keeping bundles minimal.
136
+
137
+ ---
138
+
139
+ # Unified Metadata
140
+
141
+ The most important type in `onecore` is `Attribute`.
142
+
143
+ Unlike persistence-specific or validation-specific metadata, `Attribute` is the canonical metadata model shared across the entire ecosystem.
144
+
145
+ ```
146
+ Attribute
147
+ │
148
+ ┌───────────────┼────────────────┐
149
+ │ │ │
150
+ Validation Database Import/Export
151
+ │ │ │
152
+ validation-core sql-core import-service
153
+ mysql2-core export-kit
154
+ postgres-kit
155
+ mongodb-kit
156
+ ```
157
+
158
+ Each library consumes only the properties that it understands.
159
+
160
+ For example:
161
+
162
+ Validation libraries use
163
+
164
+ * required
165
+ * format
166
+ * gt
167
+ * lt
168
+ * resource
169
+ * noValidate
170
+
171
+ Database libraries use
172
+
173
+ * noInsert
174
+ * noUpdate
175
+ * version
176
+ * createdAt
177
+ * updatedAt
178
+ * length
179
+ * type
180
+
181
+ The same metadata definition can therefore be used for
182
+
183
+ * Validation
184
+ * Database mapping
185
+ * CSV Import
186
+ * CSV Export
187
+ * Search
188
+ * Formatting
189
+ * Localization
190
+
191
+ without duplication.
192
+
193
+ ---
194
+
195
+ # Shared Interfaces
196
+
197
+ `onecore` defines the common contracts used by the ecosystem.
198
+
199
+ ## Database
200
+
201
+ * Repository
202
+ * GenericRepository
203
+ * SearchRepository
204
+ * Transaction
205
+ * Statement
206
+ * QueryBuilder
207
+
208
+ Implemented by
209
+
210
+ * sql-core
211
+ * mysql2-core
212
+ * postgres-kit
213
+ * mongodb-kit
214
+
215
+ ---
216
+
217
+ ## Validation
218
+
219
+ * Validator<T>
220
+
221
+ Implemented by
222
+
223
+ * validation-core
224
+
225
+ ---
226
+
227
+ ## Cache
228
+
229
+ * CachePort
230
+
231
+ Implemented by
232
+
233
+ * cache-plus
234
+ * redis-plus
235
+
236
+ ---
237
+
238
+ ## Message Queue
239
+
240
+ * Producer
241
+ * Consumer
242
+ * Publisher
243
+ * Subscriber
244
+
245
+ Implemented by
246
+
247
+ * message-processing
248
+ * redis-messaging
249
+ * nats-plus
250
+ * rabbitmq-transport
251
+ * ActiveMQ libraries
252
+
253
+ ---
254
+
255
+ ## Logging
256
+
257
+ * Logger
258
+
259
+ Implemented by
260
+
261
+ * logger-core
262
+
263
+ ---
264
+
265
+ ## Health Check
266
+
267
+ * HealthChecker
268
+
269
+ Implemented by
270
+
271
+ * health-service
272
+
273
+ ---
274
+
275
+ ## HTTP
276
+
277
+ * HttpRequest
278
+ * HttpOptionsService
279
+
280
+ Implemented by
281
+
282
+ * web-clients
283
+
284
+ ---
285
+
286
+ ## Localization
287
+
288
+ * Locale
289
+ * Currency
290
+
291
+ Implemented by
292
+
293
+ * locale-service
294
+
295
+ ---
296
+
297
+ # Reusable Use Cases
298
+
299
+ `onecore` also provides reusable application-layer base classes.
300
+
301
+ Examples include
302
+
303
+ * CRUD services
304
+ * Search services
305
+ * View services
306
+
307
+ Applications can extend these classes instead of implementing common CRUD logic repeatedly.
308
+
309
+ Projects that do not use these classes pay no runtime cost.
310
+
311
+ ---
312
+
313
+ # Frontend Support
314
+
315
+ `onecore` works in frontend applications.
316
+
317
+ React applications commonly use
318
+
319
+ * Attribute
320
+ * Locale
321
+ * Currency
322
+ * Validator interfaces
323
+
324
+ without importing any backend service classes.
325
+
326
+ The final JavaScript bundle remains minimal because interfaces are removed during compilation and unused code is tree-shaken.
327
+
328
+ ---
329
+
330
+ # Backend Support
331
+
332
+ Infrastructure services often depend only on interfaces.
333
+
334
+ Examples include
335
+
336
+ * Message Queue services
337
+ * Import services
338
+ * Export services
339
+ * Background workers
340
+
341
+ Since these projects do not use application-layer base classes, the generated JavaScript contains virtually no runtime code from `onecore`.
342
+
343
+ ---
344
+
345
+ # Sample Projects
346
+
347
+ The following sample applications demonstrate different ways of using `onecore`.
348
+
349
+ ### CRUD Applications
350
+
351
+ * [**sql-modular-sample**](https://github.com/source-code-template/sql-modular-sample) — SQL modular microservice using MySQL
352
+ * [**sql-simple-modular-sample**](https://github.com/source-code-template/sql-simple-modular-sample) — SQL modular microservice using PosgreSQL
353
+ * [**mongo-simple-modular-sample**](https://github.com/source-code-template/mongo-simple-modular-sample) — MongoDB modular microservice
354
+
355
+ These projects extend the reusable CRUD and Search use-case classes.
356
+
357
+ ### Import Data
358
+ - [import-sample](https://github.com/typescript-sample/import-sample): import a fix-length file to MySql.
359
+ - [import-csv-sample](https://github.com/typescript-sample/import-csv-sample): import a CSV file to MySql.
360
+
361
+ These projects depend only on interfaces and the shared `Attribute` metadata model.
362
+
363
+ ### Export Data
364
+ - [postgres-export-sample](https://github.com/typescript-sample/postgres-export-sample): export data from Postgres to CSV.
365
+ - [mssql-export-sample](https://github.com/typescript-sample/mssql-export-sample): export data from MS SQL to CSV.
366
+ - [oracle-export-sample](https://github.com/typescript-sample/oracle-export-sample): export data from Oracle to CSV.
367
+ - [mysql-export-sample](https://github.com/typescript-sample/mysql-export-sample): export data from MySql to CSV.
368
+
369
+ These projects depend only on interfaces and the shared `Attribute` metadata model.
370
+
371
+ ### Message Queue services
372
+ - [redis-messaging-sample](https://github.com/typescript-tutorial/redis-messaging-sample): An example to consume message from Redis.
373
+ - [rabbitmq-sample](https://github.com/typescript-tutorial/rabbitmq-sample): An example to consume message from rabbitmq.
374
+ - [activemq-sample](https://github.com/typescript-tutorial/activemq-sample): An example to consume message from activemq.
375
+ - [pubsub-sample](https://github.com/typescript-tutorial/pubsub-sample): An example to consume message from pubsub.
376
+ - [ibmmq-sample](https://github.com/typescript-tutorial/ibmmq-sample): An example to consume message from ibmmq.
377
+ - [kafka-sample](https://github.com/typescript-tutorial/kafka-sample): An example to consume message from kafka.
378
+ - [nats-sample](https://github.com/typescript-tutorial/nats-sample): An example to consume message from nats.
379
+ - [sqs-sample](https://github.com/typescript-tutorial/sqs-sample): An example to consume message from AWS sqs.
380
+
381
+ These projects depend only on interfaces and the shared `Attribute` metadata model.
382
+
383
+ ---
384
+
385
+ # Design Principles
386
+
387
+ * Interface-first architecture
388
+ * Dependency inversion
389
+ * Clean Architecture
390
+ * Hexagonal Architecture
391
+ * Tree-shakeable design
392
+ * Shared metadata model
393
+ * Framework independent
394
+ * Enterprise ready
395
+
396
+ ---
397
+
398
+ # License
399
+
400
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.5.17",
3
+ "version": "0.6.0",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/cache.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface CacheService<K, V> {
1
+ export interface CachePort<K, V> {
2
2
  isEnabled?(): boolean;
3
3
  put(key: K, obj: V, expiresInSeconds?: number): Promise<boolean>;
4
4
  expire(key: K, timeToLive: number): Promise<boolean>;
@@ -7,12 +7,12 @@ export interface CacheService<K, V> {
7
7
  containsKey(key: K): Promise<boolean>;
8
8
  remove(key: K): Promise<boolean>;
9
9
  clear(): Promise<boolean>;
10
- keys?(): Promise<string[]>;
11
- count?(): Promise<number>;
12
- size?(): Promise<number>;
10
+ keys(): Promise<string[]>;
11
+ count(): Promise<number>;
12
+ size(): Promise<number>;
13
13
  }
14
14
 
15
- export interface SyncCacheService<K, V> {
15
+ export interface SyncCachePort<K, V> {
16
16
  put(key: K, obj: V, expiresInMilliseconds?: number): boolean;
17
17
  expire(key: K, timeToLive: number): boolean;
18
18
  get(key: K): V;
@@ -20,6 +20,7 @@ export interface SyncCacheService<K, V> {
20
20
  containsKey(key: K): boolean;
21
21
  remove(key: K): boolean;
22
22
  clear(): boolean;
23
- keys?(): Promise<string[]>;
24
- count?(): Promise<number>;
23
+ keys(): string[];
24
+ count(): number;
25
+ size(): number;
25
26
  }
package/src/formatter.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export interface Locale {
2
- id?: string;
2
+ id: string;
3
3
  countryCode: string;
4
4
  dateFormat: string;
5
5
  firstDayOfWeek: number;
@@ -11,6 +11,11 @@ export interface Locale {
11
11
  currencyPattern: number;
12
12
  currencySample?: string;
13
13
  }
14
+ export interface Currency {
15
+ code: string;
16
+ decimalDigits: number;
17
+ symbol: string;
18
+ }
14
19
 
15
20
  export interface StringFormatter<T> {
16
21
  format(obj: T): string;
package/src/logger.ts CHANGED
@@ -1,5 +1,8 @@
1
+ export interface NumberMap {
2
+ [key: string]: number;
3
+ }
1
4
  export interface SimpleMap {
2
- [key: string]: string|number|boolean|Date;
5
+ [key: string]: string | number | boolean | Date;
3
6
  }
4
7
  export interface LogMap {
5
8
  time: string;
@@ -11,8 +14,30 @@ export interface LogMapConfig {
11
14
  level?: string;
12
15
  msg?: string;
13
16
  }
17
+ export interface Config {
18
+ level?: string;
19
+ map?: LogMapConfig;
20
+ constants?: SimpleMap;
21
+ name?: Name;
22
+ }
23
+ export type LogConf = Config;
24
+ export interface LogConfig {
25
+ log: Config;
26
+ }
27
+ export interface Name {
28
+ trace: string;
29
+ debug: string;
30
+ info: string;
31
+ warn: string;
32
+ error: string;
33
+ panic: string;
34
+ fatal: string;
35
+ }
14
36
  export interface Logger {
37
+ name: Name;
15
38
  level: number;
39
+ map: LogMap;
40
+ constants?: SimpleMap;
16
41
  trace(msg: string, m?: SimpleMap, ctx?: any): void;
17
42
  debug(msg: string, m?: SimpleMap, ctx?: any): void;
18
43
  info(msg: string, m?: SimpleMap, ctx?: any): void;
package/src/mq.ts CHANGED
@@ -4,7 +4,8 @@ interface StringMap {
4
4
  export interface NumberMap {
5
5
  [key: number]: number;
6
6
  }
7
- export type Handle<T> = (data: T, header?: StringMap) => Promise<number>;
7
+ export type Process<T, R, M> = (data: T, attributes?: StringMap, msg?: M) => Promise<R>
8
+ export type Handle<T, R, M> = (data: T, attributes?: StringMap, msg?: M) => Promise<R>
8
9
  export type Consume<T> = (handle: (data: T, header?: StringMap) => Promise<number>) => void;
9
10
  export type Read<T> = Consume<T>;
10
11
  export type Subscribe<T> = Consume<T>;
package/src/validator.ts CHANGED
@@ -4,11 +4,13 @@ interface ErrorMessage {
4
4
  param?: string|number|Date;
5
5
  message?: string;
6
6
  }
7
-
7
+ export interface StringMap {
8
+ [key: string]: string;
9
+ }
8
10
  export interface Validator<T> {
9
- validate(model: T, ctx?: any): Promise<ErrorMessage[]>;
11
+ validate(model: T, resource?: StringMap, patch?: boolean): Promise<ErrorMessage[]>;
10
12
  }
11
13
 
12
14
  export interface SyncValidator<T> {
13
- validate(model: T, ctx?: any): ErrorMessage[];
15
+ validate(model: T, resource?: StringMap, patch?: boolean): ErrorMessage[];
14
16
  }
package/src/video.ts CHANGED
@@ -54,9 +54,6 @@ export interface CommentSnippet extends CommentInfo, YoutubeAuthor {
54
54
  parentId: string;
55
55
  }
56
56
 
57
- export interface StringMap {
58
- [key: string]: string;
59
- }
60
57
  export interface ListResult<T> {
61
58
  list: T[];
62
59
  total?: number;