(schema, options)
| 103 | } |
| 104 | |
| 105 | function build (schema, options) { |
| 106 | isValidSchema(schema) |
| 107 | |
| 108 | options = options || {} |
| 109 | |
| 110 | const context = { |
| 111 | functions: [], |
| 112 | functionsCounter: 0, |
| 113 | functionsNamesBySchema: new Map(), |
| 114 | options, |
| 115 | refResolver: new RefResolver(), |
| 116 | rootSchemaId: schema.$id || `__fjs_root_${schemaIdCounter++}`, |
| 117 | validatorSchemasIds: new Set(), |
| 118 | mergedSchemasIds: new Map(), |
| 119 | recursiveSchemas: new Set(), |
| 120 | recursivePaths: new Set(), |
| 121 | buildingSet: new Set(), |
| 122 | uid: 0 |
| 123 | } |
| 124 | |
| 125 | const schemaId = getSchemaId(schema, context.rootSchemaId) |
| 126 | if (!context.refResolver.hasSchema(schemaId)) { |
| 127 | context.refResolver.addSchema(schema, context.rootSchemaId) |
| 128 | } |
| 129 | |
| 130 | if (options.schema) { |
| 131 | for (const key in options.schema) { |
| 132 | const schema = options.schema[key] |
| 133 | const schemaId = getSchemaId(schema, key) |
| 134 | if (!context.refResolver.hasSchema(schemaId)) { |
| 135 | isValidSchema(schema, key) |
| 136 | context.refResolver.addSchema(schema, key) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (options.rounding) { |
| 142 | if (!validRoundingMethods.has(options.rounding)) { |
| 143 | throw new Error(`Unsupported integer rounding method ${options.rounding}`) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (options.largeArrayMechanism) { |
| 148 | if (validLargeArrayMechanisms.has(options.largeArrayMechanism)) { |
| 149 | largeArrayMechanism = options.largeArrayMechanism |
| 150 | } else { |
| 151 | throw new Error(`Unsupported large array mechanism ${options.largeArrayMechanism}`) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if (options.largeArraySize) { |
| 156 | const largeArraySizeType = typeof options.largeArraySize |
| 157 | let parsedNumber |
| 158 | |
| 159 | if (largeArraySizeType === 'string' && Number.isFinite((parsedNumber = Number.parseInt(options.largeArraySize, 10)))) { |
| 160 | largeArraySize = parsedNumber |
| 161 | } else if (largeArraySizeType === 'number' && Number.isInteger(options.largeArraySize)) { |
| 162 | largeArraySize = options.largeArraySize |
nothing calls this directly
no test coverage detected
searching dependent graphs…