{"version":3,"file":"derivations.cjs","names":["tsplus_module_4","tsplus_module_3","tsplus_module_1","tsplus_module_2","tsplus_module_5","tsplus_module_6","tsplus_module_7","tsplus_module_8"],"sources":["../../esm/Schema/derivations.js"],"sourcesContent":["import * as tsplus_module_1 from \"@fncts/base/collection/immutable/Vector/api\";\nimport * as tsplus_module_2 from \"@fncts/schema/ASTAnnotation\";\nimport * as tsplus_module_3 from \"@fncts/schema/AST\";\nimport * as tsplus_module_4 from \"@fncts/schema/Schema/api\";\nimport * as tsplus_module_5 from \"@fncts/schema/Schema/api/maybe\";\nimport * as tsplus_module_6 from \"@fncts/base/data/Maybe/constructors\";\nimport * as tsplus_module_7 from \"@fncts/base/data/Maybe/definition\";\nimport * as tsplus_module_8 from \"@fncts/base/data/Maybe/api\";\nimport * as tsplus_module_9 from \"@fncts/base/data/function/api\";\nimport { ownKeys } from \"@fncts/schema/utils\";\n/**\n * @tsplus derive fncts.schema.Schema<_> 10\n */\nexport function deriveValidation(...[base, brands]) {\n    return tsplus_module_4.make(tsplus_module_3.createValidation(base.ast, tsplus_module_1.from(Object.values(brands)), base.ast.annotations.annotate(tsplus_module_2.Brand, tsplus_module_1.from(Object.values(brands)))));\n}\n/**\n * @tsplus derive fncts.schema.Schema<_> 20\n */\nexport function deriveLiteral(...[value]) {\n    return tsplus_module_4.literal(value);\n}\n/**\n * @tsplus derive fncts.schema.Schema<_> 20\n */\nexport function deriveStruct(...[requiredFields, optionalFields, maybeFields, indexSchema]) {\n    const maybeFieldsKeys = ownKeys(maybeFields);\n    let propertySignatures = tsplus_module_1.map((key) => \n    // @ts-expect-error\n    tsplus_module_3.createPropertySignature(key, requiredFields[key].ast, false, true))(ownKeys(requiredFields));\n    const indexSignatures = indexSchema.map(({ key, value }) => tsplus_module_3.createIndexSignature(key.ast, value.ast, false));\n    if (optionalFields) {\n        propertySignatures = tsplus_module_1.concat(\n        // @ts-expect-error\n        tsplus_module_1.map((key) => tsplus_module_3.createPropertySignature(key, optionalFields[key].ast, true, true))(ownKeys(optionalFields)))(propertySignatures);\n    }\n    const struct = tsplus_module_4.make(tsplus_module_3.createTypeLiteral(propertySignatures, tsplus_module_1.from(indexSignatures)));\n    if (tsplus_module_1.isEmpty(maybeFieldsKeys)) {\n        return struct;\n    }\n    propertySignatures = struct.ast.propertySignatures;\n    const from = tsplus_module_4.make(tsplus_module_3.createTypeLiteral(tsplus_module_1.concat(tsplus_module_1.map((key) => tsplus_module_3.createPropertySignature(key, \n    // @ts-expect-error\n    tsplus_module_3.createUnion(tsplus_module_1.vector(tsplus_module_3.undefinedKeyword, tsplus_module_3.createLiteral(null), maybeFields[key].ast)), true, true))(maybeFieldsKeys))(propertySignatures), tsplus_module_1.from(indexSignatures)));\n    const to = tsplus_module_4.make(tsplus_module_3.createTypeLiteral(tsplus_module_1.concat(tsplus_module_1.map((key) => \n    // @ts-expect-error\n    tsplus_module_3.createPropertySignature(key, tsplus_module_5.maybe(maybeFields[key]).ast, false, true))(maybeFieldsKeys))(propertySignatures), tsplus_module_1.from(indexSignatures)));\n    return tsplus_module_4.transform(to, (input) => {\n        const output = { ...input };\n        for (const key of maybeFieldsKeys) {\n            output[key] = tsplus_module_6.fromNullable(input[key]);\n        }\n        return output;\n    }, (input) => {\n        const output = { ...input };\n        for (const key of maybeFieldsKeys) {\n            const value = input[key];\n            if (tsplus_module_7.isNothing(value)) {\n                delete output[key];\n                continue;\n            }\n            output[key] = tsplus_module_8.toUndefined(value);\n        }\n        return output;\n    })(from);\n}\n/**\n * @tsplus derive fncts.schema.Schema<_> 10\n */\nexport function deriveTuple(...[components]) {\n    return tsplus_module_4.tuple(...components);\n}\n/**\n * @tsplus derive fncts.schema.Schema lazy\n */\nexport function deriveLazy(f) {\n    let cached;\n    const ast = tsplus_module_3.createLazy(() => {\n        if (!cached) {\n            cached = f(tsplus_module_4.make(ast)).ast;\n        }\n        return cached;\n    });\n    return tsplus_module_4.make(ast);\n}\n/**\n * @tsplus derive fncts.schema.Schema[fncts.ReadonlyArray]<_> 10\n */\nexport function deriveReadonlyArray(...[element]) {\n    return tsplus_module_4.array(element);\n}\n/**\n * @tsplus derive fncts.schema.Schema[fncts.Array]<_> 10\n */\nexport function deriveArray(...[element]) {\n    return tsplus_module_4.mutableArray(element);\n}\n/**\n * @tsplus derive fncts.schema.Schema<_> 15\n */\nexport function deriveRecord(...[keySchema, valueSchema]) {\n    return tsplus_module_4.record(keySchema, valueSchema);\n}\n//# sourceMappingURL=derivations.js.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaA,SAAgB,iBAAiB,GAAG,CAAC,MAAM,SAAS;AAChD,QAAOA,yBAAgB,KAAKC,kBAAgB,iBAAiB,KAAK,KAAKC,4CAAgB,KAAK,OAAO,OAAO,OAAO,CAAC,EAAE,KAAK,IAAI,YAAY,SAASC,4BAAgB,OAAOD,4CAAgB,KAAK,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;;;;;AAK3N,SAAgB,cAAc,GAAG,CAAC,QAAQ;AACtC,QAAOF,yBAAgB,QAAQ,MAAM;;;;;AAKzC,SAAgB,aAAa,GAAG,CAAC,gBAAgB,gBAAgB,aAAa,cAAc;CACxF,MAAM,mBAAA,GAAA,oBAAA,SAA0B,YAAY;CAC5C,IAAI,qBAAqBE,4CAAgB,KAAK,QAE9CD,kBAAgB,wBAAwB,KAAK,eAAe,KAAK,KAAK,OAAO,KAAK,CAAC,EAAA,GAAA,oBAAA,SAAS,eAAe,CAAC;CAC5G,MAAM,kBAAkB,YAAY,KAAK,EAAE,KAAK,YAAYA,kBAAgB,qBAAqB,IAAI,KAAK,MAAM,KAAK,MAAM,CAAC;AAC5H,KAAI,eACA,sBAAqBC,4CAAgB,OAErCA,4CAAgB,KAAK,QAAQD,kBAAgB,wBAAwB,KAAK,eAAe,KAAK,KAAK,MAAM,KAAK,CAAC,EAAA,GAAA,oBAAA,SAAS,eAAe,CAAC,CAAC,CAAC,mBAAmB;CAEjK,MAAM,SAASD,yBAAgB,KAAKC,kBAA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