11/*
22 * @moleculer /database
3- * Copyright (c) 2022 MoleculerJS (https://github.com/moleculerjs/database)
3+ * Copyright (c) 2024 MoleculerJS (https://github.com/moleculerjs/database)
44 * MIT Licensed
55 */
66
77"use strict" ;
88
9+ const { isisActionEnabled } = require ( "./schema" ) ;
10+
911const PARAMS_FIELDS = [
1012 { type : "string" , optional : true } ,
1113 { type : "array" , optional : true , items : "string" }
@@ -52,13 +54,6 @@ module.exports = function (mixinOpts) {
5254 return null ;
5355 } ;
5456
55- const actionEnabled = name => {
56- if ( typeof mixinOpts . createActions == "object" ) {
57- return mixinOpts . createActions [ name ] !== false ;
58- }
59- return mixinOpts . createActions !== false ;
60- } ;
61-
6257 /**
6358 * Find entities by query.
6459 *
@@ -77,7 +72,7 @@ module.exports = function (mixinOpts) {
7772 *
7873 * @returns {Array<Object> } List of found entities.
7974 */
80- if ( actionEnabled ( "find" ) ) {
75+ if ( isActionEnabled ( mixinOpts , "find" ) ) {
8176 res . find = {
8277 visibility : mixinOpts . actionVisibility ,
8378 rest : mixinOpts . rest ? "GET /all" : null ,
@@ -131,7 +126,7 @@ module.exports = function (mixinOpts) {
131126 *
132127 * @returns {Number } Count of found entities.
133128 */
134- if ( actionEnabled ( "count" ) ) {
129+ if ( isActionEnabled ( mixinOpts , "count" ) ) {
135130 res . count = {
136131 visibility : mixinOpts . actionVisibility ,
137132 rest : mixinOpts . rest ? "GET /count" : null ,
@@ -166,7 +161,7 @@ module.exports = function (mixinOpts) {
166161 *
167162 * @returns {Object } List of found entities and total count.
168163 */
169- if ( actionEnabled ( "list" ) ) {
164+ if ( isActionEnabled ( mixinOpts , "list" ) ) {
170165 res . list = {
171166 visibility : mixinOpts . actionVisibility ,
172167 rest : mixinOpts . rest ? "GET /" : null ,
@@ -237,7 +232,7 @@ module.exports = function (mixinOpts) {
237232 *
238233 * @throws {EntityNotFoundError } - 404 Entity not found
239234 */
240- if ( actionEnabled ( "get" ) ) {
235+ if ( isActionEnabled ( mixinOpts , "get" ) ) {
241236 res . get = {
242237 visibility : mixinOpts . actionVisibility ,
243238 rest : mixinOpts . rest ? "GET /:id" : null ,
@@ -270,7 +265,7 @@ module.exports = function (mixinOpts) {
270265 *
271266 * @throws {EntityNotFoundError } - 404 Entity not found
272267 */
273- if ( actionEnabled ( "resolve" ) ) {
268+ if ( isActionEnabled ( mixinOpts , "resolve" ) ) {
274269 res . resolve = {
275270 visibility : mixinOpts . actionVisibility ,
276271 cache : generateCacheOptions ( [
@@ -307,7 +302,7 @@ module.exports = function (mixinOpts) {
307302 *
308303 * @returns {Object } Saved entity.
309304 */
310- if ( actionEnabled ( "create" ) ) {
305+ if ( isActionEnabled ( mixinOpts , "create" ) ) {
311306 res . create = {
312307 visibility : mixinOpts . actionVisibility ,
313308 rest : mixinOpts . rest ? "POST /" : null ,
@@ -325,7 +320,7 @@ module.exports = function (mixinOpts) {
325320 *
326321 * @returns {Array<Object> } Saved entities.
327322 */
328- if ( actionEnabled ( "createMany" ) ) {
323+ if ( isActionEnabled ( mixinOpts , "createMany" ) ) {
329324 res . createMany = {
330325 visibility : mixinOpts . actionVisibility ,
331326 rest : null ,
@@ -345,7 +340,7 @@ module.exports = function (mixinOpts) {
345340 *
346341 * @throws {EntityNotFoundError } - 404 Entity not found
347342 */
348- if ( actionEnabled ( "update" ) ) {
343+ if ( isActionEnabled ( mixinOpts , "update" ) ) {
349344 res . update = {
350345 visibility : mixinOpts . actionVisibility ,
351346 rest : mixinOpts . rest ? "PATCH /:id" : null ,
@@ -365,7 +360,7 @@ module.exports = function (mixinOpts) {
365360 *
366361 * @throws {EntityNotFoundError } - 404 Entity not found
367362 */
368- if ( actionEnabled ( "replace" ) ) {
363+ if ( isActionEnabled ( mixinOpts , "replace" ) ) {
369364 res . replace = {
370365 visibility : mixinOpts . actionVisibility ,
371366 rest : mixinOpts . rest ? "PUT /:id" : null ,
@@ -386,7 +381,7 @@ module.exports = function (mixinOpts) {
386381 *
387382 * @throws {EntityNotFoundError } - 404 Entity not found
388383 */
389- if ( actionEnabled ( "remove" ) ) {
384+ if ( isActionEnabled ( mixinOpts , "remove" ) ) {
390385 res . remove = {
391386 visibility : mixinOpts . actionVisibility ,
392387 rest : mixinOpts . rest ? "DELETE /:id" : null ,
0 commit comments