directus 9.14.1 → 9.14.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 (50) hide show
  1. package/dist/cli/commands/security/key.d.ts +1 -0
  2. package/dist/cli/commands/security/key.js +8 -0
  3. package/dist/cli/commands/security/secret.d.ts +1 -0
  4. package/dist/cli/commands/security/secret.js +8 -0
  5. package/dist/cli/index.js +6 -0
  6. package/dist/controllers/extensions.js +9 -1
  7. package/dist/database/helpers/fn/dialects/mssql.d.ts +2 -2
  8. package/dist/database/helpers/fn/dialects/mssql.js +2 -2
  9. package/dist/database/helpers/fn/dialects/mysql.d.ts +2 -2
  10. package/dist/database/helpers/fn/dialects/mysql.js +2 -2
  11. package/dist/database/helpers/fn/dialects/oracle.d.ts +1 -1
  12. package/dist/database/helpers/fn/dialects/oracle.js +2 -2
  13. package/dist/database/helpers/fn/dialects/postgres.d.ts +2 -2
  14. package/dist/database/helpers/fn/dialects/postgres.js +2 -2
  15. package/dist/database/helpers/fn/dialects/sqlite.d.ts +1 -1
  16. package/dist/database/helpers/fn/dialects/sqlite.js +2 -2
  17. package/dist/database/helpers/fn/types.d.ts +3 -2
  18. package/dist/database/helpers/fn/types.js +11 -8
  19. package/dist/database/helpers/index.d.ts +3 -3
  20. package/dist/database/helpers/schema/dialects/sqlite.d.ts +5 -0
  21. package/dist/database/helpers/schema/dialects/sqlite.js +17 -0
  22. package/dist/database/helpers/schema/index.d.ts +1 -1
  23. package/dist/database/helpers/schema/index.js +4 -4
  24. package/dist/database/helpers/schema/types.d.ts +2 -0
  25. package/dist/database/helpers/schema/types.js +6 -0
  26. package/dist/database/run-ast.js +8 -5
  27. package/dist/logger.d.ts +0 -1
  28. package/dist/middleware/authenticate.d.ts +0 -1
  29. package/dist/middleware/cache.js +3 -3
  30. package/dist/middleware/graphql.js +9 -7
  31. package/dist/middleware/respond.js +5 -5
  32. package/dist/operations/request/index.js +1 -1
  33. package/dist/services/authorization.js +15 -5
  34. package/dist/services/fields.js +4 -0
  35. package/dist/services/graphql/index.js +40 -15
  36. package/dist/services/server.js +13 -2
  37. package/dist/types/ast.d.ts +11 -4
  38. package/dist/utils/apply-query.js +5 -13
  39. package/dist/utils/apply-snapshot.js +41 -17
  40. package/dist/utils/filter-items.js +3 -6
  41. package/dist/utils/get-ast-from-query.js +18 -0
  42. package/dist/utils/get-column-path.d.ts +5 -1
  43. package/dist/utils/get-column-path.js +3 -1
  44. package/dist/utils/get-column.d.ts +2 -2
  45. package/dist/utils/get-column.js +2 -2
  46. package/dist/utils/get-config-from-env.js +1 -1
  47. package/dist/utils/merge-permissions.d.ts +0 -1
  48. package/package.json +232 -226
  49. package/dist/utils/generate-joi.d.ts +0 -3
  50. package/dist/utils/generate-joi.js +0 -145
package/package.json CHANGED
@@ -1,227 +1,233 @@
1
1
  {
2
- "name": "directus",
3
- "version": "9.14.1",
4
- "license": "GPL-3.0-only",
5
- "homepage": "https://github.com/directus/directus#readme",
6
- "description": "Directus is a real-time API and App dashboard for managing SQL database content.",
7
- "keywords": [
8
- "directus",
9
- "realtime",
10
- "database",
11
- "content",
12
- "api",
13
- "rest",
14
- "graphql",
15
- "app",
16
- "dashboard",
17
- "headless",
18
- "cms",
19
- "mysql",
20
- "postgresql",
21
- "cockroachdb",
22
- "sqlite",
23
- "framework",
24
- "vue"
25
- ],
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/directus/directus.git"
29
- },
30
- "bugs": {
31
- "url": "https://github.com/directus/directus/issues"
32
- },
33
- "author": {
34
- "name": "Monospace Inc",
35
- "email": "info@monospace.io",
36
- "url": "https://monospace.io"
37
- },
38
- "maintainers": [
39
- {
40
- "name": "Rijk van Zanten",
41
- "email": "rijkvanzanten@me.com",
42
- "url": "https://github.com/rijkvanzanten"
43
- },
44
- {
45
- "name": "Ben Haynes",
46
- "email": "ben@rngr.org",
47
- "url": "https://github.com/benhaynes"
48
- }
49
- ],
50
- "main": "dist/index.js",
51
- "exports": {
52
- ".": "./dist/index.js",
53
- "./*": "./dist/*.js",
54
- "./package.json": "./package.json"
55
- },
56
- "bin": {
57
- "directus": "cli.js"
58
- },
59
- "scripts": {
60
- "start": "npx directus start",
61
- "prebuild": "npm run cleanup",
62
- "build": "tsc --build && copyfiles \"src/**/*.*\" -e \"src/**/*.ts\" -u 1 dist",
63
- "cleanup": "rimraf dist",
64
- "dev": "cross-env NODE_ENV=development SERVE_APP=false ts-node-dev --files --transpile-only --respawn --watch \".env\" --inspect=0 --exit-child -- src/start.ts",
65
- "cli": "cross-env NODE_ENV=development SERVE_APP=false ts-node --script-mode --transpile-only src/cli/run.ts",
66
- "test": "jest",
67
- "test:coverage": "jest --coverage",
68
- "test:watch": "jest --watch"
69
- },
70
- "engines": {
71
- "node": ">=12.20.0"
72
- },
73
- "files": [
74
- "dist",
75
- "LICENSE",
76
- "README.md"
77
- ],
78
- "dependencies": {
79
- "@aws-sdk/client-ses": "^3.107.0",
80
- "@directus/app": "9.14.1",
81
- "@directus/drive": "9.14.1",
82
- "@directus/drive-azure": "9.14.1",
83
- "@directus/drive-gcs": "9.14.1",
84
- "@directus/drive-s3": "9.14.1",
85
- "@directus/extensions-sdk": "9.14.1",
86
- "@directus/format-title": "9.14.1",
87
- "@directus/schema": "9.14.1",
88
- "@directus/shared": "9.14.1",
89
- "@directus/specs": "9.14.1",
90
- "@godaddy/terminus": "^4.10.2",
91
- "@rollup/plugin-alias": "^3.1.9",
92
- "@rollup/plugin-virtual": "^2.1.0",
93
- "argon2": "^0.28.5",
94
- "async": "^3.2.4",
95
- "async-mutex": "^0.3.2",
96
- "axios": "^0.27.2",
97
- "busboy": "^1.6.0",
98
- "bytes": "^3.1.2",
99
- "camelcase": "^6.2.0",
100
- "chalk": "^4.1.1",
101
- "chokidar": "^3.5.3",
102
- "commander": "^8.0.0",
103
- "cookie-parser": "^1.4.6",
104
- "cors": "^2.8.5",
105
- "csv-parser": "^3.0.0",
106
- "date-fns": "^2.28.0",
107
- "deep-diff": "^1.0.2",
108
- "deep-map": "^2.0.0",
109
- "destroy": "^1.2.0",
110
- "dotenv": "^10.0.0",
111
- "eventemitter2": "^6.4.5",
112
- "execa": "^5.1.1",
113
- "exifr": "^7.1.3",
114
- "express": "^4.18.1",
115
- "fast-redact": "^3.1.1",
116
- "flat": "^5.0.2",
117
- "fs-extra": "^10.1.0",
118
- "globby": "^11.0.4",
119
- "graphql": "^15.5.0",
120
- "graphql-compose": "^9.0.8",
121
- "helmet": "^4.6.0",
122
- "inquirer": "^8.2.4",
123
- "ioredis": "^4.27.6",
124
- "joi": "^17.6.0",
125
- "js-yaml": "^4.1.0",
126
- "js2xmlparser": "^4.0.2",
127
- "json2csv": "^5.0.7",
128
- "jsonwebtoken": "^8.5.1",
129
- "keyv": "^4.3.0",
130
- "knex": "^2.1.0",
131
- "knex-schema-inspector": "^2.0.1",
132
- "ldapjs": "^2.3.3",
133
- "liquidjs": "^9.37.0",
134
- "lodash": "^4.17.21",
135
- "macos-release": "^2.4.1",
136
- "marked": "^4.0.16",
137
- "micromustache": "^8.0.3",
138
- "mime-types": "^2.1.35",
139
- "ms": "^2.1.3",
140
- "nanoid": "^3.1.23",
141
- "node-cron": "^3.0.1",
142
- "node-machine-id": "^1.1.12",
143
- "nodemailer": "^6.7.5",
144
- "object-hash": "^2.2.0",
145
- "openapi3-ts": "^2.0.2",
146
- "openid-client": "^5.1.6",
147
- "ora": "^5.4.0",
148
- "otplib": "^12.0.1",
149
- "pino": "6.13.3",
150
- "pino-colada": "^2.2.2",
151
- "pino-http": "5.8.0",
152
- "qs": "^6.10.5",
153
- "rate-limiter-flexible": "^2.3.7",
154
- "resolve-cwd": "^3.0.0",
155
- "rollup": "^2.75.6",
156
- "sanitize-html": "^2.7.0",
157
- "sharp": "^0.30.6",
158
- "stream-json": "^1.7.4",
159
- "strip-bom-stream": "^4.0.0",
160
- "supertest": "^6.2.3",
161
- "tmp-promise": "^3.0.3",
162
- "update-check": "^1.5.4",
163
- "uuid": "^8.3.2",
164
- "uuid-validate": "0.0.3",
165
- "wellknown": "^0.5.0"
166
- },
167
- "optionalDependencies": {
168
- "@keyv/redis": "^2.3.6",
169
- "keyv-memcache": "^1.2.5",
170
- "memcached": "^2.2.2",
171
- "mysql": "^2.18.1",
172
- "nodemailer-mailgun-transport": "^2.1.4",
173
- "pg": "^8.7.3",
174
- "sqlite3": "^5.0.8",
175
- "tedious": "^13.0.0"
176
- },
177
- "gitHead": "398839be6e3aff81e20eff349ca9f60557096f03",
178
- "devDependencies": {
179
- "@types/async": "3.2.13",
180
- "@types/body-parser": "1.19.2",
181
- "@types/busboy": "1.5.0",
182
- "@types/cookie-parser": "1.4.3",
183
- "@types/cors": "2.8.12",
184
- "@types/deep-diff": "1.0.1",
185
- "@types/destroy": "1.0.0",
186
- "@types/express": "4.17.13",
187
- "@types/express-pino-logger": "4.0.3",
188
- "@types/express-session": "1.17.4",
189
- "@types/fast-redact": "^3.0.1",
190
- "@types/flat": "5.0.2",
191
- "@types/fs-extra": "9.0.13",
192
- "@types/inquirer": "8.2.1",
193
- "@types/ioredis": "^4.28.10",
194
- "@types/jest": "27.4.1",
195
- "@types/js-yaml": "4.0.5",
196
- "@types/json2csv": "5.0.3",
197
- "@types/jsonwebtoken": "8.5.8",
198
- "@types/keyv": "3.1.4",
199
- "@types/ldapjs": "2.2.2",
200
- "@types/lodash": "4.14.182",
201
- "@types/marked": "4.0.3",
202
- "@types/mime-types": "2.1.1",
203
- "@types/ms": "0.7.31",
204
- "@types/node": "16.11.9",
205
- "@types/node-cron": "2.0.5",
206
- "@types/nodemailer": "6.4.4",
207
- "@types/object-hash": "2.2.1",
208
- "@types/pino": "6.3.12",
209
- "@types/pino-http": "5.8.1",
210
- "@types/qs": "6.9.7",
211
- "@types/sanitize-html": "2.6.2",
212
- "@types/sharp": "0.30.4",
213
- "@types/stream-json": "1.7.2",
214
- "@types/supertest": "2.0.12",
215
- "@types/uuid": "8.3.4",
216
- "@types/uuid-validate": "0.0.1",
217
- "@types/wellknown": "0.5.3",
218
- "copyfiles": "2.4.1",
219
- "cross-env": "7.0.3",
220
- "form-data": "^4.0.0",
221
- "jest": "27.5.1",
222
- "knex-mock-client": "1.8.4",
223
- "ts-jest": "27.1.3",
224
- "ts-node-dev": "1.1.8",
225
- "typescript": "4.7.3"
226
- }
227
- }
2
+ "name": "directus",
3
+ "version": "9.14.2",
4
+ "license": "GPL-3.0-only",
5
+ "homepage": "https://github.com/directus/directus#readme",
6
+ "description": "Directus is a real-time API and App dashboard for managing SQL database content.",
7
+ "keywords": [
8
+ "directus",
9
+ "realtime",
10
+ "database",
11
+ "content",
12
+ "api",
13
+ "rest",
14
+ "graphql",
15
+ "app",
16
+ "dashboard",
17
+ "headless",
18
+ "cms",
19
+ "mysql",
20
+ "postgresql",
21
+ "cockroachdb",
22
+ "sqlite",
23
+ "framework",
24
+ "vue"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/directus/directus.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/directus/directus/issues"
32
+ },
33
+ "author": {
34
+ "name": "Monospace Inc",
35
+ "email": "info@monospace.io",
36
+ "url": "https://monospace.io"
37
+ },
38
+ "maintainers": [
39
+ {
40
+ "name": "Rijk van Zanten",
41
+ "email": "rijkvanzanten@me.com",
42
+ "url": "https://github.com/rijkvanzanten"
43
+ },
44
+ {
45
+ "name": "Ben Haynes",
46
+ "email": "ben@rngr.org",
47
+ "url": "https://github.com/benhaynes"
48
+ }
49
+ ],
50
+ "main": "dist/index.js",
51
+ "exports": {
52
+ ".": "./dist/index.js",
53
+ "./*": "./dist/*.js",
54
+ "./package.json": "./package.json"
55
+ },
56
+ "bin": {
57
+ "directus": "cli.js"
58
+ },
59
+ "engines": {
60
+ "node": ">=12.20.0"
61
+ },
62
+ "files": [
63
+ "dist",
64
+ "LICENSE",
65
+ "README.md"
66
+ ],
67
+ "dependencies": {
68
+ "@aws-sdk/client-ses": "^3.107.0",
69
+ "@directus/app": "9.14.2",
70
+ "@directus/drive": "9.14.2",
71
+ "@directus/drive-azure": "9.14.2",
72
+ "@directus/drive-gcs": "9.14.2",
73
+ "@directus/drive-s3": "9.14.2",
74
+ "@directus/extensions-sdk": "^9.14.1",
75
+ "@directus/format-title": "^9.15.0",
76
+ "@directus/schema": "9.14.2",
77
+ "@directus/shared": "9.14.2",
78
+ "@directus/specs": "9.14.2",
79
+ "@godaddy/terminus": "^4.10.2",
80
+ "@rollup/plugin-alias": "^3.1.9",
81
+ "@rollup/plugin-virtual": "^2.1.0",
82
+ "argon2": "^0.28.5",
83
+ "async": "^3.2.4",
84
+ "async-mutex": "^0.3.2",
85
+ "axios": "^0.27.2",
86
+ "busboy": "^1.6.0",
87
+ "bytes": "^3.1.2",
88
+ "camelcase": "^6.2.0",
89
+ "chalk": "^4.1.1",
90
+ "chokidar": "^3.5.3",
91
+ "commander": "^8.0.0",
92
+ "cookie-parser": "^1.4.6",
93
+ "cors": "^2.8.5",
94
+ "csv-parser": "^3.0.0",
95
+ "date-fns": "^2.28.0",
96
+ "deep-diff": "^1.0.2",
97
+ "deep-map": "^2.0.0",
98
+ "destroy": "^1.2.0",
99
+ "dotenv": "^10.0.0",
100
+ "eventemitter2": "^6.4.5",
101
+ "execa": "^5.1.1",
102
+ "exifr": "^7.1.3",
103
+ "express": "^4.18.1",
104
+ "fast-redact": "^3.1.1",
105
+ "flat": "^5.0.2",
106
+ "fs-extra": "^10.1.0",
107
+ "globby": "^11.0.4",
108
+ "graphql": "^15.5.0",
109
+ "graphql-compose": "^9.0.8",
110
+ "helmet": "^4.6.0",
111
+ "inquirer": "^8.2.4",
112
+ "ioredis": "^4.27.6",
113
+ "joi": "^17.6.0",
114
+ "js-yaml": "^4.1.0",
115
+ "js2xmlparser": "^4.0.2",
116
+ "json2csv": "^5.0.7",
117
+ "jsonwebtoken": "^8.5.1",
118
+ "keyv": "^4.3.0",
119
+ "knex": "2.2.0",
120
+ "knex-schema-inspector": "^2.0.3",
121
+ "ldapjs": "^2.3.3",
122
+ "liquidjs": "^9.37.0",
123
+ "lodash": "^4.17.21",
124
+ "macos-release": "^2.4.1",
125
+ "marked": "^4.0.16",
126
+ "micromustache": "^8.0.3",
127
+ "mime-types": "^2.1.35",
128
+ "ms": "^2.1.3",
129
+ "nanoid": "^3.1.23",
130
+ "node-cron": "^3.0.1",
131
+ "node-machine-id": "^1.1.12",
132
+ "nodemailer": "^6.7.5",
133
+ "object-hash": "^2.2.0",
134
+ "openapi3-ts": "^2.0.2",
135
+ "openid-client": "^5.1.6",
136
+ "ora": "^5.4.0",
137
+ "otplib": "^12.0.1",
138
+ "pino": "6.13.3",
139
+ "pino-colada": "^2.2.2",
140
+ "pino-http": "5.8.0",
141
+ "qs": "^6.10.5",
142
+ "rate-limiter-flexible": "^2.3.7",
143
+ "resolve-cwd": "^3.0.0",
144
+ "rollup": "^2.75.6",
145
+ "sanitize-html": "^2.7.0",
146
+ "sharp": "^0.30.6",
147
+ "stream-json": "^1.7.4",
148
+ "strip-bom-stream": "^4.0.0",
149
+ "supertest": "^6.2.3",
150
+ "tmp-promise": "^3.0.3",
151
+ "update-check": "^1.5.4",
152
+ "uuid": "^8.3.2",
153
+ "uuid-validate": "0.0.3",
154
+ "wellknown": "^0.5.0"
155
+ },
156
+ "optionalDependencies": {
157
+ "@keyv/redis": "^2.3.6",
158
+ "keyv-memcache": "^1.2.5",
159
+ "memcached": "^2.2.2",
160
+ "mysql": "^2.18.1",
161
+ "nodemailer-mailgun-transport": "^2.1.4",
162
+ "oracledb": "5.3.0",
163
+ "pg": "^8.7.3",
164
+ "sqlite3": "^5.0.8",
165
+ "tedious": "^13.0.0"
166
+ },
167
+ "gitHead": "24621f3934dc77eb23441331040ed13c676ceffd",
168
+ "devDependencies": {
169
+ "@otplib/preset-default": "^12.0.1",
170
+ "@types/async": "3.2.13",
171
+ "@types/body-parser": "1.19.2",
172
+ "@types/busboy": "1.5.0",
173
+ "@types/bytes": "3.1.1",
174
+ "@types/cookie-parser": "1.4.3",
175
+ "@types/cors": "2.8.12",
176
+ "@types/deep-diff": "1.0.1",
177
+ "@types/destroy": "1.0.0",
178
+ "@types/express": "4.17.13",
179
+ "@types/express-pino-logger": "4.0.3",
180
+ "@types/express-serve-static-core": "^4.17.29",
181
+ "@types/express-session": "1.17.4",
182
+ "@types/fast-redact": "^3.0.1",
183
+ "@types/flat": "5.0.2",
184
+ "@types/fs-extra": "9.0.13",
185
+ "@types/inquirer": "8.2.1",
186
+ "@types/ioredis": "^4.28.10",
187
+ "@types/jest": "27.5.2",
188
+ "@types/js-yaml": "4.0.5",
189
+ "@types/json2csv": "5.0.3",
190
+ "@types/jsonwebtoken": "8.5.8",
191
+ "@types/keyv": "3.1.4",
192
+ "@types/ldapjs": "2.2.2",
193
+ "@types/lodash": "4.14.182",
194
+ "@types/marked": "4.0.3",
195
+ "@types/mime-types": "2.1.1",
196
+ "@types/ms": "0.7.31",
197
+ "@types/node": "16.11.9",
198
+ "@types/node-cron": "2.0.5",
199
+ "@types/nodemailer": "6.4.4",
200
+ "@types/object-hash": "2.2.1",
201
+ "@types/pino": "6.3.12",
202
+ "@types/pino-http": "5.8.1",
203
+ "@types/qs": "6.9.7",
204
+ "@types/sanitize-html": "2.6.2",
205
+ "@types/sharp": "0.30.4",
206
+ "@types/stream-json": "1.7.2",
207
+ "@types/supertest": "2.0.12",
208
+ "@types/uuid": "8.3.4",
209
+ "@types/uuid-validate": "0.0.1",
210
+ "@types/wellknown": "0.5.3",
211
+ "copyfiles": "2.4.1",
212
+ "cross-env": "7.0.3",
213
+ "form-data": "^4.0.0",
214
+ "jest": "28.1.2",
215
+ "knex-mock-client": "1.8.4",
216
+ "rimraf": "3.0.2",
217
+ "ts-jest": "28.0.5",
218
+ "ts-node": "^10.8.2",
219
+ "ts-node-dev": "1.1.8",
220
+ "typescript": "4.7.3"
221
+ },
222
+ "scripts": {
223
+ "start": "npx directus start",
224
+ "prebuild": "pnpm cleanup",
225
+ "build": "tsc --build && copyfiles \"src/**/*.*\" -e \"src/**/*.ts\" -u 1 dist",
226
+ "cleanup": "rimraf dist",
227
+ "dev": "cross-env NODE_ENV=development SERVE_APP=false ts-node-dev --files --transpile-only --respawn --watch \".env\" --inspect=0 --exit-child -- src/start.ts",
228
+ "cli": "cross-env NODE_ENV=development SERVE_APP=false ts-node --script-mode --transpile-only src/cli/run.ts",
229
+ "test": "jest",
230
+ "test:coverage": "jest --coverage",
231
+ "test:watch": "jest --watch"
232
+ }
233
+ }
@@ -1,3 +0,0 @@
1
- import { AnySchema } from 'joi';
2
- import { Filter } from '@directus/shared/types';
3
- export default function generateJoi(filter: Filter | null): AnySchema;
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const joi_1 = __importDefault(require("joi"));
7
- const lodash_1 = require("lodash");
8
- const Joi = joi_1.default.extend({
9
- type: 'string',
10
- base: joi_1.default.string(),
11
- messages: {
12
- 'string.contains': '{{#label}} must contain [{{#substring}}]',
13
- 'string.ncontains': "{{#label}} can't contain [{{#substring}}]",
14
- },
15
- rules: {
16
- contains: {
17
- args: [
18
- {
19
- name: 'substring',
20
- ref: true,
21
- assert: (val) => typeof val === 'string',
22
- message: 'must be a string',
23
- },
24
- ],
25
- method(substring) {
26
- return this.$_addRule({ name: 'contains', args: { substring } });
27
- },
28
- validate(value, helpers, { substring }) {
29
- if (value.includes(substring) === false) {
30
- return helpers.error('string.contains', { substring });
31
- }
32
- return value;
33
- },
34
- },
35
- ncontains: {
36
- args: [
37
- {
38
- name: 'substring',
39
- ref: true,
40
- assert: (val) => typeof val === 'string',
41
- message: 'must be a string',
42
- },
43
- ],
44
- method(substring) {
45
- return this.$_addRule({ name: 'ncontains', args: { substring } });
46
- },
47
- validate(value, helpers, { substring }) {
48
- if (value.includes(substring) === true) {
49
- return helpers.error('string.ncontains', { substring });
50
- }
51
- return value;
52
- },
53
- },
54
- },
55
- });
56
- function generateJoi(filter) {
57
- filter = filter || {};
58
- if (Object.keys(filter).length === 0)
59
- return Joi.any();
60
- let schema;
61
- for (const [key, value] of Object.entries(filter)) {
62
- if (key.startsWith('_') === false) {
63
- if (!schema)
64
- schema = {};
65
- const operator = Object.keys(value)[0];
66
- const val = Object.values(value)[0];
67
- schema[key] = getJoi(operator, val);
68
- }
69
- }
70
- return Joi.object(schema).unknown();
71
- }
72
- exports.default = generateJoi;
73
- function getJoi(operator, value) {
74
- if (operator === '_eq') {
75
- return Joi.any().equal(value);
76
- }
77
- if (operator === '_neq') {
78
- return Joi.any().not(value);
79
- }
80
- if (operator === '_contains') {
81
- // @ts-ignore
82
- return Joi.string().contains(value);
83
- }
84
- if (operator === '_ncontains') {
85
- // @ts-ignore
86
- return Joi.string().ncontains(value);
87
- }
88
- if (operator === '_starts_with') {
89
- return Joi.string().pattern(new RegExp(`^${(0, lodash_1.escapeRegExp)(value)}.*`), { name: 'starts_with' });
90
- }
91
- if (operator === '_nstarts_with') {
92
- return Joi.string().pattern(new RegExp(`^${(0, lodash_1.escapeRegExp)(value)}.*`), { name: 'starts_with', invert: true });
93
- }
94
- if (operator === '_ends_with') {
95
- return Joi.string().pattern(new RegExp(`.*${(0, lodash_1.escapeRegExp)(value)}$`), { name: 'ends_with' });
96
- }
97
- if (operator === '_nends_with') {
98
- return Joi.string().pattern(new RegExp(`.*${(0, lodash_1.escapeRegExp)(value)}$`), { name: 'ends_with', invert: true });
99
- }
100
- if (operator === '_in') {
101
- return Joi.any().equal(...value);
102
- }
103
- if (operator === '_nin') {
104
- return Joi.any().not(...value);
105
- }
106
- if (operator === '_gt') {
107
- return Joi.number().greater(Number(value));
108
- }
109
- if (operator === '_gte') {
110
- return Joi.number().min(Number(value));
111
- }
112
- if (operator === '_lt') {
113
- return Joi.number().less(Number(value));
114
- }
115
- if (operator === '_lte') {
116
- return Joi.number().max(Number(value));
117
- }
118
- if (operator === '_null') {
119
- return Joi.any().valid(null);
120
- }
121
- if (operator === '_nnull') {
122
- return Joi.any().invalid(null);
123
- }
124
- if (operator === '_empty') {
125
- return Joi.any().valid('');
126
- }
127
- if (operator === '_nempty') {
128
- return Joi.any().invalid('');
129
- }
130
- if (operator === '_between') {
131
- const values = value;
132
- return Joi.number().greater(values[0]).less(values[1]);
133
- }
134
- if (operator === '_nbetween') {
135
- const values = value;
136
- return Joi.number().less(values[0]).greater(values[1]);
137
- }
138
- if (operator === '_submitted') {
139
- return Joi.required();
140
- }
141
- if (operator === '_regex') {
142
- const wrapped = value.startsWith('/') && value.endsWith('/');
143
- return Joi.string().regex(new RegExp(wrapped ? value.slice(1, -1) : value));
144
- }
145
- }