/** * Copyright 2023 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * In js object, json or yaml when you want to represent optional value and still generate a type for it you can use this syntax: * { $$optional: , $$isNil: } */ declare const OPTIONAL = "$$optional"; /** * When `$$isNil == true`, the value is represented as `nil` in aqua but it will still have type inferred from `$$optional` value. */ declare const IS_NIL = "$$isNil"; type EmptyObject = Record; /** * Empty object and empty array are inferred as nil * because there is no way to infer a reasonable aqua type from just an empty object or empty array */ type NilInAqua = undefined | null | EmptyObject | []; /** * This function is used in order to construct optional syntax in js that is converted to optional values in aqua. * * @param value - value to be converted. Can be anything. * @param valueToInferTypeFrom - a fallback that is used by jsToAqua function to infer the type of the value if value is missing (is null, undefined, empty object or empty array) * @returns - js object with special syntax that is converted to optional value in aqua inside jsToAqua function * * @example * const v = makeOptional(1, 1); * // v = { $$optional: 1 } * @example * const v = makeOptional(undefined, 1); * // v = { $$optional: 1, $$isNil: true } * @example * const v = makeOptional(null, 1); * // v = { $$optional: 1, $$isNil: true } */ export declare const makeOptional: (value: NilInAqua | T, valueToInferTypeFrom: T) => { $$optional: T; $$isNil?: boolean; }; export type JsToAquaArg = { valueToConvert: unknown; fileName: string; useF64ForAllNumbers?: boolean; customTypes?: CustomTypes; }; export declare const jsToAqua: ({ valueToConvert, fileName, useF64ForAllNumbers, customTypes, }: JsToAquaArg) => string; type JsToAquaImplArg = { valueToConvert: unknown; fieldName: string; currentNesting: string; useF64ForAllNumbers: boolean; nestingLevel: number; sortedCustomTypes: Array<{ name: string; properties: string; }>; /** * "top" - is a top level type returned from the get() function of the module * "second" - are all the types of objects that are direct children of the top level type. Their names are not prefixed * "rest" - all the types. Their names are prefixed with parent type names */ level: "top" | "second" | "rest"; }; export declare const jsToAquaImpl: ({ valueToConvert, fieldName, currentNesting, useF64ForAllNumbers, nestingLevel, sortedCustomTypes, level, }: JsToAquaImplArg) => { type: string; value: string; typeDefs?: string | undefined; }; export type CustomTypes = Array<{ name: string; properties: Array; }>; export declare function fileToAqua(inputPathArg: string | undefined, outputDirPathArg: string | undefined, useF64ForAllNumbers: boolean, customTypesPath: string | undefined, parseFn: (content: string) => unknown): Promise; export {};