directus 9.23.1 → 9.23.4
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 +25 -21
- package/dist/auth/auth.d.ts +3 -3
- package/dist/auth/auth.js +2 -0
- package/dist/auth/drivers/ldap.d.ts +1 -1
- package/dist/auth/drivers/ldap.js +57 -46
- package/dist/auth/drivers/local.d.ts +1 -1
- package/dist/auth/drivers/local.js +20 -17
- package/dist/auth/drivers/oauth2.d.ts +1 -1
- package/dist/auth/drivers/oauth2.js +44 -35
- package/dist/auth/drivers/openid.d.ts +1 -1
- package/dist/auth/drivers/openid.js +50 -41
- package/dist/auth/drivers/saml.d.ts +1 -1
- package/dist/auth/drivers/saml.js +20 -17
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +8 -7
- package/dist/cache.d.ts +9 -1
- package/dist/cache.js +66 -18
- package/dist/cli/commands/bootstrap/index.js +7 -6
- package/dist/cli/commands/init/index.js +3 -3
- package/dist/cli/commands/schema/apply.js +14 -15
- package/dist/cli/commands/schema/snapshot.js +2 -2
- package/dist/cli/utils/create-db-connection.d.ts +1 -1
- package/dist/cli/utils/create-db-connection.js +3 -2
- package/dist/cli/utils/create-env/index.d.ts +2 -2
- package/dist/cli/utils/create-env/index.js +1 -1
- package/dist/cli/utils/drivers.d.ts +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +7 -7
- package/dist/controllers/activity.js +10 -11
- package/dist/controllers/assets.js +31 -25
- package/dist/controllers/auth.js +40 -26
- package/dist/controllers/collections.js +10 -10
- package/dist/controllers/dashboards.js +14 -11
- package/dist/controllers/extensions.js +3 -3
- package/dist/controllers/fields.js +20 -20
- package/dist/controllers/files.js +26 -20
- package/dist/controllers/flows.js +16 -13
- package/dist/controllers/folders.js +14 -11
- package/dist/controllers/graphql.js +6 -8
- package/dist/controllers/items.js +22 -19
- package/dist/controllers/not-found.d.ts +1 -1
- package/dist/controllers/not-found.js +1 -2
- package/dist/controllers/notifications.js +14 -11
- package/dist/controllers/operations.js +14 -11
- package/dist/controllers/panels.js +14 -11
- package/dist/controllers/permissions.js +14 -11
- package/dist/controllers/presets.js +14 -11
- package/dist/controllers/relations.js +10 -10
- package/dist/controllers/revisions.js +3 -3
- package/dist/controllers/roles.js +14 -11
- package/dist/controllers/schema.js +5 -5
- package/dist/controllers/server.js +7 -7
- package/dist/controllers/settings.js +2 -2
- package/dist/controllers/shares.js +21 -18
- package/dist/controllers/users.js +32 -36
- package/dist/controllers/utils.js +10 -15
- package/dist/controllers/webhooks.js +14 -11
- package/dist/database/helpers/fn/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mssql.js +10 -11
- package/dist/database/helpers/fn/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mysql.js +2 -3
- package/dist/database/helpers/fn/dialects/oracle.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/oracle.js +10 -11
- package/dist/database/helpers/fn/dialects/postgres.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/postgres.js +10 -11
- package/dist/database/helpers/fn/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/sqlite.js +10 -11
- package/dist/database/helpers/fn/types.d.ts +5 -6
- package/dist/database/helpers/fn/types.js +4 -5
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.js +1 -2
- package/dist/database/helpers/geometry/dialects/redshift.d.ts +2 -2
- package/dist/database/helpers/geometry/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/geometry/types.d.ts +2 -2
- package/dist/database/helpers/geometry/types.js +1 -2
- package/dist/database/helpers/index.d.ts +5 -5
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.js +1 -2
- package/dist/database/helpers/schema/dialects/oracle.d.ts +2 -2
- package/dist/database/helpers/schema/dialects/oracle.js +4 -6
- package/dist/database/helpers/schema/types.d.ts +4 -4
- package/dist/database/helpers/types.d.ts +1 -1
- package/dist/database/helpers/types.js +1 -0
- package/dist/database/index.d.ts +1 -1
- package/dist/database/index.js +13 -13
- package/dist/database/migrations/20201028A-remove-collection-foreign-keys.d.ts +1 -1
- package/dist/database/migrations/20201029A-remove-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201029B-remove-system-collections.d.ts +1 -1
- package/dist/database/migrations/20201029C-remove-system-fields.d.ts +1 -1
- package/dist/database/migrations/20201105A-add-cascade-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201105B-change-webhook-url-type.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.js +1 -2
- package/dist/database/migrations/20210304A-remove-locked-fields.d.ts +1 -1
- package/dist/database/migrations/20210312A-webhooks-collections-text.d.ts +1 -1
- package/dist/database/migrations/20210331A-add-refresh-interval.d.ts +1 -1
- package/dist/database/migrations/20210415A-make-filesize-nullable.d.ts +1 -1
- package/dist/database/migrations/20210416A-add-collections-accountability.d.ts +1 -1
- package/dist/database/migrations/20210422A-remove-files-interface.d.ts +1 -1
- package/dist/database/migrations/20210506A-rename-interfaces.d.ts +1 -1
- package/dist/database/migrations/20210510A-restructure-relations.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.d.ts +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.js +2 -2
- package/dist/database/migrations/20210521A-add-collections-icon-color.d.ts +1 -1
- package/dist/database/migrations/20210525A-add-insights.d.ts +1 -1
- package/dist/database/migrations/20210608A-add-deep-clone-config.d.ts +1 -1
- package/dist/database/migrations/20210626A-change-filesize-bigint.d.ts +1 -1
- package/dist/database/migrations/20210716A-add-conditions-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210721A-add-default-folder.d.ts +1 -1
- package/dist/database/migrations/20210802A-replace-groups.d.ts +1 -1
- package/dist/database/migrations/20210803A-add-required-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210805A-update-groups.d.ts +1 -1
- package/dist/database/migrations/20210805B-change-image-metadata-structure.d.ts +1 -1
- package/dist/database/migrations/20210805B-change-image-metadata-structure.js +15 -15
- package/dist/database/migrations/20210811A-add-geometry-config.d.ts +1 -1
- package/dist/database/migrations/20210831A-remove-limit-column.d.ts +1 -1
- package/dist/database/migrations/20210903A-add-auth-provider.d.ts +1 -1
- package/dist/database/migrations/20210907A-webhooks-collections-not-null.d.ts +1 -1
- package/dist/database/migrations/20210910A-move-module-setup.d.ts +1 -1
- package/dist/database/migrations/20210920A-webhooks-url-not-null.d.ts +1 -1
- package/dist/database/migrations/20210924A-add-collection-organization.d.ts +1 -1
- package/dist/database/migrations/20210927A-replace-fields-group.d.ts +1 -1
- package/dist/database/migrations/20210927B-replace-m2m-interface.d.ts +1 -1
- package/dist/database/migrations/20210929A-rename-login-action.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.js +7 -9
- package/dist/database/migrations/20211009A-add-auth-data.d.ts +1 -1
- package/dist/database/migrations/20211016A-add-webhook-headers.d.ts +1 -1
- package/dist/database/migrations/20211103A-set-unique-to-user-token.d.ts +1 -1
- package/dist/database/migrations/20211103B-update-special-geometry.d.ts +1 -1
- package/dist/database/migrations/20211104A-remove-collections-listing.d.ts +1 -1
- package/dist/database/migrations/20211118A-add-notifications.d.ts +1 -1
- package/dist/database/migrations/20211211A-add-shares.d.ts +1 -1
- package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +1 -1
- package/dist/database/migrations/20220303A-remove-default-project-color.d.ts +1 -1
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +1 -1
- package/dist/database/migrations/20220314A-add-translation-strings.d.ts +1 -1
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220323A-add-field-validation.d.ts +1 -1
- package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220325B-add-default-language.d.ts +1 -1
- package/dist/database/migrations/20220402A-remove-default-value-panel-icon.d.ts +1 -1
- package/dist/database/migrations/20220429A-add-flows.d.ts +1 -1
- package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +1 -1
- package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +1 -1
- package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +1 -1
- package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.d.ts +1 -1
- package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +1 -1
- package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +1 -1
- package/dist/database/migrations/20220826A-add-origin-to-accountability.d.ts +1 -1
- package/dist/database/migrations/run.d.ts +1 -1
- package/dist/database/migrations/run.js +1 -1
- package/dist/database/run-ast.d.ts +3 -3
- package/dist/database/run-ast.js +21 -30
- package/dist/database/seeds/run.d.ts +1 -1
- package/dist/database/seeds/run.js +1 -2
- package/dist/database/system-data/app-access-permissions/index.d.ts +1 -1
- package/dist/database/system-data/collections/index.d.ts +1 -1
- package/dist/database/system-data/collections/index.js +2 -2
- package/dist/database/system-data/fields/collections.yaml +2 -0
- package/dist/database/system-data/fields/index.d.ts +1 -1
- package/dist/database/system-data/fields/index.js +3 -4
- package/dist/database/system-data/fields/settings.yaml +4 -0
- package/dist/database/system-data/relations/index.d.ts +1 -1
- package/dist/emitter.d.ts +1 -1
- package/dist/emitter.js +3 -0
- package/dist/env.js +11 -3
- package/dist/exceptions/database/dialects/mssql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mssql.js +5 -6
- package/dist/exceptions/database/dialects/mysql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mysql.js +19 -25
- package/dist/exceptions/database/dialects/oracle.d.ts +1 -1
- package/dist/exceptions/database/dialects/postgres.d.ts +1 -1
- package/dist/exceptions/database/dialects/sqlite.d.ts +1 -1
- package/dist/exceptions/database/translate.d.ts +1 -1
- package/dist/exceptions/database/value-out-of-range.js +1 -1
- package/dist/exceptions/range-not-satisfiable.js +2 -3
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +43 -33
- package/dist/flows.js +65 -46
- package/dist/logger.d.ts +2 -1
- package/dist/logger.js +35 -19
- package/dist/logger.test.d.ts +1 -0
- package/dist/mailer.js +16 -16
- package/dist/messenger.js +9 -7
- package/dist/middleware/authenticate.d.ts +1 -1
- package/dist/middleware/authenticate.js +13 -6
- package/dist/middleware/cache.d.ts +1 -1
- package/dist/middleware/cache.js +16 -16
- package/dist/middleware/check-ip.d.ts +1 -1
- package/dist/middleware/check-ip.js +1 -1
- package/dist/middleware/collection-exists.d.ts +1 -1
- package/dist/middleware/collection-exists.js +5 -5
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/cors.js +7 -7
- package/dist/middleware/error-handler.d.ts +1 -1
- package/dist/middleware/error-handler.js +11 -12
- package/dist/middleware/extract-token.d.ts +1 -1
- package/dist/middleware/extract-token.js +2 -2
- package/dist/middleware/get-permissions.d.ts +1 -1
- package/dist/middleware/graphql.d.ts +1 -1
- package/dist/middleware/graphql.js +15 -9
- package/dist/middleware/rate-limiter-global.d.ts +5 -0
- package/dist/middleware/rate-limiter-global.js +48 -0
- package/dist/middleware/{rate-limiter.d.ts → rate-limiter-ip.d.ts} +2 -2
- package/dist/middleware/{rate-limiter.js → rate-limiter-ip.js} +5 -5
- package/dist/middleware/respond.d.ts +1 -1
- package/dist/middleware/respond.js +18 -19
- package/dist/middleware/sanitize-query.d.ts +1 -1
- package/dist/middleware/sanitize-query.js +1 -1
- package/dist/middleware/schema.d.ts +1 -1
- package/dist/middleware/use-collection.d.ts +1 -1
- package/dist/operations/condition/index.d.ts +1 -1
- package/dist/operations/exec/index.js +15 -4
- package/dist/operations/item-create/index.js +1 -2
- package/dist/operations/item-delete/index.d.ts +1 -1
- package/dist/operations/item-read/index.d.ts +1 -1
- package/dist/operations/item-update/index.d.ts +1 -1
- package/dist/operations/item-update/index.js +1 -2
- package/dist/operations/notification/index.js +1 -2
- package/dist/operations/request/index.js +19 -19
- package/dist/operations/trigger/index.js +2 -3
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +9 -9
- package/dist/request/validate-ip.js +2 -2
- package/dist/server.js +12 -13
- package/dist/services/activity.d.ts +1 -1
- package/dist/services/activity.js +17 -16
- package/dist/services/assets.d.ts +3 -3
- package/dist/services/assets.js +35 -37
- package/dist/services/authentication.d.ts +2 -2
- package/dist/services/authentication.js +22 -19
- package/dist/services/authorization.d.ts +3 -3
- package/dist/services/authorization.js +27 -31
- package/dist/services/collections.d.ts +5 -5
- package/dist/services/collections.js +54 -50
- package/dist/services/dashboards.d.ts +1 -1
- package/dist/services/fields.d.ts +5 -5
- package/dist/services/fields.js +50 -50
- package/dist/services/files.d.ts +1 -2
- package/dist/services/files.js +33 -27
- package/dist/services/flows.d.ts +2 -2
- package/dist/services/folders.d.ts +1 -1
- package/dist/services/graphql/index.d.ts +4 -4
- package/dist/services/graphql/index.js +259 -252
- package/dist/services/graphql/utils/add-path-to-validation-error.js +1 -2
- package/dist/services/graphql/utils/process-error.d.ts +2 -2
- package/dist/services/graphql/utils/process-error.js +11 -4
- package/dist/services/import-export.d.ts +3 -3
- package/dist/services/import-export.js +30 -27
- package/dist/services/items.d.ts +3 -3
- package/dist/services/items.js +42 -36
- package/dist/services/mail/index.d.ts +4 -4
- package/dist/services/mail/index.js +14 -10
- package/dist/services/meta.d.ts +3 -3
- package/dist/services/meta.js +11 -9
- package/dist/services/notifications.d.ts +3 -3
- package/dist/services/notifications.js +10 -9
- package/dist/services/operations.d.ts +2 -2
- package/dist/services/panels.d.ts +1 -1
- package/dist/services/payload.d.ts +3 -3
- package/dist/services/payload.js +124 -122
- package/dist/services/permissions.d.ts +3 -3
- package/dist/services/permissions.js +11 -11
- package/dist/services/presets.d.ts +1 -1
- package/dist/services/relations.d.ts +6 -6
- package/dist/services/relations.js +45 -43
- package/dist/services/revisions.d.ts +1 -1
- package/dist/services/revisions.js +3 -3
- package/dist/services/roles.d.ts +2 -2
- package/dist/services/roles.js +7 -7
- package/dist/services/schema.d.ts +3 -3
- package/dist/services/schema.js +9 -11
- package/dist/services/server.d.ts +3 -3
- package/dist/services/server.js +88 -32
- package/dist/services/settings.d.ts +1 -1
- package/dist/services/shares.d.ts +1 -1
- package/dist/services/shares.js +14 -15
- package/dist/services/specifications.d.ts +4 -4
- package/dist/services/specifications.js +137 -119
- package/dist/services/tfa.d.ts +2 -2
- package/dist/services/tfa.js +7 -5
- package/dist/services/users.d.ts +2 -6
- package/dist/services/users.js +37 -40
- package/dist/services/utils.d.ts +3 -3
- package/dist/services/utils.js +10 -8
- package/dist/services/webhooks.d.ts +2 -2
- package/dist/services/webhooks.js +2 -1
- package/dist/storage/register-locations.js +1 -1
- package/dist/types/assets.d.ts +1 -1
- package/dist/types/ast.d.ts +1 -1
- package/dist/types/auth.d.ts +2 -2
- package/dist/types/collection.d.ts +2 -2
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphql.d.ts +2 -2
- package/dist/types/items.d.ts +3 -3
- package/dist/types/services.d.ts +5 -5
- package/dist/types/snapshot.d.ts +4 -4
- package/dist/utils/apply-diff.d.ts +3 -3
- package/dist/utils/apply-diff.js +25 -28
- package/dist/utils/apply-query.d.ts +3 -3
- package/dist/utils/apply-query.js +10 -12
- package/dist/utils/apply-snapshot.d.ts +3 -3
- package/dist/utils/apply-snapshot.js +5 -6
- package/dist/utils/construct-flow-tree.d.ts +1 -1
- package/dist/utils/construct-flow-tree.js +2 -2
- package/dist/utils/dynamic-import.js +1 -1
- package/dist/utils/filter-items.d.ts +1 -1
- package/dist/utils/generate-hash.js +1 -1
- package/dist/utils/get-accountability-for-role.d.ts +2 -2
- package/dist/utils/get-accountability-for-role.js +1 -1
- package/dist/utils/get-ast-from-query.d.ts +3 -3
- package/dist/utils/get-ast-from-query.js +22 -28
- package/dist/utils/get-auth-providers.js +1 -1
- package/dist/utils/get-cache-headers.d.ts +1 -1
- package/dist/utils/get-cache-headers.js +6 -7
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +2 -3
- package/dist/utils/get-collection-from-alias.d.ts +1 -1
- package/dist/utils/get-collection-from-alias.js +1 -0
- package/dist/utils/get-column-path.d.ts +2 -2
- package/dist/utils/get-column-path.js +3 -4
- package/dist/utils/get-column.d.ts +4 -4
- package/dist/utils/get-column.js +4 -5
- package/dist/utils/get-default-value.d.ts +2 -2
- package/dist/utils/get-default-value.js +2 -3
- package/dist/utils/get-graphql-query-and-variables.d.ts +1 -1
- package/dist/utils/get-graphql-query-and-variables.js +1 -2
- package/dist/utils/get-graphql-type.d.ts +2 -2
- package/dist/utils/get-graphql-type.js +1 -1
- package/dist/utils/get-ip-from-req.d.ts +1 -1
- package/dist/utils/get-ip-from-req.js +2 -2
- package/dist/utils/get-local-type.d.ts +1 -1
- package/dist/utils/get-local-type.js +3 -3
- package/dist/utils/get-milliseconds.js +1 -2
- package/dist/utils/get-permissions.d.ts +1 -1
- package/dist/utils/get-permissions.js +12 -12
- package/dist/utils/get-relation-info.d.ts +1 -1
- package/dist/utils/get-relation-info.js +3 -5
- package/dist/utils/get-relation-type.d.ts +1 -1
- package/dist/utils/get-relation-type.js +3 -4
- package/dist/utils/get-schema.d.ts +2 -2
- package/dist/utils/get-schema.js +20 -22
- package/dist/utils/get-snapshot-diff.js +2 -3
- package/dist/utils/get-snapshot.d.ts +3 -3
- package/dist/utils/get-snapshot.js +6 -8
- package/dist/utils/is-directus-jwt.js +1 -1
- package/dist/utils/is-url-allowed.js +5 -2
- package/dist/utils/job-queue.js +2 -0
- package/dist/utils/jwt.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.js +3 -4
- package/dist/utils/merge-permissions.d.ts +3 -3
- package/dist/utils/reduce-schema.d.ts +1 -1
- package/dist/utils/reduce-schema.js +12 -12
- package/dist/utils/sanitize-query.d.ts +1 -1
- package/dist/utils/sanitize-query.js +27 -27
- package/dist/utils/sanitize-schema.d.ts +2 -2
- package/dist/utils/should-skip-cache.d.ts +7 -0
- package/dist/utils/should-skip-cache.js +21 -0
- package/dist/utils/should-skip-cache.test.d.ts +1 -0
- package/dist/utils/track.js +16 -16
- package/dist/utils/transformations.d.ts +1 -1
- package/dist/utils/transformations.js +2 -4
- package/dist/utils/url.js +7 -2
- package/dist/utils/user-name.d.ts +1 -1
- package/dist/utils/validate-diff.js +7 -8
- package/dist/utils/validate-keys.d.ts +2 -2
- package/dist/utils/validate-keys.js +1 -1
- package/dist/utils/validate-query.d.ts +1 -1
- package/dist/utils/validate-query.js +3 -3
- package/dist/utils/validate-storage.js +8 -8
- package/dist/webhooks.js +3 -3
- package/package.json +36 -37
- package/dist/utils/with-timeout.d.ts +0 -1
- package/dist/utils/with-timeout.js +0 -16
|
@@ -11,6 +11,7 @@ const use_collection_1 = __importDefault(require("../middleware/use-collection")
|
|
|
11
11
|
const validate_batch_1 = require("../middleware/validate-batch");
|
|
12
12
|
const services_1 = require("../services");
|
|
13
13
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
14
|
+
const sanitize_query_1 = require("../utils/sanitize-query");
|
|
14
15
|
const router = express_1.default.Router();
|
|
15
16
|
router.use((0, use_collection_1.default)('directus_users'));
|
|
16
17
|
router.post('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
@@ -30,11 +31,11 @@ router.post('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
30
31
|
try {
|
|
31
32
|
if (Array.isArray(req.body)) {
|
|
32
33
|
const items = await service.readMany(savedKeys, req.sanitizedQuery);
|
|
33
|
-
res.locals
|
|
34
|
+
res.locals['payload'] = { data: items };
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
37
|
const item = await service.readOne(savedKeys[0], req.sanitizedQuery);
|
|
37
|
-
res.locals
|
|
38
|
+
res.locals['payload'] = { data: item };
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
catch (error) {
|
|
@@ -56,26 +57,25 @@ const readHandler = (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
56
57
|
});
|
|
57
58
|
const item = await service.readByQuery(req.sanitizedQuery);
|
|
58
59
|
const meta = await metaService.getMetaForQuery('directus_users', req.sanitizedQuery);
|
|
59
|
-
res.locals
|
|
60
|
+
res.locals['payload'] = { data: item || null, meta };
|
|
60
61
|
return next();
|
|
61
62
|
});
|
|
62
63
|
router.get('/', (0, validate_batch_1.validateBatch)('read'), readHandler, respond_1.respond);
|
|
63
64
|
router.search('/', (0, validate_batch_1.validateBatch)('read'), readHandler, respond_1.respond);
|
|
64
65
|
router.get('/me', (0, async_handler_1.default)(async (req, res, next) => {
|
|
65
|
-
|
|
66
|
-
if ((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.share_scope) {
|
|
66
|
+
if (req.accountability?.share_scope) {
|
|
67
67
|
const user = {
|
|
68
|
-
share:
|
|
68
|
+
share: req.accountability?.share,
|
|
69
69
|
role: {
|
|
70
70
|
id: req.accountability.role,
|
|
71
71
|
admin_access: false,
|
|
72
72
|
app_access: false,
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
|
-
res.locals
|
|
75
|
+
res.locals['payload'] = { data: user };
|
|
76
76
|
return next();
|
|
77
77
|
}
|
|
78
|
-
if (!
|
|
78
|
+
if (!req.accountability?.user) {
|
|
79
79
|
throw new exceptions_1.InvalidCredentialsException();
|
|
80
80
|
}
|
|
81
81
|
const service = new services_1.UsersService({
|
|
@@ -84,11 +84,11 @@ router.get('/me', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
84
84
|
});
|
|
85
85
|
try {
|
|
86
86
|
const item = await service.readOne(req.accountability.user, req.sanitizedQuery);
|
|
87
|
-
res.locals
|
|
87
|
+
res.locals['payload'] = { data: item || null };
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
if (error instanceof exceptions_1.ForbiddenException) {
|
|
91
|
-
res.locals
|
|
91
|
+
res.locals['payload'] = { data: { id: req.accountability.user } };
|
|
92
92
|
return next();
|
|
93
93
|
}
|
|
94
94
|
throw error;
|
|
@@ -102,13 +102,12 @@ router.get('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
102
102
|
accountability: req.accountability,
|
|
103
103
|
schema: req.schema,
|
|
104
104
|
});
|
|
105
|
-
const items = await service.readOne(req.params
|
|
106
|
-
res.locals
|
|
105
|
+
const items = await service.readOne(req.params['pk'], req.sanitizedQuery);
|
|
106
|
+
res.locals['payload'] = { data: items || null };
|
|
107
107
|
return next();
|
|
108
108
|
}), respond_1.respond);
|
|
109
109
|
router.patch('/me', (0, async_handler_1.default)(async (req, res, next) => {
|
|
110
|
-
|
|
111
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
110
|
+
if (!req.accountability?.user) {
|
|
112
111
|
throw new exceptions_1.InvalidCredentialsException();
|
|
113
112
|
}
|
|
114
113
|
const service = new services_1.UsersService({
|
|
@@ -117,12 +116,11 @@ router.patch('/me', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
117
116
|
});
|
|
118
117
|
const primaryKey = await service.updateOne(req.accountability.user, req.body);
|
|
119
118
|
const item = await service.readOne(primaryKey, req.sanitizedQuery);
|
|
120
|
-
res.locals
|
|
119
|
+
res.locals['payload'] = { data: item || null };
|
|
121
120
|
return next();
|
|
122
121
|
}), respond_1.respond);
|
|
123
122
|
router.patch('/me/track/page', (0, async_handler_1.default)(async (req, _res, next) => {
|
|
124
|
-
|
|
125
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
123
|
+
if (!req.accountability?.user) {
|
|
126
124
|
throw new exceptions_1.InvalidCredentialsException();
|
|
127
125
|
}
|
|
128
126
|
if (!req.body.last_page) {
|
|
@@ -145,11 +143,12 @@ router.patch('/', (0, validate_batch_1.validateBatch)('update'), (0, async_handl
|
|
|
145
143
|
keys = await service.updateMany(req.body.keys, req.body.data);
|
|
146
144
|
}
|
|
147
145
|
else {
|
|
148
|
-
|
|
146
|
+
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query, req.accountability);
|
|
147
|
+
keys = await service.updateByQuery(sanitizedQuery, req.body.data);
|
|
149
148
|
}
|
|
150
149
|
try {
|
|
151
150
|
const result = await service.readMany(keys, req.sanitizedQuery);
|
|
152
|
-
res.locals
|
|
151
|
+
res.locals['payload'] = { data: result };
|
|
153
152
|
}
|
|
154
153
|
catch (error) {
|
|
155
154
|
if (error instanceof exceptions_1.ForbiddenException) {
|
|
@@ -164,10 +163,10 @@ router.patch('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
164
163
|
accountability: req.accountability,
|
|
165
164
|
schema: req.schema,
|
|
166
165
|
});
|
|
167
|
-
const primaryKey = await service.updateOne(req.params
|
|
166
|
+
const primaryKey = await service.updateOne(req.params['pk'], req.body);
|
|
168
167
|
try {
|
|
169
168
|
const item = await service.readOne(primaryKey, req.sanitizedQuery);
|
|
170
|
-
res.locals
|
|
169
|
+
res.locals['payload'] = { data: item || null };
|
|
171
170
|
}
|
|
172
171
|
catch (error) {
|
|
173
172
|
if (error instanceof exceptions_1.ForbiddenException) {
|
|
@@ -189,7 +188,8 @@ router.delete('/', (0, validate_batch_1.validateBatch)('delete'), (0, async_hand
|
|
|
189
188
|
await service.deleteMany(req.body.keys);
|
|
190
189
|
}
|
|
191
190
|
else {
|
|
192
|
-
|
|
191
|
+
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query, req.accountability);
|
|
192
|
+
await service.deleteByQuery(sanitizedQuery);
|
|
193
193
|
}
|
|
194
194
|
return next();
|
|
195
195
|
}), respond_1.respond);
|
|
@@ -198,7 +198,7 @@ router.delete('/:pk', (0, async_handler_1.default)(async (req, _res, next) => {
|
|
|
198
198
|
accountability: req.accountability,
|
|
199
199
|
schema: req.schema,
|
|
200
200
|
});
|
|
201
|
-
await service.deleteOne(req.params
|
|
201
|
+
await service.deleteOne(req.params['pk']);
|
|
202
202
|
return next();
|
|
203
203
|
}), respond_1.respond);
|
|
204
204
|
const inviteSchema = joi_1.default.object({
|
|
@@ -233,8 +233,7 @@ router.post('/invite/accept', (0, async_handler_1.default)(async (req, _res, nex
|
|
|
233
233
|
return next();
|
|
234
234
|
}), respond_1.respond);
|
|
235
235
|
router.post('/me/tfa/generate/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
236
|
-
|
|
237
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
236
|
+
if (!req.accountability?.user) {
|
|
238
237
|
throw new exceptions_1.InvalidCredentialsException();
|
|
239
238
|
}
|
|
240
239
|
if (!req.body.password) {
|
|
@@ -250,12 +249,11 @@ router.post('/me/tfa/generate/', (0, async_handler_1.default)(async (req, res, n
|
|
|
250
249
|
});
|
|
251
250
|
await authService.verifyPassword(req.accountability.user, req.body.password);
|
|
252
251
|
const { url, secret } = await service.generateTFA(req.accountability.user);
|
|
253
|
-
res.locals
|
|
252
|
+
res.locals['payload'] = { data: { secret, otpauth_url: url } };
|
|
254
253
|
return next();
|
|
255
254
|
}), respond_1.respond);
|
|
256
255
|
router.post('/me/tfa/enable/', (0, async_handler_1.default)(async (req, _res, next) => {
|
|
257
|
-
|
|
258
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
256
|
+
if (!req.accountability?.user) {
|
|
259
257
|
throw new exceptions_1.InvalidCredentialsException();
|
|
260
258
|
}
|
|
261
259
|
if (!req.body.secret) {
|
|
@@ -271,7 +269,7 @@ router.post('/me/tfa/enable/', (0, async_handler_1.default)(async (req, _res, ne
|
|
|
271
269
|
});
|
|
272
270
|
const role = (await rolesService.readOne(req.accountability.role));
|
|
273
271
|
if (role && role.enforce_tfa) {
|
|
274
|
-
const existingPermission = await
|
|
272
|
+
const existingPermission = await req.accountability.permissions?.find((p) => p.collection === 'directus_users' && p.action === 'update');
|
|
275
273
|
if (existingPermission) {
|
|
276
274
|
existingPermission.fields = ['tfa_secret'];
|
|
277
275
|
existingPermission.permissions = { id: { _eq: req.accountability.user } };
|
|
@@ -299,8 +297,7 @@ router.post('/me/tfa/enable/', (0, async_handler_1.default)(async (req, _res, ne
|
|
|
299
297
|
return next();
|
|
300
298
|
}), respond_1.respond);
|
|
301
299
|
router.post('/me/tfa/disable', (0, async_handler_1.default)(async (req, _res, next) => {
|
|
302
|
-
|
|
303
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
300
|
+
if (!req.accountability?.user) {
|
|
304
301
|
throw new exceptions_1.InvalidCredentialsException();
|
|
305
302
|
}
|
|
306
303
|
if (!req.body.otp) {
|
|
@@ -313,7 +310,7 @@ router.post('/me/tfa/disable', (0, async_handler_1.default)(async (req, _res, ne
|
|
|
313
310
|
});
|
|
314
311
|
const role = (await rolesService.readOne(req.accountability.role));
|
|
315
312
|
if (role && role.enforce_tfa) {
|
|
316
|
-
const existingPermission = await
|
|
313
|
+
const existingPermission = await req.accountability.permissions?.find((p) => p.collection === 'directus_users' && p.action === 'update');
|
|
317
314
|
if (existingPermission) {
|
|
318
315
|
existingPermission.fields = ['tfa_secret'];
|
|
319
316
|
existingPermission.permissions = { id: { _eq: req.accountability.user } };
|
|
@@ -345,18 +342,17 @@ router.post('/me/tfa/disable', (0, async_handler_1.default)(async (req, _res, ne
|
|
|
345
342
|
return next();
|
|
346
343
|
}), respond_1.respond);
|
|
347
344
|
router.post('/:pk/tfa/disable', (0, async_handler_1.default)(async (req, _res, next) => {
|
|
348
|
-
|
|
349
|
-
if (!((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
345
|
+
if (!req.accountability?.user) {
|
|
350
346
|
throw new exceptions_1.InvalidCredentialsException();
|
|
351
347
|
}
|
|
352
|
-
if (!req.accountability.admin || !req.params
|
|
348
|
+
if (!req.accountability.admin || !req.params['pk']) {
|
|
353
349
|
throw new exceptions_1.ForbiddenException();
|
|
354
350
|
}
|
|
355
351
|
const service = new services_1.TFAService({
|
|
356
352
|
accountability: req.accountability,
|
|
357
353
|
schema: req.schema,
|
|
358
354
|
});
|
|
359
|
-
await service.disableTFA(req.params
|
|
355
|
+
await service.disableTFA(req.params['pk']);
|
|
360
356
|
return next();
|
|
361
357
|
}), respond_1.respond);
|
|
362
358
|
exports.default = router;
|
|
@@ -17,27 +17,24 @@ const generate_hash_1 = require("../utils/generate-hash");
|
|
|
17
17
|
const sanitize_query_1 = require("../utils/sanitize-query");
|
|
18
18
|
const router = (0, express_1.Router)();
|
|
19
19
|
router.get('/random/string', (0, async_handler_1.default)(async (req, res) => {
|
|
20
|
-
var _a;
|
|
21
20
|
const { nanoid } = await import('nanoid');
|
|
22
|
-
if (req.query && req.query
|
|
21
|
+
if (req.query && req.query['length'] && Number(req.query['length']) > 500)
|
|
23
22
|
throw new exceptions_1.InvalidQueryException(`"length" can't be more than 500 characters`);
|
|
24
|
-
const string = nanoid(
|
|
23
|
+
const string = nanoid(req.query?.['length'] ? Number(req.query['length']) : 32);
|
|
25
24
|
return res.json({ data: string });
|
|
26
25
|
}));
|
|
27
26
|
router.post('/hash/generate', (0, async_handler_1.default)(async (req, res) => {
|
|
28
|
-
|
|
29
|
-
if (!((_a = req.body) === null || _a === void 0 ? void 0 : _a.string)) {
|
|
27
|
+
if (!req.body?.string) {
|
|
30
28
|
throw new exceptions_1.InvalidPayloadException(`"string" is required`);
|
|
31
29
|
}
|
|
32
30
|
const hash = await (0, generate_hash_1.generateHash)(req.body.string);
|
|
33
31
|
return res.json({ data: hash });
|
|
34
32
|
}));
|
|
35
33
|
router.post('/hash/verify', (0, async_handler_1.default)(async (req, res) => {
|
|
36
|
-
|
|
37
|
-
if (!((_a = req.body) === null || _a === void 0 ? void 0 : _a.string)) {
|
|
34
|
+
if (!req.body?.string) {
|
|
38
35
|
throw new exceptions_1.InvalidPayloadException(`"string" is required`);
|
|
39
36
|
}
|
|
40
|
-
if (!
|
|
37
|
+
if (!req.body?.hash) {
|
|
41
38
|
throw new exceptions_1.InvalidPayloadException(`"hash" is required`);
|
|
42
39
|
}
|
|
43
40
|
const result = await argon2_1.default.verify(req.body.hash, req.body.string);
|
|
@@ -63,7 +60,7 @@ router.post('/revert/:revision', (0, async_handler_1.default)(async (req, res, n
|
|
|
63
60
|
accountability: req.accountability,
|
|
64
61
|
schema: req.schema,
|
|
65
62
|
});
|
|
66
|
-
await service.revert(req.params
|
|
63
|
+
await service.revert(req.params['revision']);
|
|
67
64
|
next();
|
|
68
65
|
}), respond_1.respond);
|
|
69
66
|
router.post('/import/:collection', collection_exists_1.default, (0, async_handler_1.default)(async (req, res, next) => {
|
|
@@ -86,7 +83,7 @@ router.post('/import/:collection', collection_exists_1.default, (0, async_handle
|
|
|
86
83
|
const busboy = (0, busboy_1.default)({ headers });
|
|
87
84
|
busboy.on('file', async (_fieldname, fileStream, { mimeType }) => {
|
|
88
85
|
try {
|
|
89
|
-
await service.import(req.params
|
|
86
|
+
await service.import(req.params['collection'], mimeType, fileStream);
|
|
90
87
|
}
|
|
91
88
|
catch (err) {
|
|
92
89
|
return next(err);
|
|
@@ -97,7 +94,6 @@ router.post('/import/:collection', collection_exists_1.default, (0, async_handle
|
|
|
97
94
|
req.pipe(busboy);
|
|
98
95
|
}));
|
|
99
96
|
router.post('/export/:collection', collection_exists_1.default, (0, async_handler_1.default)(async (req, res, next) => {
|
|
100
|
-
var _a;
|
|
101
97
|
if (!req.body.query) {
|
|
102
98
|
throw new exceptions_1.InvalidPayloadException(`"query" is required.`);
|
|
103
99
|
}
|
|
@@ -108,16 +104,15 @@ router.post('/export/:collection', collection_exists_1.default, (0, async_handle
|
|
|
108
104
|
accountability: req.accountability,
|
|
109
105
|
schema: req.schema,
|
|
110
106
|
});
|
|
111
|
-
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query,
|
|
107
|
+
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query, req.accountability ?? null);
|
|
112
108
|
// We're not awaiting this, as it's supposed to run async in the background
|
|
113
|
-
service.exportToFile(req.params
|
|
109
|
+
service.exportToFile(req.params['collection'], sanitizedQuery, req.body.format, {
|
|
114
110
|
file: req.body.file,
|
|
115
111
|
});
|
|
116
112
|
return next();
|
|
117
113
|
}), respond_1.respond);
|
|
118
114
|
router.post('/cache/clear', (0, async_handler_1.default)(async (req, res) => {
|
|
119
|
-
|
|
120
|
-
if (((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true) {
|
|
115
|
+
if (req.accountability?.admin !== true) {
|
|
121
116
|
throw new exceptions_1.ForbiddenException();
|
|
122
117
|
}
|
|
123
118
|
await (0, cache_1.flushCaches)(true);
|
|
@@ -10,6 +10,7 @@ const use_collection_1 = __importDefault(require("../middleware/use-collection")
|
|
|
10
10
|
const validate_batch_1 = require("../middleware/validate-batch");
|
|
11
11
|
const services_1 = require("../services");
|
|
12
12
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
13
|
+
const sanitize_query_1 = require("../utils/sanitize-query");
|
|
13
14
|
const router = express_1.default.Router();
|
|
14
15
|
router.use((0, use_collection_1.default)('directus_webhooks'));
|
|
15
16
|
router.post('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
@@ -29,11 +30,11 @@ router.post('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
29
30
|
try {
|
|
30
31
|
if (Array.isArray(req.body)) {
|
|
31
32
|
const items = await service.readMany(savedKeys, req.sanitizedQuery);
|
|
32
|
-
res.locals
|
|
33
|
+
res.locals['payload'] = { data: items };
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
36
|
const item = await service.readOne(savedKeys[0], req.sanitizedQuery);
|
|
36
|
-
res.locals
|
|
37
|
+
res.locals['payload'] = { data: item };
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
catch (error) {
|
|
@@ -55,7 +56,7 @@ const readHandler = (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
55
56
|
});
|
|
56
57
|
const records = await service.readByQuery(req.sanitizedQuery);
|
|
57
58
|
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
|
58
|
-
res.locals
|
|
59
|
+
res.locals['payload'] = { data: records || null, meta };
|
|
59
60
|
return next();
|
|
60
61
|
});
|
|
61
62
|
router.get('/', (0, validate_batch_1.validateBatch)('read'), readHandler, respond_1.respond);
|
|
@@ -65,8 +66,8 @@ router.get('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
65
66
|
accountability: req.accountability,
|
|
66
67
|
schema: req.schema,
|
|
67
68
|
});
|
|
68
|
-
const record = await service.readOne(req.params
|
|
69
|
-
res.locals
|
|
69
|
+
const record = await service.readOne(req.params['pk'], req.sanitizedQuery);
|
|
70
|
+
res.locals['payload'] = { data: record || null };
|
|
70
71
|
return next();
|
|
71
72
|
}), respond_1.respond);
|
|
72
73
|
router.patch('/', (0, validate_batch_1.validateBatch)('update'), (0, async_handler_1.default)(async (req, res, next) => {
|
|
@@ -79,11 +80,12 @@ router.patch('/', (0, validate_batch_1.validateBatch)('update'), (0, async_handl
|
|
|
79
80
|
keys = await service.updateMany(req.body.keys, req.body.data);
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
82
|
-
|
|
83
|
+
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query, req.accountability);
|
|
84
|
+
keys = await service.updateByQuery(sanitizedQuery, req.body.data);
|
|
83
85
|
}
|
|
84
86
|
try {
|
|
85
87
|
const result = await service.readMany(keys, req.sanitizedQuery);
|
|
86
|
-
res.locals
|
|
88
|
+
res.locals['payload'] = { data: result };
|
|
87
89
|
}
|
|
88
90
|
catch (error) {
|
|
89
91
|
if (error instanceof exceptions_1.ForbiddenException) {
|
|
@@ -98,10 +100,10 @@ router.patch('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
98
100
|
accountability: req.accountability,
|
|
99
101
|
schema: req.schema,
|
|
100
102
|
});
|
|
101
|
-
const primaryKey = await service.updateOne(req.params
|
|
103
|
+
const primaryKey = await service.updateOne(req.params['pk'], req.body);
|
|
102
104
|
try {
|
|
103
105
|
const item = await service.readOne(primaryKey, req.sanitizedQuery);
|
|
104
|
-
res.locals
|
|
106
|
+
res.locals['payload'] = { data: item || null };
|
|
105
107
|
}
|
|
106
108
|
catch (error) {
|
|
107
109
|
if (error instanceof exceptions_1.ForbiddenException) {
|
|
@@ -123,7 +125,8 @@ router.delete('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
123
125
|
await service.deleteMany(req.body.keys);
|
|
124
126
|
}
|
|
125
127
|
else {
|
|
126
|
-
|
|
128
|
+
const sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)(req.body.query, req.accountability);
|
|
129
|
+
await service.deleteByQuery(sanitizedQuery);
|
|
127
130
|
}
|
|
128
131
|
return next();
|
|
129
132
|
}), respond_1.respond);
|
|
@@ -132,7 +135,7 @@ router.delete('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
132
135
|
accountability: req.accountability,
|
|
133
136
|
schema: req.schema,
|
|
134
137
|
});
|
|
135
|
-
await service.deleteOne(req.params
|
|
138
|
+
await service.deleteOne(req.params['pk']);
|
|
136
139
|
return next();
|
|
137
140
|
}), respond_1.respond);
|
|
138
141
|
exports.default = router;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import { FnHelper, FnHelperOptions } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
3
|
export declare class FnHelperMSSQL extends FnHelper {
|
|
4
4
|
year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
5
5
|
month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
@@ -10,33 +10,32 @@ const parseLocaltime = (columnType) => {
|
|
|
10
10
|
};
|
|
11
11
|
class FnHelperMSSQL extends types_1.FnHelper {
|
|
12
12
|
year(table, column, options) {
|
|
13
|
-
return this.knex.raw(`DATEPART(year, ??.??${parseLocaltime(options
|
|
13
|
+
return this.knex.raw(`DATEPART(year, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
14
14
|
}
|
|
15
15
|
month(table, column, options) {
|
|
16
|
-
return this.knex.raw(`DATEPART(month, ??.??${parseLocaltime(options
|
|
16
|
+
return this.knex.raw(`DATEPART(month, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
17
17
|
}
|
|
18
18
|
week(table, column, options) {
|
|
19
|
-
return this.knex.raw(`DATEPART(week, ??.??${parseLocaltime(options
|
|
19
|
+
return this.knex.raw(`DATEPART(week, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
20
20
|
}
|
|
21
21
|
day(table, column, options) {
|
|
22
|
-
return this.knex.raw(`DATEPART(day, ??.??${parseLocaltime(options
|
|
22
|
+
return this.knex.raw(`DATEPART(day, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
23
23
|
}
|
|
24
24
|
weekday(table, column, options) {
|
|
25
|
-
return this.knex.raw(`DATEPART(weekday, ??.??${parseLocaltime(options
|
|
25
|
+
return this.knex.raw(`DATEPART(weekday, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
26
26
|
}
|
|
27
27
|
hour(table, column, options) {
|
|
28
|
-
return this.knex.raw(`DATEPART(hour, ??.??${parseLocaltime(options
|
|
28
|
+
return this.knex.raw(`DATEPART(hour, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
29
29
|
}
|
|
30
30
|
minute(table, column, options) {
|
|
31
|
-
return this.knex.raw(`DATEPART(minute, ??.??${parseLocaltime(options
|
|
31
|
+
return this.knex.raw(`DATEPART(minute, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
32
32
|
}
|
|
33
33
|
second(table, column, options) {
|
|
34
|
-
return this.knex.raw(`DATEPART(second, ??.??${parseLocaltime(options
|
|
34
|
+
return this.knex.raw(`DATEPART(second, ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
35
35
|
}
|
|
36
36
|
count(table, column, options) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[collectionName]) === 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';
|
|
37
|
+
const collectionName = options?.originalCollectionName || table;
|
|
38
|
+
const type = this.schema.collections?.[collectionName]?.fields?.[column]?.type ?? 'unknown';
|
|
40
39
|
if (type === 'json') {
|
|
41
40
|
return this.knex.raw(`(SELECT COUNT(*) FROM OPENJSON(??.??, '$'))`, [table, column]);
|
|
42
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import { FnHelper, FnHelperOptions } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
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;
|
|
@@ -28,9 +28,8 @@ class FnHelperMySQL extends types_1.FnHelper {
|
|
|
28
28
|
return this.knex.raw('SECOND(??.??)', [table, column]);
|
|
29
29
|
}
|
|
30
30
|
count(table, column, options) {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[collectionName]) === 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';
|
|
31
|
+
const collectionName = options?.originalCollectionName || table;
|
|
32
|
+
const type = this.schema.collections?.[collectionName]?.fields?.[column]?.type ?? 'unknown';
|
|
34
33
|
if (type === 'json') {
|
|
35
34
|
return this.knex.raw('JSON_LENGTH(??.??)', [table, column]);
|
|
36
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import { FnHelper, FnHelperOptions } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
3
|
export declare class FnHelperOracle extends FnHelper {
|
|
4
4
|
year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
5
5
|
month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
@@ -10,33 +10,32 @@ const parseLocaltime = (columnType) => {
|
|
|
10
10
|
};
|
|
11
11
|
class FnHelperOracle extends types_1.FnHelper {
|
|
12
12
|
year(table, column, options) {
|
|
13
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
13
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'IYYY')`, [table, column]);
|
|
14
14
|
}
|
|
15
15
|
month(table, column, options) {
|
|
16
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
16
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'MM')`, [table, column]);
|
|
17
17
|
}
|
|
18
18
|
week(table, column, options) {
|
|
19
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
19
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'IW')`, [table, column]);
|
|
20
20
|
}
|
|
21
21
|
day(table, column, options) {
|
|
22
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
22
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'DD')`, [table, column]);
|
|
23
23
|
}
|
|
24
24
|
weekday(table, column, options) {
|
|
25
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
25
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'D')`, [table, column]);
|
|
26
26
|
}
|
|
27
27
|
hour(table, column, options) {
|
|
28
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
28
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'HH24')`, [table, column]);
|
|
29
29
|
}
|
|
30
30
|
minute(table, column, options) {
|
|
31
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
31
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'MI')`, [table, column]);
|
|
32
32
|
}
|
|
33
33
|
second(table, column, options) {
|
|
34
|
-
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options
|
|
34
|
+
return this.knex.raw(`TO_CHAR(??.??${parseLocaltime(options?.type)}, 'SS')`, [table, column]);
|
|
35
35
|
}
|
|
36
36
|
count(table, column, options) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[collectionName]) === 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';
|
|
37
|
+
const collectionName = options?.originalCollectionName || table;
|
|
38
|
+
const type = this.schema.collections?.[collectionName]?.fields?.[column]?.type ?? 'unknown';
|
|
40
39
|
if (type === 'json') {
|
|
41
40
|
return this.knex.raw("json_value(??.??, '$.size()')", [table, column]);
|
|
42
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import { FnHelper, FnHelperOptions } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
3
|
export declare class FnHelperPostgres extends FnHelper {
|
|
4
4
|
year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
5
5
|
month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
|
|
@@ -10,33 +10,32 @@ const parseLocaltime = (columnType) => {
|
|
|
10
10
|
};
|
|
11
11
|
class FnHelperPostgres extends types_1.FnHelper {
|
|
12
12
|
year(table, column, options) {
|
|
13
|
-
return this.knex.raw(`EXTRACT(YEAR FROM ??.??${parseLocaltime(options
|
|
13
|
+
return this.knex.raw(`EXTRACT(YEAR FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
14
14
|
}
|
|
15
15
|
month(table, column, options) {
|
|
16
|
-
return this.knex.raw(`EXTRACT(MONTH FROM ??.??${parseLocaltime(options
|
|
16
|
+
return this.knex.raw(`EXTRACT(MONTH FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
17
17
|
}
|
|
18
18
|
week(table, column, options) {
|
|
19
|
-
return this.knex.raw(`EXTRACT(WEEK FROM ??.??${parseLocaltime(options
|
|
19
|
+
return this.knex.raw(`EXTRACT(WEEK FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
20
20
|
}
|
|
21
21
|
day(table, column, options) {
|
|
22
|
-
return this.knex.raw(`EXTRACT(DAY FROM ??.??${parseLocaltime(options
|
|
22
|
+
return this.knex.raw(`EXTRACT(DAY FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
23
23
|
}
|
|
24
24
|
weekday(table, column, options) {
|
|
25
|
-
return this.knex.raw(`EXTRACT(DOW FROM ??.??${parseLocaltime(options
|
|
25
|
+
return this.knex.raw(`EXTRACT(DOW FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
26
26
|
}
|
|
27
27
|
hour(table, column, options) {
|
|
28
|
-
return this.knex.raw(`EXTRACT(HOUR FROM ??.??${parseLocaltime(options
|
|
28
|
+
return this.knex.raw(`EXTRACT(HOUR FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
29
29
|
}
|
|
30
30
|
minute(table, column, options) {
|
|
31
|
-
return this.knex.raw(`EXTRACT(MINUTE FROM ??.??${parseLocaltime(options
|
|
31
|
+
return this.knex.raw(`EXTRACT(MINUTE FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
32
32
|
}
|
|
33
33
|
second(table, column, options) {
|
|
34
|
-
return this.knex.raw(`EXTRACT(SECOND FROM ??.??${parseLocaltime(options
|
|
34
|
+
return this.knex.raw(`EXTRACT(SECOND FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
|
|
35
35
|
}
|
|
36
36
|
count(table, column, options) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[collectionName]) === 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';
|
|
37
|
+
const collectionName = options?.originalCollectionName || table;
|
|
38
|
+
const type = this.schema.collections?.[collectionName]?.fields?.[column]?.type ?? 'unknown';
|
|
40
39
|
if (type === 'json') {
|
|
41
40
|
const { dbType } = this.schema.collections[table].fields[column];
|
|
42
41
|
return this.knex.raw(dbType === 'jsonb' ? 'jsonb_array_length(??.??)' : 'json_array_length(??.??)', [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
1
2
|
import { FnHelper, FnHelperOptions } from '../types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
3
|
export declare class FnHelperSQLite extends FnHelper {
|
|
4
4
|
year(table: string, column: string, options?: FnHelperOptions): Knex.Raw;
|
|
5
5
|
month(table: string, column: string, options?: FnHelperOptions): Knex.Raw;
|