• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mia-platform / crud-service / 6650818505

26 Oct 2023 07:24AM UTC coverage: 96.95% (+2.6%) from 94.301%
6650818505

push

github

web-flow
fix: review of ci to update to NodeJS v20 (#211)

* ci: update setup-node action to v4

* ci: separate tests of previous MongoDB versions from v7

* ci: update setup-node action to v4

* ci: set a fixed version for coverall github action

* ci: fix coverallapps version

1645 of 1787 branches covered (0.0%)

Branch coverage included in aggregate %.

8494 of 8671 relevant lines covered (97.96%)

6911.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.53
/lib/generatePathFieldsForRawSchema.js
1
/* eslint-disable no-underscore-dangle */
97✔
2
/*
97✔
3
 * Copyright 2023 Mia s.r.l.
97✔
4
 *
97✔
5
 * Licensed under the Apache License, Version 2.0 (the "License");
97✔
6
 * you may not use this file except in compliance with the License.
97✔
7
 * You may obtain a copy of the License at
97✔
8
 *
97✔
9
 *     http://www.apache.org/licenses/LICENSE-2.0
97✔
10
 *
97✔
11
 * Unless required by applicable law or agreed to in writing, software
97✔
12
 * distributed under the License is distributed on an "AS IS" BASIS,
97✔
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
97✔
14
 * See the License for the specific language governing permissions and
97✔
15
 * limitations under the License.
97✔
16
 */
97✔
17

97✔
18
'use strict'
97✔
19

97✔
20
const {
97✔
21
  ARRAY,
97✔
22
  RAWOBJECTTYPE,
97✔
23
  JSON_SCHEMA_ARRAY_TYPE,
97✔
24
  JSON_SCHEMA_OBJECT_TYPE,
97✔
25
} = require('./consts')
97✔
26
const generatePathFromJsonSchema = require('./generatePathFromJsonSchema')
97✔
27

97✔
28
function getFieldJsonSchemaByTypeCompatibility(field) {
1,948✔
29
  if (field.type === ARRAY) {
1,948✔
30
    return {
850✔
31
      type: JSON_SCHEMA_ARRAY_TYPE,
850✔
32
      items: {
850✔
33
        type: JSON_SCHEMA_OBJECT_TYPE,
850✔
34
        properties: field.items.schema.properties,
850✔
35
        additionalProperties: field.items.schema.additionalProperties,
850✔
36
      },
850✔
37
    }
850✔
38
  }
850✔
39
  return {
1,098✔
40
    type: JSON_SCHEMA_OBJECT_TYPE,
1,098✔
41
    properties: field.schema.properties,
1,098✔
42
    additionalProperties: field.schema.additionalProperties,
1,098✔
43
  }
1,098✔
44
}
1,948✔
45

97✔
46
function getFieldJsonSchemaByType(jsonSchema) {
78✔
47
  if (jsonSchema.type === JSON_SCHEMA_ARRAY_TYPE) {
78✔
48
    return {
18✔
49
      type: JSON_SCHEMA_ARRAY_TYPE,
18✔
50
      items: {
18✔
51
        type: JSON_SCHEMA_OBJECT_TYPE,
18✔
52
        properties: jsonSchema.items.properties,
18✔
53
        additionalProperties: jsonSchema.items.additionalProperties,
18✔
54
      },
18✔
55
    }
18✔
56
  }
18✔
57
  return {
60✔
58
    type: JSON_SCHEMA_OBJECT_TYPE,
60✔
59
    properties: jsonSchema.properties,
60✔
60
    additionalProperties: jsonSchema.additionalProperties,
60✔
61
  }
60✔
62
}
78✔
63

97✔
64
const generatePathFieldsForRawSchemaCompatibility = (logger, collectionDefinition) => collectionDefinition
97✔
65
  .fields
3,707✔
66
  .filter(field => {
3,707✔
67
    const isObjectWithRawSchema = field.type === RAWOBJECTTYPE && field.schema
40,480✔
68
    const isArrayOfRawObjectWithRawSchema = field.type === ARRAY
40,480✔
69
        && field.items.type === RAWOBJECTTYPE
40,480✔
70
        && field.items.schema
40,480✔
71

40,480✔
72
    return isObjectWithRawSchema || isArrayOfRawObjectWithRawSchema
40,480✔
73
  })
3,707✔
74
  .reduce((acc, field) => {
3,707✔
75
    const jsonSchema = {
1,948✔
76
      type: JSON_SCHEMA_OBJECT_TYPE,
1,948✔
77
      properties: {
1,948✔
78
        [field.name]: getFieldJsonSchemaByTypeCompatibility(field),
1,948✔
79
      },
1,948✔
80
    }
1,948✔
81
    let generatedForFields = {}
1,948✔
82
    try {
1,948✔
83
      generatedForFields = generatePathFromJsonSchema(jsonSchema)
1,948✔
84
    } catch (error) {
1,948✔
85
      logger.error(
3✔
86
        { collectionName: collectionDefinition.name, field: field.name },
3✔
87
        error.message
3✔
88
      )
3✔
89
      throw error
3✔
90
    }
3✔
91
    return {
1,945✔
92
      paths: {
1,945✔
93
        ...acc.paths,
1,945✔
94
        ...generatedForFields.paths,
1,945✔
95
      },
1,945✔
96
      patternProperties: {
1,945✔
97
        ...acc.patternProperties,
1,945✔
98
        ...generatedForFields.patternProperties,
1,945✔
99
      },
1,945✔
100
      pathsOperators: {
1,945✔
101
        ...acc.pathsOperators,
1,945✔
102
        ...generatedForFields.pathsOperators,
1,945✔
103
      },
1,945✔
104
      patternPropertiesOperators: {
1,945✔
105
        ...acc.patternPropertiesOperators,
1,945✔
106
        ...generatedForFields.patternPropertiesOperators,
1,945✔
107
      },
1,945✔
108
    }
1,945✔
109
  }, {
3,707✔
110
    paths: {},
3,707✔
111
    patternProperties: {},
3,707✔
112
    pathsOperators: {},
3,707✔
113
    patternPropertiesOperators: {},
3,707✔
114
  })
3,707✔
115

97✔
116
module.exports = function generatePathFieldsForRawSchema(logger, collectionDefinition) {
97✔
117
  if (!collectionDefinition.schema) {
3,750✔
118
    return generatePathFieldsForRawSchemaCompatibility(logger, collectionDefinition)
3,707✔
119
  }
3,707✔
120

43✔
121
  return Object
43✔
122
    .entries(collectionDefinition.schema.properties)
43✔
123
    .filter(([, jsonSchema]) => {
43✔
124
      if (jsonSchema.__mia_configuration?.type) { return false }
590✔
125
      const isObject = jsonSchema.type === JSON_SCHEMA_OBJECT_TYPE
518✔
126
      const isArrayOfObject = jsonSchema.type === JSON_SCHEMA_ARRAY_TYPE
518✔
127
        && jsonSchema.items.type === JSON_SCHEMA_OBJECT_TYPE
590✔
128
        && Boolean(jsonSchema.items.properties)
590✔
129

590✔
130
      return isObject || isArrayOfObject
590✔
131
    })
43✔
132
    .reduce((acc, [propertyName, propertyJsonSchema]) => {
43✔
133
      const jsonSchema = {
78✔
134
        type: JSON_SCHEMA_OBJECT_TYPE,
78✔
135
        properties: {
78✔
136
          [propertyName]: getFieldJsonSchemaByType(propertyJsonSchema),
78✔
137
        },
78✔
138
      }
78✔
139
      let generatedForFields = {}
78✔
140
      try {
78✔
141
        generatedForFields = generatePathFromJsonSchema(jsonSchema)
78✔
142
      } catch (error) {
78!
143
        logger.error(
×
144
          { collectionName: collectionDefinition.name, field: propertyName },
×
145
          error.message
×
146
        )
×
147
        throw error
×
148
      }
×
149
      return {
78✔
150
        paths: {
78✔
151
          ...acc.paths,
78✔
152
          ...generatedForFields.paths,
78✔
153
        },
78✔
154
        patternProperties: {
78✔
155
          ...acc.patternProperties,
78✔
156
          ...generatedForFields.patternProperties,
78✔
157
        },
78✔
158
        pathsOperators: {
78✔
159
          ...acc.pathsOperators,
78✔
160
          ...generatedForFields.pathsOperators,
78✔
161
        },
78✔
162
        patternPropertiesOperators: {
78✔
163
          ...acc.patternPropertiesOperators,
78✔
164
          ...generatedForFields.patternPropertiesOperators,
78✔
165
        },
78✔
166
      }
78✔
167
    }, {
43✔
168
      paths: {},
43✔
169
      patternProperties: {},
43✔
170
      pathsOperators: {},
43✔
171
      patternPropertiesOperators: {},
43✔
172
    })
43✔
173
}
3,750✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc