{"version":3,"file":"derivations.mjs","names":[],"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,QAAO,gBAAgB,KAAK,gBAAgB,iBAAiB,KAAK,KAAK,gBAAgB,KAAK,OAAO,OAAO,OAAO,CAAC,EAAE,KAAK,IAAI,YAAY,SAAS,gBAAgB,OAAO,gBAAgB,KAAK,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;;;;;AAK3N,SAAgB,cAAc,GAAG,CAAC,QAAQ;AACtC,QAAO,gBAAgB,QAAQ,MAAM;;;;;AAKzC,SAAgB,aAAa,GAAG,CAAC,gBAAgB,gBAAgB,aAAa,cAAc;CACxF,MAAM,kBAAkB,QAAQ,YAAY;CAC5C,IAAI,qBAAqB,gBAAgB,KAAK,QAE9C,gBAAgB,wBAAwB,KAAK,eAAe,KAAK,KAAK,OAAO,KAAK,CAAC,CAAC,QAAQ,eAAe,CAAC;CAC5G,MAAM,kBAAkB,YAAY,KAAK,EAAE,KAAK,YAAY,gBAAgB,qBAAqB,IAAI,KAAK,MAAM,KAAK,MAAM,CAAC;AAC5H,KAAI,eACA,sBAAqB,gBAAgB,OAErC,gBAAgB,KAAK,QAAQ,gBAAgB,wBAAwB,KAAK,eAAe,KAAK,KAAK,MAAM,KAAK,CAAC,CAAC,QAAQ,eAAe,CAAC,CAAC,CAAC,mBAAmB;CAEjK,MAAM,SAAS,gBAAgB,KAAK,gBAAgB,kBAAkB,oBAAoB,gBAAgB,KAAK,gBAAgB,CAAC,CAAC;AACjI,KAAI,gBAAgB,QAAQ,gBAAgB,CACxC,QAAO;AAEX,sBAAqB,OAAO,IAAI;CAChC,MAAM,OAAO,g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