@ealforque/sequelize-field-parser 1.0.10 → 1.0.11
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 +37 -3
- package/package.json +15 -13
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ A TypeScript utility for Sequelize models that lets users specify fields to incl
|
|
|
14
14
|
- **Parse Sequelize model fields and relationships:** Easily extract and validate fields and associations from models
|
|
15
15
|
- **Generate field trees for complex models:** Build nested relationship trees for Sequelize includes
|
|
16
16
|
- **Type-safe interfaces and types:** All parsing and tree generation is type-safe
|
|
17
|
-
- **Easy integration with
|
|
17
|
+
- **Easy integration with Sequelize:** Works seamlessly with Sequelize ORM
|
|
18
18
|
- **Test-driven development with Jest:** Comprehensive test suite for robust behavior
|
|
19
19
|
- **Handles maximum relationship depth (default: 10):** Prevents runaway includes and logs warnings
|
|
20
20
|
- **Detects and prevents circular relationships:** Safely handles circular model associations
|
|
@@ -36,15 +36,49 @@ import FieldParserService from "./src/field_parser.service";
|
|
|
36
36
|
import SomeModel from "./models/SomeModel";
|
|
37
37
|
|
|
38
38
|
const parser = new FieldParserService();
|
|
39
|
-
const result = parser.parseFields(
|
|
39
|
+
const result = parser.parseFields(
|
|
40
|
+
"id,name,profile.email,profile.address.zip",
|
|
41
|
+
SomeModel,
|
|
42
|
+
);
|
|
40
43
|
console.log(result);
|
|
41
44
|
/*
|
|
42
45
|
{
|
|
43
46
|
columns: ['id', 'name'],
|
|
44
|
-
relationshipTree: {
|
|
47
|
+
relationshipTree: {
|
|
48
|
+
profile: {
|
|
49
|
+
email: true,
|
|
50
|
+
address: {
|
|
51
|
+
zip: true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
45
55
|
invalidFields: []
|
|
46
56
|
}
|
|
47
57
|
*/
|
|
58
|
+
|
|
59
|
+
// To build the Sequelize include array for multi-level relationships:
|
|
60
|
+
const include = parser.buildSequelizeInclude(
|
|
61
|
+
result.relationshipTree,
|
|
62
|
+
SomeModel,
|
|
63
|
+
);
|
|
64
|
+
console.log(include);
|
|
65
|
+
/*
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
model: ProfileModel,
|
|
69
|
+
as: 'profile',
|
|
70
|
+
attributes: ['email'],
|
|
71
|
+
include: [
|
|
72
|
+
{
|
|
73
|
+
model: AddressModel,
|
|
74
|
+
as: 'address',
|
|
75
|
+
attributes: ['zip'],
|
|
76
|
+
include: []
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
*/
|
|
48
82
|
```
|
|
49
83
|
|
|
50
84
|
---
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ealforque/sequelize-field-parser",
|
|
3
|
-
"description": "
|
|
4
|
-
"
|
|
3
|
+
"description": "TypeScript utility for parsing fields and relationships in Sequelize models, generating include trees for queries.",
|
|
4
|
+
"author": "Eric Alforque <eric.alforque@gmail.com>",
|
|
5
|
+
"version": "1.0.11",
|
|
5
6
|
"main": "dist/field_parser.service.js",
|
|
6
7
|
"types": "dist/field_parser.service.d.ts",
|
|
7
8
|
"files": [
|
|
@@ -31,17 +32,17 @@
|
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"sequelize": "6.32.1",
|
|
34
|
-
"@types/jest": "
|
|
35
|
-
"eslint": "
|
|
36
|
-
"eslint-config-prettier": "10.1.
|
|
35
|
+
"@types/jest": "30.0.0",
|
|
36
|
+
"eslint": "9.39.4",
|
|
37
|
+
"eslint-config-prettier": "10.1.8",
|
|
37
38
|
"eslint-plugin-import": "2.31.0",
|
|
38
39
|
"eslint-plugin-simple-import-sort": "12.1.1",
|
|
39
40
|
"http-status-codes": "2.3.0",
|
|
40
|
-
"jest": "
|
|
41
|
-
"prettier": "3.
|
|
41
|
+
"jest": "30.2.0",
|
|
42
|
+
"prettier": "3.8.1",
|
|
42
43
|
"sequelize-cli": "6.6.2",
|
|
43
|
-
"supertest": "7.
|
|
44
|
-
"
|
|
44
|
+
"supertest": "7.2.2",
|
|
45
|
+
"@swc/jest": "0.2.39",
|
|
45
46
|
"ts-node": "10.9.2",
|
|
46
47
|
"typescript": "5.8.3",
|
|
47
48
|
"typescript-eslint": "8.32.0"
|
|
@@ -49,10 +50,11 @@
|
|
|
49
50
|
"license": "MIT",
|
|
50
51
|
"keywords": [
|
|
51
52
|
"sequelize",
|
|
52
|
-
"
|
|
53
|
+
"field parser",
|
|
54
|
+
"typescript",
|
|
53
55
|
"orm",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
56
|
+
"include",
|
|
57
|
+
"relationships",
|
|
58
|
+
"models"
|
|
57
59
|
]
|
|
58
60
|
}
|