directus 9.6.0 → 9.8.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/dist/app.js +3 -1
- package/dist/auth/drivers/oauth2.js +3 -0
- package/dist/auth/drivers/openid.js +3 -0
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +29 -7
- package/dist/cli/commands/schema/apply.d.ts +1 -0
- package/dist/cli/commands/schema/apply.js +9 -5
- package/dist/cli/index.js +1 -0
- package/dist/controllers/assets.js +9 -1
- package/dist/controllers/utils.js +18 -1
- package/dist/database/helpers/date/dialects/default.d.ts +3 -0
- package/dist/database/helpers/date/dialects/default.js +7 -0
- package/dist/database/helpers/date/dialects/sqlite.d.ts +0 -9
- package/dist/database/helpers/date/dialects/sqlite.js +0 -24
- package/dist/database/helpers/date/index.d.ts +6 -6
- package/dist/database/helpers/date/index.js +13 -13
- package/dist/database/helpers/date/types.d.ts +0 -9
- package/dist/database/helpers/{date → fn}/dialects/mssql.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/mssql.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/mysql.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/mysql.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/oracle.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/oracle.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/postgres.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/postgres.js +14 -3
- package/dist/database/helpers/fn/dialects/sqlite.d.ts +13 -0
- package/dist/database/helpers/fn/dialects/sqlite.js +42 -0
- package/dist/database/helpers/fn/index.d.ts +7 -0
- package/dist/database/helpers/fn/index.js +17 -0
- package/dist/database/helpers/fn/types.d.ts +18 -0
- package/dist/database/helpers/fn/types.js +27 -0
- package/dist/database/helpers/index.d.ts +4 -1
- package/dist/database/helpers/index.js +7 -1
- package/dist/database/index.js +0 -3
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +3 -0
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.js +17 -0
- package/dist/database/migrations/20220314A-add-translation-strings.d.ts +3 -0
- package/dist/database/migrations/20220314A-add-translation-strings.js +15 -0
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +3 -0
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.js +77 -0
- package/dist/database/migrations/20220323A-add-field-validation.d.ts +3 -0
- package/dist/database/migrations/20220323A-add-field-validation.js +17 -0
- package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +3 -0
- package/dist/database/migrations/20220325A-fix-typecast-flags.js +49 -0
- package/dist/database/migrations/20220325B-add-default-language.d.ts +3 -0
- package/dist/database/migrations/20220325B-add-default-language.js +28 -0
- package/dist/database/migrations/run.js +1 -1
- package/dist/database/run-ast.js +11 -3
- package/dist/database/system-data/fields/activity.yaml +4 -4
- package/dist/database/system-data/fields/collections.yaml +4 -4
- package/dist/database/system-data/fields/fields.yaml +17 -8
- package/dist/database/system-data/fields/files.yaml +2 -2
- package/dist/database/system-data/fields/panels.yaml +2 -2
- package/dist/database/system-data/fields/permissions.yaml +4 -4
- package/dist/database/system-data/fields/presets.yaml +17 -3
- package/dist/database/system-data/fields/relations.yaml +1 -1
- package/dist/database/system-data/fields/revisions.yaml +2 -2
- package/dist/database/system-data/fields/roles.yaml +4 -4
- package/dist/database/system-data/fields/settings.yaml +19 -4
- package/dist/database/system-data/fields/users.yaml +2 -2
- package/dist/database/system-data/fields/webhooks.yaml +4 -4
- package/dist/env.js +6 -2
- package/dist/exceptions/database/dialects/mysql.js +23 -17
- package/dist/logger.js +2 -1
- package/dist/middleware/respond.js +7 -28
- package/dist/services/activity.js +4 -1
- package/dist/services/authorization.d.ts +1 -1
- package/dist/services/authorization.js +156 -14
- package/dist/services/collections.js +222 -198
- package/dist/services/fields.js +184 -173
- package/dist/services/files.js +69 -3
- package/dist/services/graphql.js +2 -2
- package/dist/services/import-export.d.ts +34 -0
- package/dist/services/import-export.js +270 -0
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -1
- package/dist/services/items.js +1 -0
- package/dist/services/payload.js +11 -9
- package/dist/services/permissions.js +10 -10
- package/dist/services/relations.js +93 -78
- package/dist/services/server.js +1 -0
- package/dist/services/shares.js +2 -1
- package/dist/services/users.js +3 -1
- package/dist/utils/apply-query.js +21 -3
- package/dist/utils/get-column.d.ts +6 -5
- package/dist/utils/get-column.js +16 -8
- package/dist/utils/get-date-formatted.d.ts +1 -0
- package/dist/utils/get-date-formatted.js +14 -0
- package/dist/utils/get-local-type.js +2 -2
- package/dist/utils/get-permissions.js +1 -1
- package/dist/utils/get-schema.d.ts +1 -1
- package/dist/utils/get-schema.js +16 -11
- package/dist/utils/track.js +3 -2
- package/dist/utils/url.d.ts +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/validate-storage.js +3 -1
- package/package.json +13 -12
- package/dist/services/import.d.ts +0 -13
- package/dist/services/import.js +0 -118
package/dist/app.js
CHANGED
|
@@ -111,9 +111,11 @@ async function createApp() {
|
|
|
111
111
|
// friendly. Ref #10806
|
|
112
112
|
upgradeInsecureRequests: null,
|
|
113
113
|
// These are required for MapLibre
|
|
114
|
+
// https://cdn.directus.io is required for images/videos in the official docs
|
|
114
115
|
workerSrc: ["'self'", 'blob:'],
|
|
115
116
|
childSrc: ["'self'", 'blob:'],
|
|
116
|
-
imgSrc: ["'self'", 'data:', 'blob:'],
|
|
117
|
+
imgSrc: ["'self'", 'data:', 'blob:', 'https://cdn.directus.io'],
|
|
118
|
+
mediaSrc: ["'self'", 'https://cdn.directus.io'],
|
|
117
119
|
connectSrc: ["'self'", 'https://*'],
|
|
118
120
|
},
|
|
119
121
|
}, (0, get_config_from_env_1.getConfigFromEnv)('CONTENT_SECURITY_POLICY_'))));
|
|
@@ -18,6 +18,7 @@ const async_handler_1 = __importDefault(require("../../utils/async-handler"));
|
|
|
18
18
|
const url_1 = require("../../utils/url");
|
|
19
19
|
const logger_1 = __importDefault(require("../../logger"));
|
|
20
20
|
const get_ip_from_req_1 = require("../../utils/get-ip-from-req");
|
|
21
|
+
const get_config_from_env_1 = require("../../utils/get-config-from-env");
|
|
21
22
|
class OAuth2AuthDriver extends local_1.LocalAuthDriver {
|
|
22
23
|
constructor(options, config) {
|
|
23
24
|
super(options, config);
|
|
@@ -35,11 +36,13 @@ class OAuth2AuthDriver extends local_1.LocalAuthDriver {
|
|
|
35
36
|
userinfo_endpoint: profileUrl,
|
|
36
37
|
issuer: additionalConfig.provider,
|
|
37
38
|
});
|
|
39
|
+
const clientOptionsOverrides = (0, get_config_from_env_1.getConfigFromEnv)(`AUTH_${config.provider.toUpperCase()}_CLIENT_`, [`AUTH_${config.provider.toUpperCase()}_CLIENT_ID`, `AUTH_${config.provider.toUpperCase()}_CLIENT_SECRET`], 'underscore');
|
|
38
40
|
this.client = new issuer.Client({
|
|
39
41
|
client_id: clientId,
|
|
40
42
|
client_secret: clientSecret,
|
|
41
43
|
redirect_uris: [this.redirectUrl],
|
|
42
44
|
response_types: ['code'],
|
|
45
|
+
...clientOptionsOverrides,
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
generateCodeVerifier() {
|
|
@@ -18,6 +18,7 @@ const async_handler_1 = __importDefault(require("../../utils/async-handler"));
|
|
|
18
18
|
const url_1 = require("../../utils/url");
|
|
19
19
|
const logger_1 = __importDefault(require("../../logger"));
|
|
20
20
|
const get_ip_from_req_1 = require("../../utils/get-ip-from-req");
|
|
21
|
+
const get_config_from_env_1 = require("../../utils/get-config-from-env");
|
|
21
22
|
class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
22
23
|
constructor(options, config) {
|
|
23
24
|
super(options, config);
|
|
@@ -26,6 +27,7 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
|
26
27
|
throw new exceptions_1.InvalidConfigException('Invalid provider config', { provider: additionalConfig.provider });
|
|
27
28
|
}
|
|
28
29
|
const redirectUrl = new url_1.Url(env_1.default.PUBLIC_URL).addPath('auth', 'login', additionalConfig.provider, 'callback');
|
|
30
|
+
const clientOptionsOverrides = (0, get_config_from_env_1.getConfigFromEnv)(`AUTH_${config.provider.toUpperCase()}_CLIENT_`, [`AUTH_${config.provider.toUpperCase()}_CLIENT_ID`, `AUTH_${config.provider.toUpperCase()}_CLIENT_SECRET`], 'underscore');
|
|
29
31
|
this.redirectUrl = redirectUrl.toString();
|
|
30
32
|
this.usersService = new services_1.UsersService({ knex: this.knex, schema: this.schema });
|
|
31
33
|
this.config = additionalConfig;
|
|
@@ -43,6 +45,7 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
|
43
45
|
client_secret: clientSecret,
|
|
44
46
|
redirect_uris: [this.redirectUrl],
|
|
45
47
|
response_types: ['code'],
|
|
48
|
+
...clientOptionsOverrides,
|
|
46
49
|
}));
|
|
47
50
|
})
|
|
48
51
|
.catch(reject);
|
package/dist/cache.d.ts
CHANGED
|
@@ -2,5 +2,8 @@ import Keyv from 'keyv';
|
|
|
2
2
|
export declare function getCache(): {
|
|
3
3
|
cache: Keyv | null;
|
|
4
4
|
systemCache: Keyv;
|
|
5
|
+
lockCache: Keyv;
|
|
5
6
|
};
|
|
6
|
-
export declare function flushCaches(): Promise<void>;
|
|
7
|
+
export declare function flushCaches(forced?: boolean): Promise<void>;
|
|
8
|
+
export declare function clearSystemCache(forced?: boolean): Promise<void>;
|
|
9
|
+
export declare function setSystemCache(key: string, value: any, ttl?: number): Promise<void>;
|
package/dist/cache.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.flushCaches = exports.getCache = void 0;
|
|
6
|
+
exports.setSystemCache = exports.clearSystemCache = exports.flushCaches = exports.getCache = void 0;
|
|
7
7
|
const keyv_1 = __importDefault(require("keyv"));
|
|
8
8
|
const ms_1 = __importDefault(require("ms"));
|
|
9
9
|
const env_1 = __importDefault(require("./env"));
|
|
@@ -12,25 +12,47 @@ const get_config_from_env_1 = require("./utils/get-config-from-env");
|
|
|
12
12
|
const validate_env_1 = require("./utils/validate-env");
|
|
13
13
|
let cache = null;
|
|
14
14
|
let systemCache = null;
|
|
15
|
+
let lockCache = null;
|
|
15
16
|
function getCache() {
|
|
16
17
|
if (env_1.default.CACHE_ENABLED === true && cache === null) {
|
|
17
18
|
(0, validate_env_1.validateEnv)(['CACHE_NAMESPACE', 'CACHE_TTL', 'CACHE_STORE']);
|
|
18
|
-
cache = getKeyvInstance((0, ms_1.default)(env_1.default.CACHE_TTL));
|
|
19
|
+
cache = getKeyvInstance(env_1.default.CACHE_TTL ? (0, ms_1.default)(env_1.default.CACHE_TTL) : undefined);
|
|
19
20
|
cache.on('error', (err) => logger_1.default.warn(err, `[cache] ${err}`));
|
|
20
21
|
}
|
|
21
22
|
if (systemCache === null) {
|
|
22
|
-
systemCache = getKeyvInstance(undefined, '_system');
|
|
23
|
+
systemCache = getKeyvInstance(env_1.default.CACHE_SYSTEM_TTL ? (0, ms_1.default)(env_1.default.CACHE_SYSTEM_TTL) : undefined, '_system');
|
|
23
24
|
systemCache.on('error', (err) => logger_1.default.warn(err, `[cache] ${err}`));
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
if (lockCache === null) {
|
|
27
|
+
lockCache = getKeyvInstance(undefined, '_lock');
|
|
28
|
+
lockCache.on('error', (err) => logger_1.default.warn(err, `[cache] ${err}`));
|
|
29
|
+
}
|
|
30
|
+
return { cache, systemCache, lockCache };
|
|
26
31
|
}
|
|
27
32
|
exports.getCache = getCache;
|
|
28
|
-
async function flushCaches() {
|
|
29
|
-
const {
|
|
30
|
-
await (
|
|
33
|
+
async function flushCaches(forced) {
|
|
34
|
+
const { cache } = getCache();
|
|
35
|
+
await clearSystemCache(forced);
|
|
31
36
|
await (cache === null || cache === void 0 ? void 0 : cache.clear());
|
|
32
37
|
}
|
|
33
38
|
exports.flushCaches = flushCaches;
|
|
39
|
+
async function clearSystemCache(forced) {
|
|
40
|
+
const { systemCache, lockCache } = getCache();
|
|
41
|
+
// Flush system cache when forced or when system cache lock not set
|
|
42
|
+
if (forced || !(await lockCache.get('system-cache-lock'))) {
|
|
43
|
+
await lockCache.set('system-cache-lock', true, 10000);
|
|
44
|
+
await systemCache.clear();
|
|
45
|
+
await lockCache.delete('system-cache-lock');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.clearSystemCache = clearSystemCache;
|
|
49
|
+
async function setSystemCache(key, value, ttl) {
|
|
50
|
+
const { systemCache, lockCache } = getCache();
|
|
51
|
+
if (!(await lockCache.get('system-cache-lock'))) {
|
|
52
|
+
await systemCache.set(key, value, ttl);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.setSystemCache = setSystemCache;
|
|
34
56
|
function getKeyvInstance(ttl, namespaceSuffix) {
|
|
35
57
|
switch (env_1.default.CACHE_STORE) {
|
|
36
58
|
case 'redis':
|
|
@@ -63,7 +63,9 @@ async function apply(snapshotPath, options) {
|
|
|
63
63
|
database.destroy();
|
|
64
64
|
process.exit(0);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
const dryRun = (options === null || options === void 0 ? void 0 : options.dryRun) === true;
|
|
67
|
+
const promptForChanges = !dryRun && (options === null || options === void 0 ? void 0 : options.yes) !== true;
|
|
68
|
+
if (dryRun || promptForChanges) {
|
|
67
69
|
let message = '';
|
|
68
70
|
if (snapshotDiff.collections.length > 0) {
|
|
69
71
|
message += chalk_1.default.black.underline.bold('Collections:');
|
|
@@ -141,14 +143,16 @@ async function apply(snapshotPath, options) {
|
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
}
|
|
146
|
+
message += 'The following changes will be applied:\n\n' + chalk_1.default.black(message);
|
|
147
|
+
if (dryRun) {
|
|
148
|
+
logger_1.default.info(message);
|
|
149
|
+
process.exit(0);
|
|
150
|
+
}
|
|
144
151
|
const { proceed } = await inquirer_1.default.prompt([
|
|
145
152
|
{
|
|
146
153
|
type: 'confirm',
|
|
147
154
|
name: 'proceed',
|
|
148
|
-
message:
|
|
149
|
-
chalk_1.default.black(message) +
|
|
150
|
-
'\n\n' +
|
|
151
|
-
'Would you like to continue?',
|
|
155
|
+
message: message + '\n\n' + 'Would you like to continue?',
|
|
152
156
|
},
|
|
153
157
|
]);
|
|
154
158
|
if (proceed === false) {
|
package/dist/cli/index.js
CHANGED
|
@@ -81,6 +81,7 @@ async function createCli() {
|
|
|
81
81
|
.command('apply')
|
|
82
82
|
.description('Apply a snapshot file to the current database')
|
|
83
83
|
.option('-y, --yes', `Assume "yes" as answer to all prompts and run non-interactively`)
|
|
84
|
+
.option('-d, --dry-run', 'Plan and log changes to be applied', false)
|
|
84
85
|
.argument('<path>', 'Path to snapshot file')
|
|
85
86
|
.action(apply_1.apply);
|
|
86
87
|
await emitter_1.default.emitInit('cli.after', { program });
|
|
@@ -14,6 +14,9 @@ const use_collection_1 = __importDefault(require("../middleware/use-collection")
|
|
|
14
14
|
const services_1 = require("../services");
|
|
15
15
|
const assets_1 = require("../types/assets");
|
|
16
16
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
17
|
+
const helmet_1 = __importDefault(require("helmet"));
|
|
18
|
+
const lodash_2 = require("lodash");
|
|
19
|
+
const get_config_from_env_1 = require("../utils/get-config-from-env");
|
|
17
20
|
const router = (0, express_1.Router)();
|
|
18
21
|
router.use((0, use_collection_1.default)('directus_files'));
|
|
19
22
|
router.get('/:pk',
|
|
@@ -88,7 +91,12 @@ router.get('/:pk',
|
|
|
88
91
|
return next();
|
|
89
92
|
throw new exceptions_1.InvalidQueryException(`Dynamic asset generation has been disabled for this project.`);
|
|
90
93
|
}
|
|
91
|
-
}),
|
|
94
|
+
}), helmet_1.default.contentSecurityPolicy((0, lodash_2.merge)({
|
|
95
|
+
useDefaults: false,
|
|
96
|
+
directives: {
|
|
97
|
+
defaultSrc: ['none'],
|
|
98
|
+
},
|
|
99
|
+
}, (0, get_config_from_env_1.getConfigFromEnv)('ASSETS_CONTENT_SECURITY_POLICY'))),
|
|
92
100
|
// Return file
|
|
93
101
|
(0, async_handler_1.default)(async (req, res) => {
|
|
94
102
|
var _a, _b;
|
|
@@ -95,12 +95,29 @@ router.post('/import/:collection', collection_exists_1.default, (0, async_handle
|
|
|
95
95
|
busboy.on('error', (err) => next(err));
|
|
96
96
|
req.pipe(busboy);
|
|
97
97
|
}));
|
|
98
|
+
router.post('/export/:collection', collection_exists_1.default, (0, async_handler_1.default)(async (req, res, next) => {
|
|
99
|
+
if (!req.body.query) {
|
|
100
|
+
throw new exceptions_1.InvalidPayloadException(`"query" is required.`);
|
|
101
|
+
}
|
|
102
|
+
if (!req.body.format) {
|
|
103
|
+
throw new exceptions_1.InvalidPayloadException(`"format" is required.`);
|
|
104
|
+
}
|
|
105
|
+
const service = new services_1.ExportService({
|
|
106
|
+
accountability: req.accountability,
|
|
107
|
+
schema: req.schema,
|
|
108
|
+
});
|
|
109
|
+
// We're not awaiting this, as it's supposed to run async in the background
|
|
110
|
+
service.exportToFile(req.params.collection, req.body.query, req.body.format, {
|
|
111
|
+
file: req.body.file,
|
|
112
|
+
});
|
|
113
|
+
return next();
|
|
114
|
+
}), respond_1.respond);
|
|
98
115
|
router.post('/cache/clear', (0, async_handler_1.default)(async (req, res) => {
|
|
99
116
|
var _a;
|
|
100
117
|
if (((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true) {
|
|
101
118
|
throw new exceptions_1.ForbiddenException();
|
|
102
119
|
}
|
|
103
|
-
await (0, cache_1.flushCaches)();
|
|
120
|
+
await (0, cache_1.flushCaches)(true);
|
|
104
121
|
res.status(200).end();
|
|
105
122
|
}));
|
|
106
123
|
exports.default = router;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import { DateHelper } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
2
|
export declare class DateHelperSQLite extends DateHelper {
|
|
4
|
-
year(table: string, column: string): Knex.Raw;
|
|
5
|
-
month(table: string, column: string): Knex.Raw;
|
|
6
|
-
week(table: string, column: string): Knex.Raw;
|
|
7
|
-
day(table: string, column: string): Knex.Raw;
|
|
8
|
-
weekday(table: string, column: string): Knex.Raw;
|
|
9
|
-
hour(table: string, column: string): Knex.Raw;
|
|
10
|
-
minute(table: string, column: string): Knex.Raw;
|
|
11
|
-
second(table: string, column: string): Knex.Raw;
|
|
12
3
|
parse(date: string): string;
|
|
13
4
|
}
|
|
@@ -3,30 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DateHelperSQLite = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class DateHelperSQLite extends types_1.DateHelper {
|
|
6
|
-
year(table, column) {
|
|
7
|
-
return this.knex.raw("strftime('%Y', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
8
|
-
}
|
|
9
|
-
month(table, column) {
|
|
10
|
-
return this.knex.raw("strftime('%m', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
11
|
-
}
|
|
12
|
-
week(table, column) {
|
|
13
|
-
return this.knex.raw("strftime('%W', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
14
|
-
}
|
|
15
|
-
day(table, column) {
|
|
16
|
-
return this.knex.raw("strftime('%d', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
17
|
-
}
|
|
18
|
-
weekday(table, column) {
|
|
19
|
-
return this.knex.raw("strftime('%w', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
20
|
-
}
|
|
21
|
-
hour(table, column) {
|
|
22
|
-
return this.knex.raw("strftime('%H', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
23
|
-
}
|
|
24
|
-
minute(table, column) {
|
|
25
|
-
return this.knex.raw("strftime('%M', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
26
|
-
}
|
|
27
|
-
second(table, column) {
|
|
28
|
-
return this.knex.raw("strftime('%S', ??.?? / 1000, 'unixepoch')", [table, column]);
|
|
29
|
-
}
|
|
30
6
|
parse(date) {
|
|
31
7
|
const newDate = new Date(date);
|
|
32
8
|
return (newDate.getTime() - newDate.getTimezoneOffset() * 60 * 1000).toString();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { DateHelperDefault as postgres } from './dialects/default';
|
|
2
|
+
export { DateHelperDefault as redshift } from './dialects/default';
|
|
3
|
+
export { DateHelperDefault as cockroachdb } from './dialects/default';
|
|
4
|
+
export { DateHelperDefault as oracle } from './dialects/default';
|
|
5
|
+
export { DateHelperDefault as mysql } from './dialects/default';
|
|
6
|
+
export { DateHelperDefault as mssql } from './dialects/default';
|
|
5
7
|
export { DateHelperSQLite as sqlite } from './dialects/sqlite';
|
|
6
|
-
export { DateHelperMySQL as mysql } from './dialects/mysql';
|
|
7
|
-
export { DateHelperMSSQL as mssql } from './dialects/mssql';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return
|
|
3
|
+
exports.sqlite = exports.mssql = exports.mysql = exports.oracle = exports.cockroachdb = exports.redshift = exports.postgres = void 0;
|
|
4
|
+
var default_1 = require("./dialects/default");
|
|
5
|
+
Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return default_1.DateHelperDefault; } });
|
|
6
|
+
var default_2 = require("./dialects/default");
|
|
7
|
+
Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return default_2.DateHelperDefault; } });
|
|
8
|
+
var default_3 = require("./dialects/default");
|
|
9
|
+
Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return default_3.DateHelperDefault; } });
|
|
10
|
+
var default_4 = require("./dialects/default");
|
|
11
|
+
Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return default_4.DateHelperDefault; } });
|
|
12
|
+
var default_5 = require("./dialects/default");
|
|
13
|
+
Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return default_5.DateHelperDefault; } });
|
|
14
|
+
var default_6 = require("./dialects/default");
|
|
15
|
+
Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return default_6.DateHelperDefault; } });
|
|
12
16
|
var sqlite_1 = require("./dialects/sqlite");
|
|
13
17
|
Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.DateHelperSQLite; } });
|
|
14
|
-
var mysql_1 = require("./dialects/mysql");
|
|
15
|
-
Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.DateHelperMySQL; } });
|
|
16
|
-
var mssql_1 = require("./dialects/mssql");
|
|
17
|
-
Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.DateHelperMSSQL; } });
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import { DatabaseHelper } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
2
|
export declare abstract class DateHelper extends DatabaseHelper {
|
|
4
|
-
abstract year(table: string, column: string): Knex.Raw;
|
|
5
|
-
abstract month(table: string, column: string): Knex.Raw;
|
|
6
|
-
abstract week(table: string, column: string): Knex.Raw;
|
|
7
|
-
abstract day(table: string, column: string): Knex.Raw;
|
|
8
|
-
abstract weekday(table: string, column: string): Knex.Raw;
|
|
9
|
-
abstract hour(table: string, column: string): Knex.Raw;
|
|
10
|
-
abstract minute(table: string, column: string): Knex.Raw;
|
|
11
|
-
abstract second(table: string, column: string): Knex.Raw;
|
|
12
3
|
parse(date: string): string;
|
|
13
4
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FnHelper } from '../types';
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class FnHelperMSSQL extends FnHelper {
|
|
4
4
|
year(table: string, column: string): Knex.Raw;
|
|
5
5
|
month(table: string, column: string): Knex.Raw;
|
|
6
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -9,4 +9,5 @@ export declare class DateHelperMSSQL extends DateHelper {
|
|
|
9
9
|
hour(table: string, column: string): Knex.Raw;
|
|
10
10
|
minute(table: string, column: string): Knex.Raw;
|
|
11
11
|
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
count(table: string, column: string): Knex.Raw<any>;
|
|
12
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FnHelperMSSQL = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
class
|
|
5
|
+
class FnHelperMSSQL extends types_1.FnHelper {
|
|
6
6
|
year(table, column) {
|
|
7
7
|
return this.knex.raw('DATEPART(year, ??.??)', [table, column]);
|
|
8
8
|
}
|
|
@@ -27,5 +27,16 @@ class DateHelperMSSQL extends types_1.DateHelper {
|
|
|
27
27
|
second(table, column) {
|
|
28
28
|
return this.knex.raw('DATEPART(second, ??.??)', [table, column]);
|
|
29
29
|
}
|
|
30
|
+
count(table, column) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
|
|
33
|
+
if (type === 'json') {
|
|
34
|
+
return this.knex.raw(`(SELECT COUNT(*) FROM OPENJSON(??.??, '$'))`, [table, column]);
|
|
35
|
+
}
|
|
36
|
+
if (type === 'alias') {
|
|
37
|
+
return this._relationalCount(table, column);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Couldn't extract type from ${table}.${column}`);
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
exports.
|
|
42
|
+
exports.FnHelperMSSQL = FnHelperMSSQL;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FnHelper } from '../types';
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class FnHelperMySQL extends FnHelper {
|
|
4
4
|
year(table: string, column: string): Knex.Raw;
|
|
5
5
|
month(table: string, column: string): Knex.Raw;
|
|
6
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -9,4 +9,5 @@ export declare class DateHelperMySQL extends DateHelper {
|
|
|
9
9
|
hour(table: string, column: string): Knex.Raw;
|
|
10
10
|
minute(table: string, column: string): Knex.Raw;
|
|
11
11
|
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
count(table: string, column: string): Knex.Raw;
|
|
12
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FnHelperMySQL = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
class
|
|
5
|
+
class FnHelperMySQL extends types_1.FnHelper {
|
|
6
6
|
year(table, column) {
|
|
7
7
|
return this.knex.raw('YEAR(??.??)', [table, column]);
|
|
8
8
|
}
|
|
@@ -27,5 +27,16 @@ class DateHelperMySQL extends types_1.DateHelper {
|
|
|
27
27
|
second(table, column) {
|
|
28
28
|
return this.knex.raw('SECOND(??.??)', [table, column]);
|
|
29
29
|
}
|
|
30
|
+
count(table, column) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
|
|
33
|
+
if (type === 'json') {
|
|
34
|
+
return this.knex.raw('JSON_LENGTH(??.??)', [table, column]);
|
|
35
|
+
}
|
|
36
|
+
if (type === 'alias') {
|
|
37
|
+
return this._relationalCount(table, column);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Couldn't extract type from ${table}.${column}`);
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
exports.
|
|
42
|
+
exports.FnHelperMySQL = FnHelperMySQL;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FnHelper } from '../types';
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class FnHelperOracle extends FnHelper {
|
|
4
4
|
year(table: string, column: string): Knex.Raw;
|
|
5
5
|
month(table: string, column: string): Knex.Raw;
|
|
6
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -9,4 +9,5 @@ export declare class DateHelperOracle extends DateHelper {
|
|
|
9
9
|
hour(table: string, column: string): Knex.Raw;
|
|
10
10
|
minute(table: string, column: string): Knex.Raw;
|
|
11
11
|
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
count(table: string, column: string): Knex.Raw<any>;
|
|
12
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FnHelperOracle = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
class
|
|
5
|
+
class FnHelperOracle extends types_1.FnHelper {
|
|
6
6
|
year(table, column) {
|
|
7
7
|
return this.knex.raw("TO_CHAR(??.??, 'IYYY')", [table, column]);
|
|
8
8
|
}
|
|
@@ -27,5 +27,16 @@ class DateHelperOracle extends types_1.DateHelper {
|
|
|
27
27
|
second(table, column) {
|
|
28
28
|
return this.knex.raw("TO_CHAR(??.??, 'SS')", [table, column]);
|
|
29
29
|
}
|
|
30
|
+
count(table, column) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
|
|
33
|
+
if (type === 'json') {
|
|
34
|
+
return this.knex.raw("json_value(??.??, '$.size()')", [table, column]);
|
|
35
|
+
}
|
|
36
|
+
if (type === 'alias') {
|
|
37
|
+
return this._relationalCount(table, column);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Couldn't extract type from ${table}.${column}`);
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
exports.
|
|
42
|
+
exports.FnHelperOracle = FnHelperOracle;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FnHelper } from '../types';
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class FnHelperPostgres extends FnHelper {
|
|
4
4
|
year(table: string, column: string): Knex.Raw;
|
|
5
5
|
month(table: string, column: string): Knex.Raw;
|
|
6
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -9,4 +9,5 @@ export declare class DateHelperPostgres extends DateHelper {
|
|
|
9
9
|
hour(table: string, column: string): Knex.Raw;
|
|
10
10
|
minute(table: string, column: string): Knex.Raw;
|
|
11
11
|
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
count(table: string, column: string): Knex.Raw;
|
|
12
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FnHelperPostgres = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
class
|
|
5
|
+
class FnHelperPostgres extends types_1.FnHelper {
|
|
6
6
|
year(table, column) {
|
|
7
7
|
return this.knex.raw('EXTRACT(YEAR FROM ??.??)', [table, column]);
|
|
8
8
|
}
|
|
@@ -27,5 +27,16 @@ class DateHelperPostgres extends types_1.DateHelper {
|
|
|
27
27
|
second(table, column) {
|
|
28
28
|
return this.knex.raw('EXTRACT(SECOND FROM ??.??)', [table, column]);
|
|
29
29
|
}
|
|
30
|
+
count(table, column) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
|
|
33
|
+
if (type === 'json') {
|
|
34
|
+
return this.knex.raw('json_array_length(??.??)', [table, column]);
|
|
35
|
+
}
|
|
36
|
+
if (type === 'alias') {
|
|
37
|
+
return this._relationalCount(table, column);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Couldn't extract type from ${table}.${column}`);
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
exports.
|
|
42
|
+
exports.FnHelperPostgres = FnHelperPostgres;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FnHelper } from '../types';
|
|
2
|
+
import { Knex } from 'knex';
|
|
3
|
+
export declare class FnHelperSQLite extends FnHelper {
|
|
4
|
+
year(table: string, column: string): Knex.Raw;
|
|
5
|
+
month(table: string, column: string): Knex.Raw;
|
|
6
|
+
week(table: string, column: string): Knex.Raw;
|
|
7
|
+
day(table: string, column: string): Knex.Raw;
|
|
8
|
+
weekday(table: string, column: string): Knex.Raw;
|
|
9
|
+
hour(table: string, column: string): Knex.Raw;
|
|
10
|
+
minute(table: string, column: string): Knex.Raw;
|
|
11
|
+
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
count(table: string, column: string): Knex.Raw<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FnHelperSQLite = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class FnHelperSQLite extends types_1.FnHelper {
|
|
6
|
+
year(table, column) {
|
|
7
|
+
return this.knex.raw("CAST(strftime('%Y', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
8
|
+
}
|
|
9
|
+
month(table, column) {
|
|
10
|
+
return this.knex.raw("CAST(strftime('%m', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
11
|
+
}
|
|
12
|
+
week(table, column) {
|
|
13
|
+
return this.knex.raw("CAST(strftime('%W', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
14
|
+
}
|
|
15
|
+
day(table, column) {
|
|
16
|
+
return this.knex.raw("CAST(strftime('%d', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
17
|
+
}
|
|
18
|
+
weekday(table, column) {
|
|
19
|
+
return this.knex.raw("CAST(strftime('%w', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
20
|
+
}
|
|
21
|
+
hour(table, column) {
|
|
22
|
+
return this.knex.raw("CAST(strftime('%H', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
23
|
+
}
|
|
24
|
+
minute(table, column) {
|
|
25
|
+
return this.knex.raw("CAST(strftime('%M', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
26
|
+
}
|
|
27
|
+
second(table, column) {
|
|
28
|
+
return this.knex.raw("CAST(strftime('%S', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
|
|
29
|
+
}
|
|
30
|
+
count(table, column) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
|
|
33
|
+
if (type === 'json') {
|
|
34
|
+
return this.knex.raw(`json_array_length(??.??, '$')`, [table, column]);
|
|
35
|
+
}
|
|
36
|
+
if (type === 'alias') {
|
|
37
|
+
return this._relationalCount(table, column);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Couldn't extract type from ${table}.${column}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FnHelperSQLite = FnHelperSQLite;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FnHelperPostgres as postgres } from './dialects/postgres';
|
|
2
|
+
export { FnHelperPostgres as redshift } from './dialects/postgres';
|
|
3
|
+
export { FnHelperPostgres as cockroachdb } from './dialects/postgres';
|
|
4
|
+
export { FnHelperOracle as oracle } from './dialects/oracle';
|
|
5
|
+
export { FnHelperSQLite as sqlite } from './dialects/sqlite';
|
|
6
|
+
export { FnHelperMySQL as mysql } from './dialects/mysql';
|
|
7
|
+
export { FnHelperMSSQL as mssql } from './dialects/mssql';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mssql = exports.mysql = exports.sqlite = exports.oracle = exports.cockroachdb = exports.redshift = exports.postgres = void 0;
|
|
4
|
+
var postgres_1 = require("./dialects/postgres");
|
|
5
|
+
Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return postgres_1.FnHelperPostgres; } });
|
|
6
|
+
var postgres_2 = require("./dialects/postgres");
|
|
7
|
+
Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return postgres_2.FnHelperPostgres; } });
|
|
8
|
+
var postgres_3 = require("./dialects/postgres");
|
|
9
|
+
Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return postgres_3.FnHelperPostgres; } });
|
|
10
|
+
var oracle_1 = require("./dialects/oracle");
|
|
11
|
+
Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return oracle_1.FnHelperOracle; } });
|
|
12
|
+
var sqlite_1 = require("./dialects/sqlite");
|
|
13
|
+
Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.FnHelperSQLite; } });
|
|
14
|
+
var mysql_1 = require("./dialects/mysql");
|
|
15
|
+
Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.FnHelperMySQL; } });
|
|
16
|
+
var mssql_1 = require("./dialects/mssql");
|
|
17
|
+
Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.FnHelperMSSQL; } });
|