@ackplus/nest-crud-request 0.0.1 → 0.0.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/LICENSE +21 -0
- package/README.md +130 -6
- package/eslint.config.cjs +22 -0
- package/jest.config.ts +10 -0
- package/package.json +14 -8
- package/project.json +9 -0
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +3 -0
- package/{lib → src/lib}/query-builder.d.ts +1 -1
- package/src/lib/query-builder.js +123 -0
- package/src/lib/query-builder.js.map +1 -0
- package/src/lib/query-builder.ts +139 -0
- package/src/lib/relation-builder.js +59 -0
- package/src/lib/relation-builder.js.map +1 -0
- package/src/lib/relation-builder.ts +64 -0
- package/src/lib/types.js +37 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/types.ts +48 -0
- package/src/lib/utils.js +15 -0
- package/src/lib/utils.js.map +1 -0
- package/src/lib/utils.ts +11 -0
- package/src/lib/where-builder.js +106 -0
- package/src/lib/where-builder.js.map +1 -0
- package/src/lib/where-builder.ts +124 -0
- package/src/test/query-builder-where.spec.ts +173 -0
- package/src/test/query-builder.spec.ts +149 -0
- package/src/test/relation-builder.spec.ts +32 -0
- package/tsconfig.json +21 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +15 -0
- package/vite.config.ts +46 -0
- package/index.js +0 -137
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{lib → src/lib}/relation-builder.d.ts +0 -0
- /package/{lib → src/lib}/types.d.ts +0 -0
- /package/{lib → src/lib}/utils.d.ts +0 -0
- /package/{lib → src/lib}/where-builder.d.ts +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RelationBuilder } from '../lib/relation-builder';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
describe('RelationBuilder', () => {
|
|
5
|
+
let relationBuilder: RelationBuilder;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
relationBuilder = new RelationBuilder();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should handle empty relations', () => {
|
|
12
|
+
// Initially, the relations should be empty
|
|
13
|
+
expect(relationBuilder.toObject()).toEqual([]);
|
|
14
|
+
|
|
15
|
+
// Clear any relations if set
|
|
16
|
+
relationBuilder.clear();
|
|
17
|
+
expect(relationBuilder.toObject()).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should handle setting empty relations', () => {
|
|
21
|
+
// Set empty relations
|
|
22
|
+
relationBuilder.setRelations([]);
|
|
23
|
+
expect(relationBuilder.toObject()).toEqual([]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should handle clearing relations', () => {
|
|
27
|
+
// Add some relations and then clear them
|
|
28
|
+
relationBuilder.setRelations(['relation1', 'relation2']);
|
|
29
|
+
relationBuilder.clear();
|
|
30
|
+
expect(relationBuilder.toObject()).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noImplicitOverride": true,
|
|
8
|
+
"noImplicitReturns": true,
|
|
9
|
+
"noPropertyAccessFromIndexSignature": true
|
|
10
|
+
},
|
|
11
|
+
"files": [],
|
|
12
|
+
"include": [],
|
|
13
|
+
"references": [
|
|
14
|
+
{
|
|
15
|
+
"path": "./tsconfig.lib.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "./tsconfig.spec.json"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"moduleResolution": "node10",
|
|
7
|
+
"types": ["jest", "node"]
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"jest.config.ts",
|
|
11
|
+
"src/**/*.test.ts",
|
|
12
|
+
"src/**/*.spec.ts",
|
|
13
|
+
"src/**/*.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import dts from 'vite-plugin-dts';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
6
|
+
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
root: __dirname,
|
|
10
|
+
cacheDir: '../../node_modules/.vite/packages/nest-crud-request',
|
|
11
|
+
plugins: [
|
|
12
|
+
nxViteTsPaths(),
|
|
13
|
+
nxCopyAssetsPlugin(['*.md']),
|
|
14
|
+
dts({
|
|
15
|
+
entryRoot: 'src',
|
|
16
|
+
tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
// Uncomment this if you are using workers.
|
|
20
|
+
// worker: {
|
|
21
|
+
// plugins: [ nxViteTsPaths() ],
|
|
22
|
+
// },
|
|
23
|
+
// Configuration for building your library.
|
|
24
|
+
// See: https://vitejs.dev/guide/build.html#library-mode
|
|
25
|
+
build: {
|
|
26
|
+
outDir: '../../dist/packages/nest-crud-request',
|
|
27
|
+
emptyOutDir: true,
|
|
28
|
+
reportCompressedSize: true,
|
|
29
|
+
commonjsOptions: {
|
|
30
|
+
transformMixedEsModules: true,
|
|
31
|
+
},
|
|
32
|
+
lib: {
|
|
33
|
+
// Could also be a dictionary or array of multiple entry points.
|
|
34
|
+
entry: 'src/index.ts',
|
|
35
|
+
name: 'nest-crud-request',
|
|
36
|
+
fileName: 'index',
|
|
37
|
+
// Change this to the formats you want to support.
|
|
38
|
+
// Don't forget to update your package.json as well.
|
|
39
|
+
formats: ['es'],
|
|
40
|
+
},
|
|
41
|
+
rollupOptions: {
|
|
42
|
+
// External packages that should not be bundled into your library.
|
|
43
|
+
external: [],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
package/index.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
var w = (i, e) => () => (e || i((e = { exports: {} }).exports, e), e.exports);
|
|
2
|
-
var B = w((r) => {
|
|
3
|
-
Object.defineProperty(r, "__esModule", { value: !0 });
|
|
4
|
-
r.QueryBuilder = void 0;
|
|
5
|
-
const c = require("./relation-builder"), b = require("./utils"), a = require("./where-builder");
|
|
6
|
-
class j {
|
|
7
|
-
constructor(e) {
|
|
8
|
-
this.options = {}, this.whereBuilder = new a.WhereBuilder(), this.relationBuilder = new c.RelationBuilder(), this.options = e, this.setOptions(e);
|
|
9
|
-
}
|
|
10
|
-
setOptions(e) {
|
|
11
|
-
return this.options = e, this.whereBuilder = new a.WhereBuilder(e.where), this.relationBuilder = new c.RelationBuilder(e.relations), this;
|
|
12
|
-
}
|
|
13
|
-
mergeOptions(e, t = !1) {
|
|
14
|
-
let s = {};
|
|
15
|
-
return t ? s = (0, b.deepMerge)(this.options, e) : s = {
|
|
16
|
-
...this.options,
|
|
17
|
-
...e
|
|
18
|
-
}, this.setOptions(s), this;
|
|
19
|
-
}
|
|
20
|
-
addSelect(e) {
|
|
21
|
-
return this.options.select || (this.options.select = []), Array.isArray(e) ? this.options.select.push(...e) : this.options.select.push(e), this;
|
|
22
|
-
}
|
|
23
|
-
removeSelect(e) {
|
|
24
|
-
return this.options.select && (Array.isArray(e) ? this.options.select = this.options.select.filter((t) => !e.includes(t)) : this.options.select = this.options.select.filter((t) => t !== e)), this;
|
|
25
|
-
}
|
|
26
|
-
addRelation(e, t, s) {
|
|
27
|
-
return this.relationBuilder.add(e, t, s), this;
|
|
28
|
-
}
|
|
29
|
-
removeRelation(e) {
|
|
30
|
-
return this.relationBuilder.remove(e), this;
|
|
31
|
-
}
|
|
32
|
-
where(...e) {
|
|
33
|
-
return this.whereBuilder.where(...e), this;
|
|
34
|
-
}
|
|
35
|
-
andWhere(...e) {
|
|
36
|
-
return this.whereBuilder.andWhere(...e), this;
|
|
37
|
-
}
|
|
38
|
-
orWhere(...e) {
|
|
39
|
-
return this.whereBuilder.orWhere(...e), this;
|
|
40
|
-
}
|
|
41
|
-
addOrder(e, t) {
|
|
42
|
-
return this.options.order || (this.options.order = {}), this.options.order[e] = t, this;
|
|
43
|
-
}
|
|
44
|
-
removeOrder(e) {
|
|
45
|
-
return this.options.order && delete this.options.order[e], this;
|
|
46
|
-
}
|
|
47
|
-
setSkip(e) {
|
|
48
|
-
return this.options.skip = e, this;
|
|
49
|
-
}
|
|
50
|
-
setTake(e) {
|
|
51
|
-
return this.options.take = e, this;
|
|
52
|
-
}
|
|
53
|
-
toObject() {
|
|
54
|
-
const e = {
|
|
55
|
-
...this.options
|
|
56
|
-
};
|
|
57
|
-
return this.whereBuilder.hasConditions() ? e.where = this.whereBuilder.toObject() : delete e.where, this.relationBuilder.hasRelations() ? e.relations = this.relationBuilder.toObject() : delete e.relations, e;
|
|
58
|
-
}
|
|
59
|
-
toJson() {
|
|
60
|
-
const e = this.toObject();
|
|
61
|
-
return JSON.stringify(e);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
r.QueryBuilder = j;
|
|
65
|
-
Object.defineProperty(r, "__esModule", { value: !0 });
|
|
66
|
-
r.WhereBuilder = void 0;
|
|
67
|
-
const l = require("./types");
|
|
68
|
-
class u {
|
|
69
|
-
constructor(e) {
|
|
70
|
-
this.whereObject = {}, this.whereObject = e || {};
|
|
71
|
-
}
|
|
72
|
-
clear() {
|
|
73
|
-
return this.whereObject = {}, this;
|
|
74
|
-
}
|
|
75
|
-
where(...e) {
|
|
76
|
-
return this.parseCondition(null, ...e), this;
|
|
77
|
-
}
|
|
78
|
-
andWhere(...e) {
|
|
79
|
-
return this.parseCondition(l.WhereLogicalOperatorEnum.AND, ...e), this;
|
|
80
|
-
}
|
|
81
|
-
orWhere(...e) {
|
|
82
|
-
return this.parseCondition(l.WhereLogicalOperatorEnum.OR, ...e), this;
|
|
83
|
-
}
|
|
84
|
-
removeWhere(e) {
|
|
85
|
-
const t = e.split(".");
|
|
86
|
-
let s = this.whereObject;
|
|
87
|
-
for (let n = 0; n < t.length - 1; n++) {
|
|
88
|
-
if (!s[t[n]])
|
|
89
|
-
return this;
|
|
90
|
-
s = s[t[n]];
|
|
91
|
-
}
|
|
92
|
-
return delete s[t[t.length - 1]], this;
|
|
93
|
-
}
|
|
94
|
-
hasConditions() {
|
|
95
|
-
return Object.keys(this.whereObject).length > 0;
|
|
96
|
-
}
|
|
97
|
-
toObject() {
|
|
98
|
-
return this.whereObject;
|
|
99
|
-
}
|
|
100
|
-
toJson() {
|
|
101
|
-
return JSON.stringify(this.whereObject);
|
|
102
|
-
}
|
|
103
|
-
parseCondition(e, ...t) {
|
|
104
|
-
let s, n, o;
|
|
105
|
-
if (t.length !== 0) if (t.length === 1) {
|
|
106
|
-
const h = t[0];
|
|
107
|
-
if (typeof h == "function") {
|
|
108
|
-
const d = new u();
|
|
109
|
-
h(d), this.updateCondition(d.toObject(), e);
|
|
110
|
-
} else h instanceof u ? this.updateCondition(h.toObject(), e) : this.updateCondition(h, e);
|
|
111
|
-
} else (t.length === 2 || t.length === 3) && (t.length === 2 ? (s = t[0], o = t[1], typeof o == "object" ? Object.keys(o)[0].startsWith("$") ? this.updateCondition({ [s]: o }, e) : this.updateCondition({ [s]: { [l.WhereOperatorEnum.EQ]: o } }, e) : this.updateCondition({ [s]: { [l.WhereOperatorEnum.EQ]: o } }, e)) : (s = t[0], n = t[1], o = t[2], this.updateCondition({ [s]: { [n]: o } }, e)));
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
updateCondition(e, t) {
|
|
115
|
-
t === null ? this.whereObject = {
|
|
116
|
-
...this.whereObject,
|
|
117
|
-
...e
|
|
118
|
-
} : this.whereObject[t] = [...this.whereObject[t] || [], e].filter(Boolean);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
r.WhereBuilder = u;
|
|
122
|
-
Object.defineProperty(r, "__esModule", { value: !0 });
|
|
123
|
-
r.OrderDirectionEnum = r.WhereOperatorEnum = r.WhereLogicalOperatorEnum = void 0;
|
|
124
|
-
var f;
|
|
125
|
-
(function(i) {
|
|
126
|
-
i.AND = "$and", i.OR = "$or";
|
|
127
|
-
})(f || (r.WhereLogicalOperatorEnum = f = {}));
|
|
128
|
-
var O;
|
|
129
|
-
(function(i) {
|
|
130
|
-
i.EQ = "$eq", i.NOT_EQ = "$ne", i.GT = "$gt", i.GT_OR_EQ = "$gte", i.LT = "$lt", i.LT_OR_EQ = "$lte", i.IN = "$in", i.NOT_IN = "$notIn", i.LIKE = "$like", i.NOT_LIKE = "$notLike", i.ILIKE = "$iLike", i.NOT_ILIKE = "$notIlike", i.IS_NULL = "$isNull", i.IS_NOT_NULL = "$isNotNull", i.BETWEEN = "$between", i.NOT_BETWEEN = "$notBetween", i.NULL = "$null", i.NOT_NULL = "$notNull", i.IS_TRUE = "$isTrue", i.IS_FALSE = "$isFalse";
|
|
131
|
-
})(O || (r.WhereOperatorEnum = O = {}));
|
|
132
|
-
var p;
|
|
133
|
-
(function(i) {
|
|
134
|
-
i.ASC = "ASC", i.DESC = "DESC";
|
|
135
|
-
})(p || (r.OrderDirectionEnum = p = {}));
|
|
136
|
-
});
|
|
137
|
-
export default B();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|