MCPcopy Index your code
hub / github.com/fastify/fast-json-stringify / build

Function build

index.js:105–243  ·  view source on GitHub ↗
(schema, options)

Source from the content-addressed store, hash-verified

103}
104
105function 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

Callers

nothing calls this directly

Calls 6

addSchemaMethod · 0.95
isValidSchemaFunction · 0.85
getSchemaIdFunction · 0.85
detectRecursiveSchemasFunction · 0.85
buildValueFunction · 0.85
buildStandaloneCodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…