@youjunhuang/entity-core 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +72 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -8,12 +8,80 @@ Shared entity core library for Mycena core.
8
8
  npm i --save-dev @youjunhuang/entity-core
9
9
  ```
10
10
 
11
+
12
+ ## Concepts
13
+
14
+ This library is structured around three main concepts:
15
+
16
+ ### 1. Models (`/models`)
17
+ **Database-agnostic entity definitions.**
18
+ These are pure TypeScript interfaces and enums that define the shape of your data entities. They are independent of any specific database implementation.
19
+ - **Purpose**: Define the "What".
20
+ - **Example**: `Camera`, `User`, `Event`.
21
+
22
+ ### 2. Schemas (`/schemas`)
23
+ **Database-specific implementations.**
24
+ These define how the Models are mapped to a specific database (e.g., MongoDB via Mongoose, SQL via TypeORM).
25
+ - **Purpose**: Define the "How" (storage).
26
+ - **Current Support**: MongoDB (`/schemas/mongo`).
27
+
28
+ ### 3. Data Access (`/data_access`)
29
+ **Repositories and Services.**
30
+ These provide the logic to interact with the database using the Schemas. They abstract the database operations from the business logic.
31
+ - **Purpose**: Define the "How" (access).
32
+ - **Current Support**: MongoDB Repositories (`/data_access/mongo`).
33
+
11
34
  ## Usage
12
35
 
13
- Import models, schemas, or data access objects from the package:
36
+ ### Importing Models
37
+
38
+ Use Models to type your objects and ensure type safety across your application.
14
39
 
15
40
  ```typescript
16
- import { Camera } from '@youjunhuang/entity-core';
17
- // or
18
- import * as EntityCore from '@youjunhuang/entity-core';
41
+ import { Camera, CameraStatus, CameraType } from '@youjunhuang/entity-core';
42
+
43
+ const myCamera: Camera = {
44
+ id: 'cam-001',
45
+ name: 'Front Door',
46
+ type: CameraType.SHOTGUN,
47
+ status: CameraStatus.Online,
48
+ // ... other properties
49
+ };
50
+ ```
51
+
52
+ ### Using Schemas (NestJS Example)
53
+
54
+ Import Schemas to define your Mongoose models in a NestJS application.
55
+
56
+ ```typescript
57
+ import { Module } from '@nestjs/common';
58
+ import { MongooseModule } from '@nestjs/mongoose';
59
+ import { CameraMongo, CameraMongoSchema } from '@youjunhuang/entity-core';
60
+
61
+ @Module({
62
+ imports: [
63
+ MongooseModule.forFeature([
64
+ { name: CameraMongo.name, schema: CameraMongoSchema },
65
+ ]),
66
+ ],
67
+ })
68
+ export class CameraModule {}
69
+ ```
70
+
71
+ ### Using Data Access Repositories
72
+
73
+ Import and use Repositories to perform database operations.
74
+
75
+ ```typescript
76
+ import { Injectable } from '@nestjs/common';
77
+ import { CameraMongoRepository } from '@youjunhuang/entity-core';
78
+
79
+ @Injectable()
80
+ export class CameraService {
81
+ constructor(private readonly cameraRepo: CameraMongoRepository) {}
82
+
83
+ async findAll() {
84
+ return this.cameraRepo.findAll();
85
+ }
86
+ }
19
87
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youjunhuang/entity-core",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [