directus 9.22.4 → 9.23.3
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 +19 -14
- package/dist/auth/auth.d.ts +3 -3
- package/dist/auth/auth.js +2 -0
- package/dist/auth/drivers/ldap.d.ts +2 -2
- package/dist/auth/drivers/ldap.js +47 -36
- package/dist/auth/drivers/local.d.ts +1 -1
- package/dist/auth/drivers/local.js +13 -10
- package/dist/auth/drivers/oauth2.d.ts +1 -1
- package/dist/auth/drivers/oauth2.js +22 -15
- package/dist/auth/drivers/openid.d.ts +1 -1
- package/dist/auth/drivers/openid.js +23 -16
- package/dist/auth/drivers/saml.d.ts +1 -1
- package/dist/auth/drivers/saml.js +10 -7
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +4 -4
- package/dist/cache.d.ts +9 -1
- package/dist/cache.js +59 -16
- package/dist/cli/commands/bootstrap/index.js +2 -2
- package/dist/cli/commands/init/index.js +3 -3
- package/dist/cli/commands/schema/apply.js +21 -20
- package/dist/cli/commands/schema/snapshot.js +2 -2
- package/dist/cli/utils/create-db-connection.d.ts +2 -1
- package/dist/cli/utils/create-db-connection.js +2 -1
- package/dist/cli/utils/create-env/env-stub.liquid +1 -1
- package/dist/cli/utils/create-env/index.d.ts +2 -2
- package/dist/cli/utils/drivers.d.ts +3 -9
- package/dist/constants.d.ts +3 -9
- package/dist/constants.js +5 -10
- package/dist/controllers/activity.js +1 -2
- package/dist/controllers/assets.js +17 -12
- package/dist/controllers/auth.js +29 -15
- package/dist/controllers/dashboards.js +5 -2
- package/dist/controllers/extensions.js +7 -7
- package/dist/controllers/fields.js +4 -4
- package/dist/controllers/files.js +11 -6
- package/dist/controllers/flows.js +5 -2
- package/dist/controllers/folders.js +5 -2
- package/dist/controllers/graphql.js +6 -0
- package/dist/controllers/items.js +5 -2
- package/dist/controllers/not-found.d.ts +1 -1
- package/dist/controllers/not-found.js +1 -2
- package/dist/controllers/notifications.js +5 -2
- package/dist/controllers/operations.js +5 -2
- package/dist/controllers/panels.js +5 -2
- package/dist/controllers/permissions.js +5 -2
- package/dist/controllers/presets.js +5 -2
- package/dist/controllers/roles.js +5 -2
- package/dist/controllers/schema.d.ts +2 -0
- package/dist/controllers/schema.js +98 -0
- package/dist/controllers/shares.js +8 -5
- package/dist/controllers/users.js +16 -20
- package/dist/controllers/utils.js +6 -11
- package/dist/controllers/webhooks.js +5 -2
- 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 -5
- package/dist/database/helpers/fn/types.js +5 -4
- 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 +2 -2
- 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 +5 -2
- package/dist/database/helpers/schema/dialects/oracle.js +23 -0
- package/dist/database/helpers/schema/types.d.ts +9 -7
- package/dist/database/helpers/schema/types.js +7 -1
- package/dist/database/helpers/types.d.ts +1 -1
- package/dist/database/helpers/types.js +1 -0
- package/dist/database/index.d.ts +2 -1
- package/dist/database/index.js +8 -8
- 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/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/run-ast.d.ts +3 -3
- package/dist/database/run-ast.js +19 -28
- 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/fields/collections.yaml +2 -0
- package/dist/database/system-data/fields/index.d.ts +1 -1
- package/dist/database/system-data/fields/index.js +1 -2
- 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 +19 -4
- 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 +34 -24
- package/dist/flows.js +56 -30
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +19 -3
- package/dist/messenger.js +8 -6
- package/dist/middleware/authenticate.d.ts +1 -1
- package/dist/middleware/authenticate.js +12 -5
- package/dist/middleware/cache.d.ts +1 -1
- package/dist/middleware/cache.js +7 -7
- 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 +2 -2
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/error-handler.d.ts +1 -1
- package/dist/middleware/error-handler.js +9 -10
- package/dist/middleware/extract-token.d.ts +1 -1
- package/dist/middleware/get-permissions.d.ts +1 -1
- package/dist/middleware/graphql.d.ts +1 -1
- package/dist/middleware/graphql.js +3 -3
- 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} +3 -3
- package/dist/middleware/respond.d.ts +1 -1
- package/dist/middleware/respond.js +18 -14
- package/dist/middleware/sanitize-query.d.ts +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 +14 -3
- 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 +21 -20
- package/dist/operations/trigger/index.d.ts +2 -0
- package/dist/operations/trigger/index.js +27 -11
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +8 -8
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.js +18 -0
- package/dist/request/index.test.d.ts +1 -0
- package/dist/request/request-interceptor.d.ts +2 -0
- package/dist/request/request-interceptor.js +33 -0
- package/dist/request/request-interceptor.test.d.ts +1 -0
- package/dist/request/response-interceptor.d.ts +2 -0
- package/dist/request/response-interceptor.js +9 -0
- package/dist/request/response-interceptor.test.d.ts +1 -0
- package/dist/request/validate-ip.d.ts +1 -0
- package/dist/request/validate-ip.js +27 -0
- package/dist/request/validate-ip.test.d.ts +1 -0
- package/dist/server.js +8 -9
- package/dist/services/activity.d.ts +1 -1
- package/dist/services/activity.js +7 -6
- package/dist/services/assets.d.ts +3 -3
- package/dist/services/assets.js +33 -26
- package/dist/services/authentication.d.ts +2 -2
- package/dist/services/authentication.js +18 -15
- 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 +52 -48
- package/dist/services/dashboards.d.ts +1 -1
- package/dist/services/fields.d.ts +5 -5
- package/dist/services/fields.js +49 -48
- package/dist/services/files.d.ts +1 -2
- package/dist/services/files.js +70 -108
- 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 +181 -170
- 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 +29 -9
- package/dist/services/import-export.d.ts +7 -5
- package/dist/services/import-export.js +41 -24
- package/dist/services/import-export.test.d.ts +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/items.d.ts +3 -3
- package/dist/services/items.js +67 -42
- package/dist/services/mail/index.d.ts +4 -4
- package/dist/services/mail/index.js +9 -5
- package/dist/services/meta.d.ts +3 -3
- package/dist/services/meta.js +10 -9
- package/dist/services/notifications.d.ts +3 -3
- package/dist/services/notifications.js +7 -6
- 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 +47 -43
- package/dist/services/revisions.d.ts +1 -1
- package/dist/services/roles.d.ts +2 -2
- package/dist/services/roles.js +34 -13
- package/dist/services/schema.d.ts +15 -0
- package/dist/services/schema.js +56 -0
- package/dist/services/schema.test.d.ts +1 -0
- package/dist/services/server.d.ts +3 -3
- package/dist/services/server.js +69 -13
- package/dist/services/settings.d.ts +1 -1
- package/dist/services/shares.d.ts +2 -2
- package/dist/services/shares.js +14 -15
- package/dist/services/specifications.d.ts +4 -4
- package/dist/services/specifications.js +132 -116
- package/dist/services/tfa.d.ts +2 -2
- package/dist/services/tfa.js +7 -5
- package/dist/services/users.d.ts +3 -3
- package/dist/services/users.js +89 -62
- 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/types/assets.d.ts +2 -2
- 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/database.d.ts +3 -0
- package/dist/types/database.js +4 -0
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphql.d.ts +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/items.d.ts +7 -2
- package/dist/types/services.d.ts +5 -5
- package/dist/types/snapshot.d.ts +25 -3
- package/dist/types/snapshot.js +14 -0
- package/dist/utils/apply-diff.d.ts +9 -0
- package/dist/utils/apply-diff.js +256 -0
- package/dist/utils/apply-diff.test.d.ts +1 -0
- package/dist/utils/apply-query.d.ts +3 -3
- package/dist/utils/apply-query.js +15 -16
- package/dist/utils/apply-snapshot.d.ts +3 -5
- package/dist/utils/apply-snapshot.js +9 -240
- package/dist/utils/construct-flow-tree.d.ts +1 -1
- package/dist/utils/construct-flow-tree.js +2 -2
- package/dist/utils/filter-items.d.ts +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-cache-headers.d.ts +4 -2
- package/dist/utils/get-cache-headers.js +21 -21
- package/dist/utils/get-cache-headers.test.d.ts +1 -0
- 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-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 +1 -2
- 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-local-type.d.ts +1 -1
- package/dist/utils/get-local-type.js +3 -3
- package/dist/utils/get-milliseconds.d.ts +4 -0
- package/dist/utils/get-milliseconds.js +14 -0
- package/dist/utils/get-milliseconds.test.d.ts +1 -0
- package/dist/utils/get-permissions.d.ts +1 -1
- package/dist/utils/get-permissions.js +1 -1
- 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 +19 -21
- package/dist/utils/get-snapshot-diff.js +10 -7
- package/dist/utils/get-snapshot.d.ts +3 -3
- package/dist/utils/get-snapshot.js +35 -14
- package/dist/utils/get-versioned-hash.d.ts +1 -0
- package/dist/utils/get-versioned-hash.js +12 -0
- package/dist/utils/get-versioned-hash.test.d.ts +1 -0
- package/dist/utils/is-directus-jwt.js +1 -1
- package/dist/utils/job-queue.js +2 -0
- package/dist/utils/jwt.d.ts +1 -1
- package/dist/utils/map-values-deep.d.ts +1 -0
- package/dist/utils/map-values-deep.js +29 -0
- package/dist/utils/map-values-deep.test.d.ts +1 -0
- 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/redact-header-cookies.d.ts +1 -0
- package/dist/utils/redact-header-cookies.js +11 -0
- package/dist/utils/redact-header-cookies.test.d.ts +1 -0
- 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 +1 -1
- package/dist/utils/sanitize-schema.d.ts +30 -0
- package/dist/utils/sanitize-schema.js +80 -0
- package/dist/utils/sanitize-schema.test.d.ts +1 -0
- 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 +3 -3
- package/dist/utils/transformations.d.ts +1 -1
- package/dist/utils/transformations.js +2 -4
- package/dist/utils/url.js +9 -8
- package/dist/utils/url.test.d.ts +1 -0
- package/dist/utils/user-name.d.ts +1 -1
- package/dist/utils/validate-diff.d.ts +7 -0
- package/dist/utils/validate-diff.js +113 -0
- package/dist/utils/validate-diff.test.d.ts +1 -0
- 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-query.test.d.ts +1 -0
- package/dist/utils/validate-snapshot.d.ts +5 -0
- package/dist/utils/validate-snapshot.js +71 -0
- package/dist/utils/validate-snapshot.test.d.ts +1 -0
- package/dist/webhooks.js +4 -3
- package/package.json +62 -62
|
@@ -0,0 +1,256 @@
|
|
|
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
|
+
exports.isNestedMetaUpdate = exports.applyDiff = void 0;
|
|
7
|
+
const deep_diff_1 = require("deep-diff");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const cache_1 = require("../cache");
|
|
10
|
+
const database_1 = __importDefault(require("../database"));
|
|
11
|
+
const emitter_1 = __importDefault(require("../emitter"));
|
|
12
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
13
|
+
const services_1 = require("../services");
|
|
14
|
+
const types_1 = require("../types");
|
|
15
|
+
const get_schema_1 = require("./get-schema");
|
|
16
|
+
async function applyDiff(currentSnapshot, snapshotDiff, options) {
|
|
17
|
+
const database = options?.database ?? (0, database_1.default)();
|
|
18
|
+
const schema = options?.schema ?? (await (0, get_schema_1.getSchema)({ database, bypassCache: true }));
|
|
19
|
+
const nestedActionEvents = [];
|
|
20
|
+
const mutationOptions = {
|
|
21
|
+
autoPurgeSystemCache: false,
|
|
22
|
+
bypassEmitAction: (params) => nestedActionEvents.push(params),
|
|
23
|
+
};
|
|
24
|
+
await database.transaction(async (trx) => {
|
|
25
|
+
const collectionsService = new services_1.CollectionsService({ knex: trx, schema });
|
|
26
|
+
const getNestedCollectionsToCreate = (currentLevelCollection) => snapshotDiff.collections.filter(({ diff }) => diff[0].rhs?.meta?.group === currentLevelCollection);
|
|
27
|
+
const getNestedCollectionsToDelete = (currentLevelCollection) => snapshotDiff.collections.filter(({ diff }) => diff[0].lhs?.meta?.group === currentLevelCollection);
|
|
28
|
+
const createCollections = async (collections) => {
|
|
29
|
+
for (const { collection, diff } of collections) {
|
|
30
|
+
if (diff?.[0].kind === types_1.DiffKind.NEW && diff[0].rhs) {
|
|
31
|
+
// We'll nest the to-be-created fields in the same collection creation, to prevent
|
|
32
|
+
// creating a collection without a primary key
|
|
33
|
+
const fields = snapshotDiff.fields
|
|
34
|
+
.filter((fieldDiff) => fieldDiff.collection === collection)
|
|
35
|
+
.map((fieldDiff) => fieldDiff.diff[0].rhs)
|
|
36
|
+
.map((fieldDiff) => {
|
|
37
|
+
// Casts field type to UUID when applying non-PostgreSQL schema onto PostgreSQL database.
|
|
38
|
+
// This is needed because they snapshots UUID fields as char/varchar with length 36.
|
|
39
|
+
if (['char', 'varchar'].includes(String(fieldDiff.schema?.data_type).toLowerCase()) &&
|
|
40
|
+
fieldDiff.schema?.max_length === 36 &&
|
|
41
|
+
(fieldDiff.schema?.is_primary_key ||
|
|
42
|
+
(fieldDiff.schema?.foreign_key_table && fieldDiff.schema?.foreign_key_column))) {
|
|
43
|
+
return (0, lodash_1.merge)(fieldDiff, { type: 'uuid', schema: { data_type: 'uuid', max_length: null } });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return fieldDiff;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
await collectionsService.createOne({
|
|
51
|
+
...diff[0].rhs,
|
|
52
|
+
fields,
|
|
53
|
+
}, mutationOptions);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
logger_1.default.error(`Failed to create collection "${collection}"`);
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
// Now that the fields are in for this collection, we can strip them from the field edits
|
|
60
|
+
snapshotDiff.fields = snapshotDiff.fields.filter((fieldDiff) => fieldDiff.collection !== collection);
|
|
61
|
+
await createCollections(getNestedCollectionsToCreate(collection));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const deleteCollections = async (collections) => {
|
|
66
|
+
for (const { collection, diff } of collections) {
|
|
67
|
+
if (diff?.[0].kind === types_1.DiffKind.DELETE) {
|
|
68
|
+
const relations = schema.relations.filter((r) => r.related_collection === collection || r.collection === collection);
|
|
69
|
+
if (relations.length > 0) {
|
|
70
|
+
const relationsService = new services_1.RelationsService({ knex: trx, schema });
|
|
71
|
+
for (const relation of relations) {
|
|
72
|
+
try {
|
|
73
|
+
await relationsService.deleteOne(relation.collection, relation.field, mutationOptions);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
logger_1.default.error(`Failed to delete collection "${collection}" due to relation "${relation.collection}.${relation.field}"`);
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// clean up deleted relations from existing schema
|
|
81
|
+
schema.relations = schema.relations.filter((r) => r.related_collection !== collection && r.collection !== collection);
|
|
82
|
+
}
|
|
83
|
+
await deleteCollections(getNestedCollectionsToDelete(collection));
|
|
84
|
+
try {
|
|
85
|
+
await collectionsService.deleteOne(collection, mutationOptions);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
logger_1.default.error(`Failed to delete collection "${collection}"`);
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Finds all collections that need to be created
|
|
95
|
+
const filterCollectionsForCreation = ({ diff }) => {
|
|
96
|
+
// Check new collections only
|
|
97
|
+
const isNewCollection = diff[0].kind === types_1.DiffKind.NEW;
|
|
98
|
+
if (!isNewCollection)
|
|
99
|
+
return false;
|
|
100
|
+
// Create now if no group
|
|
101
|
+
const groupName = diff[0].rhs.meta?.group;
|
|
102
|
+
if (!groupName)
|
|
103
|
+
return true;
|
|
104
|
+
// Check if parent collection already exists in schema
|
|
105
|
+
const parentExists = currentSnapshot.collections.find((c) => c.collection === groupName) !== undefined;
|
|
106
|
+
// If this is a new collection and the parent collection doesn't exist in current schema ->
|
|
107
|
+
// Check if the parent collection will be created as part of applying this snapshot ->
|
|
108
|
+
// If yes -> this collection will be created recursively
|
|
109
|
+
// If not -> create now
|
|
110
|
+
// (ex.)
|
|
111
|
+
// TopLevelCollection - I exist in current schema
|
|
112
|
+
// NestedCollection - I exist in snapshotDiff as a new collection
|
|
113
|
+
// TheCurrentCollectionInIteration - I exist in snapshotDiff as a new collection but will be created as part of NestedCollection
|
|
114
|
+
const parentWillBeCreatedInThisApply = snapshotDiff.collections.filter(({ collection, diff }) => diff[0].kind === types_1.DiffKind.NEW && collection === groupName).length > 0;
|
|
115
|
+
// Has group, but parent is not new, parent is also not being created in this snapshot apply
|
|
116
|
+
if (parentExists && !parentWillBeCreatedInThisApply)
|
|
117
|
+
return true;
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
// Create top level collections (no group, or highest level in existing group) first,
|
|
121
|
+
// then continue with nested collections recursively
|
|
122
|
+
await createCollections(snapshotDiff.collections.filter(filterCollectionsForCreation));
|
|
123
|
+
// delete top level collections (no group) first, then continue with nested collections recursively
|
|
124
|
+
await deleteCollections(snapshotDiff.collections.filter(({ diff }) => diff[0].kind === types_1.DiffKind.DELETE && diff[0].lhs.meta?.group === null));
|
|
125
|
+
for (const { collection, diff } of snapshotDiff.collections) {
|
|
126
|
+
if (diff?.[0].kind === types_1.DiffKind.EDIT || diff?.[0].kind === types_1.DiffKind.ARRAY) {
|
|
127
|
+
const currentCollection = currentSnapshot.collections.find((field) => {
|
|
128
|
+
return field.collection === collection;
|
|
129
|
+
});
|
|
130
|
+
if (currentCollection) {
|
|
131
|
+
try {
|
|
132
|
+
const newValues = diff.reduce((acc, currentDiff) => {
|
|
133
|
+
(0, deep_diff_1.applyChange)(acc, undefined, currentDiff);
|
|
134
|
+
return acc;
|
|
135
|
+
}, (0, lodash_1.cloneDeep)(currentCollection));
|
|
136
|
+
await collectionsService.updateOne(collection, newValues, mutationOptions);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
logger_1.default.error(`Failed to update collection "${collection}"`);
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const fieldsService = new services_1.FieldsService({
|
|
146
|
+
knex: trx,
|
|
147
|
+
schema: await (0, get_schema_1.getSchema)({ database: trx, bypassCache: true }),
|
|
148
|
+
});
|
|
149
|
+
for (const { collection, field, diff } of snapshotDiff.fields) {
|
|
150
|
+
if (diff?.[0].kind === types_1.DiffKind.NEW && !isNestedMetaUpdate(diff?.[0])) {
|
|
151
|
+
try {
|
|
152
|
+
await fieldsService.createField(collection, diff[0].rhs, undefined, mutationOptions);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
logger_1.default.error(`Failed to create field "${collection}.${field}"`);
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (diff?.[0].kind === types_1.DiffKind.EDIT || diff?.[0].kind === types_1.DiffKind.ARRAY || isNestedMetaUpdate(diff?.[0])) {
|
|
160
|
+
const currentField = currentSnapshot.fields.find((snapshotField) => {
|
|
161
|
+
return snapshotField.collection === collection && snapshotField.field === field;
|
|
162
|
+
});
|
|
163
|
+
if (currentField) {
|
|
164
|
+
try {
|
|
165
|
+
const newValues = diff.reduce((acc, currentDiff) => {
|
|
166
|
+
(0, deep_diff_1.applyChange)(acc, undefined, currentDiff);
|
|
167
|
+
return acc;
|
|
168
|
+
}, (0, lodash_1.cloneDeep)(currentField));
|
|
169
|
+
await fieldsService.updateField(collection, newValues, mutationOptions);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
logger_1.default.error(`Failed to update field "${collection}.${field}"`);
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (diff?.[0].kind === types_1.DiffKind.DELETE && !isNestedMetaUpdate(diff?.[0])) {
|
|
178
|
+
try {
|
|
179
|
+
await fieldsService.deleteField(collection, field, mutationOptions);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
logger_1.default.error(`Failed to delete field "${collection}.${field}"`);
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
185
|
+
// Field deletion also cleans up the relationship. We should ignore any relationship
|
|
186
|
+
// changes attached to this now non-existing field
|
|
187
|
+
snapshotDiff.relations = snapshotDiff.relations.filter((relation) => (relation.collection === collection && relation.field === field) === false);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const relationsService = new services_1.RelationsService({
|
|
191
|
+
knex: trx,
|
|
192
|
+
schema: await (0, get_schema_1.getSchema)({ database: trx, bypassCache: true }),
|
|
193
|
+
});
|
|
194
|
+
for (const { collection, field, diff } of snapshotDiff.relations) {
|
|
195
|
+
const structure = {};
|
|
196
|
+
for (const diffEdit of diff) {
|
|
197
|
+
(0, lodash_1.set)(structure, diffEdit.path, undefined);
|
|
198
|
+
}
|
|
199
|
+
if (diff?.[0].kind === types_1.DiffKind.NEW) {
|
|
200
|
+
try {
|
|
201
|
+
await relationsService.createOne(diff[0].rhs, mutationOptions);
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
logger_1.default.error(`Failed to create relation "${collection}.${field}"`);
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (diff?.[0].kind === types_1.DiffKind.EDIT || diff?.[0].kind === types_1.DiffKind.ARRAY) {
|
|
209
|
+
const currentRelation = currentSnapshot.relations.find((relation) => {
|
|
210
|
+
return relation.collection === collection && relation.field === field;
|
|
211
|
+
});
|
|
212
|
+
if (currentRelation) {
|
|
213
|
+
try {
|
|
214
|
+
const newValues = diff.reduce((acc, currentDiff) => {
|
|
215
|
+
(0, deep_diff_1.applyChange)(acc, undefined, currentDiff);
|
|
216
|
+
return acc;
|
|
217
|
+
}, (0, lodash_1.cloneDeep)(currentRelation));
|
|
218
|
+
await relationsService.updateOne(collection, field, newValues, mutationOptions);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
logger_1.default.error(`Failed to update relation "${collection}.${field}"`);
|
|
222
|
+
throw err;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (diff?.[0].kind === types_1.DiffKind.DELETE) {
|
|
227
|
+
try {
|
|
228
|
+
await relationsService.deleteOne(collection, field, mutationOptions);
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
logger_1.default.error(`Failed to delete relation "${collection}.${field}"`);
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
await (0, cache_1.clearSystemCache)();
|
|
238
|
+
if (nestedActionEvents.length > 0) {
|
|
239
|
+
const updatedSchema = await (0, get_schema_1.getSchema)({ database, bypassCache: true });
|
|
240
|
+
for (const nestedActionEvent of nestedActionEvents) {
|
|
241
|
+
nestedActionEvent.context.schema = updatedSchema;
|
|
242
|
+
emitter_1.default.emitAction(nestedActionEvent.event, nestedActionEvent.meta, nestedActionEvent.context);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.applyDiff = applyDiff;
|
|
247
|
+
function isNestedMetaUpdate(diff) {
|
|
248
|
+
if (!diff)
|
|
249
|
+
return false;
|
|
250
|
+
if (diff.kind !== types_1.DiffKind.NEW && diff.kind !== types_1.DiffKind.DELETE)
|
|
251
|
+
return false;
|
|
252
|
+
if (!diff.path || diff.path.length < 2 || diff.path[0] !== 'meta')
|
|
253
|
+
return false;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
exports.isNestedMetaUpdate = isNestedMetaUpdate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Aggregate, Filter, Query, SchemaOverview } from '@directus/shared/types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
1
|
+
import type { Aggregate, Filter, Query, SchemaOverview } from '@directus/shared/types';
|
|
2
|
+
import type { Knex } from 'knex';
|
|
3
3
|
import { AliasMap } from './get-column-path';
|
|
4
4
|
export declare const generateAlias: (size?: number | undefined) => string;
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ export declare const generateAlias: (size?: number | undefined) => string;
|
|
|
8
8
|
export default function applyQuery(knex: Knex, collection: string, dbQuery: Knex.QueryBuilder, query: Query, schema: SchemaOverview, options?: {
|
|
9
9
|
aliasMap?: AliasMap;
|
|
10
10
|
isInnerQuery?: boolean;
|
|
11
|
-
hasMultiRelationalSort?: boolean;
|
|
11
|
+
hasMultiRelationalSort?: boolean | undefined;
|
|
12
12
|
}): {
|
|
13
13
|
query: Knex.QueryBuilder<any, any>;
|
|
14
14
|
hasMultiRelationalFilter: boolean;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.applyAggregate = exports.applySearch = exports.applyFilter = exports.applyOffset = exports.applyLimit = exports.applySort = exports.generateAlias = void 0;
|
|
7
|
+
const utils_1 = require("@directus/shared/utils");
|
|
7
8
|
const lodash_1 = require("lodash");
|
|
8
9
|
const uuid_validate_1 = __importDefault(require("uuid-validate"));
|
|
9
10
|
const helpers_1 = require("../database/helpers");
|
|
@@ -11,7 +12,6 @@ const invalid_query_1 = require("../exceptions/invalid-query");
|
|
|
11
12
|
const get_column_1 = require("./get-column");
|
|
12
13
|
const get_column_path_1 = require("./get-column-path");
|
|
13
14
|
const get_relation_info_1 = require("./get-relation-info");
|
|
14
|
-
const utils_1 = require("@directus/shared/utils");
|
|
15
15
|
const strip_function_1 = require("./strip-function");
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
const non_secure_1 = require("nanoid/non-secure");
|
|
@@ -20,18 +20,17 @@ exports.generateAlias = (0, non_secure_1.customAlphabet)('abcdefghijklmnopqrstuv
|
|
|
20
20
|
* Apply the Query to a given Knex query builder instance
|
|
21
21
|
*/
|
|
22
22
|
function applyQuery(knex, collection, dbQuery, query, schema, options) {
|
|
23
|
-
|
|
24
|
-
const aliasMap = (_a = options === null || options === void 0 ? void 0 : options.aliasMap) !== null && _a !== void 0 ? _a : Object.create(null);
|
|
23
|
+
const aliasMap = options?.aliasMap ?? Object.create(null);
|
|
25
24
|
let hasMultiRelationalFilter = false;
|
|
26
|
-
if (query.sort && !(options === null || options === void 0 ? void 0 : options.isInnerQuery) && !(options === null || options === void 0 ? void 0 : options.hasMultiRelationalSort)) {
|
|
27
|
-
applySort(knex, schema, dbQuery, query.sort, collection, aliasMap);
|
|
28
|
-
}
|
|
29
25
|
applyLimit(knex, dbQuery, query.limit);
|
|
30
26
|
if (query.offset) {
|
|
31
27
|
applyOffset(knex, dbQuery, query.offset);
|
|
32
28
|
}
|
|
33
29
|
if (query.page && query.limit && query.limit !== -1) {
|
|
34
|
-
dbQuery
|
|
30
|
+
applyOffset(knex, dbQuery, query.limit * (query.page - 1));
|
|
31
|
+
}
|
|
32
|
+
if (query.sort && !options?.isInnerQuery && !options?.hasMultiRelationalSort) {
|
|
33
|
+
applySort(knex, schema, dbQuery, query.sort, collection, aliasMap);
|
|
35
34
|
}
|
|
36
35
|
if (query.search) {
|
|
37
36
|
applySearch(schema, dbQuery, query.search, collection);
|
|
@@ -54,7 +53,6 @@ function addJoin({ path, collection, aliasMap, rootQuery, schema, relations, kne
|
|
|
54
53
|
followRelation(path);
|
|
55
54
|
return hasMultiRelational;
|
|
56
55
|
function followRelation(pathParts, parentCollection = collection, parentFields) {
|
|
57
|
-
var _a, _b, _c;
|
|
58
56
|
/**
|
|
59
57
|
* For A2M fields, the path can contain an optional collection scope <field>:<scope>
|
|
60
58
|
*/
|
|
@@ -64,12 +62,12 @@ function addJoin({ path, collection, aliasMap, rootQuery, schema, relations, kne
|
|
|
64
62
|
return;
|
|
65
63
|
}
|
|
66
64
|
const existingAlias = parentFields
|
|
67
|
-
?
|
|
68
|
-
:
|
|
65
|
+
? aliasMap[`${parentFields}.${pathParts[0]}`]?.alias
|
|
66
|
+
: aliasMap[pathParts[0]]?.alias;
|
|
69
67
|
if (!existingAlias) {
|
|
70
68
|
const alias = (0, exports.generateAlias)();
|
|
71
69
|
const aliasKey = parentFields ? `${parentFields}.${pathParts[0]}` : pathParts[0];
|
|
72
|
-
const aliasedParentCollection =
|
|
70
|
+
const aliasedParentCollection = aliasMap[parentFields ?? '']?.alias || parentCollection;
|
|
73
71
|
aliasMap[aliasKey] = { alias, collection: '' };
|
|
74
72
|
if (relationType === 'm2o') {
|
|
75
73
|
rootQuery.leftJoin({ [alias]: relation.related_collection }, `${aliasedParentCollection}.${relation.field}`, `${alias}.${schema.collections[relation.related_collection].primary}`);
|
|
@@ -136,7 +134,7 @@ function applySort(knex, schema, rootQuery, rootSort, collection, aliasMap, retu
|
|
|
136
134
|
if (column.length === 1) {
|
|
137
135
|
const pathRoot = column[0].split(':')[0];
|
|
138
136
|
const { relation, relationType } = (0, get_relation_info_1.getRelationInfo)(relations, collection, pathRoot);
|
|
139
|
-
if (!relation || ['m2o', 'a2o'].includes(relationType
|
|
137
|
+
if (!relation || ['m2o', 'a2o'].includes(relationType ?? '')) {
|
|
140
138
|
return {
|
|
141
139
|
order,
|
|
142
140
|
column: returnRecords ? column[0] : (0, get_column_1.getColumn)(knex, collection, column[0], false, schema),
|
|
@@ -170,6 +168,8 @@ function applySort(knex, schema, rootQuery, rootSort, collection, aliasMap, retu
|
|
|
170
168
|
});
|
|
171
169
|
if (returnRecords)
|
|
172
170
|
return { sortRecords, hasMultiRelationalSort };
|
|
171
|
+
// Clears the order if any, eg: from MSSQL offset
|
|
172
|
+
rootQuery.clear('order');
|
|
173
173
|
rootQuery.orderBy(sortRecords);
|
|
174
174
|
}
|
|
175
175
|
exports.applySort = applySort;
|
|
@@ -223,7 +223,6 @@ function applyFilter(knex, schema, rootQuery, rootFilter, collection, aliasMap)
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
function addWhereClauses(knex, dbQuery, filter, collection, logical = 'and') {
|
|
226
|
-
var _a;
|
|
227
226
|
for (const [key, value] of Object.entries(filter)) {
|
|
228
227
|
if (key === '_or' || key === '_and') {
|
|
229
228
|
// If the _or array contains an empty object (full permissions), we should short-circuit and ignore all other
|
|
@@ -265,7 +264,7 @@ function applyFilter(knex, schema, rootQuery, rootFilter, collection, aliasMap)
|
|
|
265
264
|
.whereNotNull(column);
|
|
266
265
|
applyQuery(knex, relation.collection, subQueryKnex, { filter }, schema);
|
|
267
266
|
};
|
|
268
|
-
const childKey =
|
|
267
|
+
const childKey = Object.keys(value)?.[0];
|
|
269
268
|
if (childKey === '_none') {
|
|
270
269
|
dbQuery[logical].whereNotIn(pkField, subQueryBuilder(Object.values(value)[0]));
|
|
271
270
|
continue;
|
|
@@ -333,12 +332,12 @@ function applyFilter(knex, schema, rootQuery, rootFilter, collection, aliasMap)
|
|
|
333
332
|
}
|
|
334
333
|
if (operator === '_empty' || (operator === '_nempty' && compareValue === false)) {
|
|
335
334
|
dbQuery[logical].andWhere((query) => {
|
|
336
|
-
query.
|
|
335
|
+
query.whereNull(key).orWhere(key, '=', '');
|
|
337
336
|
});
|
|
338
337
|
}
|
|
339
338
|
if (operator === '_nempty' || (operator === '_empty' && compareValue === false)) {
|
|
340
339
|
dbQuery[logical].andWhere((query) => {
|
|
341
|
-
query.
|
|
340
|
+
query.whereNotNull(key).orWhere(key, '!=', '');
|
|
342
341
|
});
|
|
343
342
|
}
|
|
344
343
|
// The following fields however, require a value to be run. If no value is passed, we
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { SchemaOverview } from '@directus/shared/types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Snapshot, SnapshotDiff, SnapshotField } from '../types';
|
|
1
|
+
import type { SchemaOverview } from '@directus/shared/types';
|
|
2
|
+
import type { Knex } from 'knex';
|
|
3
|
+
import type { Snapshot, SnapshotDiff } from '../types';
|
|
5
4
|
export declare function applySnapshot(snapshot: Snapshot, options?: {
|
|
6
5
|
database?: Knex;
|
|
7
6
|
schema?: SchemaOverview;
|
|
8
7
|
current?: Snapshot;
|
|
9
8
|
diff?: SnapshotDiff;
|
|
10
9
|
}): Promise<void>;
|
|
11
|
-
export declare function isNestedMetaUpdate(diff: Diff<SnapshotField | undefined>): boolean;
|