diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..6c07fef --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,45 @@ +import { Decoder } from 'io-ts'; +import { FSEntity } from './utils/fs'; +import { taskEither } from 'fp-ts'; +import { Either } from 'fp-ts/lib/Either'; +import { ResolveRefContext } from './utils/ref'; +import { Reader } from 'fp-ts/lib/Reader'; +export interface Language { + (documents: Record): Either; +} +export interface GenerateOptions { + /** + * Base directory for the generation task. + * Relative paths provided in the `out` and `spec` options are resolved relative to this path. + * @default current working directory + */ + readonly cwd?: string; + /** + * Path to the output files. + * Relative paths are resolved relative to `cwd`. + */ + readonly out: string; + /** + * Path to the source schema. + * Supports local files and remote URLs, YAML and JSON formats. + * Relative paths are resolved relative to `cwd` + */ + readonly spec: string; + /** + * The `decoder` is used to parse the specification file. In most cases, one of the following decoders should be + * chosen depending on the source format: + * - `SwaggerObject` + * - `OpenapiObjectCodec` + * - `AsyncAPIObjectCodec` + */ + readonly decoder: Decoder; + /** + * The `language` implements the generation of the code from the intermediate format `A` into actual + * file system objects. Most users should import one of the predefined languages: + * - `import { serialize as serializeSwagger2 } from '@devexperts/swagger-codegen-ts/dist/language/typescript/2.0'` + * - `import { serialize as serializeOpenAPI3 } from '@devexperts/swagger-codegen-ts/dist/language/typescript/3.0'` + * - `import { serialize as serializeAsyncAPI } from '@devexperts/swagger-codegen-ts/dist/language/typescript/asyncapi-2.0.0'` + */ + readonly language: Reader>; +} +export declare const generate: (options: GenerateOptions) => taskEither.TaskEither; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..b71e79d --- /dev/null +++ b/dist/index.js @@ -0,0 +1,74 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const fs_1 = require("./utils/fs"); +const path = require("path"); +const $RefParser = require("json-schema-ref-parser"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const Either_1 = require("fp-ts/lib/Either"); +const function_1 = require("fp-ts/lib/function"); +const io_ts_2 = require("./utils/io-ts"); +const sketch_121_1 = require("./parsers/sketch-121"); +const log = (...args) => console.log('[SWAGGER-CODEGEN-TS]:', ...args); +const getUnsafe = fp_ts_1.either.fold(e => { + throw e; +}, function_1.identity); +exports.generate = (options) => fp_ts_1.taskEither.tryCatch(() => __awaiter(void 0, void 0, void 0, function* () { + const cwd = options.cwd || process.cwd(); + const out = path.isAbsolute(options.out) ? options.out : path.resolve(cwd, options.out); + const spec = path.isAbsolute(options.spec) ? options.spec : path.resolve(cwd, options.spec); + log('Processing', spec); + const $refs = yield $RefParser.resolve(spec, { + dereference: { + circular: 'ignore', + }, + parse: { + sketch: sketch_121_1.sketchParser121, + }, + }); + const specs = pipeable_1.pipe(Object.entries($refs.values()), fp_ts_1.array.reduce({}, (acc, [fullPath, schema]) => { + const isRoot = fullPath === spec; + const relative = path.relative(cwd, fullPath); + // skip specLike check for root because it should always be decoded with passed decoder and fail + if (!isRoot && Either_1.isLeft(specLikeCodec.decode(schema))) { + log('Unable to decode', relative, 'as spec. Treat it as an arbitrary json.'); + // this is not a spec - treat as arbitrary json + return acc; + } + // use getUnsafe to fail fast if unable to decode a spec + const decoded = getUnsafe(io_ts_2.reportIfFailed(options.decoder.decode(schema))); + log('Decoded', relative); + return Object.assign(Object.assign({}, acc), { [relative]: decoded }); + })); + log('Writing to', out); + const resolveRef = ($ref, decoder) => pipeable_1.pipe(fp_ts_1.either.tryCatch(() => $refs.get($ref), Either_1.toError), fp_ts_1.either.chain(resolved => io_ts_2.reportIfFailed(decoder.decode(resolved)))); + yield fs_1.write(out, getUnsafe(options.language({ resolveRef })(specs))); + log('Done'); +}), function_1.identity); +const specLikeCodec = io_ts_1.union([ + io_ts_1.type({ + swagger: io_ts_1.literal('2.0'), + }), + io_ts_1.type({ + openapi: io_ts_1.union([io_ts_1.literal('3.0.0'), io_ts_1.literal('3.0.1'), io_ts_1.literal('3.0.2')]), + }), + io_ts_1.type({ + asyncapi: io_ts_1.literal('2.0.0'), + }), + io_ts_1.type({ + // sketch-like structure + meta: io_ts_1.type({ + version: io_ts_1.literal(121), + }), + }), +]); diff --git a/dist/language/typescript/2.0/index.d.ts b/dist/language/typescript/2.0/index.d.ts new file mode 100644 index 0000000..159f38a --- /dev/null +++ b/dist/language/typescript/2.0/index.d.ts @@ -0,0 +1,6 @@ +import { SwaggerObject } from '../../../schema/2.0/swagger-object'; +import { SerializeOptions } from '../common/utils'; +import { FSEntity } from '../../../utils/fs'; +import { Dictionary } from '../../../utils/types'; +import { either } from 'fp-ts'; +export declare const serialize: import("fp-ts/lib/Reader").Reader, options?: SerializeOptions) => either.Either>; diff --git a/dist/language/typescript/2.0/index.js b/dist/language/typescript/2.0/index.js new file mode 100644 index 0000000..5570e71 --- /dev/null +++ b/dist/language/typescript/2.0/index.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../common/utils"); +const fs_1 = require("../../../utils/fs"); +const fp_ts_1 = require("fp-ts"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const swagger_object_1 = require("./serializers/swagger-object"); +const prettier_1 = require("prettier"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +exports.serialize = reader_utils_1.combineReader(swagger_object_1.serializeSwaggerObject, serializeSwaggerObject => (documents, options = {}) => pipeable_1.pipe(documents, fp_ts_1.record.collect(serializeSwaggerObject), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized => fs_1.map(fs_1.fragment(serialized), content => prettier_1.format(content, options.prettierConfig || utils_1.defaultPrettierConfig))))); diff --git a/dist/language/typescript/2.0/serializers/definitions-object.d.ts b/dist/language/typescript/2.0/serializers/definitions-object.d.ts new file mode 100644 index 0000000..744ee34 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/definitions-object.d.ts @@ -0,0 +1,5 @@ +import { Directory } from '../../../../utils/fs'; +import { DefinitionsObject } from '../../../../schema/2.0/definitions-object'; +import { either } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +export declare const serializeDefinitions: (from: Ref, definitions: DefinitionsObject) => either.Either; diff --git a/dist/language/typescript/2.0/serializers/definitions-object.js b/dist/language/typescript/2.0/serializers/definitions-object.js new file mode 100644 index 0000000..68eef50 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/definitions-object.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const schema_object_1 = require("./schema-object"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const utils_1 = require("../../common/utils"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +exports.serializeDefinitions = (from, definitions) => pipeable_1.pipe(definitions, fp_ts_1.record.collect((name, definition) => pipeable_1.pipe(from, ref_1.addPathParts(name), fp_ts_1.either.chain(from => serializeDefinition(from, name, definition)))), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized => fs_1.directory(utils_1.DEFINITIONS_DIRECTORY, serialized))); +const serializeDefinition = (from, name, definition) => pipeable_1.pipe(schema_object_1.serializeSchemaObject(from, definition), fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${name}.ts`, ` + ${dependencies} + + export type ${name} = ${serialized.type}; + export const ${utils_1.getIOName(name)} = ${serialized.io}; + `); +})); diff --git a/dist/language/typescript/2.0/serializers/items-object.d.ts b/dist/language/typescript/2.0/serializers/items-object.d.ts new file mode 100644 index 0000000..326a0bf --- /dev/null +++ b/dist/language/typescript/2.0/serializers/items-object.d.ts @@ -0,0 +1,5 @@ +import { ItemsObject } from '../../../../schema/2.0/items-object'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Ref } from '../../../../utils/ref'; +import { either } from 'fp-ts'; +export declare const serializeItemsObject: (from: Ref, itemsObject: ItemsObject) => either.Either; diff --git a/dist/language/typescript/2.0/serializers/items-object.js b/dist/language/typescript/2.0/serializers/items-object.js new file mode 100644 index 0000000..b92fdbd --- /dev/null +++ b/dist/language/typescript/2.0/serializers/items-object.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const Either_1 = require("fp-ts/lib/Either"); +const Option_1 = require("fp-ts/lib/Option"); +exports.serializeItemsObject = (from, itemsObject) => { + switch (itemsObject.type) { + case 'array': { + return pipeable_1.pipe(exports.serializeItemsObject(from, itemsObject.items), fp_ts_1.either.map(serialized_type_1.getSerializedArrayType(Option_1.none))); + } + case 'string': { + return serialized_type_1.getSerializedStringType(from, itemsObject.format); + } + case 'number': { + return Either_1.right(serialized_type_1.SERIALIZED_NUMBER_TYPE); + } + case 'integer': { + return Either_1.right(serialized_type_1.SERIALIZED_INTEGER_TYPE); + } + case 'boolean': { + return Either_1.right(serialized_type_1.SERIALIZED_BOOLEAN_TYPE); + } + } +}; diff --git a/dist/language/typescript/2.0/serializers/operation-object.d.ts b/dist/language/typescript/2.0/serializers/operation-object.d.ts new file mode 100644 index 0000000..15ec9eb --- /dev/null +++ b/dist/language/typescript/2.0/serializers/operation-object.d.ts @@ -0,0 +1,12 @@ +import { OperationObject } from '../../../../schema/2.0/operation-object'; +import { SerializedType } from '../../common/data/serialized-type'; +import { HTTPMethod } from '../../common/utils'; +import { Either } from 'fp-ts/lib/Either'; +import { ResolveRefContext, Ref } from '../../../../utils/ref'; +import { QueryParameterObject } from '../../../../schema/2.0/parameter-object'; +import { PathItemObject } from '../../../../schema/2.0/path-item-object'; +import { Kind } from '../../../../utils/types'; +import { SerializedFragment } from '../../common/data/serialized-fragment'; +export declare const serializeOperationObject: import("fp-ts/lib/Reader").Reader, url: string, method: HTTPMethod, kind: Kind, operation: OperationObject, pathItem: PathItemObject) => Either>; +export declare const getCollectionSeparator: (format: "csv" | "ssv" | "tsv" | "pipes") => string; +export declare const serializeQueryParameterObject: (from: Ref, parameter: QueryParameterObject, serialized: SerializedType, target: string) => Either; diff --git a/dist/language/typescript/2.0/serializers/operation-object.js b/dist/language/typescript/2.0/serializers/operation-object.js new file mode 100644 index 0000000..0d2c1f8 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/operation-object.js @@ -0,0 +1,249 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const Option_1 = require("fp-ts/lib/Option"); +const responses_object_1 = require("./responses-object"); +const serialized_parameter_1 = require("../../common/data/serialized-parameter"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const array_1 = require("../../../../utils/array"); +const string_1 = require("../../../../utils/string"); +const utils_1 = require("../../common/utils"); +const Either_1 = require("fp-ts/lib/Either"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +const client_1 = require("../../common/bundled/client"); +const parameter_object_1 = require("../../../../schema/2.0/parameter-object"); +const reference_object_1 = require("../../../../schema/2.0/reference-object"); +const parameter_object_2 = require("./parameter-object"); +const serialized_path_parameter_1 = require("../../common/data/serialized-path-parameter"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const Reader_1 = require("fp-ts/lib/Reader"); +const schema_object_1 = require("./schema-object"); +const Eq_1 = require("fp-ts/lib/Eq"); +const serialized_fragment_1 = require("../../common/data/serialized-fragment"); +const option_1 = require("../../../../utils/option"); +const function_1 = require("fp-ts/lib/function"); +const serialized_header_parameters_1 = require("../../common/data/serialized-header-parameters"); +const contains = fp_ts_1.array.elem(Eq_1.getStructEq({ + name: Eq_1.eqString, + in: Eq_1.eqString, +})); +const getParameters = reader_utils_1.combineReader(Reader_1.ask(), e => (from, operation, pathItem) => { + const processedParameters = []; + const pathParameters = []; + const serializedPathParameters = []; + const serializedQueryParameters = []; + const bodyParameters = []; + const serializedHeaderParameters = []; + const formDataParameters = []; + const queryStringFragments = []; + const parameters = pipeable_1.pipe( + // note that PathItem parameters should go after OperationObject parameters because they have lower priority + // this means that OperationObject can override PathItemObject parameters + [operation.parameters, pathItem.parameters], fp_ts_1.array.compact, fp_ts_1.array.flatten); + for (const parameter of parameters) { + const resolved = reference_object_1.ReferenceObjectCodec.is(parameter) + ? pipeable_1.pipe(e.resolveRef(parameter.$ref, parameter_object_1.ParameterObjectCodec), fp_ts_1.either.mapLeft(() => new Error(`Unable to resolve parameter with $ref "${parameter.$ref}"`))) + : Either_1.right(parameter); + if (Either_1.isLeft(resolved)) { + return resolved; + } + // if parameter has already been processed then skip it + if (contains(resolved.right, processedParameters)) { + continue; + } + processedParameters.push(resolved.right); + const required = parameter_object_2.isRequired(resolved.right); + const serialized = reference_object_1.ReferenceObjectCodec.is(parameter) + ? pipeable_1.pipe(ref_1.fromString(parameter.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from)), fp_ts_1.either.map(serialized_parameter_1.fromSerializedType(required))) + : parameter_object_2.serializeParameterObject(from, resolved.right); + if (Either_1.isLeft(serialized)) { + return serialized; + } + switch (resolved.right.in) { + case 'body': { + bodyParameters.push(resolved.right); + break; + } + case 'header': { + const serializedParameter = pipeable_1.pipe(serialized.right, serialized_header_parameters_1.fromSerializedHeaderParameter(resolved.right.name), serialized_header_parameters_1.getSerializedHeaderParameterType); + serializedHeaderParameters.push(serializedParameter); + break; + } + case 'formData': { + formDataParameters.push(resolved.right); + break; + } + case 'path': { + pathParameters.push(resolved.right); + const serializedParameter = pipeable_1.pipe(serialized.right, serialized_path_parameter_1.fromSerializedParameter(resolved.right.name), serialized_path_parameter_1.getSerializedPathParameterType); + serializedPathParameters.push(serializedParameter); + break; + } + case 'query': { + const serializedParameter = serialized_type_1.getSerializedOptionalType(required, serialized.right); + const queryStringFragment = exports.serializeQueryParameterObject(from, resolved.right, serializedParameter, 'parameters.query'); + if (Either_1.isLeft(queryStringFragment)) { + return queryStringFragment; + } + queryStringFragments.push(queryStringFragment.right); + serializedQueryParameters.push(serialized_type_1.getSerializedPropertyType(resolved.right.name, true, serializedParameter)); + break; + } + } + } + const serializedQueryParameter = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(serializedQueryParameters), fp_ts_1.option.map(parameters => pipeable_1.pipe(serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), parameters), serialized_type_1.getSerializedObjectType()))); + // according to spec there can be only one body parameter + const serializedBodyParameter = pipeable_1.pipe(fp_ts_1.array.head(bodyParameters), fp_ts_1.option.map(parameter => { + const required = parameter_object_2.isRequired(parameter); + return pipeable_1.pipe(schema_object_1.serializeSchemaObject(from, parameter.schema), fp_ts_1.either.map(serialized => serialized_type_1.getSerializedOptionalType(required, serialized))); + }), option_1.sequenceOptionEither); + const serializedHeadersParameter = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(serializedHeaderParameters), fp_ts_1.option.map(parameters => pipeable_1.pipe(serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), parameters), serialized_type_1.getSerializedObjectType()))); + const queryString = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(queryStringFragments), fp_ts_1.option.map(queryStringFragments => serialized_fragment_1.intercalateSerializedFragmentsNEA(serialized_fragment_1.serializedFragment(',', [], []), queryStringFragments)), fp_ts_1.option.map(f => serialized_fragment_1.combineFragmentsK(f, c => serialized_fragment_1.serializedFragment(`compact([${c}]).join('&')`, [serialized_dependency_1.serializedDependency('compact', 'fp-ts/lib/Array')], [])))); + return either_utils_1.combineEither(serializedBodyParameter, serializedBodyParameter => ({ + pathParameters, + serializedPathParameters, + serializedQueryParameter, + serializedBodyParameter, + serializedHeadersParameter, + formDataParameters, + queryString, + })); +}); +exports.serializeOperationObject = reader_utils_1.combineReader(getParameters, getParameters => (from, url, method, kind, operation, pathItem) => { + const parameters = getParameters(from, operation, pathItem); + const operationName = getOperationName(url, operation, method); + const isSuccessResponse = (code) => { + const status = parseInt(code, 10); + return status >= 200 && status < 300; + }; + const serializedResponses = responses_object_1.serializeOperationResponses(from, pipeable_1.pipe(operation.responses, fp_ts_1.record.filterWithIndex(isSuccessResponse))); + const deprecated = pipeable_1.pipe(operation.deprecated, fp_ts_1.option.filter(function_1.identity), Option_1.map(() => `@deprecated`)); + const responseType = pipeable_1.pipe(operation.produces, Option_1.fold(() => 'json', produces => { + if (produces.includes('application/octet-stream')) { + return 'blob'; + } + if (produces.includes('text/plain')) { + return 'text'; + } + return 'json'; + })); + return either_utils_1.combineEither(parameters, serializedResponses, client_1.clientRef, (parameters, serializedResponses, clientRef) => { + const hasQueryParameters = Option_1.isSome(parameters.serializedQueryParameter); + const hasBodyParameters = Option_1.isSome(parameters.serializedBodyParameter); + const hasHeaderParameters = Option_1.isSome(parameters.serializedHeadersParameter); + const hasParameters = hasQueryParameters || hasBodyParameters || hasHeaderParameters; + const bodyType = pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(body => `body: ${body.type},`), fp_ts_1.option.getOrElse(() => '')); + const bodyIO = pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(body => `const body = ${body.io}.encode(parameters.body);`), fp_ts_1.option.getOrElse(() => '')); + const queryType = pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(query => `query: ${query.type},`), fp_ts_1.option.getOrElse(() => '')); + const queryIO = pipeable_1.pipe(parameters.queryString, fp_ts_1.option.map(query => `const query = ${query.value};`), fp_ts_1.option.getOrElse(() => '')); + const headersType = pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(headers => `headers: ${headers.type}`), fp_ts_1.option.getOrElse(() => '')); + const headersIO = pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(headers => `const headers = ${headers.io}.encode(parameters.headers)`), fp_ts_1.option.getOrElse(() => '')); + const argsType = array_1.concatIf(hasParameters, parameters.serializedPathParameters.map(p => p.type), [`parameters: { ${queryType}${bodyType}${headersType} }`]).join(','); + const type = ` + ${utils_1.getJSDoc(fp_ts_1.array.compact([deprecated, operation.summary]))} + readonly ${operationName}: (${argsType}) => ${utils_1.getKindValue(kind, serializedResponses.type)}; + `; + const argsIO = array_1.concatIf(hasParameters, parameters.pathParameters.map(p => p.name), ['parameters']).join(','); + const io = ` + ${operationName}: (${argsIO}) => { + ${bodyIO} + ${queryIO} + ${headersIO} + + return e.httpClient.chain( + e.httpClient.request({ + url: ${utils_1.getURL(url, parameters.serializedPathParameters)}, + method: '${method}', + responseType: '${responseType}', + ${string_1.when(hasQueryParameters, 'query,')} + ${string_1.when(hasBodyParameters, 'body,')} + ${string_1.when(hasHeaderParameters, 'headers')} + }), + value => + pipe( + ${serializedResponses.io}.decode(value), + either.mapLeft(ResponseValidationError.create), + either.fold(error => e.httpClient.throwError(error), decoded => e.httpClient.of(decoded)), + ), + ); + }, + `; + const dependencies = [ + serialized_dependency_1.serializedDependency('ResponseValidationError', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('pipe', 'fp-ts/lib/pipeable'), + serialized_dependency_1.serializedDependency('either', 'fp-ts'), + serialized_dependency_1.getSerializedKindDependency(kind), + ...serializedResponses.dependencies, + ...fp_ts_1.array.flatten([ + ...parameters.serializedPathParameters.map(p => p.dependencies), + ...fp_ts_1.array.compact([ + pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.queryString, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(p => p.dependencies)), + ]), + ]), + ]; + const refs = fp_ts_1.array.flatten([ + ...parameters.serializedPathParameters.map(p => p.refs), + ...fp_ts_1.array.compact([ + pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(p => p.refs)), + pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(p => p.refs)), + pipeable_1.pipe(parameters.queryString, fp_ts_1.option.map(p => p.refs)), + ]), + ...parameters.serializedPathParameters.map(p => p.refs), + ]); + return serialized_type_1.serializedType(type, io, dependencies, refs); + }); +}); +const getOperationName = (url, operation, httpMethod) => pipeable_1.pipe(operation.operationId, Option_1.getOrElse(() => `${httpMethod}_${utils_1.getSafePropertyName(url)}`)); +exports.getCollectionSeparator = (format) => { + switch (format) { + case 'csv': { + return ','; + } + case 'ssv': { + return ' '; + } + case 'tsv': { + return '\t'; + } + case 'pipes': { + return '|'; + } + } +}; +exports.serializeQueryParameterObject = (from, parameter, serialized, target) => { + const required = parameter_object_2.isRequired(parameter); + const encoded = serialized_fragment_1.serializedFragment(`${serialized.io}.encode(${target}.${parameter.name})`, serialized.dependencies, serialized.refs); + switch (parameter.type) { + case 'string': + case 'integer': + case 'number': + case 'boolean': { + const f = serialized_fragment_1.serializedFragment(`value => some(encodeURIComponent('${parameter.name}') + '=' + encodeURIComponent(value))`, [serialized_dependency_1.serializedDependency('some', 'fp-ts/lib/Option')], []); + return Either_1.right(serialized_fragment_1.getSerializedOptionCallFragment(!required, f, encoded)); + } + case 'array': { + const collectionFormat = pipeable_1.pipe(parameter.collectionFormat, fp_ts_1.option.getOrElse(() => 'csv')); + switch (collectionFormat) { + case 'csv': + case 'ssv': + case 'tsv': + case 'pipes': { + const s = exports.getCollectionSeparator(collectionFormat); + const f = serialized_fragment_1.serializedFragment(`value => some(encodeURIComponent('${parameter.name}') + '=' + encodeURIComponent(value.join('${s}')))`, [serialized_dependency_1.serializedDependency('some', 'fp-ts/lib/Option')], []); + return Either_1.right(serialized_fragment_1.getSerializedOptionCallFragment(!required, f, encoded)); + } + case 'multi': { + const f = serialized_fragment_1.serializedFragment(`value => some(value.map(item => encodeURIComponent('${parameter.name}') + '=' + encodeURIComponent(item)).join('&'))`, [serialized_dependency_1.serializedDependency('some', 'fp-ts/lib/Option')], []); + return Either_1.right(serialized_fragment_1.getSerializedOptionCallFragment(!required, f, encoded)); + } + } + return Either_1.left(new Error('Invalid ArrayQueryParameterObject')); + } + } +}; diff --git a/dist/language/typescript/2.0/serializers/parameter-object.d.ts b/dist/language/typescript/2.0/serializers/parameter-object.d.ts new file mode 100644 index 0000000..fdd545d --- /dev/null +++ b/dist/language/typescript/2.0/serializers/parameter-object.d.ts @@ -0,0 +1,6 @@ +import { Ref } from '../../../../utils/ref'; +import { ParameterObject } from '../../../../schema/2.0/parameter-object'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedParameter } from '../../common/data/serialized-parameter'; +export declare const serializeParameterObject: (from: Ref, parameterObject: ParameterObject) => Either; +export declare const isRequired: (parameterObject: ParameterObject) => boolean; diff --git a/dist/language/typescript/2.0/serializers/parameter-object.js b/dist/language/typescript/2.0/serializers/parameter-object.js new file mode 100644 index 0000000..7db1b1f --- /dev/null +++ b/dist/language/typescript/2.0/serializers/parameter-object.js @@ -0,0 +1,46 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const items_object_1 = require("./items-object"); +const schema_object_1 = require("./schema-object"); +const Either_1 = require("fp-ts/lib/Either"); +const serialized_parameter_1 = require("../../common/data/serialized-parameter"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const function_1 = require("fp-ts/lib/function"); +const Option_1 = require("fp-ts/lib/Option"); +exports.serializeParameterObject = (from, parameterObject) => { + const toSerializedParameter = serialized_parameter_1.fromSerializedType(exports.isRequired(parameterObject)); + switch (parameterObject.in) { + case 'path': + case 'query': + case 'header': + case 'formData': { + switch (parameterObject.type) { + case 'string': { + return pipeable_1.pipe(serialized_type_1.getSerializedStringType(from, parameterObject.format), fp_ts_1.either.map(toSerializedParameter)); + } + case 'number': { + return Either_1.right(toSerializedParameter(serialized_type_1.SERIALIZED_NUMBER_TYPE)); + } + case 'integer': { + return Either_1.right(toSerializedParameter(serialized_type_1.SERIALIZED_INTEGER_TYPE)); + } + case 'boolean': { + return Either_1.right(toSerializedParameter(serialized_type_1.SERIALIZED_BOOLEAN_TYPE)); + } + case 'array': { + return pipeable_1.pipe(items_object_1.serializeItemsObject(from, parameterObject.items), fp_ts_1.either.map(serialized_type_1.getSerializedArrayType(Option_1.none)), fp_ts_1.either.map(toSerializedParameter)); + } + case 'file': + return Either_1.right(toSerializedParameter(serialized_type_1.SERIALIZED_UNKNOWN_TYPE)); + } + } + case 'body': { + return pipeable_1.pipe(schema_object_1.serializeSchemaObject(from, parameterObject.schema), fp_ts_1.either.map(toSerializedParameter)); + } + } +}; +exports.isRequired = (parameterObject) => parameterObject.in === 'path' + ? parameterObject.required + : pipeable_1.pipe(parameterObject.required, fp_ts_1.option.getOrElse(function_1.constFalse)); diff --git a/dist/language/typescript/2.0/serializers/parameters-definitions-object.d.ts b/dist/language/typescript/2.0/serializers/parameters-definitions-object.d.ts new file mode 100644 index 0000000..16c33db --- /dev/null +++ b/dist/language/typescript/2.0/serializers/parameters-definitions-object.d.ts @@ -0,0 +1,5 @@ +import { ParametersDefinitionsObject } from '../../../../schema/2.0/parameters-definitions-object'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +import { Ref } from '../../../../utils/ref'; +export declare const serializeParametersDefinitionsObject: (from: Ref, parametersDefinitionsObject: ParametersDefinitionsObject) => Either; diff --git a/dist/language/typescript/2.0/serializers/parameters-definitions-object.js b/dist/language/typescript/2.0/serializers/parameters-definitions-object.js new file mode 100644 index 0000000..d350bdf --- /dev/null +++ b/dist/language/typescript/2.0/serializers/parameters-definitions-object.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const utils_1 = require("../../common/utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const parameter_object_1 = require("./parameter-object"); +exports.serializeParametersDefinitionsObject = (from, parametersDefinitionsObject) => pipeable_1.pipe(parametersDefinitionsObject, fp_ts_1.record.collect((name, parameterObject) => pipeable_1.pipe(from, ref_1.addPathParts(name), fp_ts_1.either.chain(from => serializeParameter(from, parameterObject)))), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('parameters', content))); +const serializeParameter = (from, parameterObject) => pipeable_1.pipe(parameter_object_1.serializeParameterObject(from, parameterObject), fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${utils_1.getTypeName(from.name)} = ${serialized.type}; + export const ${utils_1.getIOName(from.name)} = ${serialized.io}; + `); +})); diff --git a/dist/language/typescript/2.0/serializers/path-item-object.d.ts b/dist/language/typescript/2.0/serializers/path-item-object.d.ts new file mode 100644 index 0000000..fed6983 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/path-item-object.d.ts @@ -0,0 +1,9 @@ +import { PathItemObject } from '../../../../schema/2.0/path-item-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Dictionary } from '../../../../utils/types'; +import { File } from '../../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { ResolveRefContext, Ref } from '../../../../utils/ref'; +export declare const serializePathGroup: import("fp-ts/lib/Reader").Reader, name: string, group: Dictionary) => Either>; +export declare const getTagsFromPath: (path: PathItemObject) => string[]; +export declare const serializePathItemObjectTags: (pathItemObject: PathItemObject) => Option; diff --git a/dist/language/typescript/2.0/serializers/path-item-object.js b/dist/language/typescript/2.0/serializers/path-item-object.js new file mode 100644 index 0000000..690bfc3 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/path-item-object.js @@ -0,0 +1,113 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_item_object_1 = require("../../../../schema/2.0/path-item-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const Option_1 = require("fp-ts/lib/Option"); +const operation_object_1 = require("./operation-object"); +const Array_1 = require("fp-ts/lib/Array"); +const fs_1 = require("../../../../utils/fs"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const string_1 = require("@devexperts/utils/dist/string/string"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const client_1 = require("../../common/bundled/client"); +const function_1 = require("fp-ts/lib/function"); +const array_1 = require("../../../../utils/array"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const Reader_1 = require("fp-ts/lib/Reader"); +const serializePath = reader_utils_1.combineReader(Reader_1.ask(), operation_object_1.serializeOperationObject, (e, serializeOperationObject) => { + const run = (from, url, kind, item) => { + if (Option_1.isSome(item.$ref)) { + const $ref = item.$ref.value; + return pipeable_1.pipe(e.resolveRef($ref, path_item_object_1.PathItemObjectCodec), fp_ts_1.either.mapLeft(() => new Error(`Unable to resolve PathItem $ref: "${$ref}"`)), fp_ts_1.either.chain(resolved => run(from, url, kind, resolved))); + } + else { + const get = pipeable_1.pipe(item.get, Option_1.map(operation => serializeOperationObject(from, url, 'GET', kind, operation, item))); + const put = pipeable_1.pipe(item.put, Option_1.map(operation => serializeOperationObject(from, url, 'PUT', kind, operation, item))); + const post = pipeable_1.pipe(item.post, Option_1.map(operation => serializeOperationObject(from, url, 'POST', kind, operation, item))); + const remove = pipeable_1.pipe(item.delete, Option_1.map(operation => serializeOperationObject(from, url, 'DELETE', kind, operation, item))); + const options = pipeable_1.pipe(item.options, Option_1.map(operation => serializeOperationObject(from, url, 'OPTIONS', kind, operation, item))); + const head = pipeable_1.pipe(item.head, Option_1.map(operation => serializeOperationObject(from, url, 'HEAD', kind, operation, item))); + const patch = pipeable_1.pipe(item.patch, Option_1.map(operation => serializeOperationObject(from, url, 'PATCH', kind, operation, item))); + const operations = [get, put, post, remove, options, head, patch]; + return pipeable_1.pipe(operations, Array_1.array.compact, either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + } + }; + return run; +}); +exports.serializePathGroup = reader_utils_1.combineReader(serializePath, serializePath => (from, name, group) => { + const serializedHKT = pipeable_1.pipe(group, fp_ts_1.record.collect((url, item) => serializePath(from, url, 'HKT', item)), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + const serializedKind = pipeable_1.pipe(group, fp_ts_1.record.collect((url, item) => serializePath(from, url, '*', item)), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + const serializedKind2 = pipeable_1.pipe(group, fp_ts_1.record.collect((url, item) => serializePath(from, url, '* -> *', item)), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + return either_utils_1.combineEither(serializedHKT, serializedKind, serializedKind2, client_1.clientRef, (serializedHKT, serializedKind, serializedKind2, clientRef) => { + const dependencies = serialized_dependency_1.serializeDependencies([ + ...serializedHKT.dependencies, + ...serializedKind.dependencies, + ...serializedKind2.dependencies, + serialized_dependency_1.serializedDependency('HTTPClient', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('HTTPClient1', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('HTTPClient2', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('URIS', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + ]); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export interface ${from.name} { + ${serializedHKT.type} + } + + export interface ${from.name}1 { + ${serializedKind.type} + } + + export interface ${from.name}2 { + ${serializedKind2.type} + } + + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient2 }): ${from.name}2 + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient1 }): ${from.name}1 + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient }): ${from.name}; + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient }): ${from.name} { + return { + ${serializedHKT.io} + } + } + `); + }); +}); +const getOperationsFromPath = (path) => { + const result = {}; + const operations = Array_1.array.compact([ + pipeable_1.pipe(path.get, Option_1.map(operation => function_1.tuple('get', operation))), + pipeable_1.pipe(path.post, Option_1.map(operation => function_1.tuple('post', operation))), + pipeable_1.pipe(path.put, Option_1.map(operation => function_1.tuple('put', operation))), + pipeable_1.pipe(path.delete, Option_1.map(operation => function_1.tuple('delete', operation))), + pipeable_1.pipe(path.head, Option_1.map(operation => function_1.tuple('head', operation))), + pipeable_1.pipe(path.options, Option_1.map(operation => function_1.tuple('options', operation))), + pipeable_1.pipe(path.patch, Option_1.map(operation => function_1.tuple('patch', operation))), + ]); + for (const [name, operation] of operations) { + result[name] = operation; + } + return result; +}; +exports.getTagsFromPath = (path) => { + const operations = getOperationsFromPath(path); + const tags = Array_1.flatten(Array_1.array.compact(Object.keys(operations).map(key => operations[key].tags))); + return array_1.uniqString(tags); +}; +exports.serializePathItemObjectTags = (pathItemObject) => { + const operations = [ + pathItemObject.get, + pathItemObject.post, + pathItemObject.put, + pathItemObject.delete, + pathItemObject.options, + pathItemObject.head, + pathItemObject.patch, + ]; + return pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(Array_1.array.compact(operations)), fp_ts_1.option.map(operations => array_1.uniqString(Array_1.flatten(Array_1.array.compact(operations.map(operation => operation.tags))))), fp_ts_1.option.chain(fp_ts_1.nonEmptyArray.fromArray), fp_ts_1.option.map(tags => tags.join('').replace(/\s/g, ''))); +}; diff --git a/dist/language/typescript/2.0/serializers/paths-object.d.ts b/dist/language/typescript/2.0/serializers/paths-object.d.ts new file mode 100644 index 0000000..8335f27 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/paths-object.d.ts @@ -0,0 +1,5 @@ +import { PathsObject } from '../../../../schema/2.0/paths-object'; +import { Directory } from '../../../../utils/fs'; +import { either } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +export declare const serializePaths: import("fp-ts/lib/Reader").Reader, paths: PathsObject) => either.Either>; diff --git a/dist/language/typescript/2.0/serializers/paths-object.js b/dist/language/typescript/2.0/serializers/paths-object.js new file mode 100644 index 0000000..007802d --- /dev/null +++ b/dist/language/typescript/2.0/serializers/paths-object.js @@ -0,0 +1,78 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const path_item_object_1 = require("./path-item-object"); +const utils_1 = require("../../common/utils"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const Either_1 = require("fp-ts/lib/Either"); +const ref_1 = require("../../../../utils/ref"); +const string_1 = require("@devexperts/utils/dist/string/string"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const client_1 = require("../../common/bundled/client"); +exports.serializePaths = reader_utils_1.combineReader(path_item_object_1.serializePathGroup, serializePathGroup => (from, paths) => { + const groupped = groupPathsByTag(paths); + const files = pipeable_1.pipe(groupped, fp_ts_1.record.collect((name, group) => pipeable_1.pipe(from, ref_1.addPathParts(name), fp_ts_1.either.chain(from => serializePathGroup(from, name, group)))), either_utils_1.sequenceEither); + const index = pipeable_1.pipe(from, ref_1.addPathParts(utils_1.CONTROLLERS_DIRECTORY), fp_ts_1.either.chain(from => serializePathsIndex(from, fp_ts_1.record.keys(groupped)))); + return either_utils_1.combineEither(files, index, (files, index) => fs_1.directory(utils_1.CONTROLLERS_DIRECTORY, [...files, index])); +}); +const serializePathsIndex = (from, pathNames) => { + if (Either_1.isLeft(client_1.clientRef)) { + return client_1.clientRef; + } + const pathToClient = ref_1.getRelativePath(from, client_1.clientRef.right); + const dependencies = serialized_dependency_1.serializeDependencies([ + ...fp_ts_1.array.flatten(pathNames.map(name => { + const p = `./${name}`; + return [ + serialized_dependency_1.serializedDependency(string_1.decapitalize(name), p), + serialized_dependency_1.serializedDependency(name, p), + serialized_dependency_1.serializedDependency(`${name}1`, p), + serialized_dependency_1.serializedDependency(`${name}2`, p), + ]; + })), + serialized_dependency_1.serializedDependency('URIS', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('HTTPClient', pathToClient), + serialized_dependency_1.serializedDependency('HTTPClient1', pathToClient), + serialized_dependency_1.serializedDependency('HTTPClient2', pathToClient), + ]); + const content = ` + export interface Controllers { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name};`).join('\n')} + } + export interface Controllers1 { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name}1;`).join('\n')} + } + export interface Controllers2 { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name}2;`).join('\n')} + } + + export function controllers(e: { httpClient: HTTPClient2 }): Controllers2 + export function controllers(e: { httpClient: HTTPClient1 }): Controllers1 + export function controllers(e: { httpClient: HTTPClient }): Controllers; + export function controllers(e: { httpClient: HTTPClient }): Controllers { + return { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${string_1.decapitalize(name)}(e),`).join('\n')} + } + } + `; + return Either_1.right(fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + ${content} + `)); +}; +const groupPathsByTag = (pathsObject) => { + const keys = Object.keys(pathsObject); + const result = {}; + for (const key of keys) { + const path = pathsObject[key]; + const tag = pipeable_1.pipe(path_item_object_1.serializePathItemObjectTags(path), fp_ts_1.option.map(p => utils_1.getControllerName(string_1.camelize(p, false))), fp_ts_1.option.getOrElse(() => utils_1.getControllerName('Unknown'))); + result[tag] = Object.assign(Object.assign({}, (result[tag] || {})), { [key]: path }); + } + return result; +}; diff --git a/dist/language/typescript/2.0/serializers/response-object.d.ts b/dist/language/typescript/2.0/serializers/response-object.d.ts new file mode 100644 index 0000000..a856a17 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/response-object.d.ts @@ -0,0 +1,5 @@ +import { ResponseObject } from '../../../../schema/2.0/response-object'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Either } from 'fp-ts/lib/Either'; +import { Ref } from '../../../../utils/ref'; +export declare const serializeResponseObject: (from: Ref, response: ResponseObject) => Either; diff --git a/dist/language/typescript/2.0/serializers/response-object.js b/dist/language/typescript/2.0/serializers/response-object.js new file mode 100644 index 0000000..e00aeca --- /dev/null +++ b/dist/language/typescript/2.0/serializers/response-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const schema_object_1 = require("./schema-object"); +const Either_1 = require("fp-ts/lib/Either"); +const fp_ts_1 = require("fp-ts"); +exports.serializeResponseObject = (from, response) => pipeable_1.pipe(response.schema, fp_ts_1.option.fold(() => Either_1.right(serialized_type_1.SERIALIZED_VOID_TYPE), schema => schema_object_1.serializeSchemaObject(from, schema))); diff --git a/dist/language/typescript/2.0/serializers/responses-definitions-object.d.ts b/dist/language/typescript/2.0/serializers/responses-definitions-object.d.ts new file mode 100644 index 0000000..97d0930 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/responses-definitions-object.d.ts @@ -0,0 +1,5 @@ +import { Ref } from '../../../../utils/ref'; +import { ResponsesDefinitionsObject } from '../../../../schema/2.0/responses-definitions-object'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +export declare const serializeResponsesDefinitionsObject: (from: Ref, responsesDefinitionsObject: ResponsesDefinitionsObject) => Either; diff --git a/dist/language/typescript/2.0/serializers/responses-definitions-object.js b/dist/language/typescript/2.0/serializers/responses-definitions-object.js new file mode 100644 index 0000000..5975b63 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/responses-definitions-object.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../../common/utils"); +const ref_1 = require("../../../../utils/ref"); +const fs_1 = require("../../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const response_object_1 = require("./response-object"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +exports.serializeResponsesDefinitionsObject = (from, responsesDefinitionsObject) => pipeable_1.pipe(responsesDefinitionsObject, fp_ts_1.record.collect((name, parameterObject) => pipeable_1.pipe(from, ref_1.addPathParts(name), fp_ts_1.either.chain(from => serializeResponse(from, parameterObject)))), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('responses', content))); +const serializeResponse = (from, responseObject) => pipeable_1.pipe(response_object_1.serializeResponseObject(from, responseObject), fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${utils_1.getTypeName(from.name)} = ${serialized.type}; + export const ${utils_1.getIOName(from.name)} = ${serialized.io}; + `); +})); diff --git a/dist/language/typescript/2.0/serializers/responses-object.d.ts b/dist/language/typescript/2.0/serializers/responses-object.d.ts new file mode 100644 index 0000000..05e5573 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/responses-object.d.ts @@ -0,0 +1,5 @@ +import { ResponsesObject } from '../../../../schema/2.0/responses-object'; +import { SerializedType } from '../../common/data/serialized-type'; +import { either } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +export declare const serializeOperationResponses: (from: Ref, responses: ResponsesObject) => either.Either; diff --git a/dist/language/typescript/2.0/serializers/responses-object.js b/dist/language/typescript/2.0/serializers/responses-object.js new file mode 100644 index 0000000..8fc06f7 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/responses-object.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const response_object_1 = require("./response-object"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const array_1 = require("../../../../utils/array"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +exports.serializeOperationResponses = (from, responses) => pipeable_1.pipe(responses, fp_ts_1.record.collect((code, response) => { + if (reference_object_1.ReferenceObjectCodec.is(response)) { + return pipeable_1.pipe(ref_1.fromString(response.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))); + } + else { + return response_object_1.serializeResponseObject(from, response); + } +}), either_utils_1.sequenceEither, fp_ts_1.either.map(responses => { + const serializedResponses = serialized_type_1.uniqSerializedTypesByTypeAndIO(responses); + if (serializedResponses.length === 0) { + return serialized_type_1.SERIALIZED_VOID_TYPE; + } + const combined = serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType('|', ',', [], []), serializedResponses); + const isUnion = serializedResponses.length > 1; + return serialized_type_1.serializedType(combined.type, isUnion ? `union([${combined.io}])` : combined.io, array_1.concatIfL(isUnion, combined.dependencies, () => [serialized_dependency_1.serializedDependency('union', 'io-ts')]), []); +})); diff --git a/dist/language/typescript/2.0/serializers/schema-object.d.ts b/dist/language/typescript/2.0/serializers/schema-object.d.ts new file mode 100644 index 0000000..b72ad08 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/schema-object.d.ts @@ -0,0 +1,5 @@ +import { SerializedType } from '../../common/data/serialized-type'; +import { SchemaObject } from '../../../../schema/2.0/schema-object'; +import { Ref } from '../../../../utils/ref'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeSchemaObject: (from: Ref, schema: SchemaObject) => Either; diff --git a/dist/language/typescript/2.0/serializers/schema-object.js b/dist/language/typescript/2.0/serializers/schema-object.js new file mode 100644 index 0000000..fc9b5b6 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/schema-object.js @@ -0,0 +1,68 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const schema_object_1 = require("../../../../schema/2.0/schema-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const function_1 = require("fp-ts/lib/function"); +const array_1 = require("../../../../utils/array"); +const ref_1 = require("../../../../utils/ref"); +const Either_1 = require("fp-ts/lib/Either"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const fp_ts_1 = require("fp-ts"); +const either_1 = require("../../../../utils/either"); +const reference_object_1 = require("../../../../schema/2.0/reference-object"); +exports.serializeSchemaObject = (from, schema) => serializeSchemaObjectWithRecursion(from, schema, true); +const serializeSchemaObjectWithRecursion = (from, schema, shouldTrackRecursion) => { + // check non-typed schemas first + if (reference_object_1.ReferenceObjectCodec.is(schema)) { + return pipeable_1.pipe(ref_1.fromString(schema.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))); + } + if (schema_object_1.EnumSchemaObjectCodec.is(schema)) { + return Either_1.right(serialized_type_1.getSerializedEnumType(schema.enum)); + } + if (schema_object_1.AllOfSchemaObject.is(schema)) { + return serializeAllOf(from, schema.allOf, shouldTrackRecursion); + } + // schema is typed + switch (schema.type) { + case 'null': + case 'string': + case 'number': + case 'integer': + case 'boolean': { + return serializePrimitive(from, schema); + } + case 'array': { + return pipeable_1.pipe(serializeSchemaObjectWithRecursion(from, schema.items, false), fp_ts_1.either.map(result => serialized_type_1.serializedType(`Array<${result.type}>`, `array(${result.io})`, [...result.dependencies, serialized_dependency_1.serializedDependency('array', 'io-ts')], result.refs))); + } + case 'object': { + const additionalProperties = pipeable_1.pipe(schema.additionalProperties, fp_ts_1.option.map(additionalProperties => pipeable_1.pipe(serializeSchemaObjectWithRecursion(from, additionalProperties, false), fp_ts_1.either.map(serialized_type_1.getSerializedDictionaryType()), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))))); + const properties = () => pipeable_1.pipe(schema.properties, fp_ts_1.option.map(properties => pipeable_1.pipe(properties, fp_ts_1.record.collect((name, value) => { + const isRequired = pipeable_1.pipe(schema.required, fp_ts_1.option.map(array_1.includes(name)), fp_ts_1.option.getOrElse(function_1.constFalse)); + return pipeable_1.pipe(serializeSchemaObjectWithRecursion(from, value, false), fp_ts_1.either.map(serialized_type_1.getSerializedOptionPropertyType(name, isRequired))); + }), either_utils_1.sequenceEither, fp_ts_1.either.map(s => serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), s)), fp_ts_1.either.map(serialized_type_1.getSerializedObjectType(from.name)), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))))); + return pipeable_1.pipe(additionalProperties, fp_ts_1.option.alt(properties), fp_ts_1.option.getOrElse(() => Either_1.right(serialized_type_1.SERIALIZED_UNKNOWN_TYPE))); + } + } +}; +const serializeAllOf = (from, allOf, shouldTrackRecursion) => pipeable_1.pipe(either_1.traverseNEAEither(allOf, item => serializeSchemaObjectWithRecursion(from, item, false)), fp_ts_1.either.map(serialized_type_1.getSerializedIntersectionType), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))); +const serializePrimitive = (from, schemaObject) => { + switch (schemaObject.type) { + case 'null': { + return Either_1.right(serialized_type_1.SERIALIZED_NULL_TYPE); + } + case 'string': { + return serialized_type_1.getSerializedStringType(from, schemaObject.format); + } + case 'number': { + return Either_1.right(serialized_type_1.SERIALIZED_NUMBER_TYPE); + } + case 'integer': { + return Either_1.right(serialized_type_1.SERIALIZED_INTEGER_TYPE); + } + case 'boolean': { + return Either_1.right(serialized_type_1.SERIALIZED_BOOLEAN_TYPE); + } + } +}; diff --git a/dist/language/typescript/2.0/serializers/swagger-object.d.ts b/dist/language/typescript/2.0/serializers/swagger-object.d.ts new file mode 100644 index 0000000..7042715 --- /dev/null +++ b/dist/language/typescript/2.0/serializers/swagger-object.d.ts @@ -0,0 +1,4 @@ +import { Directory } from '../../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { SwaggerObject } from '../../../../schema/2.0/swagger-object'; +export declare const serializeSwaggerObject: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/2.0/serializers/swagger-object.js b/dist/language/typescript/2.0/serializers/swagger-object.js new file mode 100644 index 0000000..8ab2b2b --- /dev/null +++ b/dist/language/typescript/2.0/serializers/swagger-object.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const definitions_object_1 = require("./definitions-object"); +const paths_object_1 = require("./paths-object"); +const utils_1 = require("../../common/utils"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +const client_1 = require("../../common/bundled/client"); +const parameters_definitions_object_1 = require("./parameters-definitions-object"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const responses_definitions_object_1 = require("./responses-definitions-object"); +const utils_2 = require("../../common/bundled/utils"); +const definitionsRef = ref_1.fromString('#/definitions'); +const parametersRef = ref_1.fromString('#/parameters'); +const responsesRef = ref_1.fromString('#/responses'); +exports.serializeSwaggerObject = reader_utils_1.combineReader(paths_object_1.serializePaths, serializePaths => (name, swaggerObject) => { + const definitions = pipeable_1.pipe(swaggerObject.definitions, fp_ts_1.option.map(definitions => pipeable_1.pipe(definitionsRef, fp_ts_1.either.chain(from => definitions_object_1.serializeDefinitions(from, definitions))))); + const parameters = pipeable_1.pipe(swaggerObject.parameters, fp_ts_1.option.map(parameters => pipeable_1.pipe(parametersRef, fp_ts_1.either.chain(ref => parameters_definitions_object_1.serializeParametersDefinitionsObject(ref, parameters))))); + const responses = pipeable_1.pipe(swaggerObject.responses, fp_ts_1.option.map(responses => pipeable_1.pipe(responsesRef, fp_ts_1.either.chain(ref => responses_definitions_object_1.serializeResponsesDefinitionsObject(ref, responses))))); + const additional = pipeable_1.pipe([definitions, parameters, responses], fp_ts_1.array.compact, either_utils_1.sequenceEither); + const paths = pipeable_1.pipe(utils_1.pathsRef, fp_ts_1.either.chain(from => serializePaths(from, swaggerObject.paths))); + return either_utils_1.combineEither(additional, paths, client_1.clientFile, utils_2.utilsFile, (additional, paths, clientFile, utilsFile) => fs_1.directory(name, [clientFile, ...additional, utilsFile, paths])); +}); diff --git a/dist/language/typescript/3.0/bundled/openapi-3-utils.d.ts b/dist/language/typescript/3.0/bundled/openapi-3-utils.d.ts new file mode 100644 index 0000000..77a26c7 --- /dev/null +++ b/dist/language/typescript/3.0/bundled/openapi-3-utils.d.ts @@ -0,0 +1,3 @@ +import { either } from 'fp-ts'; +export declare const openapi3utilsRef: either.Either>; +export declare const openapi3utilsFile: either.Either; diff --git a/dist/language/typescript/3.0/bundled/openapi-3-utils.js b/dist/language/typescript/3.0/bundled/openapi-3-utils.js new file mode 100644 index 0000000..bfb7fb2 --- /dev/null +++ b/dist/language/typescript/3.0/bundled/openapi-3-utils.js @@ -0,0 +1,172 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const fs_1 = require("../../../../utils/fs"); +const content = ` + import { size } from 'fp-ts/lib/Record'; + import { pipe } from 'fp-ts/lib/pipeable'; + import { record } from 'fp-ts'; + import { Either, left, right } from 'fp-ts/lib/Either'; + import { flow } from 'fp-ts/lib/function'; + + const join = (separator: string) => (parts: string[]): string => parts.join(separator); + + export const serializePrimitiveParameter = (style: string, name: string, value: unknown): Either => { + switch (style) { + case 'matrix': { + return right(\`;\${name}=\${encodeURIComponent(String(value))}\`); + } + case 'label': { + return right(\`.\${encodeURIComponent(String(value))}\`); + } + case 'form': { + return right(\`\${name}=\${encodeURIComponent(String(value))}\`); + } + case 'simple': { + return right(\`\${encodeURIComponent(String(value))}\`); + } + } + return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`)); + }; + + export const serializeArrayParameter = ( + style: string, + name: string, + value: unknown[], + explode: boolean, + ): Either => { + const encodedValue = value.map(flow(String, encodeURIComponent)); + + switch (style) { + case 'matrix': { + return right( + encodedValue.length === 0 + ? \`;\${name}\` + : explode + ? \`\${encodedValue.map(item => \`;\${name}=\${item}\`).join('')}\` + : \`;\${name}=\${encodedValue.join(',')}\`, + ); + } + case 'label': { + return right(encodedValue.map(item => \`.\${item}\`).join('')); + } + case 'form': { + return right(explode ? \`\${encodedValue.map(item => \`\${name}=\${item}\`).join('&')}\` : \`\${name}=\${encodedValue.join(',')}\`); + } + case 'simple': { + return right(encodedValue.join(',')); + } + case 'spaceDelimited': { + return right(encodedValue.join(' ')); + } + case 'pipeDelimited': { + return right(encodedValue.join('|')); + } + } + return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`)); + }; + + export const serializeObjectParameter = ( + style: string, + name: string, + value: Record, + explode: boolean, + ): Either => { + switch (style) { + case 'matrix': { + return right( + size(value) === 0 + ? \`;\${name}\` + : explode + ? pipe( + value, + record.collect((key, item) => \`;\${key}=\${item}\`), + join(''), + ) + : \`;\${name}=\${pipe( + value, + record.collect((key, item) => \`\${key},\${item}\`), + join(','), + )}\`, + ); + } + case 'label': { + return right( + explode + ? pipe( + value, + record.collect((key, item) => \`.\${key}=\${item}\`), + join(''), + ) + : pipe( + value, + record.collect((key, item) => \`.\${key}.\${item}\`), + join(''), + ), + ); + } + case 'form': { + return right( + explode + ? pipe( + value, + record.collect((key, item) => \`\${key}=\${item}\`), + join('&'), + ) + : \`\${name}=\${pipe( + value, + record.collect((key, item) => \`\${key},\${item}\`), + join(','), + )}\`, + ); + } + case 'simple': { + return right( + explode + ? pipe( + value, + record.collect((key, item) => \`\${key}=\${item}\`), + join(','), + ) + : pipe( + value, + record.collect((key, item) => \`\${key},\${item}\`), + join(','), + ), + ); + } + case 'spaceDelimited': { + return right( + pipe( + value, + record.collect((key, item) => \`\${key} \${item}\`), + join(' '), + ), + ); + } + case 'pipeDelimited': { + return right( + pipe( + value, + record.collect((key, item) => \`\${key}|\${item}\`), + join('|'), + ), + ); + } + case 'deepObject': { + return right( + pipe( + value, + record.collect((key, item) => \`\${name}[\${key}]=\${item}\`), + join('&'), + ), + ); + } + } + return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`)); + }; +`; +exports.openapi3utilsRef = ref_1.fromString('#/utils/openapi-3-utils'); +exports.openapi3utilsFile = pipeable_1.pipe(exports.openapi3utilsRef, fp_ts_1.either.map(ref => fs_1.fromRef(ref, '.ts', content))); diff --git a/dist/language/typescript/3.0/index.d.ts b/dist/language/typescript/3.0/index.d.ts new file mode 100644 index 0000000..3a9f3f2 --- /dev/null +++ b/dist/language/typescript/3.0/index.d.ts @@ -0,0 +1,8 @@ +import { FSEntity } from '../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { Dictionary } from '../../../utils/types'; +import { OpenapiObject } from '../../../schema/3.0/openapi-object'; +import { SerializeOptions } from '../common/utils'; +export { serializeDocument } from './serializers/document'; +export declare const serializeCustom: import("fp-ts/lib/Reader").Reader, import("fp-ts/lib/Reader").Reader, (documents: Dictionary, options?: SerializeOptions) => Either>>; +export declare const serialize: import("fp-ts/lib/Reader").Reader, (documents: Dictionary, options?: SerializeOptions) => Either>; diff --git a/dist/language/typescript/3.0/index.js b/dist/language/typescript/3.0/index.js new file mode 100644 index 0000000..57ca04a --- /dev/null +++ b/dist/language/typescript/3.0/index.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const document_1 = require("./serializers/document"); +const prettier_1 = require("prettier"); +const fs_1 = require("../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const utils_1 = require("../common/utils"); +const schema_object_1 = require("./serializers/schema-object"); +var document_2 = require("./serializers/document"); +exports.serializeDocument = document_2.serializeDocument; +exports.serializeCustom = pipeable_1.pipe(reader_utils_1.combineReader(document_1.serializeDocument, serializeDocument => (documents, options = {}) => pipeable_1.pipe(documents, fp_ts_1.record.collect(serializeDocument), either_utils_1.sequenceEither, fp_ts_1.either.map(e => fs_1.map(fs_1.fragment(e), content => prettier_1.format(content, options.prettierConfig || utils_1.defaultPrettierConfig))))), reader => reader_utils_1.deferReader(reader, 'resolveRef')); +exports.serialize = exports.serializeCustom({ serializePrimitive: schema_object_1.serializePrimitiveDefault }); diff --git a/dist/language/typescript/3.0/serializers/components-object.d.ts b/dist/language/typescript/3.0/serializers/components-object.d.ts new file mode 100644 index 0000000..b6ffaec --- /dev/null +++ b/dist/language/typescript/3.0/serializers/components-object.d.ts @@ -0,0 +1,5 @@ +import { Either } from 'fp-ts/lib/Either'; +import { Directory } from '../../../../utils/fs'; +import { Ref } from '../../../../utils/ref'; +import { ComponentsObject } from '../../../../schema/3.0/components-object'; +export declare const serializeComponentsObject: import("fp-ts/lib/Reader").Reader) => (componentsObject: ComponentsObject) => Either>; diff --git a/dist/language/typescript/3.0/serializers/components-object.js b/dist/language/typescript/3.0/serializers/components-object.js new file mode 100644 index 0000000..c41ef93 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/components-object.js @@ -0,0 +1,94 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Either_1 = require("fp-ts/lib/Either"); +const fs_1 = require("../../../../utils/fs"); +const schema_object_1 = require("./schema-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const fp_ts_1 = require("fp-ts"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const utils_1 = require("../../common/utils"); +const ref_1 = require("../../../../utils/ref"); +const schema_object_2 = require("../../../../schema/3.0/schema-object"); +const parameter_object_1 = require("../../../../schema/3.0/parameter-object"); +const parameter_object_2 = require("./parameter-object"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const response_object_1 = require("../../../../schema/3.0/response-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const response_object_2 = require("./response-object"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const request_body_object_1 = require("../../../../schema/3.0/request-body-object"); +const request_body_object_2 = require("./request-body-object"); +const serializeSchema = reader_utils_1.combineReader(schema_object_1.serializeSchemaObject, serializeSchemaObject => (from, schema) => { + const typeName = utils_1.getTypeName(from.name); + const ioName = utils_1.getIOName(from.name); + const serialized = pipeable_1.pipe(schema, serializeSchemaObject(from, typeName)); + const dependencies = pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized => serialized_dependency_1.serializeDependencies(serialized.dependencies))); + return either_utils_1.combineEither(serialized, dependencies, (serialized, dependencies) => fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${typeName} = ${serialized.type}; + export const ${ioName} = ${serialized.io}; + `)); +}); +const serializeSchemas = reader_utils_1.combineReader(utils_1.context, serializeSchema, (e, serializeSchema) => (from, schemas) => pipeable_1.pipe(schemas, fp_ts_1.record.collect((name, schema) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(schema) + ? e.resolveRef(schema.$ref, schema_object_2.SchemaObjectCodec) + : Either_1.right(schema); + const ref = pipeable_1.pipe(from, ref_1.addPathParts('schemas', name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([resolved, ref]) => serializeSchema(ref, resolved))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('schemas', content)))); +const serializeParameter = reader_utils_1.combineReader(parameter_object_2.serializeParameterObject, serializeParameterObject => (from, parameterObject) => pipeable_1.pipe(serializeParameterObject(from, parameterObject), fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${utils_1.getTypeName(from.name)} = ${serialized.type}; + export const ${utils_1.getIOName(from.name)} = ${serialized.io}; + `); +}))); +const serializeParameters = reader_utils_1.combineReader(utils_1.context, serializeParameter, (e, serializeParameter) => (from, parameters) => pipeable_1.pipe(parameters, fp_ts_1.record.collect((name, parameter) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(parameter) + ? e.resolveRef(parameter.$ref, parameter_object_1.ParameterObjectCodec) + : Either_1.right(parameter); + const ref = pipeable_1.pipe(from, ref_1.addPathParts('parameters', name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([parameter, from]) => serializeParameter(from, parameter))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('parameters', content)))); +const serializeResponse = reader_utils_1.combineReader(response_object_2.serializeResponseObject, serializeResponseObject => (from, responseObject) => pipeable_1.pipe(serializeResponseObject(from, responseObject), fp_ts_1.option.getOrElse(() => Either_1.right(serialized_type_1.SERIALIZED_VOID_TYPE)), fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${utils_1.getTypeName(from.name)} = ${serialized.type}; + export const ${utils_1.getIOName(from.name)} = ${serialized.io}; + `); +}))); +const serializeResponses = reader_utils_1.combineReader(utils_1.context, serializeResponse, (e, serializeResponse) => (from, responses) => pipeable_1.pipe(responses, fp_ts_1.record.collect((name, response) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(response) + ? e.resolveRef(response.$ref, response_object_1.ResponseObjectCodec) + : Either_1.right(response); + const ref = pipeable_1.pipe(from, ref_1.addPathParts('responses', name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([resolved, ref]) => serializeResponse(ref, resolved))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('responses', content)))); +const serializeRequestBody = reader_utils_1.combineReader(request_body_object_2.serializeRequestBodyObject, serializeRequestBodyObject => (from, requestBody) => pipeable_1.pipe(serializeRequestBodyObject(from, requestBody), fp_ts_1.either.map(serialized => fs_1.file(`${from.name}.ts`, ` + ${serialized_dependency_1.serializeDependencies(serialized.dependencies)} + + export type ${utils_1.getTypeName(from.name)} = ${serialized.type}; + export const ${utils_1.getIOName(from.name)} = ${serialized.io}; + `)))); +const serializeRequestBodies = reader_utils_1.combineReader(utils_1.context, serializeRequestBody, (e, serializeRequestBody) => (from, requestBodies) => { + return pipeable_1.pipe(requestBodies, fp_ts_1.record.collect((name, requestBody) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(requestBody) + ? e.resolveRef(requestBody.$ref, request_body_object_1.RequestBodyObjectCodec) + : Either_1.right(requestBody); + const ref = pipeable_1.pipe(from, ref_1.addPathParts('requestBodies', name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([resolved, ref]) => serializeRequestBody(ref, resolved))); + }), either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('requestBodies', content))); +}); +exports.serializeComponentsObject = reader_utils_1.combineReader(serializeParameters, serializeResponses, serializeSchemas, serializeRequestBodies, (serializeParameters, serializeResponses, serializeSchemas, serializeRequestBodies) => (from) => (componentsObject) => { + const schemas = pipeable_1.pipe(componentsObject.schemas, fp_ts_1.option.map(schemas => serializeSchemas(from, schemas))); + const parameters = pipeable_1.pipe(componentsObject.parameters, fp_ts_1.option.map(parameters => serializeParameters(from, parameters))); + const responses = pipeable_1.pipe(componentsObject.responses, fp_ts_1.option.map(responses => serializeResponses(from, responses))); + const requestBodies = pipeable_1.pipe(componentsObject.requestBodies, fp_ts_1.option.map(requestBodies => serializeRequestBodies(from, requestBodies))); + return pipeable_1.pipe([schemas, parameters, responses, requestBodies], fp_ts_1.array.compact, either_utils_1.sequenceEither, fp_ts_1.either.map(content => fs_1.directory('components', content))); +}); diff --git a/dist/language/typescript/3.0/serializers/document.d.ts b/dist/language/typescript/3.0/serializers/document.d.ts new file mode 100644 index 0000000..dc0f97e --- /dev/null +++ b/dist/language/typescript/3.0/serializers/document.d.ts @@ -0,0 +1,4 @@ +import { Directory } from '../../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { OpenapiObject } from '../../../../schema/3.0/openapi-object'; +export declare const serializeDocument: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/3.0/serializers/document.js b/dist/language/typescript/3.0/serializers/document.js new file mode 100644 index 0000000..3ed7be5 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/document.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const paths_object_1 = require("./paths-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const components_object_1 = require("./components-object"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +const fp_ts_1 = require("fp-ts"); +const function_1 = require("../../../../utils/function"); +const utils_1 = require("../../common/utils"); +const client_1 = require("../../common/bundled/client"); +const openapi_3_utils_1 = require("../bundled/openapi-3-utils"); +const utils_2 = require("../../common/bundled/utils"); +exports.serializeDocument = reader_utils_1.combineReader(components_object_1.serializeComponentsObject, paths_object_1.serializePathsObject, (serializeComponentsObject, serializePathsObject) => (name, document) => { + const componentsRef = ref_1.fromString('#/components'); + const paths = pipeable_1.pipe(utils_1.pathsRef, fp_ts_1.either.map(serializePathsObject), fp_ts_1.either.chain(function_1.applyTo(document.paths))); + const components = pipeable_1.pipe(document.components, fp_ts_1.option.map(components => pipeable_1.pipe(componentsRef, fp_ts_1.either.map(serializeComponentsObject), fp_ts_1.either.chain(function_1.applyTo(components))))); + const additional = pipeable_1.pipe(fp_ts_1.array.compact([components]), either_utils_1.sequenceEither); + return either_utils_1.combineEither(paths, additional, client_1.clientFile, utils_2.utilsFile, openapi_3_utils_1.openapi3utilsFile, (paths, additional, clientFile, utilsFile, openapi3utilsFile) => fs_1.directory(name, [paths, ...additional, clientFile, utilsFile, openapi3utilsFile])); +}); diff --git a/dist/language/typescript/3.0/serializers/operation-object.d.ts b/dist/language/typescript/3.0/serializers/operation-object.d.ts new file mode 100644 index 0000000..b808092 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/operation-object.d.ts @@ -0,0 +1,23 @@ +import { HTTPMethod } from '../../common/utils'; +import { SerializedType } from '../../common/data/serialized-type'; +import { either } from 'fp-ts'; +import { SerializedPathParameter } from '../../common/data/serialized-path-parameter'; +import { ResolveRefContext, Ref } from '../../../../utils/ref'; +import { OperationObject } from '../../../../schema/3.0/operation-object'; +import { ParameterObject } from '../../../../schema/3.0/parameter-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Kind } from '../../../../utils/types'; +import { PathItemObject } from '../../../../schema/3.0/path-item-object'; +import { SerializedFragment } from '../../common/data/serialized-fragment'; +export declare const getOperationName: (pattern: string, operation: OperationObject, method: HTTPMethod) => string; +interface Parameters { + readonly pathParameters: ParameterObject[]; + readonly serializedPathParameters: SerializedPathParameter[]; + readonly serializedQueryParameter: Option; + readonly serializedBodyParameter: Option; + readonly serializedHeadersParameter: Option; + readonly serializedQueryString: Option; +} +export declare const getParameters: import("fp-ts/lib/Reader").Reader, operation: OperationObject, pathItem: PathItemObject) => either.Either>; +export declare const serializeOperationObject: import("fp-ts/lib/Reader").Reader, kind: Kind, operation: OperationObject, pathItem: PathItemObject) => either.Either>; +export {}; diff --git a/dist/language/typescript/3.0/serializers/operation-object.js b/dist/language/typescript/3.0/serializers/operation-object.js new file mode 100644 index 0000000..54cb146 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/operation-object.js @@ -0,0 +1,239 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../../common/utils"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const parameter_object_1 = require("./parameter-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const responses_object_1 = require("./responses-object"); +const fp_ts_1 = require("fp-ts"); +const Either_1 = require("fp-ts/lib/Either"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const serialized_parameter_1 = require("../../common/data/serialized-parameter"); +const serialized_path_parameter_1 = require("../../common/data/serialized-path-parameter"); +const array_1 = require("../../../../utils/array"); +const string_1 = require("../../../../utils/string"); +const request_body_object_1 = require("./request-body-object"); +const ref_1 = require("../../../../utils/ref"); +const parameter_object_2 = require("../../../../schema/3.0/parameter-object"); +const request_body_object_2 = require("../../../../schema/3.0/request-body-object"); +const Option_1 = require("fp-ts/lib/Option"); +const function_1 = require("fp-ts/lib/function"); +const client_1 = require("../../common/bundled/client"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const Eq_1 = require("fp-ts/lib/Eq"); +const Reader_1 = require("fp-ts/lib/Reader"); +const serialized_fragment_1 = require("../../common/data/serialized-fragment"); +const schema_object_1 = require("../../../../schema/3.0/schema-object"); +const serialized_header_parameters_1 = require("../../common/data/serialized-header-parameters"); +exports.getOperationName = (pattern, operation, method) => pipeable_1.pipe(operation.operationId, fp_ts_1.option.getOrElse(() => `${method}_${utils_1.getSafePropertyName(pattern)}`)); +const eqParameterByNameAndIn = Eq_1.getStructEq({ + name: Eq_1.eqString, + in: Eq_1.eqString, +}); +const contains = fp_ts_1.array.elem(eqParameterByNameAndIn); +exports.getParameters = reader_utils_1.combineReader(Reader_1.ask(), parameter_object_1.serializeParameterObject, request_body_object_1.serializeRequestBodyObject, (e, serializeParameterObject, serializeRequestBodyObject) => (from, operation, pathItem) => { + const processedParameters = []; + const pathParameters = []; + const serializedPathParameters = []; + const serializedQueryParameters = []; + let serializedBodyParameter = Option_1.none; + const queryStringFragments = []; + const serializedHeaderParameters = []; + // note that PathItem parameters should go after OperationObject parameters because they have lower priority + // this means that OperationObject can override PathItemObject parameters + const parameters = fp_ts_1.array.flatten(fp_ts_1.array.compact([operation.parameters, pathItem.parameters])); + for (const parameter of parameters) { + const resolved = reference_object_1.ReferenceObjectCodec.is(parameter) + ? e.resolveRef(parameter.$ref, parameter_object_2.ParameterObjectCodec) + : Either_1.right(Object.assign(Object.assign({}, parameter), { name: utils_1.getTypeName(parameter.name) })); + if (Either_1.isLeft(resolved)) { + return resolved; + } + // if parameter has already been processed then skip it + if (contains(resolved.right, processedParameters)) { + continue; + } + processedParameters.push(resolved.right); + const required = parameter_object_1.isRequired(resolved.right); + const serialized = reference_object_1.ReferenceObjectCodec.is(parameter) + ? pipeable_1.pipe(ref_1.fromString(parameter.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from)), fp_ts_1.either.map(serialized_parameter_1.fromSerializedType(required))) + : serializeParameterObject(from, resolved.right); + if (Either_1.isLeft(serialized)) { + return serialized; + } + switch (resolved.right.in) { + case 'path': { + pathParameters.push(resolved.right); + const serializedParameter = pipeable_1.pipe(serialized.right, serialized_path_parameter_1.fromSerializedParameter(resolved.right.name), serialized_path_parameter_1.getSerializedPathParameterType); + serializedPathParameters.push(serializedParameter); + break; + } + case 'header': { + const serializedParameter = pipeable_1.pipe(serialized.right, serialized_header_parameters_1.fromSerializedHeaderParameter(resolved.right.name), serialized_header_parameters_1.getSerializedHeaderParameterType); + serializedHeaderParameters.push(serializedParameter); + break; + } + case 'query': { + const serializedParameter = serialized_type_1.getSerializedOptionalType(required, serialized.right); + const schema = parameter_object_1.getParameterObjectSchema(resolved.right); + const resolvedSchema = pipeable_1.pipe(schema, fp_ts_1.either.chain(schema => reference_object_1.ReferenceObjectCodec.is(schema) + ? e.resolveRef(schema.$ref, schema_object_1.SchemaObjectCodec) + : Either_1.right(schema))); + if (Either_1.isLeft(resolvedSchema)) { + return resolvedSchema; + } + const queryStringFragment = parameter_object_1.serializeQueryParameterToTemplate(from, resolved.right, resolvedSchema.right, serializedParameter, 'parameters.query'); + if (Either_1.isLeft(queryStringFragment)) { + return queryStringFragment; + } + queryStringFragments.push(queryStringFragment.right); + serializedQueryParameters.push(serialized_type_1.getSerializedPropertyType(resolved.right.name, true, serializedParameter)); + break; + } + } + } + if (Option_1.isSome(operation.requestBody)) { + const requestBody = operation.requestBody.value; + if (reference_object_1.ReferenceObjectCodec.is(requestBody)) { + const reference = ref_1.fromString(requestBody.$ref); + if (Either_1.isLeft(reference)) { + return Either_1.left(new Error(`Invalid RequestBodyObject.$ref "${requestBody.$ref}"`)); + } + const resolved = fp_ts_1.option.fromEither(e.resolveRef(requestBody.$ref, request_body_object_2.RequestBodyObjectCodec)); + if (!Option_1.isSome(resolved)) { + return Either_1.left(new Error(`Unable to resolve RequestBodyObject with ref ${requestBody.$ref}`)); + } + const serializedReference = pipeable_1.pipe(reference.right, serialized_type_1.getSerializedRefType(from)); + const required = pipeable_1.pipe(resolved.value.required, fp_ts_1.option.getOrElse(function_1.constFalse)); + serializedBodyParameter = Option_1.some(serialized_type_1.getSerializedOptionalType(required, serializedReference)); + } + else { + const required = pipeable_1.pipe(requestBody.required, fp_ts_1.option.getOrElse(function_1.constFalse)); + const serialized = pipeable_1.pipe(serializeRequestBodyObject(from, requestBody), fp_ts_1.either.map(serialized => serialized_type_1.getSerializedOptionalType(required, serialized))); + if (Either_1.isLeft(serialized)) { + return serialized; + } + serializedBodyParameter = Option_1.some(serialized.right); + } + } + const serializedQueryParameter = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(serializedQueryParameters), fp_ts_1.option.map(parameters => { + const intercalated = serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), parameters); + return pipeable_1.pipe(intercalated, serialized_type_1.getSerializedObjectType()); + })); + const serializedQueryString = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(queryStringFragments), fp_ts_1.option.map(queryStringFragments => serialized_fragment_1.intercalateSerializedFragmentsNEA(serialized_fragment_1.serializedFragment(',', [], []), queryStringFragments)), fp_ts_1.option.map(f => serialized_fragment_1.combineFragmentsK(f, c => serialized_fragment_1.serializedFragment(`compact([${c}]).join('&')`, [serialized_dependency_1.serializedDependency('compact', 'fp-ts/lib/Array')], [])))); + const serializedHeadersParameter = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(serializedHeaderParameters), fp_ts_1.option.map(parameters => pipeable_1.pipe(serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), parameters), serialized_type_1.getSerializedObjectType()))); + return Either_1.right({ + pathParameters, + serializedPathParameters, + serializedQueryParameter, + serializedHeadersParameter, + serializedBodyParameter, + serializedQueryString, + }); +}); +exports.serializeOperationObject = reader_utils_1.combineReader(Reader_1.ask(), exports.getParameters, responses_object_1.serializeResponsesObject, (e, getParameters, serializeResponsesObject) => (pattern, method, from, kind, operation, pathItem) => { + const parameters = getParameters(from, operation, pathItem); + const operationName = exports.getOperationName(pattern, operation, method); + const deprecated = pipeable_1.pipe(operation.deprecated, fp_ts_1.option.map(() => '@deprecated')); + const serializedResponses = serializeResponsesObject(from)(operation.responses); + const serializedContentType = pipeable_1.pipe(operation.requestBody, Option_1.chain(requestBody => reference_object_1.ReferenceObjectCodec.is(requestBody) + ? Option_1.fromEither(e.resolveRef(requestBody.$ref, request_body_object_2.RequestBodyObjectCodec)) + : Option_1.some(requestBody)), Option_1.map(request => request.content), Option_1.chain(request_body_object_1.getRequestMedia), Option_1.map(({ key }) => key), Option_1.fold(() => '', contentType => `'Content-type': '${contentType}',`)); + return either_utils_1.combineEither(parameters, serializedResponses, client_1.clientRef, (parameters, serializedResponses, clientRef) => { + const hasQueryParameters = Option_1.isSome(parameters.serializedQueryParameter); + const hasBodyParameter = Option_1.isSome(parameters.serializedBodyParameter); + const hasHeaderParameters = Option_1.isSome(parameters.serializedHeadersParameter); + const hasParameters = hasQueryParameters || hasBodyParameter || hasHeaderParameters; + const bodyType = pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(body => `body: ${body.type},`), fp_ts_1.option.getOrElse(() => '')); + const bodyIO = pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(body => `const body = ${body.io}.encode(parameters.body);`), fp_ts_1.option.getOrElse(() => '')); + const queryType = pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(query => `query: ${query.type};`), fp_ts_1.option.getOrElse(() => '')); + const queryIO = pipeable_1.pipe(parameters.serializedQueryString, fp_ts_1.option.map(query => `const query = ${query.value};`), fp_ts_1.option.getOrElse(() => '')); + const headersType = pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(headers => `headers: ${headers.type};`), fp_ts_1.option.getOrElse(() => '')); + const headersIO = pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(headers => `const headers = ${headers.io}.encode(parameters.headers)`), fp_ts_1.option.getOrElse(() => '')); + const argsType = array_1.concatIf(hasParameters, parameters.serializedPathParameters.map(p => p.type), [`parameters${hasParameters ? '' : '?'}: { ${queryType}${bodyType}${headersType} }`]).join(','); + const argsTypeWithAccept = array_1.concatIf(true, parameters.serializedPathParameters.map(p => p.type), [`parameters${hasParameters ? '' : '?'}: { ${queryType}${bodyType}${headersType} accept: A; }`]).join(','); + const type = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(sr => ` + ${utils_1.getJSDoc(fp_ts_1.array.compact([deprecated, operation.summary]))} + readonly ${operationName}: (${argsType}) => ${utils_1.getKindValue(kind, sr.schema.type)}; + `, sr => ` + ${utils_1.getJSDoc(fp_ts_1.array.compact([deprecated, operation.summary]))} + ${operationName}(${argsType}): ${utils_1.getKindValue(kind, `MapToResponse${operationName}['${sr[0].mediaType}']`)}; + ${operationName}(${argsTypeWithAccept}): ${utils_1.getKindValue(kind, `MapToResponse${operationName}[A]`)};`)); + const argsIO = array_1.concatIf(hasParameters, parameters.pathParameters.map(p => p.name), ['parameters']).join(','); + const methodTypeIO = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(() => `(${argsIO})`, () => ` + (${argsTypeWithAccept}): ${utils_1.getKindValue(kind, `MapToResponse${operationName}[A]`)}`)); + const decode = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(sr => `${sr.schema.io}.decode(value)`, () => `decode(accept, value)`)); + const acceptIO = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(sr => `const accept = '${sr.mediaType}';`, sr => `const accept = (parameters && parameters.accept || '${sr[0].mediaType}') as A`)); + const mapToIO = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(() => '', sr => { + const rows = sr.map(s => `'${s.mediaType}': ${s.schema.io}`); + return `const mapToIO = { ${rows.join()} };`; + })); + const decodeIO = pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(() => '', () => `const decode = (a: A, b: unknown) => + (mapToIO[a].decode(b) as unknown) as Either;`)); + const requestHeaders = `{ + Accept: accept, + ${serializedContentType} + }`; + const io = ` + ${operationName}: ${methodTypeIO} => { + ${bodyIO} + ${queryIO} + ${headersIO} + ${acceptIO} + ${mapToIO} + ${decodeIO} + const responseType = getResponseTypeFromMediaType(accept); + const requestHeaders = ${requestHeaders} + + return e.httpClient.chain( + e.httpClient.request({ + url: ${utils_1.getURL(pattern, parameters.serializedPathParameters)}, + method: '${method}', + responseType, + ${string_1.when(hasQueryParameters, 'query,')} + ${string_1.when(hasBodyParameter, 'body,')} + headers: {${hasHeaderParameters ? '...headers,' : ''} ...requestHeaders} + }), + value => + pipe( + ${decode}, + either.mapLeft(ResponseValidationError.create), + either.fold(error => e.httpClient.throwError(error), decoded => e.httpClient.of(decoded)), + ), + ); + }, + `; + const dependencies = [ + serialized_dependency_1.serializedDependency('getResponseTypeFromMediaType', '../utils/utils'), + serialized_dependency_1.serializedDependency('ResponseValidationError', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('pipe', 'fp-ts/lib/pipeable'), + serialized_dependency_1.serializedDependency('either', 'fp-ts'), + serialized_dependency_1.getSerializedKindDependency(kind), + ...pipeable_1.pipe(serializedResponses, fp_ts_1.either.fold(s => s.schema.dependencies, function_1.flow(fp_ts_1.array.map(s => s.schema.dependencies), fp_ts_1.array.flatten, arr => [ + ...arr, + serialized_dependency_1.serializedDependency('Errors', 'io-ts'), + serialized_dependency_1.serializedDependency('Either', 'fp-ts/lib/Either'), + ]))), + ...fp_ts_1.array.flatten([ + ...parameters.serializedPathParameters.map(p => p.dependencies), + ...fp_ts_1.array.compact([ + pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.serializedQueryString, fp_ts_1.option.map(p => p.dependencies)), + pipeable_1.pipe(parameters.serializedHeadersParameter, fp_ts_1.option.map(p => p.dependencies)), + ]), + ]), + ]; + const refs = fp_ts_1.array.flatten([ + ...parameters.serializedPathParameters.map(p => p.refs), + ...fp_ts_1.array.compact([ + pipeable_1.pipe(parameters.serializedQueryParameter, fp_ts_1.option.map(p => p.refs)), + pipeable_1.pipe(parameters.serializedBodyParameter, fp_ts_1.option.map(p => p.refs)), + pipeable_1.pipe(parameters.serializedQueryString, fp_ts_1.option.map(p => p.refs)), + ]), + ]); + return serialized_type_1.serializedType(type, io, dependencies, refs); + }); +}); diff --git a/dist/language/typescript/3.0/serializers/parameter-object.d.ts b/dist/language/typescript/3.0/serializers/parameter-object.d.ts new file mode 100644 index 0000000..beee805 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/parameter-object.d.ts @@ -0,0 +1,12 @@ +import { SerializedParameter } from '../../common/data/serialized-parameter'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Ref } from '../../../../utils/ref'; +import { ParameterObject } from '../../../../schema/3.0/parameter-object'; +import { ReferenceObject } from '../../../../schema/3.0/reference-object'; +import { SchemaObject } from '../../../../schema/3.0/schema-object'; +import { SerializedFragment } from '../../common/data/serialized-fragment'; +export declare const isRequired: (parameter: ParameterObject) => boolean; +export declare const serializeParameterObject: import("fp-ts/lib/Reader").Reader, parameterObject: ParameterObject) => Either>; +export declare const getParameterObjectSchema: (parameterObject: ParameterObject) => Either; +export declare const serializeQueryParameterToTemplate: (from: Ref, parameter: ParameterObject, parameterSchema: SchemaObject, serializedSchema: SerializedType, target: string) => Either; diff --git a/dist/language/typescript/3.0/serializers/parameter-object.js b/dist/language/typescript/3.0/serializers/parameter-object.js new file mode 100644 index 0000000..c359b67 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/parameter-object.js @@ -0,0 +1,76 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_parameter_1 = require("../../common/data/serialized-parameter"); +const Either_1 = require("fp-ts/lib/Either"); +const schema_object_1 = require("./schema-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const ref_1 = require("../../../../utils/ref"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const function_1 = require("fp-ts/lib/function"); +const schema_object_2 = require("../../../../schema/3.0/schema-object"); +const serialized_fragment_1 = require("../../common/data/serialized-fragment"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const openapi_3_utils_1 = require("../bundled/openapi-3-utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const forParameter = (parameter) => `for parameter "${parameter.name}" in "${parameter.in}"`; +exports.isRequired = (parameter) => parameter.in === 'path' ? parameter.required : pipeable_1.pipe(parameter.required, fp_ts_1.option.getOrElse(function_1.constFalse)); +exports.serializeParameterObject = reader_utils_1.combineReader(schema_object_1.serializeSchemaObject, serializeSchemaObject => (from, parameterObject) => pipeable_1.pipe(exports.getParameterObjectSchema(parameterObject), fp_ts_1.either.chain(schema => { + if (reference_object_1.ReferenceObjectCodec.is(schema)) { + return pipeable_1.pipe(ref_1.fromString(schema.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))); + } + else { + return pipeable_1.pipe(schema, serializeSchemaObject(from)); + } +}), fp_ts_1.either.map(serialized_parameter_1.fromSerializedType(exports.isRequired(parameterObject))))); +exports.getParameterObjectSchema = (parameterObject) => pipeable_1.pipe(parameterObject.schema, fp_ts_1.option.alt(() => pipeable_1.pipe(parameterObject.content, fp_ts_1.option.chain(content => fp_ts_1.record.lookup('application/json', content)), fp_ts_1.option.chain(media => media.schema))), fp_ts_1.either.fromOption(() => new Error(`Unable to get schema ${forParameter(parameterObject)}`))); +const getParameterObjectStyle = (parameter) => pipeable_1.pipe(parameter.style, fp_ts_1.option.getOrElse(() => { + switch (parameter.in) { + case 'path': { + return 'simple'; + } + case 'header': { + return 'simple'; + } + case 'query': { + return 'form'; + } + case 'cookie': { + return 'form'; + } + } +})); +const getParameterExplode = (parameter) => pipeable_1.pipe(parameter.explode, fp_ts_1.option.getOrElse(() => getParameterObjectStyle(parameter) === 'form')); +exports.serializeQueryParameterToTemplate = (from, parameter, parameterSchema, serializedSchema, target) => { + if (Either_1.isLeft(openapi_3_utils_1.openapi3utilsRef)) { + return openapi_3_utils_1.openapi3utilsRef; + } + const pathToUtils = ref_1.getRelativePath(from, openapi_3_utils_1.openapi3utilsRef.right); + const required = exports.isRequired(parameter); + const encoded = serialized_fragment_1.serializedFragment(`${serializedSchema.io}.encode(${target}['${parameter.name}'])`, serializedSchema.dependencies, serializedSchema.refs); + return pipeable_1.pipe(getFn(pathToUtils, parameterSchema, parameter), fp_ts_1.either.map(fn => serialized_fragment_1.getSerializedOptionCallFragment(!required, fn, encoded))); +}; +const getFn = (pathToUtils, schema, parameter) => { + const explode = getParameterExplode(parameter); + const style = getParameterObjectStyle(parameter); + if (schema_object_2.PrimitiveSchemaObjectCodec.is(schema)) { + return Either_1.right(serialized_fragment_1.serializedFragment(`value => fromEither(serializePrimitiveParameter('${style}', '${parameter.name}', value))`, [ + serialized_dependency_1.serializedDependency('fromEither', 'fp-ts/lib/Option'), + serialized_dependency_1.serializedDependency('serializePrimitiveParameter', pathToUtils), + ], [])); + } + if (schema_object_2.ArraySchemaObjectCodec.is(schema)) { + return Either_1.right(serialized_fragment_1.serializedFragment(`value => fromEither(serializeArrayParameter('${style}', '${parameter.name}', value, ${explode}))`, [ + serialized_dependency_1.serializedDependency('fromEither', 'fp-ts/lib/Option'), + serialized_dependency_1.serializedDependency('serializeArrayParameter', pathToUtils), + ], [])); + } + if (schema_object_2.ObjectSchemaObjectCodec.is(schema)) { + return Either_1.right(serialized_fragment_1.serializedFragment(`value => fromEither(serializeObjectParameter('${style}', '${parameter.name}', value, ${explode}))`, [ + serialized_dependency_1.serializedDependency('fromEither', 'fp-ts/lib/Option'), + serialized_dependency_1.serializedDependency('serializeObjectParameter', pathToUtils), + ], [])); + } + return Either_1.left(new Error(`Unsupported schema for parameter "${parameter.name}"`)); +}; diff --git a/dist/language/typescript/3.0/serializers/path-item-object.d.ts b/dist/language/typescript/3.0/serializers/path-item-object.d.ts new file mode 100644 index 0000000..7c70aed --- /dev/null +++ b/dist/language/typescript/3.0/serializers/path-item-object.d.ts @@ -0,0 +1,8 @@ +import { SerializedType } from '../../common/data/serialized-type'; +import { Either } from 'fp-ts/lib/Either'; +import { option } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +import { PathItemObject } from '../../../../schema/3.0/path-item-object'; +import { Kind } from '../../../../utils/types'; +export declare const serializePathItemObject: import("fp-ts/lib/Reader").Reader, kind: Kind) => Either>; +export declare const serializePathItemObjectTags: (pathItemObject: PathItemObject) => option.Option; diff --git a/dist/language/typescript/3.0/serializers/path-item-object.js b/dist/language/typescript/3.0/serializers/path-item-object.js new file mode 100644 index 0000000..37afb29 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/path-item-object.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Array_1 = require("fp-ts/lib/Array"); +const array_1 = require("../../../../utils/array"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const operation_object_1 = require("./operation-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const fp_ts_1 = require("fp-ts"); +exports.serializePathItemObject = reader_utils_1.combineReader(operation_object_1.serializeOperationObject, serializeOperationObject => (pattern, item, from, kind) => { + const get = pipeable_1.pipe(item.get, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'GET', from, kind, operation, item))); + const post = pipeable_1.pipe(item.post, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'POST', from, kind, operation, item))); + const put = pipeable_1.pipe(item.put, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'PUT', from, kind, operation, item))); + const remove = pipeable_1.pipe(item.delete, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'DELETE', from, kind, operation, item))); + const patch = pipeable_1.pipe(item.patch, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'PATCH', from, kind, operation, item))); + const head = pipeable_1.pipe(item.head, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'HEAD', from, kind, operation, item))); + const options = pipeable_1.pipe(item.options, fp_ts_1.option.map(operation => serializeOperationObject(pattern, 'OPTIONS', from, kind, operation, item))); + return pipeable_1.pipe(fp_ts_1.array.compact([get, post, put, remove, patch, head, options]), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); +}); +exports.serializePathItemObjectTags = (pathItemObject) => { + const operations = [ + pathItemObject.get, + pathItemObject.post, + pathItemObject.put, + pathItemObject.delete, + pathItemObject.options, + pathItemObject.head, + pathItemObject.patch, + pathItemObject.trace, + ]; + return pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(fp_ts_1.array.compact(operations)), fp_ts_1.option.map(operations => array_1.uniqString(Array_1.flatten(fp_ts_1.array.compact(operations.map(operation => operation.tags))))), fp_ts_1.option.chain(fp_ts_1.nonEmptyArray.fromArray), fp_ts_1.option.map(tags => tags.join('').replace(/\s/g, ''))); +}; diff --git a/dist/language/typescript/3.0/serializers/paths-object.d.ts b/dist/language/typescript/3.0/serializers/paths-object.d.ts new file mode 100644 index 0000000..90ed303 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/paths-object.d.ts @@ -0,0 +1,6 @@ +import { Directory } from '../../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { reader } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +import { PathsObject } from '../../../../schema/3.0/paths-object'; +export declare const serializePathsObject: reader.Reader) => (pathsObject: PathsObject) => Either>; diff --git a/dist/language/typescript/3.0/serializers/paths-object.js b/dist/language/typescript/3.0/serializers/paths-object.js new file mode 100644 index 0000000..d6cf442 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/paths-object.js @@ -0,0 +1,128 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const Record_1 = require("fp-ts/lib/Record"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const path_item_object_1 = require("./path-item-object"); +const types_1 = require("../../../../utils/types"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const string_1 = require("@devexperts/utils/dist/string/string"); +const Either_1 = require("fp-ts/lib/Either"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const either_utils_2 = require("@devexperts/utils/dist/adt/either.utils"); +const function_1 = require("../../../../utils/function"); +const client_1 = require("../../common/bundled/client"); +const utils_1 = require("../../common/utils"); +const response_maps_1 = require("./response-maps"); +const serializeGrouppedPaths = reader_utils_1.combineReader(path_item_object_1.serializePathItemObject, response_maps_1.serializeResponseMaps, (serializePathItemObject, serializeResponseMaps) => (from) => (groupped) => { + const serializedHKT = pipeable_1.pipe(types_1.serializeDictionary(groupped, (pattern, item) => serializePathItemObject(pattern, item, from, 'HKT')), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + const serializedKind = pipeable_1.pipe(types_1.serializeDictionary(groupped, (pattern, item) => serializePathItemObject(pattern, item, from, '*')), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + const serializedKind2 = pipeable_1.pipe(types_1.serializeDictionary(groupped, (pattern, item) => serializePathItemObject(pattern, item, from, '* -> *')), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + const serializedResponseMaps = pipeable_1.pipe(types_1.serializeDictionary(groupped, (pattern, item) => serializeResponseMaps(pattern, item, from)), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); + return either_utils_2.combineEither(serializedHKT, serializedKind, serializedKind2, client_1.clientRef, serializedResponseMaps, (serializedHKT, serializedKind, serializedKind2, clientRef, serializedMaps) => { + const dependencies = serialized_dependency_1.serializeDependencies([ + ...serializedHKT.dependencies, + ...serializedKind.dependencies, + ...serializedKind2.dependencies, + serialized_dependency_1.serializedDependency('HTTPClient', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('HTTPClient1', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('HTTPClient2', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.serializedDependency('URIS', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + ]); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + ${serializedMaps.type} + + export interface ${from.name} { + ${serializedHKT.type} + } + + export interface ${from.name}1 { + ${serializedKind.type} + } + + export interface ${from.name}2 { + ${serializedKind2.type} + } + + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient2 }): ${from.name}2 + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient1 }): ${from.name}1 + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient }): ${from.name}; + export function ${string_1.decapitalize(from.name)}(e: { httpClient: HTTPClient }): ${from.name} { + return { + ${serializedHKT.io} + } + } + `); + }); +}); +exports.serializePathsObject = reader_utils_1.combineReader(serializeGrouppedPaths, serializeGrouppedPaths => (from) => (pathsObject) => { + const groupped = groupPathsByTag(pathsObject); + const files = pipeable_1.pipe(groupped, Record_1.collect((name, groupped) => pipeable_1.pipe(from, ref_1.addPathParts(name), fp_ts_1.either.map(serializeGrouppedPaths), fp_ts_1.either.chain(function_1.applyTo(groupped)))), either_utils_1.sequenceEither); + const index = pipeable_1.pipe(from, ref_1.addPathParts('paths'), fp_ts_1.either.chain(from => serializePathsIndex(from, fp_ts_1.record.keys(groupped)))); + return either_utils_2.combineEither(files, index, (files, index) => fs_1.directory('paths', [...files, index])); +}); +const groupPathsByTag = (pathsObject) => { + const keys = Object.keys(pathsObject); + const result = {}; + for (const key of keys) { + const path = pathsObject[key]; + const tag = pipeable_1.pipe(path_item_object_1.serializePathItemObjectTags(path), fp_ts_1.option.map(p => utils_1.getControllerName(string_1.camelize(p, false))), fp_ts_1.option.getOrElse(() => utils_1.getControllerName('Unknown'))); + result[tag] = Object.assign(Object.assign({}, (result[tag] || {})), { [key]: path }); + } + return result; +}; +const serializePathsIndex = (from, pathNames) => { + if (Either_1.isLeft(client_1.clientRef)) { + return client_1.clientRef; + } + const pathToClient = ref_1.getRelativePath(from, client_1.clientRef.right); + const dependencies = serialized_dependency_1.serializeDependencies([ + ...fp_ts_1.array.flatten(pathNames.map(name => { + const p = `./${name}`; + return [ + serialized_dependency_1.serializedDependency(string_1.decapitalize(name), p), + serialized_dependency_1.serializedDependency(name, p), + serialized_dependency_1.serializedDependency(`${name}1`, p), + serialized_dependency_1.serializedDependency(`${name}2`, p), + ]; + })), + serialized_dependency_1.serializedDependency('URIS', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('HTTPClient', pathToClient), + serialized_dependency_1.serializedDependency('HTTPClient1', pathToClient), + serialized_dependency_1.serializedDependency('HTTPClient2', pathToClient), + ]); + const content = ` + export interface Controllers { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name};`).join('\n')} + } + export interface Controllers1 { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name}1;`).join('\n')} + } + export interface Controllers2 { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${name}2;`).join('\n')} + } + + export function controllers(e: { httpClient: HTTPClient2 }): Controllers2 + export function controllers(e: { httpClient: HTTPClient1 }): Controllers1 + export function controllers(e: { httpClient: HTTPClient }): Controllers; + export function controllers(e: { httpClient: HTTPClient }): Controllers { + return { + ${pathNames.map(name => `${string_1.decapitalize(name)}: ${string_1.decapitalize(name)}(e),`).join('\n')} + } + } + `; + return Either_1.right(fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + ${content} + `)); +}; diff --git a/dist/language/typescript/3.0/serializers/request-body-object.d.ts b/dist/language/typescript/3.0/serializers/request-body-object.d.ts new file mode 100644 index 0000000..a601960 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/request-body-object.d.ts @@ -0,0 +1,11 @@ +import { SerializedType } from '../../common/data/serialized-type'; +import { Either } from 'fp-ts/lib/Either'; +import { option } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +import { RequestBodyObject } from '../../../../schema/3.0/request-body-object'; +import { MediaTypeObject } from '../../../../schema/3.0/media-type-object'; +export declare const getRequestMedia: (content: Record) => option.Option<{ + key: string; + value: MediaTypeObject; +}>; +export declare const serializeRequestBodyObject: import("fp-ts/lib/Reader").Reader, body: RequestBodyObject) => Either>; diff --git a/dist/language/typescript/3.0/serializers/request-body-object.js b/dist/language/typescript/3.0/serializers/request-body-object.js new file mode 100644 index 0000000..6a18cbb --- /dev/null +++ b/dist/language/typescript/3.0/serializers/request-body-object.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const schema_object_1 = require("./schema-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const Either_1 = require("fp-ts/lib/Either"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const utils_1 = require("../../common/utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const requestMediaRegexp = /^(video|audio|image|application|text|multipart|\*)\/(\w+|\*)/; +exports.getRequestMedia = (content) => utils_1.getKeyMatchValue(content, requestMediaRegexp); +exports.serializeRequestBodyObject = reader_utils_1.combineReader(schema_object_1.serializeSchemaObject, serializeSchemaObject => { + const serializeRequestBodyObject = (from, body) => pipeable_1.pipe(exports.getRequestMedia(body.content), fp_ts_1.option.chain(({ key: mediaType, value: { schema } }) => pipeable_1.pipe(schema, fp_ts_1.option.map(schema => ({ mediaType, schema })))), fp_ts_1.either.fromOption(() => new Error('No schema found for RequestBodyObject')), fp_ts_1.either.chain(({ mediaType, schema }) => { + const resType = utils_1.getResponseTypeFromMediaType(mediaType); + return serializeRequestSchema(resType, schema, from); + })); + const serializeRequestSchema = (responseType, schema, from) => { + switch (responseType) { + case 'json': + return reference_object_1.ReferenceObjectCodec.is(schema) + ? pipeable_1.pipe(ref_1.fromString(schema.$ref), Either_1.mapLeft(() => new Error(`Invalid MediaObject.content.$ref "${schema.$ref}" for RequestBodyObject`)), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObject(from)(schema); + case 'text': + return fp_ts_1.either.right(serialized_type_1.SERIALIZED_STRING_TYPE); + case 'blob': + return serialized_type_1.getSerializedBlobType(from); + } + }; + return serializeRequestBodyObject; +}); diff --git a/dist/language/typescript/3.0/serializers/response-maps.d.ts b/dist/language/typescript/3.0/serializers/response-maps.d.ts new file mode 100644 index 0000000..67035d0 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/response-maps.d.ts @@ -0,0 +1,5 @@ +import { either } from 'fp-ts'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Ref } from '../../../../utils/ref'; +import { PathItemObject } from '../../../../schema/3.0/path-item-object'; +export declare const serializeResponseMaps: import("fp-ts/lib/Reader").Reader) => either.Either>; diff --git a/dist/language/typescript/3.0/serializers/response-maps.js b/dist/language/typescript/3.0/serializers/response-maps.js new file mode 100644 index 0000000..7390c3e --- /dev/null +++ b/dist/language/typescript/3.0/serializers/response-maps.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fp_ts_1 = require("fp-ts"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const function_1 = require("fp-ts/lib/function"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const operation_object_1 = require("./operation-object"); +const responses_object_1 = require("./responses-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const serializeResponseMap = reader_utils_1.combineReader(responses_object_1.serializeResponsesObject, serializeResponsesObject => (pattern, method, from, operation) => { + const operationName = operation_object_1.getOperationName(pattern, operation, method); + const serializedResponses = serializeResponsesObject(from)(operation.responses); + return pipeable_1.pipe(serializedResponses, fp_ts_1.either.map(function_1.flow(fp_ts_1.either.fold(() => serialized_type_1.serializedType('', '', [], []), sr => { + const rows = sr.map(s => `'${s.mediaType}': ${s.schema.type};`); + const type = `type MapToResponse${operationName} = {${rows.join('')}};`; + return serialized_type_1.serializedType(type, '', [], []); // dependecies in serializeOperationObject serializedResponses + })))); +}); +exports.serializeResponseMaps = reader_utils_1.combineReader(serializeResponseMap, serializeResponseMap => (pattern, item, from) => { + const methods = [ + ['GET', item.get], + ['POST', item.post], + ['PUT', item.put], + ['DELETE', item.delete], + ['PATCH', item.patch], + ['HEAD', item.head], + ['OPTIONS', item.options], + ]; + return pipeable_1.pipe(methods, fp_ts_1.array.map(([method, opObject]) => pipeable_1.pipe(opObject, fp_ts_1.option.map(operation => serializeResponseMap(pattern, method, from, operation)))), fp_ts_1.array.compact, either_utils_1.sequenceEither, fp_ts_1.either.map(serialized_type_1.foldSerializedTypes)); +}); diff --git a/dist/language/typescript/3.0/serializers/response-object.d.ts b/dist/language/typescript/3.0/serializers/response-object.d.ts new file mode 100644 index 0000000..cd99f79 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/response-object.d.ts @@ -0,0 +1,11 @@ +import { SerializedType } from '../../common/data/serialized-type'; +import { Either } from 'fp-ts/lib/Either'; +import { Ref } from '../../../../utils/ref'; +import { option } from 'fp-ts'; +import { ResponseObject } from '../../../../schema/3.0/response-object'; +export declare type SerializedResponse = { + mediaType: string; + schema: SerializedType; +}; +export declare const serializeResponseObject: import("fp-ts/lib/Reader").Reader, responseObject: ResponseObject) => option.Option>>; +export declare const serializeResponseObjectWithMediaType: import("fp-ts/lib/Reader").Reader, responseObject: ResponseObject) => option.Option>>; diff --git a/dist/language/typescript/3.0/serializers/response-object.js b/dist/language/typescript/3.0/serializers/response-object.js new file mode 100644 index 0000000..c77e9ef --- /dev/null +++ b/dist/language/typescript/3.0/serializers/response-object.js @@ -0,0 +1,35 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const schema_object_1 = require("./schema-object"); +const ref_1 = require("../../../../utils/ref"); +const fp_ts_1 = require("fp-ts"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const utils_1 = require("../../common/utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const requestMediaRegexp = /^(video|audio|image|application|text|\*)\/(\w+|\*)/; +const serializeResponseSchema = reader_utils_1.combineReader(schema_object_1.serializeSchemaObject, serializeSchemaObject => (responseType, schema, from) => { + switch (responseType) { + case 'json': + return reference_object_1.ReferenceObjectCodec.is(schema) + ? pipeable_1.pipe(ref_1.fromString(schema.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObject(from)(schema); + case 'text': + return fp_ts_1.either.right(serialized_type_1.SERIALIZED_STRING_TYPE); + case 'blob': + return serialized_type_1.getSerializedBlobType(from); + } +}); +exports.serializeResponseObject = reader_utils_1.combineReader(schema_object_1.serializeSchemaObject, serializeResponseSchema, (serializeSchemaObject, serializeResponseSchema) => (from, responseObject) => pipeable_1.pipe(responseObject.content, fp_ts_1.option.chain(content => utils_1.getKeyMatchValue(content, requestMediaRegexp)), fp_ts_1.option.chain(({ key: mediaType, value: { schema } }) => pipeable_1.pipe(schema, fp_ts_1.option.map(schema => ({ mediaType, schema })))), fp_ts_1.option.map(({ mediaType, schema }) => { + const resType = utils_1.getResponseTypeFromMediaType(mediaType); + return serializeResponseSchema(resType, schema, from); +}))); +exports.serializeResponseObjectWithMediaType = reader_utils_1.combineReader(serializeResponseSchema, serializeResponseSchema => (from, responseObject) => pipeable_1.pipe(responseObject.content, fp_ts_1.option.chain(content => utils_1.getKeyMatchValues(content, requestMediaRegexp)), fp_ts_1.option.chain(arr => pipeable_1.pipe(arr, fp_ts_1.array.map(({ key: mediaType, value: { schema } }) => pipeable_1.pipe(schema, fp_ts_1.option.map(schema => ({ mediaType, schema })))), fp_ts_1.array.filterMap(a => a), fp_ts_1.nonEmptyArray.fromArray)), fp_ts_1.option.map(arr => pipeable_1.pipe(arr, fp_ts_1.array.map(({ mediaType, schema }) => { + const resType = utils_1.getResponseTypeFromMediaType(mediaType); + return pipeable_1.pipe(serializeResponseSchema(resType, schema, from), fp_ts_1.either.map(schema => ({ + mediaType, + schema, + }))); +}), either_utils_1.sequenceEither)))); diff --git a/dist/language/typescript/3.0/serializers/responses-object.d.ts b/dist/language/typescript/3.0/serializers/responses-object.d.ts new file mode 100644 index 0000000..405a997 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/responses-object.d.ts @@ -0,0 +1,5 @@ +import { SerializedResponse } from './response-object'; +import { either } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +import { ResponsesObject } from '../../../../schema/3.0/responses-object'; +export declare const serializeResponsesObject: import("fp-ts/lib/Reader").Reader) => (responsesObject: ResponsesObject) => either.Either>>; diff --git a/dist/language/typescript/3.0/serializers/responses-object.js b/dist/language/typescript/3.0/serializers/responses-object.js new file mode 100644 index 0000000..2b911ce --- /dev/null +++ b/dist/language/typescript/3.0/serializers/responses-object.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const utils_1 = require("../../common/utils"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const response_object_1 = require("./response-object"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const fp_ts_1 = require("fp-ts"); +const ref_1 = require("../../../../utils/ref"); +const function_1 = require("fp-ts/lib/function"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const Option_1 = require("fp-ts/lib/Option"); +const Eq_1 = require("fp-ts/lib/Eq"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const concatNonUniqResonses = (responses) => pipeable_1.pipe(responses, fp_ts_1.array.map(({ mediaType }) => mediaType), fp_ts_1.array.uniq(Eq_1.eqString), fp_ts_1.array.map(mediaType => { + const schemes = pipeable_1.pipe(responses, fp_ts_1.array.filter(a => a.mediaType === mediaType), fp_ts_1.array.map(a => a.schema), serialized_type_1.uniqSerializedTypesByTypeAndIO); + if (schemes.length > 1) { + const combined = serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType('|', ',', [], []), schemes); + const scheme = serialized_type_1.serializedType(combined.type, `union([${combined.io}])`, combined.dependencies.concat([serialized_dependency_1.serializedDependency('union', 'io-ts')]), []); + return { mediaType, schema: scheme }; + } + return { mediaType, schema: schemes[0] }; +})); +exports.serializeResponsesObject = reader_utils_1.combineReader(response_object_1.serializeResponseObjectWithMediaType, serializeResponseObjectWithMediaType => (from) => (responsesObject) => { + const serializedResponses = pipeable_1.pipe(utils_1.SUCCESSFUL_CODES, fp_ts_1.array.map(code => pipeable_1.pipe(fp_ts_1.record.lookup(code, responsesObject), fp_ts_1.option.chain(r => reference_object_1.ReferenceObjectCodec.is(r) + ? pipeable_1.pipe(ref_1.fromString(r.$ref), fp_ts_1.either.mapLeft(() => new Error(`Invalid ${r.$ref} for ResponsesObject'c code "${code}"`)), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from)), fp_ts_1.either.map(type => [{ mediaType: utils_1.DEFAULT_MEDIA_TYPE, schema: type }]), Option_1.some) + : serializeResponseObjectWithMediaType(from, r)))), fp_ts_1.array.compact, either_utils_1.sequenceEither, fp_ts_1.either.map(function_1.flow(fp_ts_1.array.flatten, concatNonUniqResonses))); + return pipeable_1.pipe(serializedResponses, fp_ts_1.either.map(serializedResponses => { + if (serializedResponses.length === 0) { + return fp_ts_1.either.left({ mediaType: utils_1.DEFAULT_MEDIA_TYPE, schema: serialized_type_1.SERIALIZED_VOID_TYPE }); + } + else if (serializedResponses.length === 1) { + return fp_ts_1.either.left(serializedResponses[0]); + } + else { + return fp_ts_1.either.right(serializedResponses); + } + })); +}); diff --git a/dist/language/typescript/3.0/serializers/schema-object.d.ts b/dist/language/typescript/3.0/serializers/schema-object.d.ts new file mode 100644 index 0000000..68fde97 --- /dev/null +++ b/dist/language/typescript/3.0/serializers/schema-object.d.ts @@ -0,0 +1,14 @@ +import { SerializedType } from '../../common/data/serialized-type'; +import { Either } from 'fp-ts/lib/Either'; +import { reader } from 'fp-ts'; +import { Ref } from '../../../../utils/ref'; +import { SchemaObject, PrimitiveSchemaObject } from '../../../../schema/3.0/schema-object'; +export declare type SerializeSchemaObjectWithRecursion = (from: Ref, shouldTrackRecursion: boolean, name?: string) => (schemaObject: SchemaObject) => Either; +export declare type SerializePrimitive = (from: Ref, schemaObject: PrimitiveSchemaObject) => Either; +export interface SerializeSchemaObjectWithRecursionContext { + serializePrimitive: SerializePrimitive; +} +export declare const serializeSchemaObjectWithRecursion: reader.Reader; +export declare const serializePrimitiveDefault: (from: Ref, schemaObject: PrimitiveSchemaObject) => Either; +export declare const serializeSchemaObject: reader.Reader, name?: string | undefined) => (schemaObject: SchemaObject) => Either>; +export declare const serializeSchemaObjectDefault: (from: Ref, name?: string | undefined) => (schemaObject: SchemaObject) => Either; diff --git a/dist/language/typescript/3.0/serializers/schema-object.js b/dist/language/typescript/3.0/serializers/schema-object.js new file mode 100644 index 0000000..cdb53ea --- /dev/null +++ b/dist/language/typescript/3.0/serializers/schema-object.js @@ -0,0 +1,91 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_type_1 = require("../../common/data/serialized-type"); +const Either_1 = require("fp-ts/lib/Either"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const types_1 = require("../../../../utils/types"); +const function_1 = require("fp-ts/lib/function"); +const array_1 = require("../../../../utils/array"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const ref_1 = require("../../../../utils/ref"); +const schema_object_1 = require("../../../../schema/3.0/schema-object"); +const reference_object_1 = require("../../../../schema/3.0/reference-object"); +const either_1 = require("../../../../utils/either"); +const Reader_1 = require("fp-ts/lib/Reader"); +const isAllowedAdditionalProperties = (additionalProperties) => additionalProperties !== false; +exports.serializeSchemaObjectWithRecursion = Reader_1.asks(({ serializePrimitive }) => { + const doSerialize = (from, shouldTrackRecursion, name) => schemaObject => { + const isNullable = pipeable_1.pipe(schemaObject.nullable, fp_ts_1.option.exists(function_1.identity)); + if (schema_object_1.OneOfSchemaObjectCodec.is(schemaObject)) { + return pipeable_1.pipe(serializeChildren(from, schemaObject.oneOf), fp_ts_1.either.map(serialized_type_1.getSerializedUnionType), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion)), fp_ts_1.either.map(serialized_type_1.getSerializedNullableType(isNullable))); + } + if (schema_object_1.AllOfSchemaObjectCodec.is(schemaObject)) { + return pipeable_1.pipe(serializeChildren(from, schemaObject.allOf), fp_ts_1.either.map(serialized_type_1.getSerializedIntersectionType), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion)), fp_ts_1.either.map(serialized_type_1.getSerializedNullableType(isNullable))); + } + if (schema_object_1.EnumSchemaObjectCodec.is(schemaObject)) { + return pipeable_1.pipe(serialized_type_1.getSerializedEnumType(schemaObject.enum), serialized_type_1.getSerializedNullableType(isNullable), Either_1.right); + } + switch (schemaObject.type) { + case 'string': + case 'boolean': + case 'integer': + case 'number': { + return pipeable_1.pipe(serializePrimitive(from, schemaObject), fp_ts_1.either.map(serialized_type_1.getSerializedNullableType(isNullable))); + } + case 'array': { + const { items } = schemaObject; + const serialized = reference_object_1.ReferenceObjectCodec.is(items) + ? pipeable_1.pipe(ref_1.fromString(items.$ref), Either_1.mapLeft(() => new Error(`Unable to serialize SchemaObject array items ref "${items.$ref}"`)), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : pipeable_1.pipe(items, doSerialize(from, false, undefined)); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized_type_1.getSerializedArrayType(schemaObject.minItems, name)), fp_ts_1.either.map(serialized_type_1.getSerializedNullableType(isNullable))); + } + case 'object': { + const additionalProperties = pipeable_1.pipe(schemaObject.additionalProperties, fp_ts_1.option.filter(isAllowedAdditionalProperties), fp_ts_1.option.map(additionalProperties => { + if (reference_object_1.ReferenceObjectCodec.is(additionalProperties)) { + return pipeable_1.pipe(additionalProperties.$ref, ref_1.fromString, Either_1.mapLeft(() => new Error(`Unable to serialize SchemaObject additionalProperties ref "${additionalProperties.$ref}"`)), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))); + } + else { + return additionalProperties !== true + ? pipeable_1.pipe(additionalProperties, doSerialize(from, false, undefined)) + : Either_1.right(serialized_type_1.SERIALIZED_UNKNOWN_TYPE); + } + }), fp_ts_1.option.map(fp_ts_1.either.map(serialized_type_1.getSerializedDictionaryType(name))), fp_ts_1.option.map(fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion)))); + const properties = pipeable_1.pipe(schemaObject.properties, fp_ts_1.option.map(properties => pipeable_1.pipe(types_1.serializeDictionary(properties, (name, property) => { + const isRequired = pipeable_1.pipe(schemaObject.required, fp_ts_1.option.map(array_1.includes(name)), fp_ts_1.option.getOrElse(function_1.constFalse)); + if (reference_object_1.ReferenceObjectCodec.is(property)) { + return pipeable_1.pipe(property.$ref, ref_1.fromString, Either_1.mapLeft(() => new Error(`Unable to serialize SchemaObject property "${name}" ref "${property.$ref}"`)), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from)), fp_ts_1.either.map(serialized_type_1.getSerializedOptionPropertyType(name, isRequired))); + } + else { + return pipeable_1.pipe(property, doSerialize(from, false, undefined), fp_ts_1.either.map(serialized_type_1.getSerializedOptionPropertyType(name, isRequired))); + } + }), either_utils_1.sequenceEither, fp_ts_1.either.map(s => serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), s)), fp_ts_1.either.map(serialized_type_1.getSerializedObjectType(name)), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))))); + return pipeable_1.pipe(additionalProperties, fp_ts_1.option.alt(() => properties), fp_ts_1.option.map(fp_ts_1.either.map(serialized_type_1.getSerializedNullableType(isNullable))), fp_ts_1.option.getOrElse(() => Either_1.right(serialized_type_1.SERIALIZED_UNKNOWN_TYPE))); + } + } + }; + const serializeChildren = (from, children) => either_1.traverseNEAEither(children, item => reference_object_1.ReferenceObjectCodec.is(item) + ? pipeable_1.pipe(ref_1.fromString(item.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : doSerialize(from, false)(item)); + return doSerialize; +}); +exports.serializePrimitiveDefault = (from, schemaObject) => { + switch (schemaObject.type) { + case 'string': { + return serialized_type_1.getSerializedStringType(from, schemaObject.format); + } + case 'number': { + return Either_1.right(serialized_type_1.SERIALIZED_NUMBER_TYPE); + } + case 'integer': { + return Either_1.right(serialized_type_1.SERIALIZED_INTEGER_TYPE); + } + case 'boolean': { + return Either_1.right(serialized_type_1.SERIALIZED_BOOLEAN_TYPE); + } + } +}; +exports.serializeSchemaObject = pipeable_1.pipe(exports.serializeSchemaObjectWithRecursion, fp_ts_1.reader.map((serializeSchemaObjectWithRecursion) => (from, name) => serializeSchemaObjectWithRecursion(from, true, name))); +exports.serializeSchemaObjectDefault = exports.serializeSchemaObject({ + serializePrimitive: exports.serializePrimitiveDefault, +}); diff --git a/dist/language/typescript/asyncapi-2.0.0/index.d.ts b/dist/language/typescript/asyncapi-2.0.0/index.d.ts new file mode 100644 index 0000000..da74517 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/index.d.ts @@ -0,0 +1,5 @@ +import { AsyncAPIObject } from '../../../schema/asyncapi-2.0.0/asyncapi-object'; +import { SerializeOptions } from '../common/utils'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../utils/fs'; +export declare const serialize: import("fp-ts/lib/Reader").Reader, options?: SerializeOptions) => Either>; diff --git a/dist/language/typescript/asyncapi-2.0.0/index.js b/dist/language/typescript/asyncapi-2.0.0/index.js new file mode 100644 index 0000000..f76188c --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/index.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const utils_1 = require("../common/utils"); +const fs_1 = require("../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const prettier_1 = require("prettier"); +const asyncapi_object_1 = require("./serializers/asyncapi-object"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +exports.serialize = reader_utils_1.combineReader(asyncapi_object_1.serializeAsyncAPIObject, serializeAsyncAPIObject => (documents, options = {}) => pipeable_1.pipe(documents, fp_ts_1.record.collect(serializeAsyncAPIObject), either_utils_1.sequenceEither, fp_ts_1.either.map(e => fs_1.map(fs_1.fragment(e), content => prettier_1.format(content, options.prettierConfig || utils_1.defaultPrettierConfig))))); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.d.ts new file mode 100644 index 0000000..02f41f7 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.d.ts @@ -0,0 +1,4 @@ +import { AsyncAPIObject } from '../../../../schema/asyncapi-2.0.0/asyncapi-object'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +export declare const serializeAsyncAPIObject: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.js new file mode 100644 index 0000000..e218f7a --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/asyncapi-object.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const components_object_1 = require("./components-object"); +const ref_1 = require("../../../../utils/ref"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const channels_object_1 = require("./channels-object"); +const client_1 = require("../../common/bundled/client"); +const utils_1 = require("../../common/bundled/utils"); +exports.serializeAsyncAPIObject = reader_utils_1.combineReader(components_object_1.serializeComponentsObject, channels_object_1.serializeChannelsObject, (serializeComponentsObject, serializeChannelsObject) => (name, asyncAPIObject) => { + const components = pipeable_1.pipe(asyncAPIObject.components, fp_ts_1.option.map(components => pipeable_1.pipe(ref_1.fromString('#/components'), fp_ts_1.either.chain(from => serializeComponentsObject(from, components)), fp_ts_1.either.map(content => fs_1.directory('components', [content]))))); + const additional = pipeable_1.pipe(fp_ts_1.array.compact([components]), either_utils_1.sequenceEither); + const channels = pipeable_1.pipe(ref_1.fromString('#/channels'), fp_ts_1.either.chain(from => serializeChannelsObject(from, asyncAPIObject.channels)), fp_ts_1.either.map(content => fs_1.directory('channels', [content]))); + return either_utils_1.combineEither(channels, additional, client_1.clientFile, utils_1.utilsFile, (channels, additional, clientFile, utilsFile) => fs_1.directory(name, [channels, clientFile, ...additional, utilsFile])); +}); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.d.ts new file mode 100644 index 0000000..cb4ed3f --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.d.ts @@ -0,0 +1,6 @@ +import { Ref } from '../../../../utils/ref'; +import { ChannelItemObject } from '../../../../schema/asyncapi-2.0.0/channel-item-object'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Kind } from '../../../../utils/types'; +export declare const serializeChannelItemObject: import("fp-ts/lib/Reader").Reader, channel: string, channelItemObject: ChannelItemObject, kind: Kind) => Either>; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.js new file mode 100644 index 0000000..919f0b0 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/channel-item-object.js @@ -0,0 +1,82 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const Either_1 = require("fp-ts/lib/Either"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const operation_object_1 = require("./operation-object"); +const types_1 = require("../../../../utils/types"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const client_1 = require("../../common/bundled/client"); +const schema_object_1 = require("./schema-object"); +const Option_1 = require("fp-ts/lib/Option"); +const option_utils_1 = require("@devexperts/utils/dist/adt/option.utils"); +const function_1 = require("fp-ts/lib/function"); +const string_1 = require("../../../../utils/string"); +const serialized_parameter_1 = require("../../common/data/serialized-parameter"); +const serialized_path_parameter_1 = require("../../common/data/serialized-path-parameter"); +const array_1 = require("../../../../utils/array"); +const utils_1 = require("../../common/utils"); +const reference_object_1 = require("../../../../schema/asyncapi-2.0.0/reference-object"); +const parameter_object_1 = require("../../../../schema/asyncapi-2.0.0/parameter-object"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const serializeChannelPathParameters = reader_utils_1.combineReader(utils_1.context, e => (from, params) => pipeable_1.pipe(params, fp_ts_1.record.collect((key, param) => { + const parameter = reference_object_1.ReferenceObjectCodec.is(param) + ? Option_1.fromEither(e.resolveRef(param.$ref, parameter_object_1.ParameterObjectCodec)) + : fp_ts_1.option.some(param); + const schema = pipeable_1.pipe(parameter, fp_ts_1.option.chain(parameter => parameter.schema), fp_ts_1.either.fromOption(() => new Error(`Parameter ${key} must have a schema`)), fp_ts_1.either.chain(schema => schema_object_1.serializeSchemaObject(from, schema))); + return pipeable_1.pipe(schema, fp_ts_1.either.map(schema => serialized_path_parameter_1.serializedPathParameter(key, schema.type, schema.io, true, schema.dependencies, schema.refs))); +}))); +exports.serializeChannelItemObject = reader_utils_1.combineReader(serializeChannelPathParameters, serializeChannelPathParameters => (from, channel, channelItemObject, kind) => { + const send = pipeable_1.pipe(channelItemObject.subscribe, fp_ts_1.option.map(operation => operation_object_1.serializeSubscribeOperationObject(from, channel, operation, kind))); + const message = pipeable_1.pipe(channelItemObject.publish, fp_ts_1.option.map(operation => operation_object_1.serializePublishOperationObject(from, channel, operation))); + const serialized = pipeable_1.pipe(fp_ts_1.array.compact([send, message]), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized => serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), serialized))); + const ws = pipeable_1.pipe(channelItemObject.bindings, fp_ts_1.option.chain(bindings => bindings.ws)); + const method = pipeable_1.pipe(ws, fp_ts_1.option.chain(ws => ws.method), fp_ts_1.option.getOrElse(() => 'GET')); + const query = pipeable_1.pipe(ws, fp_ts_1.option.chain(ws => ws.query), fp_ts_1.option.map(query => { + const required = isRequired(query); + return pipeable_1.pipe(validateSchemaObject(query), fp_ts_1.either.chain(query => schema_object_1.serializeSchemaObject(from, query)), fp_ts_1.either.map(serialized => serialized_type_1.getSerializedPropertyType('query', required, serialized)), fp_ts_1.either.map(serialized_parameter_1.fromSerializedType(required))); + })); + const headers = pipeable_1.pipe(ws, fp_ts_1.option.chain(ws => ws.headers), fp_ts_1.option.map(headers => { + const required = isRequired(headers); + return pipeable_1.pipe(validateSchemaObject(headers), fp_ts_1.either.chain(headers => schema_object_1.serializeSchemaObject(from, headers)), fp_ts_1.either.map(serialized => serialized_type_1.getSerializedPropertyType('headers', required, serialized)), fp_ts_1.either.map(serialized_parameter_1.fromSerializedType(required))); + })); + const bindingParameters = pipeable_1.pipe(fp_ts_1.array.compact([query, headers]), either_utils_1.sequenceEither); + const channelParameters = pipeable_1.pipe(channelItemObject.parameters, fp_ts_1.option.map(params => serializeChannelPathParameters(from, params)), fp_ts_1.option.getOrElse(() => []), either_utils_1.sequenceEither); + return either_utils_1.combineEither(serialized, client_1.clientRef, bindingParameters, channelParameters, (serialized, clientRef, bindingParameters, channelParameters) => { + const serializedBindingParameters = serialized_parameter_1.intercalateSerializedParameters(serialized_parameter_1.serializedParameter(';', ',', false, [], []), bindingParameters); + const serializedPathParameters = serialized_parameter_1.intercalateSerializedParameters(serialized_parameter_1.serializedParameter(';', ',', false, [], []), channelParameters + .map(param => serialized_type_1.getSerializedPropertyType(param.name, true, param)) + .map(serialized_parameter_1.fromSerializedType(true))); + const allSerializedParameters = serialized_parameter_1.intercalateSerializedParameters(serialized_parameter_1.serializedParameter(';', ',', false, [], []), [serializedBindingParameters, serializedPathParameters].filter(x => x.type.length)); + const encodedChannelParameters = channelParameters.map(param => (Object.assign(Object.assign({}, serialized_path_parameter_1.getSerializedPathParameterType(param)), { io: `${param.io}.encode(parameters.${param.name})` }))); + const hasBindingParameters = bindingParameters.length > 0; + const hasChannelParameters = channelParameters.length > 0; + const hasParameters = hasBindingParameters || hasChannelParameters; + const channelType = types_1.foldKind(kind, 'WebSocketClient', 'WebSocketClient1', 'WebSocketClient2'); + const type = `(${string_1.when(hasParameters, `parameters: { ${allSerializedParameters.type} }`)}) => { ${serialized.type} }`; + const io = `(${string_1.when(hasParameters, 'parameters')}) => { + ${string_1.when(hasBindingParameters, `const encoded = partial({ ${serializedBindingParameters.io} }).encode(parameters);`)} + const channel = e.webSocketClient.channel({ + channel: ${utils_1.getURL(channel, encodedChannelParameters)}, + method: '${method}', + ${string_1.when(hasBindingParameters, '...encoded,')} + }) + + return { ${serialized.io} }; + }`; + const dependencies = array_1.concatIf(hasParameters, [ + ...serialized.dependencies, + ...allSerializedParameters.dependencies, + serialized_dependency_1.serializedDependency(channelType, ref_1.getRelativePath(from, clientRef)), + ], [serialized_dependency_1.serializedDependency('partial', 'io-ts')]); + const refs = [...serialized.refs, ...allSerializedParameters.refs]; + return pipeable_1.pipe(serialized_type_1.serializedType(type, io, dependencies, refs), serialized_type_1.getSerializedOptionPropertyType(channel, true)); + }); +}); +const validateSchemaObject = (schemaObject) => Option_1.isSome(schemaObject.properties) + ? Either_1.right(schemaObject) + : Either_1.left(new Error(`ChannelItemObject.query and ChannelItemObject.header should have "properties" field`)); +const isRequired = (objectSchemaObject) => pipeable_1.pipe(option_utils_1.sequenceTOption(objectSchemaObject.properties, objectSchemaObject.required), fp_ts_1.option.map(([properties, required]) => fp_ts_1.record.keys(properties).some(key => required.has(key))), fp_ts_1.option.getOrElse(function_1.constFalse)); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.d.ts new file mode 100644 index 0000000..0b1a774 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.d.ts @@ -0,0 +1,5 @@ +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +import { Ref } from '../../../../utils/ref'; +import { ChannelsObject } from '../../../../schema/asyncapi-2.0.0/channels-object'; +export declare const serializeChannelsObject: import("fp-ts/lib/Reader").Reader, channelsObject: ChannelsObject) => Either>; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.js new file mode 100644 index 0000000..d5c76ea --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/channels-object.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = require("../../../../utils/fs"); +const ref_1 = require("../../../../utils/ref"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const channel_item_object_1 = require("./channel-item-object"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const client_1 = require("../../common/bundled/client"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const serializeChannelsObjectWithKind = reader_utils_1.combineReader(channel_item_object_1.serializeChannelItemObject, serializeChannelItemObject => (from, channelsObject, kind) => pipeable_1.pipe(channelsObject, fp_ts_1.record.collect((channel, channelItemObject) => pipeable_1.pipe(from, ref_1.addPathParts('channels'), fp_ts_1.either.chain(from => serializeChannelItemObject(from, channel, channelItemObject, kind)))), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized => serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), serialized)))); +exports.serializeChannelsObject = reader_utils_1.combineReader(serializeChannelsObjectWithKind, serializeChannelsObjectWithKind => (from, channelsObject) => { + const ref = pipeable_1.pipe(from, ref_1.addPathParts('channels')); + const serializedHKT = serializeChannelsObjectWithKind(from, channelsObject, 'HKT'); + const serializedKind = serializeChannelsObjectWithKind(from, channelsObject, '*'); + const serializedKind2 = serializeChannelsObjectWithKind(from, channelsObject, '* -> *'); + return either_utils_1.combineEither(ref, serializedHKT, serializedKind, serializedKind2, client_1.clientRef, (ref, serializedHKT, serializedKind, serializedKind2, clientRef) => { + const clientPath = ref_1.getRelativePath(ref, clientRef); + const dependencies = serialized_dependency_1.serializeDependencies([ + ...serializedHKT.dependencies, + ...serializedKind.dependencies, + ...serializedKind2.dependencies, + serialized_dependency_1.serializedDependency('URIS', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('URIS2', 'fp-ts/lib/HKT'), + serialized_dependency_1.serializedDependency('WebSocketClient', clientPath), + serialized_dependency_1.serializedDependency('WebSocketClient1', clientPath), + serialized_dependency_1.serializedDependency('WebSocketClient2', clientPath), + ]); + return fs_1.file(`${ref.name}.ts`, ` + ${dependencies} + + export interface Channels2 { + ${serializedKind2.type} + } + export interface Channels1 { + ${serializedKind.type} + } + export interface Channels { + ${serializedHKT.type} + } + + export function channels(e: { webSocketClient: WebSocketClient2 }): Channels2; + export function channels(e: { webSocketClient: WebSocketClient1 }): Channels1; + export function channels(e: { webSocketClient: WebSocketClient }): Channels; + export function channels(e: { webSocketClient: WebSocketClient }): Channels { + return { + ${serializedHKT.io} + }; + }; + `); + }); +}); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.d.ts new file mode 100644 index 0000000..1546bf0 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.d.ts @@ -0,0 +1,5 @@ +import { Ref } from '../../../../utils/ref'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +import { ComponentsObject } from '../../../../schema/asyncapi-2.0.0/components-object'; +export declare const serializeComponentsObject: import("fp-ts/lib/Reader").Reader, componentsObject: ComponentsObject) => Either>; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.js new file mode 100644 index 0000000..64f1d83 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/components-object.js @@ -0,0 +1,62 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const schema_object_1 = require("../../../../schema/asyncapi-2.0.0/schema-object"); +const Either_1 = require("fp-ts/lib/Either"); +const fs_1 = require("../../../../utils/fs"); +const utils_1 = require("../../common/utils"); +const schema_object_2 = require("./schema-object"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const reference_object_1 = require("../../../../schema/asyncapi-2.0.0/reference-object"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const message_object_1 = require("../../../../schema/asyncapi-2.0.0/message-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const serializeMessage = (from, messageObject) => { + const typeName = utils_1.getTypeName(from.name); + const ioName = utils_1.getIOName(from.name); + const serialized = reference_object_1.ReferenceObjectCodec.is(messageObject.payload) + ? pipeable_1.pipe(ref_1.fromString(messageObject.payload.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : schema_object_2.serializeSchemaObject(from, messageObject.payload); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized => fs_1.file(`${from.name}.ts`, ` + ${serialized_dependency_1.serializeDependencies(serialized.dependencies)} + + export type ${typeName} = ${serialized.type}; + export const ${ioName} = ${serialized.io}; + `))); +}; +const serializeMessages = reader_utils_1.combineReader(utils_1.context, context => (from, messages) => pipeable_1.pipe(messages, fp_ts_1.record.collect((name, message) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(message) + ? context.resolveRef(message.$ref, message_object_1.MessageObjectCodec) + : Either_1.right(message); + const ref = pipeable_1.pipe(from, ref_1.addPathParts(name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([resolved, ref]) => serializeMessage(ref, resolved))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(fs_1.fragment))); +const serializeSchema = (from, schema) => { + const typeName = utils_1.getTypeName(from.name); + const ioName = utils_1.getIOName(from.name); + const serialized = schema_object_2.serializeSchemaObject(from, schema, typeName); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized => { + const dependencies = serialized_dependency_1.serializeDependencies(serialized.dependencies); + return fs_1.file(`${from.name}.ts`, ` + ${dependencies} + + export type ${typeName} = ${serialized.type}; + export const ${ioName} = ${serialized.io}; + `); + })); +}; +const serializeSchemas = reader_utils_1.combineReader(utils_1.context, e => (from, schemas) => pipeable_1.pipe(schemas, fp_ts_1.record.collect((name, schema) => { + const resolved = reference_object_1.ReferenceObjectCodec.is(schema) + ? e.resolveRef(schema.$ref, schema_object_1.SchemaObjectCodec) + : Either_1.right(schema); + const ref = pipeable_1.pipe(from, ref_1.addPathParts(name)); + return pipeable_1.pipe(either_utils_1.sequenceTEither(resolved, ref), fp_ts_1.either.chain(([resolved, ref]) => serializeSchema(ref, resolved))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(fs_1.fragment))); +exports.serializeComponentsObject = reader_utils_1.combineReader(serializeSchemas, serializeMessages, (serializeSchemas, serializeMessages) => (from, componentsObject) => { + const schemas = pipeable_1.pipe(componentsObject.schemas, fp_ts_1.option.map(schemas => pipeable_1.pipe(from, ref_1.addPathParts('schemas'), fp_ts_1.either.chain(ref => serializeSchemas(ref, schemas)), fp_ts_1.either.map(content => fs_1.directory('schemas', [content]))))); + const messages = pipeable_1.pipe(componentsObject.messages, fp_ts_1.option.map(messages => pipeable_1.pipe(from, ref_1.addPathParts('messages'), fp_ts_1.either.chain(ref => serializeMessages(ref, messages)), fp_ts_1.either.map(content => fs_1.directory('messages', [content]))))); + return pipeable_1.pipe(fp_ts_1.array.compact([schemas, messages]), either_utils_1.sequenceEither, fp_ts_1.either.map(fs_1.fragment)); +}); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.d.ts new file mode 100644 index 0000000..70225f7 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.d.ts @@ -0,0 +1,5 @@ +import { Ref } from '../../../../utils/ref'; +import { MessageObject } from '../../../../schema/asyncapi-2.0.0/message-object'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedType } from '../../common/data/serialized-type'; +export declare const serializeMessageObject: (from: Ref, messageObject: MessageObject) => Either; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.js new file mode 100644 index 0000000..47800c7 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/message-object.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const reference_object_1 = require("../../../../schema/asyncapi-2.0.0/reference-object"); +const schema_object_1 = require("./schema-object"); +exports.serializeMessageObject = (from, messageObject) => reference_object_1.ReferenceObjectCodec.is(messageObject.payload) + ? pipeable_1.pipe(ref_1.fromString(messageObject.payload.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : schema_object_1.serializeSchemaObject(from, messageObject.payload); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.d.ts new file mode 100644 index 0000000..6139dca --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.d.ts @@ -0,0 +1,7 @@ +import { Ref } from '../../../../utils/ref'; +import { OperationObject } from '../../../../schema/asyncapi-2.0.0/operation-object'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedType } from '../../common/data/serialized-type'; +import { Kind } from '../../../../utils/types'; +export declare const serializePublishOperationObject: (from: Ref, channel: string, operationObject: OperationObject) => Either; +export declare const serializeSubscribeOperationObject: (from: Ref, channel: string, operationObject: OperationObject, kind: Kind) => Either; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.js new file mode 100644 index 0000000..3979600 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/operation-object.js @@ -0,0 +1,51 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const operation_object_1 = require("../../../../schema/asyncapi-2.0.0/operation-object"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_1 = require("../../../../utils/either"); +const reference_object_1 = require("../../../../schema/asyncapi-2.0.0/reference-object"); +const message_object_1 = require("./message-object"); +const serialized_dependency_1 = require("../../common/data/serialized-dependency"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const client_1 = require("../../common/bundled/client"); +const utils_1 = require("../../common/utils"); +exports.serializePublishOperationObject = (from, channel, operationObject) => pipeable_1.pipe(serializeMessage(from, operationObject.message), fp_ts_1.either.map(serialized => { + const type = `send: (payload: ${serialized.type}) => void`; + const io = `send: payload => { + channel.send(${serialized.io}.encode(payload)); + }`; + return serialized_type_1.serializedType(type, io, serialized.dependencies, serialized.refs); +})); +exports.serializeSubscribeOperationObject = (from, channel, operationObject, kind) => { + const serialized = serializeMessage(from, operationObject.message); + return either_utils_1.combineEither(serialized, client_1.clientRef, (serialized, clientRef) => { + const type = `message: ${utils_1.getKindValue(kind, serialized.type)}`; + const io = ` + message: + channel.chain(channel.message, message => + pipe( + ${serialized.io}.decode(message), + mapLeft(ResponseValidationError.create), + fold(error => channel.throwError(error), value => channel.of(value)), + ), + ) + `; + const dependencies = [ + ...serialized.dependencies, + serialized_dependency_1.serializedDependency('pipe', 'fp-ts/lib/pipeable'), + serialized_dependency_1.serializedDependency('mapLeft', 'fp-ts/lib/Either'), + serialized_dependency_1.serializedDependency('fold', 'fp-ts/lib/Either'), + serialized_dependency_1.serializedDependency('ResponseValidationError', ref_1.getRelativePath(from, clientRef)), + serialized_dependency_1.getSerializedKindDependency(kind), + ]; + return serialized_type_1.serializedType(type, io, dependencies, serialized.refs); + }); +}; +const serializeMessage = (from, message) => operation_object_1.OperationObjectOneOfMessageCodec.is(message) + ? pipeable_1.pipe(either_1.traverseNEAEither(message.oneOf, message => serializeSingleMessage(from, message)), fp_ts_1.either.map(serialized_type_1.getSerializedUnionType)) + : serializeSingleMessage(from, message); +const serializeSingleMessage = (from, message) => reference_object_1.ReferenceObjectCodec.is(message) ? serializeMessageReference(from, message) : message_object_1.serializeMessageObject(from, message); +const serializeMessageReference = (from, reference) => pipeable_1.pipe(ref_1.fromString(reference.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))); diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.d.ts b/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.d.ts new file mode 100644 index 0000000..657969c --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.d.ts @@ -0,0 +1,5 @@ +import { Ref } from '../../../../utils/ref'; +import { Either } from 'fp-ts/lib/Either'; +import { SerializedType } from '../../common/data/serialized-type'; +import { SchemaObject } from '../../../../schema/asyncapi-2.0.0/schema-object'; +export declare const serializeSchemaObject: (from: Ref, schemaObject: SchemaObject, name?: string | undefined) => Either; diff --git a/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.js b/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.js new file mode 100644 index 0000000..6f0d088 --- /dev/null +++ b/dist/language/typescript/asyncapi-2.0.0/serializers/schema-object.js @@ -0,0 +1,77 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const Either_1 = require("fp-ts/lib/Either"); +const serialized_type_1 = require("../../common/data/serialized-type"); +const schema_object_1 = require("../../../../schema/asyncapi-2.0.0/schema-object"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const reference_object_1 = require("../../../../schema/asyncapi-2.0.0/reference-object"); +const either_1 = require("../../../../utils/either"); +const function_1 = require("fp-ts/lib/function"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +exports.serializeSchemaObject = (from, schemaObject, name) => serializeSchemaObjectWithRecursion(from, schemaObject, true, name); +const serializeSchemaObjectWithRecursion = (from, schemaObject, shouldTrackRecursion, name) => { + // check non-types schemas + if (schema_object_1.EnumSchemaObjectCodec.is(schemaObject)) { + return Either_1.right(serialized_type_1.getSerializedEnumType(schemaObject.enum)); + } + if (schema_object_1.ConstSchemaObjectCodec.is(schemaObject)) { + return Either_1.right(serialized_type_1.getSerializedPrimitiveType(schemaObject.const)); + } + if (schema_object_1.AllOfSchemaObjectCodec.is(schemaObject)) { + return serializeAllOf(from, schemaObject.allOf, shouldTrackRecursion); + } + if (schema_object_1.OneOfSchemaObjectCodec.is(schemaObject)) { + return serializeOneOf(from, schemaObject.oneOf, shouldTrackRecursion); + } + // schema is typed at this point + switch (schemaObject.type) { + case 'null': { + return Either_1.right(serialized_type_1.SERIALIZED_NULL_TYPE); + } + case 'string': { + return serialized_type_1.getSerializedStringType(from, schemaObject.format); + } + case 'number': { + return Either_1.right(serialized_type_1.SERIALIZED_NUMBER_TYPE); + } + case 'integer': { + return Either_1.right(serialized_type_1.SERIALIZED_INTEGER_TYPE); + } + case 'boolean': { + return Either_1.right(serialized_type_1.SERIALIZED_BOOLEAN_TYPE); + } + case 'object': { + return serializeObjectSchemaObject(from, schemaObject, shouldTrackRecursion, name); + } + case 'array': { + return serializeArray(from, schemaObject, shouldTrackRecursion, name); + } + } +}; +const serializeChildren = (from, value) => either_1.traverseNEAEither(value, item => reference_object_1.ReferenceObjectCodec.is(item) + ? pipeable_1.pipe(ref_1.fromString(item.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObjectWithRecursion(from, item, false)); +const serializeAllOf = (from, value, shouldTrackRecursion) => pipeable_1.pipe(serializeChildren(from, value), fp_ts_1.either.map(serialized_type_1.getSerializedIntersectionType), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))); +const serializeOneOf = (from, value, shouldTrackRecursion) => pipeable_1.pipe(serializeChildren(from, value), fp_ts_1.either.map(serialized_type_1.getSerializedUnionType), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))); +const serializeObjectSchemaObject = (from, value, shouldTrackRecursion, name) => pipeable_1.pipe(value.additionalProperties, fp_ts_1.option.map(properties => serializeAdditionalProperties(from, properties, shouldTrackRecursion, name)), fp_ts_1.option.alt(() => serializeProperties(from, value, shouldTrackRecursion, name)), fp_ts_1.option.getOrElse(() => Either_1.right(serialized_type_1.SERIALIZED_UNKNOWN_TYPE))); +const serializeAdditionalProperties = (from, properties, shouldTrackRecursion, name) => { + const serialized = reference_object_1.ReferenceObjectCodec.is(properties) + ? pipeable_1.pipe(ref_1.fromString(properties.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObjectWithRecursion(from, properties, false); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized_type_1.getSerializedDictionaryType(name)), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))); +}; +const serializeProperties = (from, schemaObject, shouldTrackRecursion, name) => pipeable_1.pipe(schemaObject.properties, fp_ts_1.option.map(properties => pipeable_1.pipe(properties, fp_ts_1.record.collect((name, property) => { + const isRequired = pipeable_1.pipe(schemaObject.required, fp_ts_1.option.map(required => required.has(name)), fp_ts_1.option.getOrElse(function_1.constFalse)); + const serialized = reference_object_1.ReferenceObjectCodec.is(property) + ? pipeable_1.pipe(ref_1.fromString(property.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObjectWithRecursion(from, property, false); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized_type_1.getSerializedOptionPropertyType(name, isRequired))); +}), either_utils_1.sequenceEither, fp_ts_1.either.map(s => serialized_type_1.intercalateSerializedTypes(serialized_type_1.serializedType(';', ',', [], []), s)), fp_ts_1.either.map(serialized_type_1.getSerializedObjectType(name)), fp_ts_1.either.map(serialized_type_1.getSerializedRecursiveType(from, shouldTrackRecursion))))); +const serializeArray = (from, schemaObject, shouldTrackRecursion, name) => { + const serialized = reference_object_1.ReferenceObjectCodec.is(schemaObject.items) + ? pipeable_1.pipe(ref_1.fromString(schemaObject.items.$ref), fp_ts_1.either.map(serialized_type_1.getSerializedRefType(from))) + : serializeSchemaObjectWithRecursion(from, schemaObject.items, false); + return pipeable_1.pipe(serialized, fp_ts_1.either.map(serialized_type_1.getSerializedArrayType(schemaObject.minItems, name))); +}; diff --git a/dist/language/typescript/common/bundled/client.d.ts b/dist/language/typescript/common/bundled/client.d.ts new file mode 100644 index 0000000..a41d653 --- /dev/null +++ b/dist/language/typescript/common/bundled/client.d.ts @@ -0,0 +1,4 @@ +import { either } from 'fp-ts'; +export declare const clientRef: either.Either>; +export declare const client = "\n\timport { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT';\n\timport { MonadThrow, MonadThrow1, MonadThrow2 } from 'fp-ts/lib/MonadThrow';\n\timport { Errors } from 'io-ts';\n\timport { PathReporter } from 'io-ts/lib/PathReporter';\n\timport { left } from 'fp-ts/lib/Either';\n\n\texport interface Request {\n\t\treadonly method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';\n\t\treadonly url: string;\n\t\treadonly responseType: 'json' | 'blob' | 'text';\n\t\treadonly query?: string;\n\t\treadonly body?: unknown;\n\t\treadonly headers?: Record;\n\t}\n\n\texport interface HTTPClient extends MonadThrow {\n\t\treadonly request: (request: Request) => HKT;\n\t}\n\texport interface HTTPClient1 extends MonadThrow1 {\n\t\treadonly request: (request: Request) => Kind;\n\t}\n\texport interface HTTPClient2 extends MonadThrow2 {\n\t\treadonly request: (request: Request) => Kind2;\n\t}\n\n\texport interface WebSocketChannelRequest {\n\t\treadonly method: 'GET' | 'POST';\n\t\treadonly channel: string;\n\t\treadonly query?: Record;\n\t\treadonly headers?: Record;\n\t}\n\n\texport interface WebSocketClient2 {\n\t\treadonly channel: (request: WebSocketChannelRequest) => WebSocketChannel2;\n\t}\n\texport interface WebSocketClient1 {\n\t\treadonly channel: (request: WebSocketChannelRequest) => WebSocketChannel1;\n\t}\n\texport interface WebSocketClient {\n\t\treadonly channel: (request: WebSocketChannelRequest) => WebSocketChannel;\n\t}\n\n\texport interface WebSocketChannel extends MonadThrow {\n\t\treadonly send: (payload: unknown) => void;\n\t\treadonly message: HKT\n\t}\n\texport interface WebSocketChannel1 extends MonadThrow1 {\n\t\treadonly send: (payload: unknown) => void;\n\t\treadonly message: Kind\n\t}\n\texport interface WebSocketChannel2 extends MonadThrow2 {\n\t\treadonly send: (payload: unknown) => void;\n\t\treadonly message: Kind2\n\t}\n\n\texport class ResponseValidationError extends Error {\n\t\tstatic create(errors: Errors): ResponseValidationError {\n\t\t\treturn new ResponseValidationError(errors);\n\t\t}\n\n\t\tconstructor(readonly errors: Errors) {\n\t\t\tsuper(PathReporter.report(left(errors)).join('\\n\\n'));\n\t\t\tthis.name = 'ResponseValidationError';\n\t\t\tObject.setPrototypeOf(this, ResponseValidationError.prototype);\n\t\t}\n\t}\n"; +export declare const clientFile: either.Either; diff --git a/dist/language/typescript/common/bundled/client.js b/dist/language/typescript/common/bundled/client.js new file mode 100644 index 0000000..19569fa --- /dev/null +++ b/dist/language/typescript/common/bundled/client.js @@ -0,0 +1,77 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const fs_1 = require("../../../../utils/fs"); +const fp_ts_1 = require("fp-ts"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +exports.clientRef = ref_1.fromString('#/client/client'); +//TODO: make WebSocketChannelRequest.query a string after https://github.com/asyncapi/asyncapi/issues/294 +exports.client = ` + import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT'; + import { MonadThrow, MonadThrow1, MonadThrow2 } from 'fp-ts/lib/MonadThrow'; + import { Errors } from 'io-ts'; + import { PathReporter } from 'io-ts/lib/PathReporter'; + import { left } from 'fp-ts/lib/Either'; + + export interface Request { + readonly method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; + readonly url: string; + readonly responseType: 'json' | 'blob' | 'text'; + readonly query?: string; + readonly body?: unknown; + readonly headers?: Record; + } + + export interface HTTPClient extends MonadThrow { + readonly request: (request: Request) => HKT; + } + export interface HTTPClient1 extends MonadThrow1 { + readonly request: (request: Request) => Kind; + } + export interface HTTPClient2 extends MonadThrow2 { + readonly request: (request: Request) => Kind2; + } + + export interface WebSocketChannelRequest { + readonly method: 'GET' | 'POST'; + readonly channel: string; + readonly query?: Record; + readonly headers?: Record; + } + + export interface WebSocketClient2 { + readonly channel: (request: WebSocketChannelRequest) => WebSocketChannel2; + } + export interface WebSocketClient1 { + readonly channel: (request: WebSocketChannelRequest) => WebSocketChannel1; + } + export interface WebSocketClient { + readonly channel: (request: WebSocketChannelRequest) => WebSocketChannel; + } + + export interface WebSocketChannel extends MonadThrow { + readonly send: (payload: unknown) => void; + readonly message: HKT + } + export interface WebSocketChannel1 extends MonadThrow1 { + readonly send: (payload: unknown) => void; + readonly message: Kind + } + export interface WebSocketChannel2 extends MonadThrow2 { + readonly send: (payload: unknown) => void; + readonly message: Kind2 + } + + export class ResponseValidationError extends Error { + static create(errors: Errors): ResponseValidationError { + return new ResponseValidationError(errors); + } + + constructor(readonly errors: Errors) { + super(PathReporter.report(left(errors)).join('\\n\\n')); + this.name = 'ResponseValidationError'; + Object.setPrototypeOf(this, ResponseValidationError.prototype); + } + } +`; +exports.clientFile = pipeable_1.pipe(exports.clientRef, fp_ts_1.either.map(ref => fs_1.fromRef(ref, '.ts', exports.client))); diff --git a/dist/language/typescript/common/bundled/utils.d.ts b/dist/language/typescript/common/bundled/utils.d.ts new file mode 100644 index 0000000..83e8e7c --- /dev/null +++ b/dist/language/typescript/common/bundled/utils.d.ts @@ -0,0 +1,3 @@ +import { either } from 'fp-ts'; +export declare const utilsRef: either.Either>; +export declare const utilsFile: either.Either; diff --git a/dist/language/typescript/common/bundled/utils.js b/dist/language/typescript/common/bundled/utils.js new file mode 100644 index 0000000..7a9d4a5 --- /dev/null +++ b/dist/language/typescript/common/bundled/utils.js @@ -0,0 +1,93 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const fs_1 = require("../../../../utils/fs"); +exports.utilsRef = ref_1.fromString('#/utils/utils'); +const utils = ` + import { either, left, right } from 'fp-ts/lib/Either'; + import { + Type, + type, + TypeOf, + failure, + success, + string as tstring, + literal, + Validate, + Context, + getValidationError, + } from 'io-ts'; + + export const DateFromISODateStringIO = new Type( + 'DateFromISODateString', + (u): u is Date => u instanceof Date, + (u, c) => + either.chain(tstring.validate(u, c), dateString => { + const [year, calendarMonth, day] = dateString.split('-'); + const d = new Date(+year, +calendarMonth - 1, +day); + return isNaN(d.getTime()) ? failure(u, c) : success(d); + }), + a => + \`\${a.getFullYear().toString().padStart(4, '0')}-\${(a.getMonth() + 1).toString().padStart(2, '0')}-\${a + .getDate() + .toString() + .padStart(2, '0')}\`, + ); + + export type Base64 = TypeOf; + + export const Base64IO = type({ + string: tstring, + format: literal('base64'), + }); + + export const Base64FromStringIO = new Type( + 'Base64FromString', + (u): u is Base64 => Base64IO.is(u), + (u, c) => either.chain(tstring.validate(u, c), string => success({ string, format: 'base64' })), + a => a.string, + ); + + export type Binary = TypeOf; + + export const BinaryIO = type({ + string: tstring, + format: literal('binary'), + }); + + export const BinaryFromStringIO = new Type( + 'BinaryFromString', + (u): u is Binary => BinaryIO.is(u), + (u, c) => either.chain(tstring.validate(u, c), string => success({ string, format: 'binary' })), + a => a.string, + ); + + const validateBlob: Validate = (u: unknown, c: Context) => + u instanceof Blob ? right(u) : left([getValidationError(u, c)]); + + export const BlobToBlobIO = new Type( + 'Base64FromString', + (u): u is Blob => u instanceof Blob, + validateBlob, + a => a, + ); + + const blobMediaRegexp = /^(video|audio|image|application)/; + const textMediaRegexp = /^text/; + export const getResponseTypeFromMediaType = (mediaType: string) => { + if (mediaType === 'application/json') { + return 'json'; + } + if (blobMediaRegexp.test(mediaType)) { + return 'blob'; + } + if (textMediaRegexp.test(mediaType)) { + return 'text'; + } + return 'json'; + }; + +`; +exports.utilsFile = pipeable_1.pipe(exports.utilsRef, fp_ts_1.either.map(ref => fs_1.fromRef(ref, '.ts', utils))); diff --git a/dist/language/typescript/common/data/serialized-dependency.d.ts b/dist/language/typescript/common/data/serialized-dependency.d.ts new file mode 100644 index 0000000..a754548 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-dependency.d.ts @@ -0,0 +1,17 @@ +import { Kind } from '../../../../utils/types'; +import { Eq } from 'fp-ts/lib/Eq'; +import { ord } from 'fp-ts'; +export interface SerializedDependency { + readonly name: string; + readonly path: string; +} +export declare const serializedDependency: (name: string, path: string) => SerializedDependency; +export declare const serializeDependencies: (dependencies: SerializedDependency[]) => string; +export declare const ordDependencyByPath: ord.Ord; +export declare const ordDependencyByName: ord.Ord; +export declare const monoidDependencies: import("fp-ts/lib/Monoid").Monoid; +export declare const OPTION_DEPENDENCIES: SerializedDependency[]; +export declare const LITERAL_DEPENDENCY: SerializedDependency; +export declare const eqSerializedDependency: Eq; +export declare const uniqSerializedDependencies: (as: SerializedDependency[]) => SerializedDependency[]; +export declare const getSerializedKindDependency: (kind: Kind) => SerializedDependency; diff --git a/dist/language/typescript/common/data/serialized-dependency.js b/dist/language/typescript/common/data/serialized-dependency.js new file mode 100644 index 0000000..8c2946b --- /dev/null +++ b/dist/language/typescript/common/data/serialized-dependency.js @@ -0,0 +1,43 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); +const Record_1 = require("fp-ts/lib/Record"); +const array_1 = require("../../../../utils/array"); +const Array_1 = require("fp-ts/lib/Array"); +const Eq_1 = require("fp-ts/lib/Eq"); +const fp_ts_1 = require("fp-ts"); +const Ord_1 = require("fp-ts/lib/Ord"); +exports.serializedDependency = (name, path) => ({ + name, + path, +}); +exports.serializeDependencies = (dependencies) => pipeable_1.pipe(dependencies, NonEmptyArray_1.groupBy(dependency => dependency.path), Record_1.collect((key, dependencies) => { + const names = pipeable_1.pipe(array_1.uniqString(dependencies.map(dependency => dependency.name)), array_1.join(',')); + return `import { ${names} } from '${NonEmptyArray_1.head(dependencies).path}';`; +}), array_1.join('')); +exports.ordDependencyByPath = fp_ts_1.ord.contramap((dep) => dep.path)(Ord_1.ordString); +exports.ordDependencyByName = fp_ts_1.ord.contramap((dep) => dep.name)(Ord_1.ordString); +exports.monoidDependencies = Array_1.getMonoid(); +const dependencyOption = exports.serializedDependency('Option', 'fp-ts/lib/Option'); +const dependencyOptionFromNullable = exports.serializedDependency('optionFromNullable', 'io-ts-types/lib/optionFromNullable'); +exports.OPTION_DEPENDENCIES = [dependencyOption, dependencyOptionFromNullable]; +exports.LITERAL_DEPENDENCY = exports.serializedDependency('literal', 'io-ts'); +exports.eqSerializedDependency = Eq_1.getStructEq({ + name: Eq_1.eqString, + path: Eq_1.eqString, +}); +exports.uniqSerializedDependencies = Array_1.uniq(exports.eqSerializedDependency); +exports.getSerializedKindDependency = (kind) => { + switch (kind) { + case 'HKT': { + return exports.serializedDependency('HKT', 'fp-ts/lib/HKT'); + } + case '*': { + return exports.serializedDependency('Kind', 'fp-ts/lib/HKT'); + } + case '* -> *': { + return exports.serializedDependency('Kind2', 'fp-ts/lib/HKT'); + } + } +}; diff --git a/dist/language/typescript/common/data/serialized-fragment.d.ts b/dist/language/typescript/common/data/serialized-fragment.d.ts new file mode 100644 index 0000000..3ac0678 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-fragment.d.ts @@ -0,0 +1,30 @@ +import { SerializedDependency } from './serialized-dependency'; +import { Monoid } from 'fp-ts/lib/Monoid'; +import { Ref } from '../../../../utils/ref'; +export interface SerializedFragment { + readonly value: string; + readonly dependencies: SerializedDependency[]; + readonly refs: Ref[]; +} +export declare const serializedFragment: (value: string, dependencies: SerializedDependency[], refs: Ref[]) => SerializedFragment; +export declare const monoidSerializedFragment: Monoid; +export declare const intercalateSerializedFragmentsNEA: (sep: SerializedFragment, fm: import("fp-ts/lib/NonEmptyArray").NonEmptyArray) => SerializedFragment; +export declare const intercalateSerializedFragments: (sep: SerializedFragment, fm: SerializedFragment[]) => SerializedFragment; +export declare const foldSerializedFragments: (as: SerializedFragment[]) => SerializedFragment; +export declare function combineFragments(a: SerializedFragment, p: (a: string) => string): SerializedFragment; +export declare function combineFragments(a: SerializedFragment, b: SerializedFragment, p: (a: string, b: string) => string): SerializedFragment; +export declare function combineFragments(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, p: (a: string, b: string, c: string) => string): SerializedFragment; +export declare function combineFragments(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, p: (a: string, b: string, c: string, d: string) => string): SerializedFragment; +export declare function combineFragments(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, e: SerializedFragment, p: (a: string, b: string, c: string, d: string, e: string) => string): SerializedFragment; +export declare function combineFragments(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, e: SerializedFragment, f: SerializedFragment, p: (a: string, b: string, c: string, d: string, e: string, f: string) => string): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, p: (a: string) => SerializedFragment): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, b: SerializedFragment, p: (a: string, b: string) => SerializedFragment): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, p: (a: string, b: string, c: string) => SerializedFragment): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, p: (a: string, b: string, c: string, d: string) => SerializedFragment): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, e: SerializedFragment, p: (a: string, b: string, c: string, d: string, e: string) => SerializedFragment): SerializedFragment; +export declare function combineFragmentsK(a: SerializedFragment, b: SerializedFragment, c: SerializedFragment, d: SerializedFragment, e: SerializedFragment, f: SerializedFragment, p: (a: string, b: string, c: string, d: string, e: string, f: string) => SerializedFragment): SerializedFragment; +/** + * @param f returns an Option + */ +export declare const getSerializedOptionCallFragment: (nullable: boolean, f: SerializedFragment, a: SerializedFragment) => SerializedFragment; +export declare const commaFragment: SerializedFragment; diff --git a/dist/language/typescript/common/data/serialized-fragment.js b/dist/language/typescript/common/data/serialized-fragment.js new file mode 100644 index 0000000..cd3287b --- /dev/null +++ b/dist/language/typescript/common/data/serialized-fragment.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_dependency_1 = require("./serialized-dependency"); +const Monoid_1 = require("fp-ts/lib/Monoid"); +const Array_1 = require("fp-ts/lib/Array"); +const Foldable_1 = require("fp-ts/lib/Foldable"); +const NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); +const ref_1 = require("../../../../utils/ref"); +const fp_ts_1 = require("fp-ts"); +exports.serializedFragment = (value, dependencies, refs) => ({ + value, + dependencies: serialized_dependency_1.uniqSerializedDependencies(dependencies), + refs: ref_1.uniqRefs(refs), +}); +exports.monoidSerializedFragment = Monoid_1.getStructMonoid({ + value: Monoid_1.monoidString, + dependencies: Array_1.getMonoid(), + refs: Array_1.getMonoid(), +}); +exports.intercalateSerializedFragmentsNEA = Foldable_1.intercalate(exports.monoidSerializedFragment, NonEmptyArray_1.nonEmptyArray); +exports.intercalateSerializedFragments = Foldable_1.intercalate(exports.monoidSerializedFragment, fp_ts_1.array.array); +exports.foldSerializedFragments = Monoid_1.fold(exports.monoidSerializedFragment); +function combineFragments(...args) { + const fragments = args.slice(0, -1); + const project = args[args.length - 1]; + const fragment = project(...fragments.map(f => f.value)); + const dependencies = fp_ts_1.array.flatten(fragments.map(f => f.dependencies)); + const refs = fp_ts_1.array.flatten(fragments.map(f => f.refs)); + return exports.serializedFragment(fragment, dependencies, refs); +} +exports.combineFragments = combineFragments; +function combineFragmentsK(...args) { + const fragments = args.slice(0, -1); + const project = args[args.length - 1]; + const fragment = project(...fragments.map(f => f.value)); + const dependencies = fp_ts_1.array.flatten(fragments.map(f => f.dependencies)); + const refs = fp_ts_1.array.flatten(fragments.map(f => f.refs)); + return exports.serializedFragment(fragment.value, dependencies.concat(fragment.dependencies), refs.concat(fragment.refs)); +} +exports.combineFragmentsK = combineFragmentsK; +/** + * @param f returns an Option + */ +exports.getSerializedOptionCallFragment = (nullable, f, a) => combineFragmentsK(f, a, (fn, a) => nullable + ? exports.serializedFragment(`pipe( + ${a}, + option.fromNullable, + option.chain(${fn}), + )`, [serialized_dependency_1.serializedDependency('option', 'fp-ts'), serialized_dependency_1.serializedDependency('pipe', 'fp-ts/lib/pipeable')], []) + : exports.serializedFragment(`pipe( + ${a}, + ${fn}, + )`, [serialized_dependency_1.serializedDependency('pipe', 'fp-ts/lib/pipeable')], [])); +exports.commaFragment = exports.serializedFragment(', ', [], []); diff --git a/dist/language/typescript/common/data/serialized-header-parameters.d.ts b/dist/language/typescript/common/data/serialized-header-parameters.d.ts new file mode 100644 index 0000000..6c9f13f --- /dev/null +++ b/dist/language/typescript/common/data/serialized-header-parameters.d.ts @@ -0,0 +1,9 @@ +import { Ref } from '../../../../utils/ref'; +import { SerializedDependency } from './serialized-dependency'; +import { SerializedParameter } from './serialized-parameter'; +export interface SerializedHeaderParameter extends SerializedParameter { + readonly name: string; +} +export declare const serializedHeaderParameter: (name: string, type: string, io: string, isRequired: boolean, dependencies: SerializedDependency[], refs: Ref[]) => SerializedHeaderParameter; +export declare const fromSerializedHeaderParameter: (name: string) => (serialized: SerializedParameter) => SerializedHeaderParameter; +export declare const getSerializedHeaderParameterType: (serialized: SerializedHeaderParameter) => SerializedHeaderParameter; diff --git a/dist/language/typescript/common/data/serialized-header-parameters.js b/dist/language/typescript/common/data/serialized-header-parameters.js new file mode 100644 index 0000000..98d8e91 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-header-parameters.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const ref_1 = require("../../../../utils/ref"); +const utils_1 = require("../utils"); +const serialized_dependency_1 = require("./serialized-dependency"); +exports.serializedHeaderParameter = (name, type, io, isRequired, dependencies, refs) => ({ + name, + type, + io, + isRequired, + dependencies: serialized_dependency_1.uniqSerializedDependencies(dependencies), + refs: ref_1.uniqRefs(refs), +}); +exports.fromSerializedHeaderParameter = (name) => (serialized) => (Object.assign(Object.assign({}, serialized), { name })); +exports.getSerializedHeaderParameterType = (serialized) => { + const name = utils_1.getTypeName(serialized.name); + return exports.serializedHeaderParameter(name, `${name}: ${serialized.isRequired ? serialized.type : `option.Option<${serialized.type}>`}`, `${name}: ${serialized.isRequired ? serialized.io : `optionFromNullable(${serialized.io})`}`, serialized.isRequired, serialized.dependencies.concat(serialized.isRequired + ? [] + : [ + serialized_dependency_1.serializedDependency('optionFromNullable', 'io-ts-types/lib/optionFromNullable'), + serialized_dependency_1.serializedDependency('option', 'fp-ts'), + ]), serialized.refs); +}; diff --git a/dist/language/typescript/common/data/serialized-parameter.d.ts b/dist/language/typescript/common/data/serialized-parameter.d.ts new file mode 100644 index 0000000..bd99835 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-parameter.d.ts @@ -0,0 +1,11 @@ +import { SerializedType } from './serialized-type'; +import { SerializedDependency } from './serialized-dependency'; +import { Monoid } from 'fp-ts/lib/Monoid'; +import { Ref } from '../../../../utils/ref'; +export interface SerializedParameter extends SerializedType { + readonly isRequired: boolean; +} +export declare const serializedParameter: (type: string, io: string, isRequired: boolean, dependencies: SerializedDependency[], refs: Ref[]) => SerializedParameter; +export declare const fromSerializedType: (isRequired: boolean) => (serializedType: SerializedType) => SerializedParameter; +export declare const monoidSerializedParameter: Monoid; +export declare const intercalateSerializedParameters: (sep: SerializedParameter, fm: SerializedParameter[]) => SerializedParameter; diff --git a/dist/language/typescript/common/data/serialized-parameter.js b/dist/language/typescript/common/data/serialized-parameter.js new file mode 100644 index 0000000..eefe9e5 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-parameter.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_dependency_1 = require("./serialized-dependency"); +const Monoid_1 = require("fp-ts/lib/Monoid"); +const Foldable_1 = require("fp-ts/lib/Foldable"); +const Array_1 = require("fp-ts/lib/Array"); +const ref_1 = require("../../../../utils/ref"); +exports.serializedParameter = (type, io, isRequired, dependencies, refs) => ({ + type, + io, + isRequired, + dependencies: serialized_dependency_1.uniqSerializedDependencies(dependencies), + refs: ref_1.uniqRefs(refs), +}); +exports.fromSerializedType = (isRequired) => (serializedType) => (Object.assign(Object.assign({}, serializedType), { isRequired })); +exports.monoidSerializedParameter = Monoid_1.getStructMonoid({ + type: Monoid_1.monoidString, + io: Monoid_1.monoidString, + dependencies: serialized_dependency_1.monoidDependencies, + isRequired: Monoid_1.monoidAny, + refs: Array_1.getMonoid(), +}); +exports.intercalateSerializedParameters = Foldable_1.intercalate(exports.monoidSerializedParameter, Array_1.array); diff --git a/dist/language/typescript/common/data/serialized-path-parameter.d.ts b/dist/language/typescript/common/data/serialized-path-parameter.d.ts new file mode 100644 index 0000000..a5d7dd4 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-path-parameter.d.ts @@ -0,0 +1,9 @@ +import { SerializedDependency } from './serialized-dependency'; +import { SerializedParameter } from './serialized-parameter'; +import { Ref } from '../../../../utils/ref'; +export interface SerializedPathParameter extends SerializedParameter { + readonly name: string; +} +export declare const serializedPathParameter: (name: string, type: string, io: string, isRequired: boolean, dependencies: SerializedDependency[], refs: Ref[]) => SerializedPathParameter; +export declare const fromSerializedParameter: (name: string) => (serialized: SerializedParameter) => SerializedPathParameter; +export declare const getSerializedPathParameterType: (serialized: SerializedPathParameter) => SerializedPathParameter; diff --git a/dist/language/typescript/common/data/serialized-path-parameter.js b/dist/language/typescript/common/data/serialized-path-parameter.js new file mode 100644 index 0000000..d8dd9d5 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-path-parameter.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_dependency_1 = require("./serialized-dependency"); +const ref_1 = require("../../../../utils/ref"); +const utils_1 = require("../utils"); +exports.serializedPathParameter = (name, type, io, isRequired, dependencies, refs) => ({ + name, + type, + io, + isRequired, + dependencies: serialized_dependency_1.uniqSerializedDependencies(dependencies), + refs: ref_1.uniqRefs(refs), +}); +exports.fromSerializedParameter = (name) => (serialized) => (Object.assign(Object.assign({}, serialized), { name })); +exports.getSerializedPathParameterType = (serialized) => { + const name = utils_1.getTypeName(serialized.name); + return exports.serializedPathParameter(name, `${name}: ${serialized.type}`, `${serialized.io}.encode(${name})`, serialized.isRequired, serialized.dependencies, serialized.refs); +}; diff --git a/dist/language/typescript/common/data/serialized-type.d.ts b/dist/language/typescript/common/data/serialized-type.d.ts new file mode 100644 index 0000000..26e3317 --- /dev/null +++ b/dist/language/typescript/common/data/serialized-type.d.ts @@ -0,0 +1,43 @@ +import { SerializedDependency } from './serialized-dependency'; +import { Monoid } from 'fp-ts/lib/Monoid'; +import { Ref } from '../../../../utils/ref'; +import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; +import { JSONPrimitive } from '../../../../utils/io-ts'; +import { option } from 'fp-ts'; +import { Either } from 'fp-ts/lib/Either'; +export interface SerializedType { + readonly type: string; + readonly io: string; + readonly dependencies: SerializedDependency[]; + readonly refs: Ref[]; +} +export declare const serializedType: (type: string, io: string, dependencies: SerializedDependency[], refs: Ref[]) => SerializedType; +export declare const monoidSerializedType: Monoid; +export declare const foldSerializedTypes: (as: SerializedType[]) => SerializedType; +export declare const intercalateSerializedTypes: (sep: SerializedType, fm: SerializedType[]) => SerializedType; +export declare const uniqSerializedTypesByTypeAndIO: (as: SerializedType[]) => SerializedType[]; +export declare const SERIALIZED_VOID_TYPE: SerializedType; +export declare const SERIALIZED_UNKNOWN_TYPE: SerializedType; +export declare const getSerializedBlobType: (from: Ref) => Either; +export declare const SERIALIZED_BOOLEAN_TYPE: SerializedType; +export declare const SERIALIZED_NUMBER_TYPE: SerializedType; +export declare const SERIALIZED_INTEGER_TYPE: SerializedType; +export declare const SERIALIZED_DATETIME_TYPE: SerializedType; +export declare const SERIALIZED_DATE_TYPE: SerializedType; +export declare const SERIALIZED_STRING_TYPE: SerializedType; +export declare const getSerializedStringType: (from: Ref, format: option.Option) => Either; +export declare const SERIALIZED_NULL_TYPE: SerializedType; +export declare const getSerializedNullableType: (isNullable: boolean) => (type: SerializedType) => SerializedType; +export declare const getSerializedArrayType: (minItems: option.Option, name?: string | undefined) => (serialized: SerializedType) => SerializedType; +export declare const getSerializedRefType: (from: Ref) => (to: Ref) => SerializedType; +export declare const getSerializedObjectType: (name?: string | undefined) => (serialized: SerializedType) => SerializedType; +export declare const getSerializedDictionaryType: (name?: string | undefined) => (serialized: SerializedType) => SerializedType; +export declare const getSerializedRecursiveType: (from: Ref, shouldTrackRecursion: boolean) => (serialized: SerializedType) => SerializedType; +export declare const getSerializedUnionType: (serialized: NonEmptyArray) => SerializedType; +export declare const getSerializedIntersectionType: (serialized: NonEmptyArray) => SerializedType; +export declare const getSerializedEnumType: (value: NonEmptyArray) => SerializedType; +export declare const getSerializedPrimitiveType: (value: JSONPrimitive) => SerializedType; +export declare const getSerializedOptionType: (serialized: SerializedType) => SerializedType; +export declare const getSerializedOptionalType: (isRequired: boolean, serialized: SerializedType) => SerializedType; +export declare const getSerializedPropertyType: (name: string, isRequired: boolean, serialized: SerializedType) => SerializedType; +export declare const getSerializedOptionPropertyType: (name: string, isRequired: boolean) => (serialized: SerializedType) => SerializedType; diff --git a/dist/language/typescript/common/data/serialized-type.js b/dist/language/typescript/common/data/serialized-type.js new file mode 100644 index 0000000..8a631ce --- /dev/null +++ b/dist/language/typescript/common/data/serialized-type.js @@ -0,0 +1,136 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serialized_dependency_1 = require("./serialized-dependency"); +const Monoid_1 = require("fp-ts/lib/Monoid"); +const Foldable_1 = require("fp-ts/lib/Foldable"); +const Array_1 = require("fp-ts/lib/Array"); +const Eq_1 = require("fp-ts/lib/Eq"); +const ref_1 = require("../../../../utils/ref"); +const utils_1 = require("../utils"); +const array_1 = require("../../../../utils/array"); +const string_1 = require("../../../../utils/string"); +const NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const Option_1 = require("fp-ts/lib/Option"); +const utils_2 = require("../bundled/utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +exports.serializedType = (type, io, dependencies, refs) => ({ + type, + io, + dependencies: serialized_dependency_1.uniqSerializedDependencies(dependencies), + refs: ref_1.uniqRefs(refs), +}); +exports.monoidSerializedType = Monoid_1.getStructMonoid({ + type: Monoid_1.monoidString, + io: Monoid_1.monoidString, + dependencies: serialized_dependency_1.monoidDependencies, + refs: Array_1.getMonoid(), +}); +exports.foldSerializedTypes = Monoid_1.fold(exports.monoidSerializedType); +exports.intercalateSerializedTypes = Foldable_1.intercalate(exports.monoidSerializedType, Array_1.array); +const eqSerializedTypeByTypeAndIO = Eq_1.getStructEq({ + type: Eq_1.eqString, + io: Eq_1.eqString, +}); +exports.uniqSerializedTypesByTypeAndIO = Array_1.uniq(eqSerializedTypeByTypeAndIO); +exports.SERIALIZED_VOID_TYPE = exports.serializedType('void', 'tvoid', [serialized_dependency_1.serializedDependency('void as tvoid', 'io-ts')], []); +exports.SERIALIZED_UNKNOWN_TYPE = exports.serializedType('unknown', 'unknown', [serialized_dependency_1.serializedDependency('unknown', 'io-ts')], []); +exports.getSerializedBlobType = (from) => { + return either_utils_1.combineEither(utils_2.utilsRef, utilsRef => exports.serializedType('Blob', 'BlobToBlobIO', [serialized_dependency_1.serializedDependency('BlobToBlobIO', ref_1.getRelativePath(from, utilsRef))], [])); +}; +exports.SERIALIZED_BOOLEAN_TYPE = exports.serializedType('boolean', 'boolean', [serialized_dependency_1.serializedDependency('boolean', 'io-ts')], []); +exports.SERIALIZED_NUMBER_TYPE = exports.serializedType('number', 'number', [serialized_dependency_1.serializedDependency('number', 'io-ts')], []); +exports.SERIALIZED_INTEGER_TYPE = exports.serializedType('Int', 'Int', [serialized_dependency_1.serializedDependency('Int', 'io-ts')], []); +exports.SERIALIZED_DATETIME_TYPE = exports.serializedType('Date', 'DateFromISOString', [serialized_dependency_1.serializedDependency('DateFromISOString', 'io-ts-types/lib/DateFromISOString')], []); +exports.SERIALIZED_DATE_TYPE = exports.serializedType('Date', 'DateFromISODateStringIO', [serialized_dependency_1.serializedDependency('DateFromISODateStringIO', '../utils/utils')], []); +exports.SERIALIZED_STRING_TYPE = exports.serializedType('string', 'string', [serialized_dependency_1.serializedDependency('string', 'io-ts')], []); +exports.getSerializedStringType = (from, format) => { + return either_utils_1.combineEither(utils_2.utilsRef, utilsRef => { + return pipeable_1.pipe(format, fp_ts_1.option.chain(format => { + // https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 + switch (format) { + case 'date-time': { + return Option_1.some(exports.SERIALIZED_DATETIME_TYPE); + } + case 'date': { + return Option_1.some(exports.serializedType('Date', 'DateFromISODateStringIO', [serialized_dependency_1.serializedDependency('DateFromISODateStringIO', ref_1.getRelativePath(from, utilsRef))], [])); + } + case 'byte': + case 'base64': { + return Option_1.some(exports.serializedType('Base64', 'Base64FromStringIO', [ + serialized_dependency_1.serializedDependency('Base64FromStringIO', ref_1.getRelativePath(from, utilsRef)), + serialized_dependency_1.serializedDependency('Base64', ref_1.getRelativePath(from, utilsRef)), + ], [])); + } + case 'binary': { + return Option_1.some(exports.serializedType('Binary', 'BinaryFromStringIO', [ + serialized_dependency_1.serializedDependency('BinaryFromStringIO', ref_1.getRelativePath(from, utilsRef)), + serialized_dependency_1.serializedDependency('Binary', ref_1.getRelativePath(from, utilsRef)), + ], [])); + } + } + return Option_1.none; + }), fp_ts_1.option.getOrElse(() => exports.SERIALIZED_STRING_TYPE)); + }); +}; +exports.SERIALIZED_NULL_TYPE = exports.serializedType('null', 'nullType', [serialized_dependency_1.serializedDependency('nullType', 'io-ts')], []); +exports.getSerializedNullableType = (isNullable) => (type) => isNullable ? exports.getSerializedUnionType([type, exports.SERIALIZED_NULL_TYPE]) : type; +exports.getSerializedArrayType = (minItems, name) => (serialized) => pipeable_1.pipe(minItems, Option_1.exists(minItems => minItems > 0), isNonEmpty => isNonEmpty + ? exports.serializedType(`NonEmptyArray<${serialized.type}>`, `nonEmptyArray(${serialized.io}${string_1.when(name !== undefined, `, '${name}'`)})`, [ + ...serialized.dependencies, + serialized_dependency_1.serializedDependency('nonEmptyArray', 'io-ts-types/lib/nonEmptyArray'), + serialized_dependency_1.serializedDependency('NonEmptyArray', 'fp-ts/lib/NonEmptyArray'), + ], serialized.refs) + : exports.serializedType(`Array<${serialized.type}>`, `array(${serialized.io}${string_1.when(name !== undefined, `, '${name}'`)})`, [...serialized.dependencies, serialized_dependency_1.serializedDependency('array', 'io-ts')], serialized.refs)); +exports.getSerializedRefType = (from) => (to) => { + const isRecursive = from.$ref === to.$ref; + const p = ref_1.getRelativePath(from, to); + const type = utils_1.getTypeName(to.name); + const io = utils_1.getIOName(to.name); + const ref = to.name === type ? to : Object.assign(Object.assign({}, to), { name: type }); + const dependencies = array_1.concatIfL(!isRecursive, [], () => [ + serialized_dependency_1.serializedDependency(type, p), + serialized_dependency_1.serializedDependency(io, p), + ]); + return exports.serializedType(type, io, dependencies, [ref]); +}; +exports.getSerializedObjectType = (name) => (serialized) => exports.serializedType(`{ ${serialized.type} }`, `type({ ${serialized.io} }${string_1.when(name !== undefined, `, '${name}'`)})`, [...serialized.dependencies, serialized_dependency_1.serializedDependency('type', 'io-ts')], serialized.refs); +exports.getSerializedDictionaryType = (name) => (serialized) => exports.serializedType(`{ [key: string]: ${serialized.type} }`, `record(string, ${serialized.io}${string_1.when(name !== undefined, `, '${name}'`)})`, [...serialized.dependencies, serialized_dependency_1.serializedDependency('record', 'io-ts'), serialized_dependency_1.serializedDependency('string', 'io-ts')], serialized.refs); +exports.getSerializedRecursiveType = (from, shouldTrackRecursion) => (serialized) => { + const typeName = utils_1.getTypeName(from.name); + const ioName = utils_1.getIOName(from.name); + return shouldTrackRecursion && serialized.refs.some(ref => ref.$ref === from.$ref) + ? exports.serializedType(serialized.type, `recursion<${typeName}, unknown>('${ioName}', ${ioName} => ${serialized.io})`, [...serialized.dependencies, serialized_dependency_1.serializedDependency('recursion', 'io-ts')], serialized.refs) + : serialized; +}; +exports.getSerializedUnionType = (serialized) => { + if (serialized.length === 1) { + return NonEmptyArray_1.head(serialized); + } + else { + const intercalated = exports.intercalateSerializedTypes(exports.serializedType(' | ', ',', [], []), serialized); + return exports.serializedType(`(${intercalated.type})`, `union([${intercalated.io}])`, [...intercalated.dependencies, serialized_dependency_1.serializedDependency('union', 'io-ts')], intercalated.refs); + } +}; +exports.getSerializedIntersectionType = (serialized) => { + if (serialized.length === 1) { + return NonEmptyArray_1.head(serialized); + } + else { + const intercalated = exports.intercalateSerializedTypes(exports.serializedType(' & ', ',', [], []), serialized); + return exports.serializedType(`${intercalated.type}`, `intersection([${intercalated.io}])`, [...intercalated.dependencies, serialized_dependency_1.serializedDependency('intersection', 'io-ts')], intercalated.refs); + } +}; +exports.getSerializedEnumType = (value) => pipeable_1.pipe(value, fp_ts_1.nonEmptyArray.map(exports.getSerializedPrimitiveType), exports.getSerializedUnionType); +exports.getSerializedPrimitiveType = (value) => { + const serialized = JSON.stringify(value); + return exports.serializedType(serialized, `literal(${serialized})`, [serialized_dependency_1.LITERAL_DEPENDENCY], []); +}; +exports.getSerializedOptionType = (serialized) => exports.serializedType(`Option<${serialized.type}>`, `optionFromNullable(${serialized.io})`, [...serialized.dependencies, ...serialized_dependency_1.OPTION_DEPENDENCIES], serialized.refs); +exports.getSerializedOptionalType = (isRequired, serialized) => isRequired ? serialized : exports.getSerializedOptionType(serialized); +exports.getSerializedPropertyType = (name, isRequired, serialized) => { + const safeName = utils_1.UNSAFE_PROPERTY_PATTERN.test(name) ? `['${name}']` : name; + return exports.serializedType(`${safeName}${string_1.when(!isRequired, '?')}: ${serialized.type}`, `${safeName}: ${serialized.io}`, serialized.dependencies, serialized.refs); +}; +exports.getSerializedOptionPropertyType = (name, isRequired) => (serialized) => exports.getSerializedPropertyType(name, true, exports.getSerializedOptionalType(isRequired, serialized)); diff --git a/dist/language/typescript/common/utils.d.ts b/dist/language/typescript/common/utils.d.ts new file mode 100644 index 0000000..979b15b --- /dev/null +++ b/dist/language/typescript/common/utils.d.ts @@ -0,0 +1,35 @@ +import { SerializedPathParameter } from './data/serialized-path-parameter'; +import { Options } from 'prettier'; +import { ResolveRefContext } from '../../../utils/ref'; +import { Kind } from '../../../utils/types'; +import { option, nonEmptyArray } from 'fp-ts'; +export declare const SUCCESSFUL_CODES: string[]; +export declare const CONTROLLERS_DIRECTORY = "controllers"; +export declare const DEFINITIONS_DIRECTORY = "definitions"; +export declare type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; +export declare type XHRResponseType = 'json' | 'blob' | 'text'; +export declare const getTypeName: (name: string) => string; +export declare const getIOName: (name: string) => string; +export declare const getURL: (pattern: string, pathParameters: SerializedPathParameter[]) => string; +export declare const getJSDoc: (lines: string[]) => string; +export declare const defaultPrettierConfig: Options; +export interface SerializeOptions { + prettierConfig?: Options; +} +export declare const pathsRef: import("fp-ts/lib/Either").Either>; +export declare const getKindValue: (kind: Kind, value: string) => string; +export declare const getControllerName: (name: string) => string; +export declare const escapeCommpent: (value: string) => string; +export declare const UNSAFE_PROPERTY_PATTERN: RegExp; +export declare const getSafePropertyName: (value: string) => string; +export declare const context: import("fp-ts/lib/Reader").Reader; +export declare const getKeyMatchValue: (record: Record, regexp: RegExp) => option.Option<{ + key: T; + value: Record[T]; +}>; +export declare const getKeyMatchValues: (record: Record, regexp: RegExp) => option.Option[T]; +}>>; +export declare const DEFAULT_MEDIA_TYPE = "application/json"; +export declare const getResponseTypeFromMediaType: (mediaType: string) => XHRResponseType; diff --git a/dist/language/typescript/common/utils.js b/dist/language/typescript/common/utils.js new file mode 100644 index 0000000..b281850 --- /dev/null +++ b/dist/language/typescript/common/utils.js @@ -0,0 +1,76 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const string_1 = require("../../../utils/string"); +const ref_1 = require("../../../utils/ref"); +const Reader_1 = require("fp-ts/lib/Reader"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const Record_1 = require("fp-ts/lib/Record"); +const fp_ts_1 = require("fp-ts"); +exports.SUCCESSFUL_CODES = ['200', '201', 'default']; +exports.CONTROLLERS_DIRECTORY = 'controllers'; +exports.DEFINITIONS_DIRECTORY = 'definitions'; +const INVALID_NAMES = ['Error', 'Promise', 'PromiseLike', 'Array', 'ArrayLike', 'Function', 'Object']; +const TYPE_NAME_NORMALIZE_REGEX = /\W/g; +const normalize = (name) => name.replace(TYPE_NAME_NORMALIZE_REGEX, '_').replace(/^(\d)/, '_$1'); +exports.getTypeName = (name) => { + if (name.length === 0) { + return 'Type'; + } + const normalized = normalize(name); + return INVALID_NAMES.includes(name) ? `${normalized}Type` : normalized; +}; +exports.getIOName = (name) => `${normalize(name)}IO`; +exports.getURL = (pattern, pathParameters) => pathParameters.reduce((acc, p) => acc.replace(`{${p.name}}`, `\$\{encodeURIComponent(${p.io}.toString())\}`), `\`${pattern}\``); +exports.getJSDoc = (lines) => string_1.unless(lines.length === 0, `/** + ${lines.map(line => `* ${line}`).join('\n')} + */`); +exports.defaultPrettierConfig = { + bracketSpacing: true, + jsxBracketSameLine: true, + parser: 'typescript', + printWidth: 120, + semi: true, + singleQuote: true, + tabWidth: 4, + trailingComma: 'all', + useTabs: true, +}; +exports.pathsRef = ref_1.fromString('#/paths'); +exports.getKindValue = (kind, value) => { + switch (kind) { + case 'HKT': { + return `HKT`; + } + case '*': { + return `Kind`; + } + case '* -> *': { + return `Kind2`; + } + } +}; +exports.getControllerName = (name) => `${name}Controller`; +const COMMENT_PATTERN = /\/\*(.*)\*\//; +const REPLACE_COMMENT_PATTERN = new RegExp(COMMENT_PATTERN, 'g'); +exports.escapeCommpent = (value) => value.replace(REPLACE_COMMENT_PATTERN, '\\/*$1*\\/'); +exports.UNSAFE_PROPERTY_PATTERN = /[^a-zA-Z_0-9]/; +const REPLACE_PATTERN = new RegExp(exports.UNSAFE_PROPERTY_PATTERN, 'g'); +exports.getSafePropertyName = (value) => value.replace(REPLACE_PATTERN, '_').replace(/^(\d)/, '_$1') || '_'; +exports.context = Reader_1.ask(); +exports.getKeyMatchValue = (record, regexp) => pipeable_1.pipe(record, Record_1.keys, fp_ts_1.array.findFirst(s => regexp.test(s)), fp_ts_1.option.map(key => ({ key, value: record[key] }))); +exports.getKeyMatchValues = (record, regexp) => pipeable_1.pipe(record, Record_1.keys, fp_ts_1.array.filter(s => regexp.test(s)), fp_ts_1.nonEmptyArray.fromArray, fp_ts_1.option.map(fp_ts_1.nonEmptyArray.map(key => ({ key, value: record[key] })))); +const blobMediaRegexp = /^(video|audio|image|application)/; +const textMediaRegexp = /^text/; +exports.DEFAULT_MEDIA_TYPE = 'application/json'; +exports.getResponseTypeFromMediaType = (mediaType) => { + if (mediaType === 'application/json') { + return 'json'; + } + if (blobMediaRegexp.test(mediaType)) { + return 'blob'; + } + if (textMediaRegexp.test(mediaType)) { + return 'text'; + } + return 'json'; +}; diff --git a/dist/language/typescript/sketch-121/index.d.ts b/dist/language/typescript/sketch-121/index.d.ts new file mode 100644 index 0000000..a78893a --- /dev/null +++ b/dist/language/typescript/sketch-121/index.d.ts @@ -0,0 +1,5 @@ +import { SerializeOptions } from '../common/utils'; +import { FSEntity } from '../../../utils/fs'; +import { Either } from 'fp-ts/lib/Either'; +import { FileFormat } from '../../../schema/sketch-121/file-format'; +export declare const serialize: import("fp-ts/lib/Reader").Reader, options?: SerializeOptions) => Either>; diff --git a/dist/language/typescript/sketch-121/index.js b/dist/language/typescript/sketch-121/index.js new file mode 100644 index 0000000..a05cce9 --- /dev/null +++ b/dist/language/typescript/sketch-121/index.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../common/utils"); +const fs_1 = require("../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const prettier_1 = require("prettier"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const file_format_1 = require("./serializers/file-format"); +exports.serialize = reader_utils_1.combineReader(file_format_1.serializeFileFormat, serializeFileFormat => (files, options = {}) => pipeable_1.pipe(files, fp_ts_1.record.collect((name, file) => pipeable_1.pipe(serializeFileFormat(file), fp_ts_1.either.map(fp_ts_1.option.map(content => fs_1.directory(name, [content]))))), either_utils_1.sequenceEither, fp_ts_1.either.map(serialized => fs_1.map(fs_1.fragment(fp_ts_1.array.compact(serialized)), content => prettier_1.format(content, options.prettierConfig || utils_1.defaultPrettierConfig))))); diff --git a/dist/language/typescript/sketch-121/serializers/document.d.ts b/dist/language/typescript/sketch-121/serializers/document.d.ts new file mode 100644 index 0000000..1029747 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/document.d.ts @@ -0,0 +1,5 @@ +import { Either } from 'fp-ts/lib/Either'; +import { Document } from '../../../../schema/sketch-121/document'; +import { option } from 'fp-ts'; +import { FSEntity } from '../../../../utils/fs'; +export declare const serializeDocument: import("fp-ts/lib/Reader").Reader Either>>; diff --git a/dist/language/typescript/sketch-121/serializers/document.js b/dist/language/typescript/sketch-121/serializers/document.js new file mode 100644 index 0000000..238af3c --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/document.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const shared_styled_container_1 = require("./objects/shared-styled-container"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const shared_text_style_container_1 = require("./objects/shared-text-style-container"); +const foreign_layer_style_1 = require("./objects/foreign-layer-style"); +const either_1 = require("../../../../utils/either"); +const option_1 = require("../../../../utils/option"); +const foreign_text_style_1 = require("./objects/foreign-text-style"); +const fs_1 = require("../../../../utils/fs"); +const asset_collection_1 = require("./objects/asset-collection"); +const page_1 = require("./objects/page"); +exports.serializeDocument = reader_utils_1.combineReader(shared_styled_container_1.serializeSharedStyleContainer, shared_text_style_container_1.serializeSharedTextStyleContainer, foreign_layer_style_1.serializeForeignLayerStyle, foreign_text_style_1.serializeForeignTextStyle, asset_collection_1.serializeAssetCollection, page_1.serializePage, (serializeSharedStyleContainer, serializeSharedTextStyleContainer, serializeForeignLayerStyle, serializeForeignTextStyle, serializeAssetCollection, serializePage) => (document) => { + const layerStyles = pipeable_1.pipe(serializeSharedStyleContainer(document.layerStyles), fp_ts_1.either.map(fp_ts_1.option.map(content => fs_1.file('layer-styles.ts', content)))); + const layerTextStyles = pipeable_1.pipe(serializeSharedTextStyleContainer(document.layerTextStyles), fp_ts_1.either.map(fp_ts_1.option.map(content => fs_1.file('layer-text-styles.ts', content)))); + const foreignLayerStyles = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(document.foreignLayerStyles), fp_ts_1.option.map(styles => pipeable_1.pipe(either_1.traverseNEAEither(styles, serializeForeignLayerStyle), fp_ts_1.either.map(styles => fs_1.file('foreign-layer-styles.ts', styles.join(''))))), option_1.sequenceOptionEither); + const foreignTextStyles = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(document.foreignTextStyles), fp_ts_1.option.map(styles => pipeable_1.pipe(either_1.traverseNEAEither(styles, serializeForeignTextStyle), fp_ts_1.either.map(styles => fs_1.file('foreign-text-styles.ts', styles.join(''))))), option_1.sequenceOptionEither); + const assets = pipeable_1.pipe(serializeAssetCollection(document.assets), fp_ts_1.either.map(fp_ts_1.option.map(assets => fs_1.file('assets.ts', assets)))); + const layers = either_1.traverseOptionEither(fp_ts_1.nonEmptyArray.fromArray(document.pages), pages => pipeable_1.pipe(either_1.traverseNEAEither(pages, serializePage), fp_ts_1.either.map(pagesLayers => fs_1.file('layers.ts', pagesLayers.join(''))))); + return either_utils_1.combineEither(layerStyles, layerTextStyles, foreignLayerStyles, foreignTextStyles, assets, layers, (layerStyles, layerTextStyles, foreignLayerStyles, foreignTextStyles, assets, layers) => pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(fp_ts_1.array.compact([ + layerStyles, + layerTextStyles, + foreignLayerStyles, + foreignTextStyles, + assets, + layers, + ])), fp_ts_1.option.map(fs_1.fragment))); +}); diff --git a/dist/language/typescript/sketch-121/serializers/enums/blend-mode.d.ts b/dist/language/typescript/sketch-121/serializers/enums/blend-mode.d.ts new file mode 100644 index 0000000..f75b324 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/blend-mode.d.ts @@ -0,0 +1,12 @@ +import { BlendMode } from '../../../../../schema/sketch-121/enums/blend-mode'; +import { Either } from 'fp-ts/lib/Either'; +/** + * @see https://www.w3schools.com/cssref/pr_background-blend-mode.asp + */ +export declare type BackgroundBlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'saturation' | 'color' | 'luminosity'; +/** + * @see https://www.w3schools.com/cssref/pr_mix-blend-mode.asp + */ +export declare type MixBlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity'; +export declare const getBackgroundBlendMode: (mode: BlendMode) => Either; +export declare const getMixBlendMode: (mode: BlendMode) => Either; diff --git a/dist/language/typescript/sketch-121/serializers/enums/blend-mode.js b/dist/language/typescript/sketch-121/serializers/enums/blend-mode.js new file mode 100644 index 0000000..0fdd421 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/blend-mode.js @@ -0,0 +1,85 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Either_1 = require("fp-ts/lib/Either"); +exports.getBackgroundBlendMode = (mode) => { + const invalid = Either_1.left(new Error(`Unsupported BlendMode for background-blend-mode: "${mode}"`)); + switch (mode) { + case 'Normal': + return Either_1.right('normal'); + case 'Darken': + return Either_1.right('darken'); + case 'Multiply': + return Either_1.right('multiply'); + case 'Color burn': + return invalid; + case 'Lighten': + return Either_1.right('lighten'); + case 'Screen': + return Either_1.right('screen'); + case 'Color dodge': + return Either_1.right('color-dodge'); + case 'Overlay': + return Either_1.right('overlay'); + case 'Soft light': + return invalid; + case 'Hard light': + return invalid; + case 'Difference': + return invalid; + case 'Exclusion': + return invalid; + case 'Hue': + return invalid; + case 'Saturation': + return Either_1.right('saturation'); + case 'Color': + return Either_1.right('color'); + case 'Luminosity': + return Either_1.right('luminosity'); + case 'Plus darker': + return invalid; + case 'Plus lighter': + return invalid; + } +}; +exports.getMixBlendMode = (mode) => { + const invalid = Either_1.left(new Error(`Unsupported BlendMode for mix-blend-mode: "${mode}"`)); + switch (mode) { + case 'Normal': + return Either_1.right('normal'); + case 'Darken': + return Either_1.right('darken'); + case 'Multiply': + return Either_1.right('multiply'); + case 'Color burn': + return Either_1.right('color-burn'); + case 'Lighten': + return Either_1.right('lighten'); + case 'Screen': + return Either_1.right('screen'); + case 'Color dodge': + return Either_1.right('color-dodge'); + case 'Overlay': + return Either_1.right('overlay'); + case 'Soft light': + return invalid; + case 'Hard light': + return invalid; + case 'Difference': + return Either_1.right('difference'); + case 'Exclusion': + return Either_1.right('exclusion'); + case 'Hue': + return Either_1.right('hue'); + case 'Saturation': + return Either_1.right('saturation'); + case 'Color': + return Either_1.right('color'); + case 'Luminosity': + return Either_1.right('luminosity'); + case 'Plus darker': + return invalid; + case 'Plus lighter': + return invalid; + } +}; diff --git a/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.d.ts b/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.d.ts new file mode 100644 index 0000000..812f63c --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.d.ts @@ -0,0 +1,3 @@ +import { TextHorizontalAlignment } from '../../../../../schema/sketch-121/enums/text-horizontal-alignment'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeTextHorizontalAlignment: (alignment: TextHorizontalAlignment) => Either; diff --git a/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.js b/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.js new file mode 100644 index 0000000..ffcbdba --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/text-horizontal-alignment.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Either_1 = require("fp-ts/lib/Either"); +exports.serializeTextHorizontalAlignment = (alignment) => { + switch (alignment) { + case 'Centered': { + return Either_1.right('center'); + } + case 'Justified': { + return Either_1.right('justify'); + } + case 'Left': { + return Either_1.right('left'); + } + case 'Right': { + return Either_1.right('right'); + } + case 'Natural': { + return Either_1.left(new Error('TextHorizontalAlignment.Natural is not supported')); + } + } +}; diff --git a/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.d.ts b/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.d.ts new file mode 100644 index 0000000..83583da --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.d.ts @@ -0,0 +1,2 @@ +import { TextVerticalAlignment } from '../../../../../schema/sketch-121/enums/text-vertical-alignment'; +export declare const serializeTextVerticalAlignment: (alignment: TextVerticalAlignment) => string; diff --git a/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.js b/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.js new file mode 100644 index 0000000..86b43d4 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/text-vertical-alignment.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.serializeTextVerticalAlignment = (alignment) => { + switch (alignment) { + case 'Top': { + return 'top'; + } + case 'Middle': { + return 'middle'; + } + case 'Bottom': { + return 'bottom'; + } + } +}; diff --git a/dist/language/typescript/sketch-121/serializers/enums/underline-style.d.ts b/dist/language/typescript/sketch-121/serializers/enums/underline-style.d.ts new file mode 100644 index 0000000..2242d30 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/underline-style.d.ts @@ -0,0 +1,2 @@ +import { UnderlineStyle } from '../../../../../schema/sketch-121/enums/underline-style'; +export declare const serializeUnderlineStyle: (style: UnderlineStyle) => string; diff --git a/dist/language/typescript/sketch-121/serializers/enums/underline-style.js b/dist/language/typescript/sketch-121/serializers/enums/underline-style.js new file mode 100644 index 0000000..fe09625 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/enums/underline-style.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.serializeUnderlineStyle = (style) => { + switch (style) { + case 'None': { + return 'normal'; + } + case 'Underlined': { + return 'underline'; + } + } +}; diff --git a/dist/language/typescript/sketch-121/serializers/file-format.d.ts b/dist/language/typescript/sketch-121/serializers/file-format.d.ts new file mode 100644 index 0000000..9a7fac8 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/file-format.d.ts @@ -0,0 +1,5 @@ +import { FileFormat } from '../../../../schema/sketch-121/file-format'; +import { Either } from 'fp-ts/lib/Either'; +import { FSEntity } from '../../../../utils/fs'; +import { option } from 'fp-ts'; +export declare const serializeFileFormat: import("fp-ts/lib/Reader").Reader Either>>; diff --git a/dist/language/typescript/sketch-121/serializers/file-format.js b/dist/language/typescript/sketch-121/serializers/file-format.js new file mode 100644 index 0000000..9ac266f --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/file-format.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const document_1 = require("./document"); +const fs_1 = require("../../../../utils/fs"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +exports.serializeFileFormat = reader_utils_1.combineReader(document_1.serializeDocument, serializeDocument => (fileFormat) => { + const document = serializeDocument(fileFormat.document); + return either_utils_1.combineEither(document, document => pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(fp_ts_1.array.compact([document])), fp_ts_1.option.map(fs_1.fragment))); +}); diff --git a/dist/language/typescript/sketch-121/serializers/objects/asset-collection.d.ts b/dist/language/typescript/sketch-121/serializers/objects/asset-collection.d.ts new file mode 100644 index 0000000..3d30b0d --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/asset-collection.d.ts @@ -0,0 +1,4 @@ +import { AssetCollection } from '../../../../../schema/sketch-121/objects/asset-collection'; +import { Either } from 'fp-ts/lib/Either'; +import { Option } from 'fp-ts/lib/Option'; +export declare const serializeAssetCollection: import("fp-ts/lib/Reader").Reader Either>>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/asset-collection.js b/dist/language/typescript/sketch-121/serializers/objects/asset-collection.js new file mode 100644 index 0000000..70e366a --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/asset-collection.js @@ -0,0 +1,46 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +const fp_ts_1 = require("fp-ts"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const utils_1 = require("../../../common/utils"); +const gradient_1 = require("./gradient"); +const either_1 = require("../../../../../utils/either"); +const option_1 = require("../../../../../utils/option"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const utils_2 = require("../../utils"); +exports.serializeAssetCollection = reader_utils_1.combineReader(utils_2.context, context => (assets) => { + const colorAssets = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(assets.colorAssets), fp_ts_1.option.map(fp_ts_1.nonEmptyArray.map(colorAsset => { + const safeName = context.nameStorage.getSafeName(colorAsset.do_objectID, colorAsset.name); + const color = color_1.serializeColor(colorAsset.color); + return ` + ${utils_1.getJSDoc([colorAsset.name, colorAsset.do_objectID])} + const ${safeName} = '${color}'; + `; + })), fp_ts_1.option.map(lines => lines.join('\n'))); + const gradientAssets = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(assets.gradientAssets), fp_ts_1.option.map(gradientAssets => either_1.traverseNEAEither(gradientAssets, gradientAsset => { + const safeName = context.nameStorage.getSafeName(gradientAsset.do_objectID, gradientAsset.name); + return pipeable_1.pipe(gradient_1.serializeGradient(gradientAsset.gradient), fp_ts_1.either.map(gradient => ` + ${utils_1.getJSDoc([gradientAsset.name, gradientAsset.do_objectID])} + const ${safeName} = '${gradient}'; + `)); + })), option_1.sequenceOptionEither, fp_ts_1.either.map(fp_ts_1.option.map(lines => lines.join('\n')))); + const colors = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(assets.colors), fp_ts_1.option.map(colors => ` + ${utils_1.getJSDoc(['Colors'])} + const colors = [ + ${colors.map(color => `'${color_1.serializeColor(color)}'`).join(', ')} + ]; + `)); + const gradients = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(assets.gradients), fp_ts_1.option.map(gradients => either_1.traverseNEAEither(gradients, gradient_1.serializeGradient)), option_1.sequenceOptionEither, fp_ts_1.either.map(fp_ts_1.option.map(gradients => ` + ${utils_1.getJSDoc(['Gradients'])} + const gradients = [ + ${gradients.map(gradient => `'${gradient}'`).join(', ')} + ]; + `))); + return either_utils_1.combineEither(gradients, gradientAssets, (gradients, gradientAssets) => pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(fp_ts_1.array.compact([colorAssets, gradientAssets, colors, gradients])), fp_ts_1.option.map(parts => ` + ${utils_1.getJSDoc(['Assets', assets.do_objectID])} + + ${parts.join('\n')} + `))); +}); diff --git a/dist/language/typescript/sketch-121/serializers/objects/border.d.ts b/dist/language/typescript/sketch-121/serializers/objects/border.d.ts new file mode 100644 index 0000000..f6a88c4 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/border.d.ts @@ -0,0 +1,4 @@ +import { Border } from '../../../../../schema/sketch-121/objects/border'; +import { Either } from 'fp-ts/lib/Either'; +import { BorderOptions } from '../../../../../schema/sketch-121/objects/border-options'; +export declare const serializeBorder: (border: Border, borderOptions: BorderOptions) => Either; diff --git a/dist/language/typescript/sketch-121/serializers/objects/border.js b/dist/language/typescript/sketch-121/serializers/objects/border.js new file mode 100644 index 0000000..286bd3d --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/border.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Either_1 = require("fp-ts/lib/Either"); +const color_1 = require("./color"); +const gradient_1 = require("./gradient"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +exports.serializeBorder = (border, borderOptions) => { + const width = `${border.thickness}px`; + const style = borderOptions.isEnabled && borderOptions.dashPattern.length > 0 ? 'dashed' : 'solid'; + switch (border.fillType) { + case 'Color': + const color = color_1.serializeColor(border.color); + return Either_1.right(`border: '${style} ${width} ${color}'`); + case 'Gradient': + const gradient = gradient_1.serializeGradient(border.gradient); + return pipeable_1.pipe(gradient, fp_ts_1.either.map(gradient => ` + borderStyle: '${style}', + borderWidth: '${width}', + borderImageSource: '${gradient}', + borderImageSlice: '1' + `)); + case 'Pattern': { + return Either_1.left(new Error(`Border.fillType "Pattern" is not supported`)); + } + } +}; diff --git a/dist/language/typescript/sketch-121/serializers/objects/color.d.ts b/dist/language/typescript/sketch-121/serializers/objects/color.d.ts new file mode 100644 index 0000000..5d6b1a9 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/color.d.ts @@ -0,0 +1,2 @@ +import { Color } from '../../../../../schema/sketch-121/objects/color'; +export declare const serializeColor: (color: Color) => string; diff --git a/dist/language/typescript/sketch-121/serializers/objects/color.js b/dist/language/typescript/sketch-121/serializers/objects/color.js new file mode 100644 index 0000000..d224337 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/color.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const c = require("color"); +const toValue = (unit) => Math.round(255 * unit); +exports.serializeColor = (color) => c({ + alpha: color.alpha, + r: toValue(color.red), + g: toValue(color.green), + b: toValue(color.blue), +}).string(); diff --git a/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.d.ts b/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.d.ts new file mode 100644 index 0000000..7b61062 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.d.ts @@ -0,0 +1,3 @@ +import { ForeignLayerStyle } from '../../../../../schema/sketch-121/objects/foreign-layer-style'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeForeignLayerStyle: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.js b/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.js new file mode 100644 index 0000000..c49c890 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/foreign-layer-style.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const shared_style_1 = require("./shared-style"); +exports.serializeForeignLayerStyle = reader_utils_1.combineReader(shared_style_1.serializeSharedStyle, serializeSharedStyle => (style) => serializeSharedStyle(style.localSharedStyle, [style.sourceLibraryName])); diff --git a/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.d.ts b/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.d.ts new file mode 100644 index 0000000..b4fed14 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.d.ts @@ -0,0 +1,3 @@ +import { Either } from 'fp-ts/lib/Either'; +import { ForeignTextStyle } from '../../../../../schema/sketch-121/objects/foreign-text-style'; +export declare const serializeForeignTextStyle: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.js b/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.js new file mode 100644 index 0000000..63f9ff5 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/foreign-text-style.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const shared_style_1 = require("./shared-style"); +exports.serializeForeignTextStyle = reader_utils_1.combineReader(shared_style_1.serializeSharedStyle, serializeSharedStyle => (style) => serializeSharedStyle(style.localSharedStyle, [style.sourceLibraryName])); diff --git a/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.d.ts b/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.d.ts new file mode 100644 index 0000000..0eecd33 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.d.ts @@ -0,0 +1,3 @@ +import { GradientStop } from '../../../../../schema/sketch-121/objects/gradient-stop'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeGradientStop: (stop: GradientStop) => Either; diff --git a/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.js b/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.js new file mode 100644 index 0000000..4091eaa --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/gradient-stop.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +const io_ts_1 = require("../../../../../utils/io-ts"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +exports.serializeGradientStop = (stop) => { + const color = color_1.serializeColor(stop.color); + const positionInPercents = io_ts_1.percentageFromFraction(stop.position); + return either_utils_1.combineEither(positionInPercents, position => `${color} ${position}%`); +}; diff --git a/dist/language/typescript/sketch-121/serializers/objects/gradient.d.ts b/dist/language/typescript/sketch-121/serializers/objects/gradient.d.ts new file mode 100644 index 0000000..ac11d23 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/gradient.d.ts @@ -0,0 +1,3 @@ +import { Gradient } from '../../../../../schema/sketch-121/objects/gradient'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeGradient: (gradient: Gradient) => Either; diff --git a/dist/language/typescript/sketch-121/serializers/objects/gradient.js b/dist/language/typescript/sketch-121/serializers/objects/gradient.js new file mode 100644 index 0000000..ac1aa09 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/gradient.js @@ -0,0 +1,34 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gradient_stop_1 = require("./gradient-stop"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const serializeGradientStops = (stops) => pipeable_1.pipe(stops.map(gradient_stop_1.serializeGradientStop), either_utils_1.sequenceEither, fp_ts_1.either.map(stops => stops.join(', '))); +const serializeLinearGradient = (gradient) => { + const angle = getAngle(gradient.from, gradient.to); + const stops = serializeGradientStops(gradient.stops); + return either_utils_1.combineEither(stops, stops => `linear-gradient(${angle}deg, ${stops})`); +}; +const serializeRadialGradient = (gradient) => { + const stops = serializeGradientStops(gradient.stops); + return either_utils_1.combineEither(stops, stops => `radial-gradient(${stops})`); +}; +const serializeConicGradient = (gradient) => { + const stops = serializeGradientStops(gradient.stops); + return either_utils_1.combineEither(stops, stops => `conic-gradient(${stops})`); +}; +exports.serializeGradient = (gradient) => { + switch (gradient.gradientType) { + case 0: { + return serializeLinearGradient(gradient); + } + case 1: { + return serializeRadialGradient(gradient); + } + case 2: { + return serializeConicGradient(gradient); + } + } +}; +const getAngle = (start, end) => 90 - (Math.atan2(end.y - start.y, end.x - start.x) * 180) / Math.PI; diff --git a/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.d.ts b/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.d.ts new file mode 100644 index 0000000..4728edf --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.d.ts @@ -0,0 +1,2 @@ +import { InnerShadow } from '../../../../../schema/sketch-121/objects/inner-shadow'; +export declare const serializeInnerShadow: (shadow: InnerShadow) => string; diff --git a/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.js b/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.js new file mode 100644 index 0000000..472d958 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/inner-shadow.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +exports.serializeInnerShadow = (shadow) => { + const color = color_1.serializeColor(shadow.color); + return `inset ${shadow.offsetX}px ${shadow.offsetY}px ${shadow.blurRadius}px ${shadow.spread}px ${color}`; +}; diff --git a/dist/language/typescript/sketch-121/serializers/objects/layer.d.ts b/dist/language/typescript/sketch-121/serializers/objects/layer.d.ts new file mode 100644 index 0000000..d278728 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/layer.d.ts @@ -0,0 +1,3 @@ +import { Layer } from '../../../../../schema/sketch-121/objects/layer'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeLayer: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/layer.js b/dist/language/typescript/sketch-121/serializers/objects/layer.js new file mode 100644 index 0000000..e24d315 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/layer.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../../../common/utils"); +const style_1 = require("./style"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const utils_2 = require("../../utils"); +const fp_ts_1 = require("fp-ts"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const either_1 = require("../../../../../utils/either"); +const function_1 = require("fp-ts/lib/function"); +exports.serializeLayer = reader_utils_1.combineReader(utils_2.context, context => (layer, jsdoc) => { + const layerNameWithPrefix = `layer_${layer.name}`; + const safeName = context.nameStorage.getSafeName(layer.do_objectID, layerNameWithPrefix); + const layerStyle = style_1.serializeStyle(layer.style); + const nestedLayersStyles = either_1.traverseOptionEither(layer.layers, layers => pipeable_1.pipe(either_1.traverseArrayEither(layers, exports.serializeLayer(context)), fp_ts_1.either.map(styles => styles.join('')))); + return either_utils_1.combineEither(layerStyle, nestedLayersStyles, (pageStyle, nestedPagesStyles) => ` + ${utils_1.getJSDoc([...(jsdoc || []), utils_1.escapeCommpent(layer.name), layer.do_objectID])} + export const ${safeName}: { name: string; styles: Partial } = { + name: '${layer.name}', + styles: { + ${pageStyle} + }, + }; + ${fp_ts_1.option.fold(function_1.constant(''), function_1.identity)(nestedPagesStyles)} + `); +}); diff --git a/dist/language/typescript/sketch-121/serializers/objects/page.d.ts b/dist/language/typescript/sketch-121/serializers/objects/page.d.ts new file mode 100644 index 0000000..ef6b7b8 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/page.d.ts @@ -0,0 +1,3 @@ +import { Page } from '../../../../../schema/sketch-121/objects/page'; +import { either } from 'fp-ts'; +export declare const serializePage: import("fp-ts/lib/Reader").Reader either.Either>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/page.js b/dist/language/typescript/sketch-121/serializers/objects/page.js new file mode 100644 index 0000000..af00e68 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/page.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fp_ts_1 = require("fp-ts"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const layer_1 = require("./layer"); +const either_1 = require("../../../../../utils/either"); +exports.serializePage = reader_utils_1.combineReader(layer_1.serializeLayer, serializeLayer => (page) => pipeable_1.pipe(either_1.traverseArrayEither(page.layers, serializeLayer), fp_ts_1.either.map(styles => styles.join('')))); diff --git a/dist/language/typescript/sketch-121/serializers/objects/shadow.d.ts b/dist/language/typescript/sketch-121/serializers/objects/shadow.d.ts new file mode 100644 index 0000000..7cb4e1f --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shadow.d.ts @@ -0,0 +1,2 @@ +import { Shadow } from '../../../../../schema/sketch-121/objects/shadow'; +export declare const serializeShadow: (shadow: Shadow) => string; diff --git a/dist/language/typescript/sketch-121/serializers/objects/shadow.js b/dist/language/typescript/sketch-121/serializers/objects/shadow.js new file mode 100644 index 0000000..0b70871 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shadow.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +exports.serializeShadow = (shadow) => { + const color = color_1.serializeColor(shadow.color); + return `${shadow.offsetX}px ${shadow.offsetY}px ${shadow.blurRadius}px ${shadow.spread}px ${color}`; +}; diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-style.d.ts b/dist/language/typescript/sketch-121/serializers/objects/shared-style.d.ts new file mode 100644 index 0000000..f7391bc --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-style.d.ts @@ -0,0 +1,3 @@ +import { SharedStyle } from '../../../../../schema/sketch-121/objects/shared-style'; +import { Either } from 'fp-ts/lib/Either'; +export declare const serializeSharedStyle: import("fp-ts/lib/Reader").Reader Either>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-style.js b/dist/language/typescript/sketch-121/serializers/objects/shared-style.js new file mode 100644 index 0000000..24c8499 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-style.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const utils_1 = require("../../../common/utils"); +const style_1 = require("./style"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const utils_2 = require("../../utils"); +exports.serializeSharedStyle = reader_utils_1.combineReader(utils_2.context, context => (sharedStyle, jsdoc) => { + const style = style_1.serializeStyle(sharedStyle.value); + const safeName = context.nameStorage.getSafeName(sharedStyle.do_objectID, sharedStyle.name); + return either_utils_1.combineEither(style, style => ` + ${utils_1.getJSDoc([...(jsdoc || []), sharedStyle.name, sharedStyle.do_objectID])} + export const ${safeName}: Partial = { + ${style} + }; + `); +}); diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.d.ts b/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.d.ts new file mode 100644 index 0000000..b6501d9 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.d.ts @@ -0,0 +1,4 @@ +import { SharedStyleContainer } from '../../../../../schema/sketch-121/objects/shared-style-container'; +import { Either } from 'fp-ts/lib/Either'; +import { option } from 'fp-ts'; +export declare const serializeSharedStyleContainer: import("fp-ts/lib/Reader").Reader Either>>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.js b/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.js new file mode 100644 index 0000000..9f1e4d6 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-styled-container.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const shared_style_1 = require("./shared-style"); +const fp_ts_1 = require("fp-ts"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const either_1 = require("../../../../../utils/either"); +const option_1 = require("../../../../../utils/option"); +exports.serializeSharedStyleContainer = reader_utils_1.combineReader(shared_style_1.serializeSharedStyle, serializeSharedStyle => (sharedStyleContainer) => pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(sharedStyleContainer.objects), fp_ts_1.option.map(objects => pipeable_1.pipe(either_1.traverseNEAEither(objects, serializeSharedStyle), fp_ts_1.either.map(styles => styles.join('')))), option_1.sequenceOptionEither)); diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.d.ts b/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.d.ts new file mode 100644 index 0000000..8a9d19e --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.d.ts @@ -0,0 +1,4 @@ +import { Either } from 'fp-ts/lib/Either'; +import { option } from 'fp-ts'; +import { SharedTextStyleContainer } from '../../../../../schema/sketch-121/objects/shared-text-style-container'; +export declare const serializeSharedTextStyleContainer: import("fp-ts/lib/Reader").Reader Either>>; diff --git a/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.js b/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.js new file mode 100644 index 0000000..671fbbf --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/shared-text-style-container.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const shared_style_1 = require("./shared-style"); +const fp_ts_1 = require("fp-ts"); +const reader_utils_1 = require("@devexperts/utils/dist/adt/reader.utils"); +const either_1 = require("../../../../../utils/either"); +const option_1 = require("../../../../../utils/option"); +exports.serializeSharedTextStyleContainer = reader_utils_1.combineReader(shared_style_1.serializeSharedStyle, serializeSharedStyle => (sharedTextStyleContainer) => pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray(sharedTextStyleContainer.objects), fp_ts_1.option.map(objects => pipeable_1.pipe(either_1.traverseNEAEither(objects, serializeSharedStyle), fp_ts_1.either.map(values => values.join('')))), option_1.sequenceOptionEither)); diff --git a/dist/language/typescript/sketch-121/serializers/objects/style.d.ts b/dist/language/typescript/sketch-121/serializers/objects/style.d.ts new file mode 100644 index 0000000..5e8b1eb --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/style.d.ts @@ -0,0 +1,3 @@ +import { Style } from '../../../../../schema/sketch-121/objects/style'; +import { either } from 'fp-ts'; +export declare const serializeStyle: (style: Style) => either.Either; diff --git a/dist/language/typescript/sketch-121/serializers/objects/style.js b/dist/language/typescript/sketch-121/serializers/objects/style.js new file mode 100644 index 0000000..14c7f16 --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/style.js @@ -0,0 +1,42 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const color_1 = require("./color"); +const gradient_1 = require("./gradient"); +const either_utils_1 = require("@devexperts/utils/dist/adt/either.utils"); +const blend_mode_1 = require("../enums/blend-mode"); +const border_1 = require("./border"); +const option_1 = require("../../../../../utils/option"); +const inner_shadow_1 = require("./inner-shadow"); +const shadow_1 = require("./shadow"); +const text_style_1 = require("./text-style"); +exports.serializeStyle = (style) => { + const fills = pipeable_1.pipe(style.fills, fp_ts_1.option.map(fp_ts_1.array.filter(fill => fill.isEnabled)), fp_ts_1.option.chain(fp_ts_1.nonEmptyArray.fromArray)); + const borders = pipeable_1.pipe(style.borders, fp_ts_1.option.map(fp_ts_1.array.filter(border => border.isEnabled))); + const innerShadows = style.innerShadows.filter(shadow => shadow.isEnabled); + const shadows = pipeable_1.pipe(style.shadows, fp_ts_1.option.map(fp_ts_1.array.filter(shadow => shadow.isEnabled))); + const backgroundColor = pipeable_1.pipe(fills, fp_ts_1.option.chain(fp_ts_1.nonEmptyArray.filter(fill => fill.fillType === 'Color')), fp_ts_1.option.map(fills => pipeable_1.pipe(fills, fp_ts_1.nonEmptyArray.map(fill => color_1.serializeColor(fill.color)), colors => `backgroundColor: '${colors.join(', ')}'`))); + const backgroundImage = pipeable_1.pipe(fills, fp_ts_1.option.chain(fp_ts_1.nonEmptyArray.filter(fill => fill.fillType === 'Gradient')), fp_ts_1.option.map(fills => pipeable_1.pipe(fills, fp_ts_1.nonEmptyArray.map(fill => gradient_1.serializeGradient(fill.gradient)), fp_ts_1.nonEmptyArray.nonEmptyArray.sequence(fp_ts_1.either.either), fp_ts_1.either.map(gradients => `backgroundImage: '${gradients.join(', ')}'`))), option_1.sequenceOptionEither); + const backgroundBlendMode = pipeable_1.pipe(fills, fp_ts_1.option.map(fp_ts_1.array.filterMap(fill => fp_ts_1.option.fromEither(blend_mode_1.getBackgroundBlendMode(fill.contextSettings.blendMode)))), fp_ts_1.option.chain(fp_ts_1.array.last), fp_ts_1.option.filter(mode => mode !== 'normal'), fp_ts_1.option.map(mode => `backgroundBlendMode: '${mode}'`)); + const mixBlendMode = pipeable_1.pipe(style.contextSettings, fp_ts_1.option.chain(settings => fp_ts_1.option.fromEither(blend_mode_1.getMixBlendMode(settings.blendMode))), fp_ts_1.option.filter(mode => mode !== 'normal'), fp_ts_1.option.map(mode => `mixBlendMode: '${mode}'`)); + const opacity = pipeable_1.pipe(style.contextSettings, fp_ts_1.option.map(settings => settings.opacity), fp_ts_1.option.filter(n => n !== 1), fp_ts_1.option.map(opacity => `opacity: '${opacity}'`)); + const border = pipeable_1.pipe(borders, fp_ts_1.option.map(fp_ts_1.array.filterMap(border => fp_ts_1.option.fromEither(border_1.serializeBorder(border, style.borderOptions)))), fp_ts_1.option.chain(fp_ts_1.array.last)); + const boxShadow = pipeable_1.pipe(fp_ts_1.nonEmptyArray.fromArray([ + ...innerShadows.map(inner_shadow_1.serializeInnerShadow), + ...fp_ts_1.array.flatten(fp_ts_1.array.compact([pipeable_1.pipe(shadows, fp_ts_1.option.map(fp_ts_1.array.map(shadow_1.serializeShadow)))])), + ]), fp_ts_1.option.map(shadows => `boxShadow: '${shadows.join(', ')}'`)); + const textStyle = pipeable_1.pipe(style.textStyle, fp_ts_1.option.map(text_style_1.serializeTextStyle)); + return either_utils_1.combineEither(backgroundImage, backgroundImage => fp_ts_1.array + .compact([ + backgroundBlendMode, + backgroundColor, + backgroundImage, + mixBlendMode, + opacity, + border, + boxShadow, + textStyle, + ]) + .join(', ')); +}; diff --git a/dist/language/typescript/sketch-121/serializers/objects/text-style.d.ts b/dist/language/typescript/sketch-121/serializers/objects/text-style.d.ts new file mode 100644 index 0000000..56ccbcd --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/text-style.d.ts @@ -0,0 +1,2 @@ +import { TextStyle } from '../../../../../schema/sketch-121/objects/text-style'; +export declare const serializeTextStyle: (textStyle: TextStyle) => string; diff --git a/dist/language/typescript/sketch-121/serializers/objects/text-style.js b/dist/language/typescript/sketch-121/serializers/objects/text-style.js new file mode 100644 index 0000000..9549d4c --- /dev/null +++ b/dist/language/typescript/sketch-121/serializers/objects/text-style.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pipeable_1 = require("fp-ts/lib/pipeable"); +const fp_ts_1 = require("fp-ts"); +const color_1 = require("./color"); +const text_vertical_alignment_1 = require("../enums/text-vertical-alignment"); +const text_horizontal_alignment_1 = require("../enums/text-horizontal-alignment"); +const underline_style_1 = require("../enums/underline-style"); +exports.serializeTextStyle = (textStyle) => { + const textAlign = pipeable_1.pipe(textStyle.encodedAttributes.paragraphStyle, fp_ts_1.option.chain(style => style.alignment), fp_ts_1.option.chain(alignment => fp_ts_1.option.fromEither(text_horizontal_alignment_1.serializeTextHorizontalAlignment(alignment))), fp_ts_1.option.map(alignment => `textAlign: ${JSON.stringify(alignment)}`)); + const lineHeight = pipeable_1.pipe(textStyle.encodedAttributes.paragraphStyle, fp_ts_1.option.chain(style => style.maximumLineHeight), fp_ts_1.option.alt(() => pipeable_1.pipe(textStyle.encodedAttributes.paragraphStyle, fp_ts_1.option.chain(style => style.minimumLineHeight))), fp_ts_1.option.map(lineHeight => `lineHeight: '${lineHeight}px'`)); + const textDecoration = pipeable_1.pipe(textStyle.encodedAttributes.underlineStyle, fp_ts_1.option.map(style => `textDecoration: ${JSON.stringify(underline_style_1.serializeUnderlineStyle(style))}`)); + const letterSpacing = pipeable_1.pipe(textStyle.encodedAttributes.kerning, fp_ts_1.option.map(kerning => `letterSpacing: '${kerning}px'`)); + const color = pipeable_1.pipe(textStyle.encodedAttributes.MSAttributedStringColorAttribute, fp_ts_1.option.map(color => `color: ${JSON.stringify(color_1.serializeColor(color))}`)); + const verticalAlign = `verticalAlign: ${JSON.stringify(text_vertical_alignment_1.serializeTextVerticalAlignment(textStyle.verticalAlignment))}`; + const fontFamily = `fontFamily: ${JSON.stringify(textStyle.encodedAttributes.MSAttributedStringFontAttribute.attributes.name)}`; + const fontSize = `fontSize: '${textStyle.encodedAttributes.MSAttributedStringFontAttribute.attributes.size}px'`; + return [ + fontFamily, + fontSize, + verticalAlign, + ...fp_ts_1.array.compact([color, textAlign, lineHeight, textDecoration, letterSpacing]), + ].join(', '); +}; diff --git a/dist/language/typescript/sketch-121/utils.d.ts b/dist/language/typescript/sketch-121/utils.d.ts new file mode 100644 index 0000000..93cca47 --- /dev/null +++ b/dist/language/typescript/sketch-121/utils.d.ts @@ -0,0 +1,10 @@ +export interface NameStorage { + readonly getSafeName: (uuid: string, name: string) => string; +} +export declare const createNameStorage: () => { + getSafeName: (uuid: string, name: string) => string; +}; +export interface Context { + readonly nameStorage: NameStorage; +} +export declare const context: import("fp-ts/lib/Reader").Reader; diff --git a/dist/language/typescript/sketch-121/utils.js b/dist/language/typescript/sketch-121/utils.js new file mode 100644 index 0000000..0c507d4 --- /dev/null +++ b/dist/language/typescript/sketch-121/utils.js @@ -0,0 +1,41 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const Reader_1 = require("fp-ts/lib/Reader"); +const utils_1 = require("../common/utils"); +exports.createNameStorage = () => { + const nameToUuid = new Map(); + const uuidToName = new Map(); + const nameToCounter = new Map(); + const getSafeNameWithCounter = (safeName) => { + const counter = nameToCounter.get(safeName) || 1; + const nameWithCounter = safeName + counter; + nameToCounter.set(safeName, counter + 1); + return !nameToUuid.has(nameWithCounter) ? nameWithCounter : getSafeNameWithCounter(safeName); + }; + const getSafeName = (uuid, name) => { + const safeName = utils_1.getSafePropertyName(name); + // check if we have a name for such uuid + const storedName = uuidToName.get(uuid); + if (storedName !== undefined) { + return storedName; + } + // no name - generate one + // check if we have such name + if (!nameToUuid.has(safeName)) { + // no collisions + nameToUuid.set(safeName, uuid); + uuidToName.set(uuid, safeName); + nameToCounter.set(safeName, 0); + return safeName; + } + // we already have such safeName stored - increase counter and store under uuid + const nameWithCounter = getSafeNameWithCounter(safeName); + nameToUuid.set(nameWithCounter, uuid); + uuidToName.set(uuid, nameWithCounter); + return nameWithCounter; + }; + return { + getSafeName, + }; +}; +exports.context = Reader_1.ask(); diff --git a/dist/parsers/sketch-121.d.ts b/dist/parsers/sketch-121.d.ts new file mode 100644 index 0000000..d0c7d2b --- /dev/null +++ b/dist/parsers/sketch-121.d.ts @@ -0,0 +1,7 @@ +import { FileInfo } from 'json-schema-ref-parser'; +export declare const sketchParser121: { + order: number; + allowEmpty: boolean; + canParse: (file: FileInfo) => boolean; + parse: (file: FileInfo) => Promise; +}; diff --git a/dist/parsers/sketch-121.js b/dist/parsers/sketch-121.js new file mode 100644 index 0000000..2335ff5 --- /dev/null +++ b/dist/parsers/sketch-121.js @@ -0,0 +1,51 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const AdmZip = require("adm-zip"); +const io_ts_1 = require("io-ts"); +const Either_1 = require("fp-ts/lib/Either"); +const log = (...args) => console.log('[SKETCH-PARSER]:', ...args); +exports.sketchParser121 = { + order: 90, + allowEmpty: false, + canParse: (file) => file.extension === 'sketch', + parse: (file) => __awaiter(void 0, void 0, void 0, function* () { + log('Unzipping', file.url); + const zip = new AdmZip(file.data); + log('Parsing document.json'); + const document = toJSON(zip.getEntry('document.json').getData()); + log('Parsing meta.json'); + const meta = toJSON(zip.getEntry('meta.json').getData()); + log('Parsing user.json'); + const user = toJSON(zip.getEntry('user.json').getData()); + const decodedDocument = documentCodec.decode(document); + if (Either_1.isLeft(decodedDocument)) { + throw decodedDocument.left; + } + const pages = decodedDocument.right.pages.map(page => { + const entry = `${page._ref}.json`; + log('Parsing', entry); + return toJSON(zip.getEntry(entry).getData()); + }); + log('Done'); + return { + document: Object.assign(Object.assign({}, document), { pages }), + meta, + user, + }; + }), +}; +const documentCodec = io_ts_1.type({ + pages: io_ts_1.array(io_ts_1.type({ + _ref: io_ts_1.string, + })), +}); +const toJSON = (buffer) => JSON.parse(buffer.toString('utf-8')); diff --git a/dist/schema/2.0/contact-object.d.ts b/dist/schema/2.0/contact-object.d.ts new file mode 100644 index 0000000..a27221f --- /dev/null +++ b/dist/schema/2.0/contact-object.d.ts @@ -0,0 +1,11 @@ +import { Option } from 'fp-ts/lib/Option'; +export interface ContactObject { + readonly name: Option; + readonly url: Option; + readonly email: Option; +} +export declare const ContactObject: import("io-ts").TypeC<{ + name: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + email: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/contact-object.js b/dist/schema/2.0/contact-object.js new file mode 100644 index 0000000..a242b76 --- /dev/null +++ b/dist/schema/2.0/contact-object.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.ContactObject = io_ts_2.type({ + name: io_ts_1.stringOption, + url: io_ts_1.stringOption, + email: io_ts_1.stringOption, +}, 'ContactObject'); diff --git a/dist/schema/2.0/definitions-object.d.ts b/dist/schema/2.0/definitions-object.d.ts new file mode 100644 index 0000000..2464a23 --- /dev/null +++ b/dist/schema/2.0/definitions-object.d.ts @@ -0,0 +1,5 @@ +import { Dictionary } from '../../utils/types'; +import { SchemaObject } from './schema-object'; +export interface DefinitionsObject extends Dictionary { +} +export declare const DefinitionsObject: import("io-ts").RecordC>; diff --git a/dist/schema/2.0/definitions-object.js b/dist/schema/2.0/definitions-object.js new file mode 100644 index 0000000..d3393a2 --- /dev/null +++ b/dist/schema/2.0/definitions-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const schema_object_1 = require("./schema-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.DefinitionsObject = io_ts_1.dictionary(schema_object_1.SchemaObjectCodec, 'DefinitionsObject'); diff --git a/dist/schema/2.0/example-object.d.ts b/dist/schema/2.0/example-object.d.ts new file mode 100644 index 0000000..813dc49 --- /dev/null +++ b/dist/schema/2.0/example-object.d.ts @@ -0,0 +1,4 @@ +import { Dictionary } from '../../utils/types'; +export interface ExampleObject extends Dictionary { +} +export declare const ExampleObject: import("io-ts").RecordC; diff --git a/dist/schema/2.0/example-object.js b/dist/schema/2.0/example-object.js new file mode 100644 index 0000000..bf10063 --- /dev/null +++ b/dist/schema/2.0/example-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.ExampleObject = io_ts_1.dictionary(io_ts_2.string, 'ExampleObject'); diff --git a/dist/schema/2.0/external-documentation-object.d.ts b/dist/schema/2.0/external-documentation-object.d.ts new file mode 100644 index 0000000..5fbabfd --- /dev/null +++ b/dist/schema/2.0/external-documentation-object.d.ts @@ -0,0 +1,9 @@ +import { Option } from 'fp-ts/lib/Option'; +export interface ExternalDocumentationObject { + readonly description: Option; + readonly url: string; +} +export declare const ExternalDocumentationObject: import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; +}>; diff --git a/dist/schema/2.0/external-documentation-object.js b/dist/schema/2.0/external-documentation-object.js new file mode 100644 index 0000000..3cbe826 --- /dev/null +++ b/dist/schema/2.0/external-documentation-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.ExternalDocumentationObject = io_ts_2.type({ + description: io_ts_1.stringOption, + url: io_ts_2.string, +}, 'ExternalDocumentationObject'); diff --git a/dist/schema/2.0/header-object.d.ts b/dist/schema/2.0/header-object.d.ts new file mode 100644 index 0000000..2e5fbef --- /dev/null +++ b/dist/schema/2.0/header-object.d.ts @@ -0,0 +1,8 @@ +import { ItemsObject } from './items-object'; +import { Option } from 'fp-ts/lib/Option'; +export declare type HeaderObject = ItemsObject & { + readonly description: Option; +}; +export declare const HeaderObject: import("io-ts").IntersectionC<[import("../../utils/io-ts").Codec, import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>]>; diff --git a/dist/schema/2.0/header-object.js b/dist/schema/2.0/header-object.js new file mode 100644 index 0000000..a73a913 --- /dev/null +++ b/dist/schema/2.0/header-object.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const items_object_1 = require("./items-object"); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.HeaderObject = io_ts_2.intersection([ + items_object_1.ItemsObjectCodec, + io_ts_2.type({ + description: io_ts_1.stringOption, + }), +], 'HeaderObject'); diff --git a/dist/schema/2.0/headers-object.d.ts b/dist/schema/2.0/headers-object.d.ts new file mode 100644 index 0000000..07aad17 --- /dev/null +++ b/dist/schema/2.0/headers-object.d.ts @@ -0,0 +1,7 @@ +import { Dictionary } from '../../utils/types'; +import { HeaderObject } from './header-object'; +export interface HeadersObject extends Dictionary { +} +export declare const HeadersObject: import("io-ts").RecordC, import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>]>>; diff --git a/dist/schema/2.0/headers-object.js b/dist/schema/2.0/headers-object.js new file mode 100644 index 0000000..227dfb5 --- /dev/null +++ b/dist/schema/2.0/headers-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const header_object_1 = require("./header-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.HeadersObject = io_ts_1.dictionary(header_object_1.HeaderObject, 'HeadersObject'); diff --git a/dist/schema/2.0/info-object.d.ts b/dist/schema/2.0/info-object.d.ts new file mode 100644 index 0000000..1295530 --- /dev/null +++ b/dist/schema/2.0/info-object.d.ts @@ -0,0 +1,26 @@ +import { ContactObject } from './contact-object'; +import { LicenseObject } from './license-object'; +import { Option } from 'fp-ts/lib/Option'; +export interface InfoObject { + readonly title: string; + readonly description: Option; + readonly termsOfService: Option; + readonly contact: Option; + readonly license: Option; + readonly version: string; +} +export declare const InfoObject: import("io-ts").TypeC<{ + title: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + termsOfService: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + contact: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + email: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>>; + license: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>>; + version: import("io-ts").StringC; +}>; diff --git a/dist/schema/2.0/info-object.js b/dist/schema/2.0/info-object.js new file mode 100644 index 0000000..39c029a --- /dev/null +++ b/dist/schema/2.0/info-object.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const contact_object_1 = require("./contact-object"); +const license_object_1 = require("./license-object"); +const io_ts_2 = require("io-ts"); +exports.InfoObject = io_ts_2.type({ + title: io_ts_2.string, + description: io_ts_1.stringOption, + termsOfService: io_ts_1.stringOption, + contact: optionFromNullable_1.optionFromNullable(contact_object_1.ContactObject), + license: optionFromNullable_1.optionFromNullable(license_object_1.LicenseObject), + version: io_ts_2.string, +}, 'InfoObject'); diff --git a/dist/schema/2.0/items-object.d.ts b/dist/schema/2.0/items-object.d.ts new file mode 100644 index 0000000..d30be56 --- /dev/null +++ b/dist/schema/2.0/items-object.d.ts @@ -0,0 +1,29 @@ +import { Codec } from '../../utils/io-ts'; +import { Option } from 'fp-ts/lib/Option'; +export interface BaseItemsObject { + readonly format: Option; + readonly collectionFormat: Option<'csv' | 'ssv' | 'tsv' | 'pipes'>; + readonly maximum: Option; + readonly exclusiveMaximum: Option; + readonly minimum: Option; + readonly exclusiveMinimum: Option; + readonly maxLength: Option; + readonly minLength: Option; + readonly pattern: Option; + readonly maxItems: Option; + readonly minItems: Option; + readonly uniqueItems: Option; + readonly enum: Option>; + readonly multipleOf: Option; +} +export declare type ArrayItemsObjectCollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes'; +export interface ArrayItemsObject extends BaseItemsObject { + readonly type: 'array'; + readonly items: ItemsObject; + readonly collectionFormat: Option; +} +export interface NonArrayItemsObject extends BaseItemsObject { + readonly type: 'string' | 'number' | 'integer' | 'boolean'; +} +export declare type ItemsObject = ArrayItemsObject | NonArrayItemsObject; +export declare const ItemsObjectCodec: Codec; diff --git a/dist/schema/2.0/items-object.js b/dist/schema/2.0/items-object.js new file mode 100644 index 0000000..42b1c28 --- /dev/null +++ b/dist/schema/2.0/items-object.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const BaseItemsObjectProps = { + format: io_ts_1.stringOption, + collectionFormat: optionFromNullable_1.optionFromNullable(io_ts_2.union([io_ts_2.literal('csv'), io_ts_2.literal('ssv'), io_ts_2.literal('tsv'), io_ts_2.literal('pipes')])), + maximum: io_ts_1.numberOption, + exclusiveMaximum: io_ts_1.booleanOption, + minimum: io_ts_1.numberOption, + exclusiveMinimum: io_ts_1.booleanOption, + maxLength: io_ts_1.numberOption, + minLength: io_ts_1.numberOption, + pattern: io_ts_1.stringOption, + maxItems: io_ts_1.numberOption, + minItems: io_ts_1.numberOption, + uniqueItems: io_ts_1.booleanOption, + enum: io_ts_1.primitiveArrayOption, + multipleOf: io_ts_1.numberOption, +}; +const ArrayItemsObjectCodec = io_ts_2.recursion('ArrayItemsObject', () => io_ts_2.type(Object.assign(Object.assign({}, BaseItemsObjectProps), { type: io_ts_2.literal('array'), items: exports.ItemsObjectCodec, collectionFormat: optionFromNullable_1.optionFromNullable(io_ts_2.union([io_ts_2.literal('csv'), io_ts_2.literal('ssv'), io_ts_2.literal('tsv'), io_ts_2.literal('pipes')])) }))); +const NonArrayItemsObjectCodec = io_ts_2.type(Object.assign(Object.assign({}, BaseItemsObjectProps), { type: io_ts_2.union([io_ts_2.literal('string'), io_ts_2.literal('number'), io_ts_2.literal('integer'), io_ts_2.literal('boolean')]) })); +exports.ItemsObjectCodec = io_ts_2.recursion('ItemsObject', () => io_ts_2.union([ArrayItemsObjectCodec, NonArrayItemsObjectCodec])); diff --git a/dist/schema/2.0/license-object.d.ts b/dist/schema/2.0/license-object.d.ts new file mode 100644 index 0000000..9f4f3ba --- /dev/null +++ b/dist/schema/2.0/license-object.d.ts @@ -0,0 +1,9 @@ +import { Option } from 'fp-ts/lib/Option'; +export interface LicenseObject { + readonly name: string; + readonly url: Option; +} +export declare const LicenseObject: import("io-ts").TypeC<{ + name: import("io-ts").StringC; + url: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/license-object.js b/dist/schema/2.0/license-object.js new file mode 100644 index 0000000..d334847 --- /dev/null +++ b/dist/schema/2.0/license-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.LicenseObject = io_ts_2.type({ + name: io_ts_2.string, + url: io_ts_1.stringOption, +}, 'LicenseObject'); diff --git a/dist/schema/2.0/operation-object.d.ts b/dist/schema/2.0/operation-object.d.ts new file mode 100644 index 0000000..c36747f --- /dev/null +++ b/dist/schema/2.0/operation-object.d.ts @@ -0,0 +1,37 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { ParameterObject } from './parameter-object'; +import { ReferenceObject } from './reference-object'; +import { ResponsesObject } from './responses-object'; +import { SecurityRequirementObject } from './security-requirement-object'; +export interface OperationObject { + readonly tags: Option; + readonly summary: Option; + readonly description: Option; + readonly externalDocs: Option; + readonly operationId: Option; + readonly consumes: Option; + readonly produces: Option; + readonly parameters: Option>; + readonly responses: ResponsesObject; + readonly schemes: Option; + readonly deprecated: Option; + readonly security: Option; +} +export declare const OperationObject: import("io-ts").TypeC<{ + tags: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; +}>; diff --git a/dist/schema/2.0/operation-object.js b/dist/schema/2.0/operation-object.js new file mode 100644 index 0000000..7109809 --- /dev/null +++ b/dist/schema/2.0/operation-object.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const external_documentation_object_1 = require("./external-documentation-object"); +const parameter_object_1 = require("./parameter-object"); +const reference_object_1 = require("./reference-object"); +const responses_object_1 = require("./responses-object"); +const security_requirement_object_1 = require("./security-requirement-object"); +const io_ts_1 = require("../../utils/io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const io_ts_2 = require("io-ts"); +exports.OperationObject = io_ts_2.type({ + tags: io_ts_1.stringArrayOption, + summary: io_ts_1.stringOption, + description: io_ts_1.stringOption, + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObject), + operationId: io_ts_1.stringOption, + consumes: io_ts_1.stringArrayOption, + produces: io_ts_1.stringArrayOption, + parameters: optionFromNullable_1.optionFromNullable(io_ts_2.array(io_ts_2.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]))), + responses: responses_object_1.ResponsesObject, + schemes: io_ts_1.stringArrayOption, + deprecated: io_ts_1.booleanOption, + security: optionFromNullable_1.optionFromNullable(io_ts_2.array(security_requirement_object_1.SecurityRequirementObject)), +}, 'OperationObject'); diff --git a/dist/schema/2.0/parameter-object.d.ts b/dist/schema/2.0/parameter-object.d.ts new file mode 100644 index 0000000..fa2da61 --- /dev/null +++ b/dist/schema/2.0/parameter-object.d.ts @@ -0,0 +1,60 @@ +import { Codec } from '../../utils/io-ts'; +import { SchemaObject } from './schema-object'; +import { Option } from 'fp-ts/lib/Option'; +import { ItemsObject } from './items-object'; +export interface BaseParameterObject { + readonly required: Option; + readonly name: string; + readonly description: Option; +} +export declare type ArrayParameterObjectCollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; +export interface BaseArrayParameterObject { + readonly type: 'array'; + readonly items: ItemsObject; + readonly collectionFormat: Option; +} +export interface BaseNonArrayParameterObject { + readonly type: 'string' | 'number' | 'integer' | 'boolean'; + readonly format: Option; +} +export interface BodyParameterObject extends BaseParameterObject { + readonly in: 'body'; + readonly schema: SchemaObject; +} +export interface BaseFormDataParameterObject extends BaseParameterObject { + readonly in: 'formData'; +} +export interface ArrayFormDataParameterObject extends BaseFormDataParameterObject, BaseArrayParameterObject { +} +export interface NonArrayFormDataParameterObject extends BaseFormDataParameterObject, Omit { + readonly type: 'string' | 'number' | 'integer' | 'boolean' | 'file'; +} +export declare type FormDataParameterObject = ArrayFormDataParameterObject | NonArrayFormDataParameterObject; +export interface BaseQueryParameterObject extends BaseParameterObject { + readonly in: 'query'; +} +export interface ArrayQueryParameterObject extends BaseQueryParameterObject, BaseArrayParameterObject { +} +export declare const ArrayQueryParameterObjectCodec: Codec; +export interface NonArrayQueryParameterObject extends BaseQueryParameterObject, BaseNonArrayParameterObject { +} +export declare type QueryParameterObject = ArrayQueryParameterObject | NonArrayQueryParameterObject; +export interface BasePathParameterObject extends Omit { + readonly in: 'path'; + readonly required: true; +} +export interface ArrayPathParameterObject extends BasePathParameterObject, BaseArrayParameterObject { +} +export interface NonArrayPathParameterObject extends BasePathParameterObject, BaseNonArrayParameterObject { +} +export declare type PathParameterObject = ArrayPathParameterObject | NonArrayPathParameterObject; +export interface BaseHeaderParameterObject extends BaseParameterObject { + readonly in: 'header'; +} +export interface ArrayHeaderParameterObject extends BaseHeaderParameterObject, BaseArrayParameterObject { +} +export interface NonArrayHeaderParameterObject extends BaseHeaderParameterObject, BaseNonArrayParameterObject { +} +export declare type HeaderParameterObject = ArrayHeaderParameterObject | NonArrayHeaderParameterObject; +export declare type ParameterObject = BodyParameterObject | FormDataParameterObject | QueryParameterObject | PathParameterObject | HeaderParameterObject; +export declare const ParameterObjectCodec: Codec; diff --git a/dist/schema/2.0/parameter-object.js b/dist/schema/2.0/parameter-object.js new file mode 100644 index 0000000..8fa018f --- /dev/null +++ b/dist/schema/2.0/parameter-object.js @@ -0,0 +1,56 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const schema_object_1 = require("./schema-object"); +const items_object_1 = require("./items-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const BaseParameterObjectProps = { + required: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), + name: io_ts_1.string, + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}; +const BaseArrayParameterObjectProps = { + type: io_ts_1.literal('array'), + items: items_object_1.ItemsObjectCodec, + collectionFormat: optionFromNullable_1.optionFromNullable(io_ts_1.union([io_ts_1.literal('csv'), io_ts_1.literal('ssv'), io_ts_1.literal('tsv'), io_ts_1.literal('pipes'), io_ts_1.literal('multi')])), +}; +const BaseNonArrayParameterObjectProps = { + type: io_ts_1.union([io_ts_1.literal('string'), io_ts_1.literal('number'), io_ts_1.literal('integer'), io_ts_1.literal('boolean')]), + format: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}; +const BodyParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseParameterObjectProps), { in: io_ts_1.literal('body'), schema: schema_object_1.SchemaObjectCodec }), 'BodyParameterObject'); +const BaseFormDataParameterObjectProps = Object.assign(Object.assign({}, BaseParameterObjectProps), { in: io_ts_1.literal('formData') }); +const ArrayFormDataParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseFormDataParameterObjectProps), BaseArrayParameterObjectProps)); +const NonArrayFormDataParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign(Object.assign({}, BaseFormDataParameterObjectProps), BaseNonArrayParameterObjectProps), { type: io_ts_1.union([io_ts_1.literal('string'), io_ts_1.literal('number'), io_ts_1.literal('integer'), io_ts_1.literal('boolean'), io_ts_1.literal('file')]) })); +const FormDataParameterObjectCodec = io_ts_1.union([ + ArrayFormDataParameterObjectCodec, + NonArrayFormDataParameterObjectCodec, +]); +const BaseQueryParameterObjectProps = Object.assign(Object.assign({}, BaseParameterObjectProps), { in: io_ts_1.literal('query') }); +exports.ArrayQueryParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseQueryParameterObjectProps), BaseArrayParameterObjectProps)); +const NonArrayQueryHeaderPathParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseQueryParameterObjectProps), BaseNonArrayParameterObjectProps)); +const QueryParameterObjectCodec = io_ts_1.union([ + exports.ArrayQueryParameterObjectCodec, + NonArrayQueryHeaderPathParameterObjectCodec, +]); +const BasePathParameterObjectProps = Object.assign(Object.assign({}, BaseParameterObjectProps), { in: io_ts_1.literal('path'), required: io_ts_1.literal(true) }); +const ArrayPathParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BasePathParameterObjectProps), BaseArrayParameterObjectProps)); +const NonArrayPathParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BasePathParameterObjectProps), BaseNonArrayParameterObjectProps)); +const PathParameterObjectCodec = io_ts_1.union([ + ArrayPathParameterObjectCodec, + NonArrayPathParameterObjectCodec, +]); +const BaseHeaderParameterObjectProps = Object.assign(Object.assign({}, BaseParameterObjectProps), { in: io_ts_1.literal('header') }); +const ArrayHeaderParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseHeaderParameterObjectProps), BaseArrayParameterObjectProps)); +const NonArrayHeaderParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseHeaderParameterObjectProps), BaseNonArrayParameterObjectProps)); +const HeaderParameterObjectCodec = io_ts_1.union([ + ArrayHeaderParameterObjectCodec, + NonArrayHeaderParameterObjectCodec, +]); +exports.ParameterObjectCodec = io_ts_1.union([ + BodyParameterObjectCodec, + FormDataParameterObjectCodec, + QueryParameterObjectCodec, + PathParameterObjectCodec, + HeaderParameterObjectCodec, +], 'ParameterObject'); diff --git a/dist/schema/2.0/parameters-definitions-object.d.ts b/dist/schema/2.0/parameters-definitions-object.d.ts new file mode 100644 index 0000000..528c9ca --- /dev/null +++ b/dist/schema/2.0/parameters-definitions-object.d.ts @@ -0,0 +1,5 @@ +import { Dictionary } from '../../utils/types'; +import { ParameterObject } from './parameter-object'; +export interface ParametersDefinitionsObject extends Dictionary { +} +export declare const ParametersDefinitionsObject: import("io-ts").RecordC>; diff --git a/dist/schema/2.0/parameters-definitions-object.js b/dist/schema/2.0/parameters-definitions-object.js new file mode 100644 index 0000000..f3c471e --- /dev/null +++ b/dist/schema/2.0/parameters-definitions-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const parameter_object_1 = require("./parameter-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.ParametersDefinitionsObject = io_ts_1.dictionary(parameter_object_1.ParameterObjectCodec, 'ParametersDefinitionsObject'); diff --git a/dist/schema/2.0/path-item-object.d.ts b/dist/schema/2.0/path-item-object.d.ts new file mode 100644 index 0000000..565c1aa --- /dev/null +++ b/dist/schema/2.0/path-item-object.d.ts @@ -0,0 +1,138 @@ +import { OperationObject } from './operation-object'; +import { ParameterObject } from './parameter-object'; +import { ReferenceObject } from './reference-object'; +import { Option } from 'fp-ts/lib/Option'; +export interface PathItemObject { + readonly $ref: Option; + readonly get: Option; + readonly put: Option; + readonly post: Option; + readonly delete: Option; + readonly options: Option; + readonly head: Option; + readonly patch: Option; + readonly parameters: Option>; +} +export declare const PathItemObjectCodec: import("io-ts").TypeC<{ + $ref: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + get: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + put: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + post: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + delete: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + options: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + head: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + patch: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; +}>; diff --git a/dist/schema/2.0/path-item-object.js b/dist/schema/2.0/path-item-object.js new file mode 100644 index 0000000..9997812 --- /dev/null +++ b/dist/schema/2.0/path-item-object.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const operation_object_1 = require("./operation-object"); +const parameter_object_1 = require("./parameter-object"); +const reference_object_1 = require("./reference-object"); +const io_ts_2 = require("io-ts"); +exports.PathItemObjectCodec = io_ts_2.type({ + $ref: io_ts_1.stringOption, + get: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + put: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + post: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + delete: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + options: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + head: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + patch: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObject), + parameters: optionFromNullable_1.optionFromNullable(io_ts_2.array(io_ts_2.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]))), +}, 'PathItemObject'); diff --git a/dist/schema/2.0/paths-object.d.ts b/dist/schema/2.0/paths-object.d.ts new file mode 100644 index 0000000..c7ae18f --- /dev/null +++ b/dist/schema/2.0/paths-object.d.ts @@ -0,0 +1,127 @@ +import { Dictionary } from '../../utils/types'; +import { PathItemObject } from './path-item-object'; +export interface PathsObject extends Dictionary { +} +export declare const PathsObject: import("io-ts").RecordC; + get: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + put: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + post: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + delete: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + options: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + head: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + patch: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; +}>>; diff --git a/dist/schema/2.0/paths-object.js b/dist/schema/2.0/paths-object.js new file mode 100644 index 0000000..7a6b054 --- /dev/null +++ b/dist/schema/2.0/paths-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_item_object_1 = require("./path-item-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.PathsObject = io_ts_1.dictionary(path_item_object_1.PathItemObjectCodec, 'PathsObject'); diff --git a/dist/schema/2.0/reference-object.d.ts b/dist/schema/2.0/reference-object.d.ts new file mode 100644 index 0000000..be703fa --- /dev/null +++ b/dist/schema/2.0/reference-object.d.ts @@ -0,0 +1,5 @@ +import { Codec } from '../../utils/io-ts'; +export interface ReferenceObject { + readonly $ref: string; +} +export declare const ReferenceObjectCodec: Codec; diff --git a/dist/schema/2.0/reference-object.js b/dist/schema/2.0/reference-object.js new file mode 100644 index 0000000..6755230 --- /dev/null +++ b/dist/schema/2.0/reference-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.ReferenceObjectCodec = io_ts_1.type({ + $ref: io_ts_1.string, +}, 'ReferenceObject'); diff --git a/dist/schema/2.0/response-object.d.ts b/dist/schema/2.0/response-object.d.ts new file mode 100644 index 0000000..60ccc23 --- /dev/null +++ b/dist/schema/2.0/response-object.d.ts @@ -0,0 +1,18 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ExampleObject } from './example-object'; +import { HeadersObject } from './headers-object'; +import { SchemaObject } from './schema-object'; +export interface ResponseObject { + readonly description: string; + readonly schema: Option; + readonly headers: Option; + readonly examples: Option; +} +export declare const ResponseObject: import("io-ts").TypeC<{ + description: import("io-ts").StringC; + schema: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + headers: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>]>>>; + examples: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; +}>; diff --git a/dist/schema/2.0/response-object.js b/dist/schema/2.0/response-object.js new file mode 100644 index 0000000..3e61a09 --- /dev/null +++ b/dist/schema/2.0/response-object.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const example_object_1 = require("./example-object"); +const headers_object_1 = require("./headers-object"); +const schema_object_1 = require("./schema-object"); +const io_ts_1 = require("io-ts"); +exports.ResponseObject = io_ts_1.type({ + description: io_ts_1.string, + schema: optionFromNullable_1.optionFromNullable(schema_object_1.SchemaObjectCodec), + headers: optionFromNullable_1.optionFromNullable(headers_object_1.HeadersObject), + examples: optionFromNullable_1.optionFromNullable(example_object_1.ExampleObject), +}, 'ResponseObject'); diff --git a/dist/schema/2.0/responses-definitions-object.d.ts b/dist/schema/2.0/responses-definitions-object.d.ts new file mode 100644 index 0000000..383f630 --- /dev/null +++ b/dist/schema/2.0/responses-definitions-object.d.ts @@ -0,0 +1,12 @@ +import { Dictionary } from '../../utils/types'; +import { ResponseObject } from './response-object'; +export interface ResponsesDefinitionsObject extends Dictionary { +} +export declare const ResponsesDefinitionsObject: import("io-ts").RecordC>; + headers: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>]>>>; + examples: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; +}>>; diff --git a/dist/schema/2.0/responses-definitions-object.js b/dist/schema/2.0/responses-definitions-object.js new file mode 100644 index 0000000..9487d57 --- /dev/null +++ b/dist/schema/2.0/responses-definitions-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const response_object_1 = require("./response-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.ResponsesDefinitionsObject = io_ts_1.dictionary(response_object_1.ResponseObject, 'ResponsesDefinitionsObject'); diff --git a/dist/schema/2.0/responses-object.d.ts b/dist/schema/2.0/responses-object.d.ts new file mode 100644 index 0000000..d766d88 --- /dev/null +++ b/dist/schema/2.0/responses-object.d.ts @@ -0,0 +1,7 @@ +import { Dictionary } from '../../utils/types'; +import { ResponseObject } from './response-object'; +import { Codec } from '../../utils/io-ts'; +import { ReferenceObject } from './reference-object'; +export interface ResponsesObject extends Dictionary { +} +export declare const ResponsesObject: Codec; diff --git a/dist/schema/2.0/responses-object.js b/dist/schema/2.0/responses-object.js new file mode 100644 index 0000000..b3e5be4 --- /dev/null +++ b/dist/schema/2.0/responses-object.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const response_object_1 = require("./response-object"); +const io_ts_1 = require("../../utils/io-ts"); +const reference_object_1 = require("./reference-object"); +const io_ts_2 = require("io-ts"); +exports.ResponsesObject = io_ts_1.dictionary(io_ts_2.union([reference_object_1.ReferenceObjectCodec, response_object_1.ResponseObject]), 'ResponsesObject'); diff --git a/dist/schema/2.0/schema-object.d.ts b/dist/schema/2.0/schema-object.d.ts new file mode 100644 index 0000000..38bd0a8 --- /dev/null +++ b/dist/schema/2.0/schema-object.d.ts @@ -0,0 +1,35 @@ +import { Codec, JSONPrimitive } from '../../utils/io-ts'; +import { ReferenceObject } from './reference-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Dictionary } from '../../utils/types'; +import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; +export interface BaseSchemaObject { + readonly description: Option; +} +export declare const BaseSchemaObjectCodec: Codec; +export interface EnumSchemaObject extends BaseSchemaObject { + readonly enum: NonEmptyArray; +} +export declare const EnumSchemaObjectCodec: Codec; +export interface PrimitiveSchemaObject extends BaseSchemaObject { + readonly format: Option; + readonly type: 'null' | 'string' | 'number' | 'integer' | 'boolean'; +} +export declare const PrimitiveSchemaObjectCodec: Codec; +export interface AllOfSchemaObject extends BaseSchemaObject { + readonly allOf: NonEmptyArray; +} +export declare const AllOfSchemaObject: Codec; +export interface ArraySchemaObject extends BaseSchemaObject { + readonly type: 'array'; + readonly items: SchemaObject; +} +export declare const ArraySchemaObjectCodec: Codec; +export interface ObjectSchemaObject extends BaseSchemaObject { + readonly type: 'object'; + readonly properties: Option>; + readonly required: Option; + readonly additionalProperties: Option; +} +export declare type SchemaObject = ReferenceObject | EnumSchemaObject | PrimitiveSchemaObject | AllOfSchemaObject | ObjectSchemaObject | ArraySchemaObject; +export declare const SchemaObjectCodec: Codec; diff --git a/dist/schema/2.0/schema-object.js b/dist/schema/2.0/schema-object.js new file mode 100644 index 0000000..48d9d10 --- /dev/null +++ b/dist/schema/2.0/schema-object.js @@ -0,0 +1,59 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const reference_object_1 = require("./reference-object"); +const io_ts_2 = require("io-ts"); +const nonEmptyArray_1 = require("io-ts-types/lib/nonEmptyArray"); +exports.BaseSchemaObjectCodec = io_ts_2.type({ + description: optionFromNullable_1.optionFromNullable(io_ts_2.string), +}); +exports.EnumSchemaObjectCodec = io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + enum: nonEmptyArray_1.nonEmptyArray(io_ts_1.JSONPrimitiveCodec), + }), +], 'EnumSchemaObject'); +exports.PrimitiveSchemaObjectCodec = io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + format: optionFromNullable_1.optionFromNullable(io_ts_2.string), + type: io_ts_2.union([ + io_ts_2.literal('null'), + io_ts_2.literal('string'), + io_ts_2.literal('number'), + io_ts_2.literal('integer'), + io_ts_2.literal('boolean'), + ]), + }), +], 'PrimitiveSchemaObject'); +exports.AllOfSchemaObject = io_ts_2.recursion('ReferenceOrAllOfSchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + allOf: nonEmptyArray_1.nonEmptyArray(io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + }), +])); +exports.ArraySchemaObjectCodec = io_ts_2.recursion('ArraySchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('array'), + items: exports.SchemaObjectCodec, + }), +])); +const ObjectSchemaObjectCodec = io_ts_2.recursion('ObjectSchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + required: io_ts_1.stringArrayOption, + type: io_ts_2.literal('object'), + properties: optionFromNullable_1.optionFromNullable(io_ts_1.dictionary(exports.SchemaObjectCodec, 'Dictionary')), + additionalProperties: optionFromNullable_1.optionFromNullable(exports.SchemaObjectCodec), + }), +])); +exports.SchemaObjectCodec = io_ts_2.recursion('SchemaObject', () => io_ts_2.union([ + reference_object_1.ReferenceObjectCodec, + exports.EnumSchemaObjectCodec, + exports.PrimitiveSchemaObjectCodec, + exports.AllOfSchemaObject, + ObjectSchemaObjectCodec, + exports.ArraySchemaObjectCodec, +])); diff --git a/dist/schema/2.0/scopes-object.d.ts b/dist/schema/2.0/scopes-object.d.ts new file mode 100644 index 0000000..502aaf3 --- /dev/null +++ b/dist/schema/2.0/scopes-object.d.ts @@ -0,0 +1,4 @@ +import { Dictionary } from '../../utils/types'; +export interface ScopesObject extends Dictionary { +} +export declare const ScopesObject: import("io-ts").RecordC; diff --git a/dist/schema/2.0/scopes-object.js b/dist/schema/2.0/scopes-object.js new file mode 100644 index 0000000..642671b --- /dev/null +++ b/dist/schema/2.0/scopes-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.ScopesObject = io_ts_1.dictionary(io_ts_2.string, 'ScopesObject'); diff --git a/dist/schema/2.0/security-definitions-object.d.ts b/dist/schema/2.0/security-definitions-object.d.ts new file mode 100644 index 0000000..7babc91 --- /dev/null +++ b/dist/schema/2.0/security-definitions-object.d.ts @@ -0,0 +1,37 @@ +import { Dictionary } from '../../utils/types'; +import { SecuritySchemeObject } from './security-scheme-object/security-scheme-object'; +export interface SecurityDefinitionsObject extends Dictionary { +} +export declare const SecurityDefinitionsObject: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"apiKey">; + in: import("io-ts").UnionC<[import("io-ts").LiteralC<"query">, import("io-ts").LiteralC<"header">]>; + name: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").UnionC<[import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"implicit">; + authorizationUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"password">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"application">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"accessCode">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>]>]>>; diff --git a/dist/schema/2.0/security-definitions-object.js b/dist/schema/2.0/security-definitions-object.js new file mode 100644 index 0000000..77029b3 --- /dev/null +++ b/dist/schema/2.0/security-definitions-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const security_scheme_object_1 = require("./security-scheme-object/security-scheme-object"); +const io_ts_1 = require("../../utils/io-ts"); +exports.SecurityDefinitionsObject = io_ts_1.dictionary(security_scheme_object_1.SecuritySchemeObject, 'SecurityDefinitionsObject'); diff --git a/dist/schema/2.0/security-requirement-object.d.ts b/dist/schema/2.0/security-requirement-object.d.ts new file mode 100644 index 0000000..b5496f3 --- /dev/null +++ b/dist/schema/2.0/security-requirement-object.d.ts @@ -0,0 +1,4 @@ +import { Dictionary } from '../../utils/types'; +export interface SecurityRequirementObject extends Dictionary { +} +export declare const SecurityRequirementObject: import("io-ts").RecordC>; diff --git a/dist/schema/2.0/security-requirement-object.js b/dist/schema/2.0/security-requirement-object.js new file mode 100644 index 0000000..efdf707 --- /dev/null +++ b/dist/schema/2.0/security-requirement-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.SecurityRequirementObject = io_ts_1.dictionary(io_ts_2.array(io_ts_2.string), 'SecurityRequirementObject'); diff --git a/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.d.ts new file mode 100644 index 0000000..3b1ab7c --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.d.ts @@ -0,0 +1,15 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +import { ScopesObject } from '../scopes-object'; +export interface AccessCodeOAuth2SecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'oauth2'; + readonly flow: 'accessCode'; + readonly tokenUrl: string; + readonly scopes: ScopesObject; +} +export declare const AccessCodeOAuth2SecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"accessCode">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.js new file mode 100644 index 0000000..864b4c8 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/access-code-oauth2-security-scheme-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const scopes_object_1 = require("../scopes-object"); +const io_ts_1 = require("io-ts"); +exports.AccessCodeOAuth2SecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('oauth2'), flow: io_ts_1.literal('accessCode'), tokenUrl: io_ts_1.string, scopes: scopes_object_1.ScopesObject }), 'AccessCodeOAuth2SecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.d.ts new file mode 100644 index 0000000..0a8cbcc --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.d.ts @@ -0,0 +1,12 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +export interface ApiKeySecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'apiKey'; + readonly in: 'query' | 'header'; + readonly name: string; +} +export declare const ApiKeySecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"apiKey">; + in: import("io-ts").UnionC<[import("io-ts").LiteralC<"query">, import("io-ts").LiteralC<"header">]>; + name: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.js new file mode 100644 index 0000000..e72260b --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/api-key-security-scheme-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const io_ts_1 = require("io-ts"); +exports.ApiKeySecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('apiKey'), in: io_ts_1.union([io_ts_1.literal('query'), io_ts_1.literal('header')]), name: io_ts_1.string }), 'ApiKeySecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.d.ts new file mode 100644 index 0000000..ef7a850 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.d.ts @@ -0,0 +1,15 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +import { ScopesObject } from '../scopes-object'; +export interface ApplicationOAuth2SecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'oauth2'; + readonly flow: 'application'; + readonly tokenUrl: string; + readonly scopes: ScopesObject; +} +export declare const ApplicationOAuth2SecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"application">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.js new file mode 100644 index 0000000..be47544 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/application-oauth2-security-scheme-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const scopes_object_1 = require("../scopes-object"); +const io_ts_1 = require("io-ts"); +exports.ApplicationOAuth2SecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('oauth2'), flow: io_ts_1.literal('application'), tokenUrl: io_ts_1.string, scopes: scopes_object_1.ScopesObject }), 'ApplicationOAuth2SecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/base-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/base-security-scheme-object.d.ts new file mode 100644 index 0000000..b86ccda --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/base-security-scheme-object.d.ts @@ -0,0 +1,7 @@ +import { Option } from 'fp-ts/lib/Option'; +export interface BaseSecuritySchemeObjectProps { + readonly description: Option; +} +export declare const BaseSecuritySchemeObjectProps: { + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}; diff --git a/dist/schema/2.0/security-scheme-object/base-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/base-security-scheme-object.js new file mode 100644 index 0000000..a1df7b9 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/base-security-scheme-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +exports.BaseSecuritySchemeObjectProps = { + description: io_ts_1.stringOption, +}; diff --git a/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.d.ts new file mode 100644 index 0000000..3ed55b4 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.d.ts @@ -0,0 +1,8 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +export interface BasicSecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'basic'; +} +export declare const BasicSecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"basic">; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.js new file mode 100644 index 0000000..c19779b --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/basic-security-scheme-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const io_ts_1 = require("io-ts"); +exports.BasicSecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('basic') }), 'BasicSecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.d.ts new file mode 100644 index 0000000..026550e --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.d.ts @@ -0,0 +1,15 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +import { ScopesObject } from '../scopes-object'; +export interface ImplicitOAuth2SecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'oauth2'; + readonly flow: 'implicit'; + readonly authorizationUrl: string; + readonly scopes: ScopesObject; +} +export declare const ImplicitOAuth2SecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"implicit">; + authorizationUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.js new file mode 100644 index 0000000..f5d5c7a --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/implicit-oauth2-security-scheme-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const scopes_object_1 = require("../scopes-object"); +const io_ts_1 = require("io-ts"); +exports.ImplicitOAuth2SecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('oauth2'), flow: io_ts_1.literal('implicit'), authorizationUrl: io_ts_1.string, scopes: scopes_object_1.ScopesObject }), 'ImplicitOAuth2SecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.d.ts new file mode 100644 index 0000000..403893d --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.d.ts @@ -0,0 +1,30 @@ +import { ImplicitOAuth2SecuritySchemeObject } from './implicit-oauth2-security-scheme-object'; +import { PasswordOAuth2SecuritySchemeObject } from './password-oauth2-security-scheme-object'; +import { ApplicationOAuth2SecuritySchemeObject } from './application-oauth2-security-scheme-object'; +import { AccessCodeOAuth2SecuritySchemeObject } from './access-code-oauth2-security-scheme-object'; +export declare type OAuth2SecuritySchemeObject = ImplicitOAuth2SecuritySchemeObject | PasswordOAuth2SecuritySchemeObject | ApplicationOAuth2SecuritySchemeObject | AccessCodeOAuth2SecuritySchemeObject; +export declare const OAuth2SecuritySchemeObject: import("io-ts").UnionC<[import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"implicit">; + authorizationUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"password">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"application">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"accessCode">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>]>; diff --git a/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.js new file mode 100644 index 0000000..9896f1b --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/oauth2-security-scheme-object.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const implicit_oauth2_security_scheme_object_1 = require("./implicit-oauth2-security-scheme-object"); +const password_oauth2_security_scheme_object_1 = require("./password-oauth2-security-scheme-object"); +const application_oauth2_security_scheme_object_1 = require("./application-oauth2-security-scheme-object"); +const access_code_oauth2_security_scheme_object_1 = require("./access-code-oauth2-security-scheme-object"); +const io_ts_1 = require("io-ts"); +exports.OAuth2SecuritySchemeObject = io_ts_1.union([ + implicit_oauth2_security_scheme_object_1.ImplicitOAuth2SecuritySchemeObject, + password_oauth2_security_scheme_object_1.PasswordOAuth2SecuritySchemeObject, + application_oauth2_security_scheme_object_1.ApplicationOAuth2SecuritySchemeObject, + access_code_oauth2_security_scheme_object_1.AccessCodeOAuth2SecuritySchemeObject, +], 'OAuth2SecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.d.ts new file mode 100644 index 0000000..a6a1ff3 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.d.ts @@ -0,0 +1,15 @@ +import { BaseSecuritySchemeObjectProps } from './base-security-scheme-object'; +import { ScopesObject } from '../scopes-object'; +export interface PasswordOAuth2SecuritySchemeObject extends BaseSecuritySchemeObjectProps { + readonly type: 'oauth2'; + readonly flow: 'password'; + readonly tokenUrl: string; + readonly scopes: ScopesObject; +} +export declare const PasswordOAuth2SecuritySchemeObject: import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"password">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>; diff --git a/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.js b/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.js new file mode 100644 index 0000000..5484999 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/password-oauth2-security-scheme-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_security_scheme_object_1 = require("./base-security-scheme-object"); +const scopes_object_1 = require("../scopes-object"); +const io_ts_1 = require("io-ts"); +exports.PasswordOAuth2SecuritySchemeObject = io_ts_1.type(Object.assign(Object.assign({}, base_security_scheme_object_1.BaseSecuritySchemeObjectProps), { type: io_ts_1.literal('oauth2'), flow: io_ts_1.literal('password'), tokenUrl: io_ts_1.string, scopes: scopes_object_1.ScopesObject }), 'PasswordOAuth2SecuritySchemeObject'); diff --git a/dist/schema/2.0/security-scheme-object/security-scheme-object.d.ts b/dist/schema/2.0/security-scheme-object/security-scheme-object.d.ts new file mode 100644 index 0000000..6458fca --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/security-scheme-object.d.ts @@ -0,0 +1,37 @@ +import { BasicSecuritySchemeObject } from './basic-security-scheme-object'; +import { ApiKeySecuritySchemeObject } from './api-key-security-scheme-object'; +import { OAuth2SecuritySchemeObject } from './oauth2-security-scheme-object'; +export declare type SecuritySchemeObject = BasicSecuritySchemeObject | ApiKeySecuritySchemeObject | OAuth2SecuritySchemeObject; +export declare const SecuritySchemeObject: import("io-ts").UnionC<[import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"basic">; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"apiKey">; + in: import("io-ts").UnionC<[import("io-ts").LiteralC<"query">, import("io-ts").LiteralC<"header">]>; + name: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").UnionC<[import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"implicit">; + authorizationUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"password">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"application">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"accessCode">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; +}>]>]>; diff --git a/dist/schema/2.0/security-scheme-object/security-scheme-object.js b/dist/schema/2.0/security-scheme-object/security-scheme-object.js new file mode 100644 index 0000000..13bc684 --- /dev/null +++ b/dist/schema/2.0/security-scheme-object/security-scheme-object.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const basic_security_scheme_object_1 = require("./basic-security-scheme-object"); +const api_key_security_scheme_object_1 = require("./api-key-security-scheme-object"); +const oauth2_security_scheme_object_1 = require("./oauth2-security-scheme-object"); +const io_ts_1 = require("io-ts"); +exports.SecuritySchemeObject = io_ts_1.union([basic_security_scheme_object_1.BasicSecuritySchemeObject, api_key_security_scheme_object_1.ApiKeySecuritySchemeObject, oauth2_security_scheme_object_1.OAuth2SecuritySchemeObject], 'SecuritySchemeObject'); diff --git a/dist/schema/2.0/swagger-object.d.ts b/dist/schema/2.0/swagger-object.d.ts new file mode 100644 index 0000000..fe4975a --- /dev/null +++ b/dist/schema/2.0/swagger-object.d.ts @@ -0,0 +1,229 @@ +import { Option } from 'fp-ts/lib/Option'; +import { InfoObject } from './info-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { SecurityRequirementObject } from './security-requirement-object'; +import { TagObject } from './tag-object'; +import { ResponsesDefinitionsObject } from './responses-definitions-object'; +import { SecurityDefinitionsObject } from './security-definitions-object'; +import { DefinitionsObject } from './definitions-object'; +import { PathsObject } from './paths-object'; +import { ParametersDefinitionsObject } from './parameters-definitions-object'; +export interface SwaggerObject { + readonly basePath: Option; + readonly consumes: Option; + readonly definitions: Option; + readonly externalDocs: Option; + readonly host: Option; + readonly info: InfoObject; + readonly parameters: Option; + readonly paths: PathsObject; + readonly produces: Option; + readonly responses: Option; + readonly schemes: Option; + readonly security: Option; + readonly securityDefinitions: Option; + readonly swagger: string; + readonly tags: Option; +} +export declare const SwaggerObject: import("io-ts").TypeC<{ + basePath: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + definitions: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + host: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + info: import("io-ts").TypeC<{ + title: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + termsOfService: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + contact: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + email: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>>; + license: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>>; + version: import("io-ts").StringC; + }>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>; + paths: import("io-ts").RecordC; + get: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + put: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + post: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + delete: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + options: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + head: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + patch: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + summary: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + operationId: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + consumes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + responses: import("../../utils/io-ts").Codec; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + deprecated: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + }>>; + parameters: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("../../utils/io-ts").Codec]>>>; + }>>; + produces: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + responses: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + headers: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC, import("io-ts").TypeC<{ + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>]>>>; + examples: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + }>>>; + schemes: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>; + security: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC>>>; + securityDefinitions: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"apiKey">; + in: import("io-ts").UnionC<[import("io-ts").LiteralC<"query">, import("io-ts").LiteralC<"header">]>; + name: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>, import("io-ts").UnionC<[import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"implicit">; + authorizationUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"password">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"application">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>, import("io-ts").TypeC<{ + type: import("io-ts").LiteralC<"oauth2">; + flow: import("io-ts").LiteralC<"accessCode">; + tokenUrl: import("io-ts").StringC; + scopes: import("io-ts").RecordC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + }>]>]>>>; + swagger: import("io-ts").StringC; + tags: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; + }>>>; +}>; diff --git a/dist/schema/2.0/swagger-object.js b/dist/schema/2.0/swagger-object.js new file mode 100644 index 0000000..c7fc1c8 --- /dev/null +++ b/dist/schema/2.0/swagger-object.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const io_ts_1 = require("../../utils/io-ts"); +const info_object_1 = require("./info-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +const security_requirement_object_1 = require("./security-requirement-object"); +const tag_object_1 = require("./tag-object"); +const responses_definitions_object_1 = require("./responses-definitions-object"); +const security_definitions_object_1 = require("./security-definitions-object"); +const definitions_object_1 = require("./definitions-object"); +const paths_object_1 = require("./paths-object"); +const parameters_definitions_object_1 = require("./parameters-definitions-object"); +const io_ts_2 = require("io-ts"); +exports.SwaggerObject = io_ts_2.type({ + basePath: io_ts_1.stringOption, + consumes: io_ts_1.stringArrayOption, + definitions: optionFromNullable_1.optionFromNullable(definitions_object_1.DefinitionsObject), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObject), + host: io_ts_1.stringOption, + info: info_object_1.InfoObject, + parameters: optionFromNullable_1.optionFromNullable(parameters_definitions_object_1.ParametersDefinitionsObject), + paths: paths_object_1.PathsObject, + produces: io_ts_1.stringArrayOption, + responses: optionFromNullable_1.optionFromNullable(responses_definitions_object_1.ResponsesDefinitionsObject), + schemes: io_ts_1.stringArrayOption, + security: optionFromNullable_1.optionFromNullable(io_ts_2.array(security_requirement_object_1.SecurityRequirementObject)), + securityDefinitions: optionFromNullable_1.optionFromNullable(security_definitions_object_1.SecurityDefinitionsObject), + swagger: io_ts_2.string, + tags: optionFromNullable_1.optionFromNullable(io_ts_2.array(tag_object_1.TagObject)), +}, 'SwaggerObject'); diff --git a/dist/schema/2.0/tag-object.d.ts b/dist/schema/2.0/tag-object.d.ts new file mode 100644 index 0000000..2e0ddfa --- /dev/null +++ b/dist/schema/2.0/tag-object.d.ts @@ -0,0 +1,15 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ExternalDocumentationObject } from './external-documentation-object'; +export interface TagObject { + readonly name: string; + readonly description: Option; + readonly externalDocs: Option; +} +export declare const TagObject: import("io-ts").TypeC<{ + name: import("io-ts").StringC; + description: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + externalDocs: import("io-ts-types/lib/optionFromNullable").OptionFromNullableC; + url: import("io-ts").StringC; + }>>; +}>; diff --git a/dist/schema/2.0/tag-object.js b/dist/schema/2.0/tag-object.js new file mode 100644 index 0000000..074795a --- /dev/null +++ b/dist/schema/2.0/tag-object.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const external_documentation_object_1 = require("./external-documentation-object"); +const io_ts_1 = require("../../utils/io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const io_ts_2 = require("io-ts"); +exports.TagObject = io_ts_2.type({ + name: io_ts_2.string, + description: io_ts_1.stringOption, + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObject), +}, 'TagObject'); diff --git a/dist/schema/3.0/components-object.d.ts b/dist/schema/3.0/components-object.d.ts new file mode 100644 index 0000000..be76aff --- /dev/null +++ b/dist/schema/3.0/components-object.d.ts @@ -0,0 +1,14 @@ +import { ReferenceObject } from './reference-object'; +import { SchemaObject } from './schema-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +import { ParameterObject } from './parameter-object'; +import { ResponseObject } from './response-object'; +import { RequestBodyObject } from './request-body-object'; +export interface ComponentsObject { + readonly schemas: Option>; + readonly parameters: Option>; + readonly responses: Option>; + readonly requestBodies: Option>; +} +export declare const ComponentsObjectCodec: Codec; diff --git a/dist/schema/3.0/components-object.js b/dist/schema/3.0/components-object.js new file mode 100644 index 0000000..2832ec4 --- /dev/null +++ b/dist/schema/3.0/components-object.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const reference_object_1 = require("./reference-object"); +const schema_object_1 = require("./schema-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const parameter_object_1 = require("./parameter-object"); +const response_object_1 = require("./response-object"); +const request_body_object_1 = require("./request-body-object"); +exports.ComponentsObjectCodec = io_ts_1.type({ + schemas: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.SchemaObjectCodec]))), + parameters: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]))), + responses: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, response_object_1.ResponseObjectCodec]))), + requestBodies: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, request_body_object_1.RequestBodyObjectCodec]))), +}, 'ComponentsObject'); diff --git a/dist/schema/3.0/media-type-object.d.ts b/dist/schema/3.0/media-type-object.d.ts new file mode 100644 index 0000000..d434749 --- /dev/null +++ b/dist/schema/3.0/media-type-object.d.ts @@ -0,0 +1,8 @@ +import { SchemaObject } from './schema-object'; +import { ReferenceObject } from './reference-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface MediaTypeObject { + readonly schema: Option; +} +export declare const MediaTypeObjectCodec: Codec; diff --git a/dist/schema/3.0/media-type-object.js b/dist/schema/3.0/media-type-object.js new file mode 100644 index 0000000..d426de4 --- /dev/null +++ b/dist/schema/3.0/media-type-object.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const schema_object_1 = require("./schema-object"); +const reference_object_1 = require("./reference-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.MediaTypeObjectCodec = io_ts_1.type({ + schema: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.SchemaObjectCodec])), +}, 'MediaTypeObject'); diff --git a/dist/schema/3.0/openapi-object.d.ts b/dist/schema/3.0/openapi-object.d.ts new file mode 100644 index 0000000..7c6f8b4 --- /dev/null +++ b/dist/schema/3.0/openapi-object.d.ts @@ -0,0 +1,10 @@ +import { Type } from 'io-ts'; +import { PathsObject } from './paths-object'; +import { ComponentsObject } from './components-object'; +import { Option } from 'fp-ts/lib/Option'; +export interface OpenapiObject { + readonly openapi: '3.0.0' | '3.0.1' | '3.0.2'; + readonly paths: PathsObject; + readonly components: Option; +} +export declare const OpenapiObjectCodec: Type; diff --git a/dist/schema/3.0/openapi-object.js b/dist/schema/3.0/openapi-object.js new file mode 100644 index 0000000..8d030d1 --- /dev/null +++ b/dist/schema/3.0/openapi-object.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const paths_object_1 = require("./paths-object"); +const components_object_1 = require("./components-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.OpenapiObjectCodec = io_ts_1.type({ + openapi: io_ts_1.union([io_ts_1.literal('3.0.0'), io_ts_1.literal('3.0.1'), io_ts_1.literal('3.0.2')], 'OpenapiObject'), + paths: paths_object_1.PathsObjectCodec, + components: optionFromNullable_1.optionFromNullable(components_object_1.ComponentsObjectCodec), +}, 'OpenapiObject'); diff --git a/dist/schema/3.0/operation-object.d.ts b/dist/schema/3.0/operation-object.d.ts new file mode 100644 index 0000000..f55251f --- /dev/null +++ b/dist/schema/3.0/operation-object.d.ts @@ -0,0 +1,17 @@ +import { ReferenceObject } from './reference-object'; +import { ParameterObject } from './parameter-object'; +import { RequestBodyObject } from './request-body-object'; +import { ResponsesObject } from './responses-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface OperationObject { + readonly tags: Option; + readonly summary: Option; + readonly description: Option; + readonly operationId: Option; + readonly parameters: Option>; + readonly requestBody: Option; + readonly responses: ResponsesObject; + readonly deprecated: Option; +} +export declare const OperationObjectCodec: Codec; diff --git a/dist/schema/3.0/operation-object.js b/dist/schema/3.0/operation-object.js new file mode 100644 index 0000000..0e8021d --- /dev/null +++ b/dist/schema/3.0/operation-object.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const reference_object_1 = require("./reference-object"); +const parameter_object_1 = require("./parameter-object"); +const request_body_object_1 = require("./request-body-object"); +const responses_object_1 = require("./responses-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.OperationObjectCodec = io_ts_1.type({ + tags: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.string)), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + operationId: optionFromNullable_1.optionFromNullable(io_ts_1.string), + parameters: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]))), + requestBody: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, request_body_object_1.RequestBodyObjectCodec])), + responses: responses_object_1.ResponsesObjectCodec, + deprecated: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), +}, 'OperationObject'); diff --git a/dist/schema/3.0/parameter-object.d.ts b/dist/schema/3.0/parameter-object.d.ts new file mode 100644 index 0000000..ed60f40 --- /dev/null +++ b/dist/schema/3.0/parameter-object.d.ts @@ -0,0 +1,33 @@ +import { ReferenceObject } from './reference-object'; +import { SchemaObject } from './schema-object'; +import { MediaTypeObject } from './media-type-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export declare type ParameterObjectStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject'; +export interface BaseParameterObject { + readonly name: string; + readonly description: Option; + readonly deprecated: Option; + readonly schema: Option; + readonly content: Option>; + readonly explode: Option; + readonly style: Option; +} +export interface PathParameterObject extends BaseParameterObject { + readonly in: 'path'; + readonly required: true; +} +export interface HeaderParameterObject extends BaseParameterObject { + readonly in: 'header'; + readonly required: Option; +} +export interface QueryParameterObject extends BaseParameterObject { + readonly in: 'query'; + readonly required: Option; +} +export interface CookieParameterObject extends BaseParameterObject { + readonly in: 'cookie'; + readonly required: Option; +} +export declare type ParameterObject = PathParameterObject | HeaderParameterObject | QueryParameterObject | CookieParameterObject; +export declare const ParameterObjectCodec: Codec; diff --git a/dist/schema/3.0/parameter-object.js b/dist/schema/3.0/parameter-object.js new file mode 100644 index 0000000..4017a03 --- /dev/null +++ b/dist/schema/3.0/parameter-object.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const reference_object_1 = require("./reference-object"); +const schema_object_1 = require("./schema-object"); +const media_type_object_1 = require("./media-type-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const BaseParameterObjectCodecProps = { + name: io_ts_1.string, + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + deprecated: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), + schema: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.SchemaObjectCodec])), + content: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, media_type_object_1.MediaTypeObjectCodec)), + explode: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), + style: optionFromNullable_1.optionFromNullable(io_ts_1.union([ + io_ts_1.literal('matrix'), + io_ts_1.literal('label'), + io_ts_1.literal('form'), + io_ts_1.literal('simple'), + io_ts_1.literal('spaceDelimited'), + io_ts_1.literal('pipeDelimited'), + io_ts_1.literal('deepObject'), + ])), +}; +const PathParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseParameterObjectCodecProps), { in: io_ts_1.literal('path'), required: io_ts_1.literal(true) }), 'PathParameterObject'); +const HeaderParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseParameterObjectCodecProps), { in: io_ts_1.literal('header'), required: optionFromNullable_1.optionFromNullable(io_ts_1.boolean) }), 'HeaderParameterObject'); +const QueryParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseParameterObjectCodecProps), { in: io_ts_1.literal('query'), required: optionFromNullable_1.optionFromNullable(io_ts_1.boolean) }), 'QueryParameterObject'); +const CookieParameterObjectCodec = io_ts_1.type(Object.assign(Object.assign({}, BaseParameterObjectCodecProps), { in: io_ts_1.literal('cookie'), required: optionFromNullable_1.optionFromNullable(io_ts_1.boolean) }), 'CookieParameterObject'); +exports.ParameterObjectCodec = io_ts_1.union([PathParameterObjectCodec, HeaderParameterObjectCodec, QueryParameterObjectCodec, CookieParameterObjectCodec], 'ParameterObject'); diff --git a/dist/schema/3.0/path-item-object.d.ts b/dist/schema/3.0/path-item-object.d.ts new file mode 100644 index 0000000..d924f3f --- /dev/null +++ b/dist/schema/3.0/path-item-object.d.ts @@ -0,0 +1,22 @@ +import { OperationObject } from './operation-object'; +import { ServerObject } from './server-object'; +import { ReferenceObject } from './reference-object'; +import { ParameterObject } from './parameter-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface PathItemObject { + readonly $ref: Option; + readonly summary: Option; + readonly description: Option; + readonly get: Option; + readonly put: Option; + readonly post: Option; + readonly delete: Option; + readonly options: Option; + readonly head: Option; + readonly patch: Option; + readonly trace: Option; + readonly servers: Option; + readonly parameters: Option>; +} +export declare const PathItemObjectCodec: Codec; diff --git a/dist/schema/3.0/path-item-object.js b/dist/schema/3.0/path-item-object.js new file mode 100644 index 0000000..028460d --- /dev/null +++ b/dist/schema/3.0/path-item-object.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const operation_object_1 = require("./operation-object"); +const server_object_1 = require("./server-object"); +const reference_object_1 = require("./reference-object"); +const parameter_object_1 = require("./parameter-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.PathItemObjectCodec = io_ts_1.type({ + $ref: optionFromNullable_1.optionFromNullable(io_ts_1.string), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + get: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + put: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + post: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + delete: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + options: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + head: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + patch: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + trace: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + servers: optionFromNullable_1.optionFromNullable(io_ts_1.array(server_object_1.ServerObjectCodec)), + parameters: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]))), +}, 'PathItemObject'); diff --git a/dist/schema/3.0/paths-object.d.ts b/dist/schema/3.0/paths-object.d.ts new file mode 100644 index 0000000..a9c07aa --- /dev/null +++ b/dist/schema/3.0/paths-object.d.ts @@ -0,0 +1,5 @@ +import { PathItemObject } from './path-item-object'; +import { Codec } from '../../utils/io-ts'; +export interface PathsObject extends Record { +} +export declare const PathsObjectCodec: Codec; diff --git a/dist/schema/3.0/paths-object.js b/dist/schema/3.0/paths-object.js new file mode 100644 index 0000000..3bd4236 --- /dev/null +++ b/dist/schema/3.0/paths-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const path_item_object_1 = require("./path-item-object"); +exports.PathsObjectCodec = io_ts_1.record(io_ts_1.string, path_item_object_1.PathItemObjectCodec, 'PathsObject'); diff --git a/dist/schema/3.0/reference-object.d.ts b/dist/schema/3.0/reference-object.d.ts new file mode 100644 index 0000000..be703fa --- /dev/null +++ b/dist/schema/3.0/reference-object.d.ts @@ -0,0 +1,5 @@ +import { Codec } from '../../utils/io-ts'; +export interface ReferenceObject { + readonly $ref: string; +} +export declare const ReferenceObjectCodec: Codec; diff --git a/dist/schema/3.0/reference-object.js b/dist/schema/3.0/reference-object.js new file mode 100644 index 0000000..6755230 --- /dev/null +++ b/dist/schema/3.0/reference-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.ReferenceObjectCodec = io_ts_1.type({ + $ref: io_ts_1.string, +}, 'ReferenceObject'); diff --git a/dist/schema/3.0/request-body-object.d.ts b/dist/schema/3.0/request-body-object.d.ts new file mode 100644 index 0000000..3084fef --- /dev/null +++ b/dist/schema/3.0/request-body-object.d.ts @@ -0,0 +1,9 @@ +import { MediaTypeObject } from './media-type-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface RequestBodyObject { + readonly description: Option; + readonly content: Record; + readonly required: Option; +} +export declare const RequestBodyObjectCodec: Codec; diff --git a/dist/schema/3.0/request-body-object.js b/dist/schema/3.0/request-body-object.js new file mode 100644 index 0000000..2b5df1a --- /dev/null +++ b/dist/schema/3.0/request-body-object.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const media_type_object_1 = require("./media-type-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.RequestBodyObjectCodec = io_ts_1.type({ + content: io_ts_1.record(io_ts_1.string, media_type_object_1.MediaTypeObjectCodec), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + required: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), +}, 'RequestBodyObject'); diff --git a/dist/schema/3.0/response-object.d.ts b/dist/schema/3.0/response-object.d.ts new file mode 100644 index 0000000..8ae0e96 --- /dev/null +++ b/dist/schema/3.0/response-object.d.ts @@ -0,0 +1,8 @@ +import { MediaTypeObject } from './media-type-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface ResponseObject { + readonly description: string; + readonly content: Option>; +} +export declare const ResponseObjectCodec: Codec; diff --git a/dist/schema/3.0/response-object.js b/dist/schema/3.0/response-object.js new file mode 100644 index 0000000..c6768a5 --- /dev/null +++ b/dist/schema/3.0/response-object.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const media_type_object_1 = require("./media-type-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ResponseObjectCodec = io_ts_1.type({ + description: io_ts_1.string, + content: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, media_type_object_1.MediaTypeObjectCodec)), +}, 'ResponseObject'); diff --git a/dist/schema/3.0/responses-object.d.ts b/dist/schema/3.0/responses-object.d.ts new file mode 100644 index 0000000..810bfd8 --- /dev/null +++ b/dist/schema/3.0/responses-object.d.ts @@ -0,0 +1,6 @@ +import { ResponseObject } from './response-object'; +import { ReferenceObject } from './reference-object'; +import { Codec } from '../../utils/io-ts'; +export interface ResponsesObject extends Record { +} +export declare const ResponsesObjectCodec: Codec; diff --git a/dist/schema/3.0/responses-object.js b/dist/schema/3.0/responses-object.js new file mode 100644 index 0000000..f587c08 --- /dev/null +++ b/dist/schema/3.0/responses-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const response_object_1 = require("./response-object"); +const reference_object_1 = require("./reference-object"); +exports.ResponsesObjectCodec = io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, response_object_1.ResponseObjectCodec]), 'ResponsesObject'); diff --git a/dist/schema/3.0/schema-object.d.ts b/dist/schema/3.0/schema-object.d.ts new file mode 100644 index 0000000..01d7fae --- /dev/null +++ b/dist/schema/3.0/schema-object.d.ts @@ -0,0 +1,47 @@ +import { ReferenceObject } from './reference-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec, JSONPrimitive } from '../../utils/io-ts'; +import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; +export interface BaseSchemaObject { + readonly format: Option; + readonly deprecated: Option; + readonly nullable: Option; + readonly maxItems: Option; + readonly minItems: Option; +} +export interface EnumSchemaObject extends BaseSchemaObject { + readonly enum: NonEmptyArray; +} +export declare const EnumSchemaObjectCodec: Codec; +/** + * Primitive type SchemaObject + * `null` is not supported as a primitive type + * @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types + */ +export interface PrimitiveSchemaObject extends BaseSchemaObject { + readonly format: Option; + readonly type: 'boolean' | 'string' | 'number' | 'integer'; +} +export declare const PrimitiveSchemaObjectCodec: Codec; +export interface ObjectSchemaObject extends BaseSchemaObject { + readonly type: 'object'; + readonly properties: Option>; + readonly additionalProperties: Option; + readonly required: Option; +} +export declare const ObjectSchemaObjectCodec: Codec; +export interface ArraySchemaObject extends BaseSchemaObject { + readonly type: 'array'; + readonly items: ReferenceObject | SchemaObject; +} +export declare const ArraySchemaObjectCodec: Codec; +export interface AllOfSchemaObject extends BaseSchemaObject { + readonly allOf: NonEmptyArray; +} +export declare const AllOfSchemaObjectCodec: Codec; +export interface OneOfSchemaObject extends BaseSchemaObject { + readonly oneOf: NonEmptyArray; +} +export declare const OneOfSchemaObjectCodec: Codec; +export declare type SchemaObject = EnumSchemaObject | PrimitiveSchemaObject | ObjectSchemaObject | ArraySchemaObject | AllOfSchemaObject | OneOfSchemaObject; +export declare const SchemaObjectCodec: Codec; diff --git a/dist/schema/3.0/schema-object.js b/dist/schema/3.0/schema-object.js new file mode 100644 index 0000000..6e1c9b1 --- /dev/null +++ b/dist/schema/3.0/schema-object.js @@ -0,0 +1,63 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const reference_object_1 = require("./reference-object"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const io_ts_2 = require("../../utils/io-ts"); +const nonEmptyArray_1 = require("io-ts-types/lib/nonEmptyArray"); +const BaseSchemaObjectCodec = io_ts_1.type({ + format: optionFromNullable_1.optionFromNullable(io_ts_1.string), + deprecated: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), + nullable: optionFromNullable_1.optionFromNullable(io_ts_1.boolean), + maxItems: io_ts_2.numberOption, + minItems: io_ts_2.numberOption, +}); +exports.EnumSchemaObjectCodec = io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + enum: nonEmptyArray_1.nonEmptyArray(io_ts_2.JSONPrimitiveCodec), + }), +], 'EnumSchemaObject'); +exports.PrimitiveSchemaObjectCodec = io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + format: optionFromNullable_1.optionFromNullable(io_ts_1.string), + type: io_ts_1.union([io_ts_1.literal('boolean'), io_ts_1.literal('string'), io_ts_1.literal('number'), io_ts_1.literal('integer')]), + }), +], 'PrimitiveSchemaObject'); +exports.ObjectSchemaObjectCodec = io_ts_1.recursion('ObjectSchemaObject', () => io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('object'), + properties: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec]))), + additionalProperties: optionFromNullable_1.optionFromNullable(io_ts_1.union([io_ts_1.boolean, reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + required: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.string)), + }), +])); +exports.ArraySchemaObjectCodec = io_ts_1.recursion('ArraySchemaObject', () => io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('array'), + items: io_ts_1.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec]), + }), +])); +exports.AllOfSchemaObjectCodec = io_ts_1.recursion('AllOfSchemaObject', () => io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + allOf: nonEmptyArray_1.nonEmptyArray(io_ts_1.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + }), +])); +exports.OneOfSchemaObjectCodec = io_ts_1.recursion('OneOfSchemaObject', () => io_ts_1.intersection([ + BaseSchemaObjectCodec, + io_ts_1.type({ + oneOf: nonEmptyArray_1.nonEmptyArray(io_ts_1.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + }), +])); +exports.SchemaObjectCodec = io_ts_1.recursion('SchemaObject', () => io_ts_1.union([ + exports.EnumSchemaObjectCodec, + exports.PrimitiveSchemaObjectCodec, + exports.ObjectSchemaObjectCodec, + exports.ArraySchemaObjectCodec, + exports.AllOfSchemaObjectCodec, + exports.OneOfSchemaObjectCodec, +])); diff --git a/dist/schema/3.0/server-object.d.ts b/dist/schema/3.0/server-object.d.ts new file mode 100644 index 0000000..42f56c4 --- /dev/null +++ b/dist/schema/3.0/server-object.d.ts @@ -0,0 +1,9 @@ +import { ServerVariableObject } from './server-variable-object'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface ServerObject { + readonly url: string; + readonly description: Option; + readonly variables: Option>; +} +export declare const ServerObjectCodec: Codec; diff --git a/dist/schema/3.0/server-object.js b/dist/schema/3.0/server-object.js new file mode 100644 index 0000000..e93ece7 --- /dev/null +++ b/dist/schema/3.0/server-object.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const server_variable_object_1 = require("./server-variable-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ServerObjectCodec = io_ts_1.type({ + url: io_ts_1.string, + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + variables: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, server_variable_object_1.ServerVariableObjectCodec)), +}, 'ServerObject'); diff --git a/dist/schema/3.0/server-variable-object.d.ts b/dist/schema/3.0/server-variable-object.d.ts new file mode 100644 index 0000000..64eac24 --- /dev/null +++ b/dist/schema/3.0/server-variable-object.d.ts @@ -0,0 +1,8 @@ +import { Codec } from '../../utils/io-ts'; +import { Option } from 'fp-ts/lib/Option'; +export interface ServerVariableObject { + readonly enum: Option; + readonly default: string; + readonly description: Option; +} +export declare const ServerVariableObjectCodec: Codec; diff --git a/dist/schema/3.0/server-variable-object.js b/dist/schema/3.0/server-variable-object.js new file mode 100644 index 0000000..e237fdf --- /dev/null +++ b/dist/schema/3.0/server-variable-object.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ServerVariableObjectCodec = io_ts_1.type({ + default: io_ts_1.string, + enum: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.string)), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}, 'ServerVariableObject'); diff --git a/dist/schema/asyncapi-2.0.0/asyncapi-object.d.ts b/dist/schema/asyncapi-2.0.0/asyncapi-object.d.ts new file mode 100644 index 0000000..3750ed4 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/asyncapi-object.d.ts @@ -0,0 +1,18 @@ +import { Option } from 'fp-ts/lib/Option'; +import { InfoObject } from './info-object'; +import { ServersObject } from './servers-object'; +import { Codec } from '../../utils/io-ts'; +import { ChannelsObject } from './channels-object'; +import { ComponentsObject } from './components-object'; +import { TagsObject } from './tags-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +export interface AsyncAPIObject { + readonly asyncapi: '2.0.0'; + readonly info: InfoObject; + readonly servers: Option; + readonly channels: ChannelsObject; + readonly components: Option; + readonly tags: Option; + readonly externalDocs: Option; +} +export declare const AsyncAPIObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/asyncapi-object.js b/dist/schema/asyncapi-2.0.0/asyncapi-object.js new file mode 100644 index 0000000..166edb7 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/asyncapi-object.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const info_object_1 = require("./info-object"); +const servers_object_1 = require("./servers-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const channels_object_1 = require("./channels-object"); +const components_object_1 = require("./components-object"); +const tags_object_1 = require("./tags-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +exports.AsyncAPIObjectCodec = io_ts_1.type({ + asyncapi: io_ts_1.literal('2.0.0'), + info: info_object_1.InfoObjectCodec, + servers: optionFromNullable_1.optionFromNullable(servers_object_1.ServersObjectCodec), + channels: channels_object_1.ChannelsObjectCodec, + components: optionFromNullable_1.optionFromNullable(components_object_1.ComponentsObjectCodec), + tags: optionFromNullable_1.optionFromNullable(tags_object_1.TagsObjectCodec), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), +}, 'AsyncAPIObject'); diff --git a/dist/schema/asyncapi-2.0.0/channel-bindings-object.d.ts b/dist/schema/asyncapi-2.0.0/channel-bindings-object.d.ts new file mode 100644 index 0000000..2d7241d --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channel-bindings-object.d.ts @@ -0,0 +1,7 @@ +import { Option } from 'fp-ts/lib/Option'; +import { WebsocketsChannelBindingObject } from './websockets-channel-binding-object'; +import { Codec } from '../../utils/io-ts'; +export interface ChannelBindingsObject { + readonly ws: Option; +} +export declare const ChannelBindingsObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/channel-bindings-object.js b/dist/schema/asyncapi-2.0.0/channel-bindings-object.js new file mode 100644 index 0000000..402ee0e --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channel-bindings-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const websockets_channel_binding_object_1 = require("./websockets-channel-binding-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ChannelBindingsObjectCodec = io_ts_1.type({ + ws: optionFromNullable_1.optionFromNullable(websockets_channel_binding_object_1.WebsocketsChannelBindingObjectCodec), +}, 'ChannelBindingsObject'); diff --git a/dist/schema/asyncapi-2.0.0/channel-item-object.d.ts b/dist/schema/asyncapi-2.0.0/channel-item-object.d.ts new file mode 100644 index 0000000..01b752f --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channel-item-object.d.ts @@ -0,0 +1,14 @@ +import { Option } from 'fp-ts/lib/Option'; +import { OperationObject } from './operation-object'; +import { ParametersObject } from './parameters-object'; +import { Codec } from '../../utils/io-ts'; +import { ChannelBindingsObject } from './channel-bindings-object'; +export interface ChannelItemObject { + readonly $ref: Option; + readonly description: Option; + readonly subscribe: Option; + readonly publish: Option; + readonly parameters: Option; + readonly bindings: Option; +} +export declare const ChannelItemObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/channel-item-object.js b/dist/schema/asyncapi-2.0.0/channel-item-object.js new file mode 100644 index 0000000..2216930 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channel-item-object.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const operation_object_1 = require("./operation-object"); +const parameters_object_1 = require("./parameters-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const channel_bindings_object_1 = require("./channel-bindings-object"); +exports.ChannelItemObjectCodec = io_ts_1.type({ + $ref: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + subscribe: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + publish: optionFromNullable_1.optionFromNullable(operation_object_1.OperationObjectCodec), + parameters: optionFromNullable_1.optionFromNullable(parameters_object_1.ParametersObjectCodec), + bindings: optionFromNullable_1.optionFromNullable(channel_bindings_object_1.ChannelBindingsObjectCodec), +}, 'ChannelItemObject'); diff --git a/dist/schema/asyncapi-2.0.0/channels-object.d.ts b/dist/schema/asyncapi-2.0.0/channels-object.d.ts new file mode 100644 index 0000000..a44a4f9 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channels-object.d.ts @@ -0,0 +1,5 @@ +import { ChannelItemObject } from './channel-item-object'; +import { Codec } from '../../utils/io-ts'; +export interface ChannelsObject extends Record { +} +export declare const ChannelsObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/channels-object.js b/dist/schema/asyncapi-2.0.0/channels-object.js new file mode 100644 index 0000000..7ad0ac6 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/channels-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const channel_item_object_1 = require("./channel-item-object"); +const io_ts_1 = require("io-ts"); +exports.ChannelsObjectCodec = io_ts_1.record(io_ts_1.string, channel_item_object_1.ChannelItemObjectCodec, 'ChannelsObject'); diff --git a/dist/schema/asyncapi-2.0.0/components-object.d.ts b/dist/schema/asyncapi-2.0.0/components-object.d.ts new file mode 100644 index 0000000..1eb7b58 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/components-object.d.ts @@ -0,0 +1,25 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ReferenceObject } from './reference-object'; +import { SchemaObject } from './schema-object'; +import { MessageObject } from './message-object'; +import { ParametersObject } from './parameters-object'; +import { CorrelationIdObject } from './correlation-id-object'; +import { OperationTraitObject } from './operation-trait-object'; +import { MessageTraitObject } from './message-trait-object'; +import { Branded } from 'io-ts'; +import { Codec } from '../../utils/io-ts'; +import { SecuritySchemeObject } from './security-scheme-object'; +export interface ComponentsObjectFieldPatternBrand { + readonly ComponentsObjectFieldPattern: unique symbol; +} +export declare type ComponentsObjectFieldPattern = Branded; +export interface ComponentsObject { + readonly schemas: Option>; + readonly messages: Option>; + readonly securitySchemes: Option>; + readonly parameters: Option>; + readonly correlationIds: Option>; + readonly operationTraits: Option>; + readonly messageTraits: Option>; +} +export declare const ComponentsObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/components-object.js b/dist/schema/asyncapi-2.0.0/components-object.js new file mode 100644 index 0000000..7ec8fe4 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/components-object.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reference_object_1 = require("./reference-object"); +const schema_object_1 = require("./schema-object"); +const message_object_1 = require("./message-object"); +const parameters_object_1 = require("./parameters-object"); +const correlation_id_object_1 = require("./correlation-id-object"); +const operation_trait_object_1 = require("./operation-trait-object"); +const message_trait_object_1 = require("./message-trait-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const security_scheme_object_1 = require("./security-scheme-object"); +const pattern = /^[a-zA-Z0-9.\-_]+$/; +const ComponentsObjectFieldPatternCodec = io_ts_1.brand(io_ts_1.string, (s) => pattern.test(s), 'ComponentsObjectFieldPattern'); +exports.ComponentsObjectCodec = io_ts_1.type({ + schemas: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.SchemaObjectCodec]))), + messages: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, message_object_1.MessageObjectCodec]))), + securitySchemes: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, security_scheme_object_1.SecuritySchemeObjectCodec]))), + parameters: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, parameters_object_1.ParametersObjectCodec]))), + correlationIds: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, correlation_id_object_1.CorrelationIdObjectCodec]))), + operationTraits: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, operation_trait_object_1.OperationTraitObjectCodec]))), + messageTraits: optionFromNullable_1.optionFromNullable(io_ts_1.record(ComponentsObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, message_trait_object_1.MessageTraitObjectCodec]))), +}, 'ComponentsObjectCodec'); diff --git a/dist/schema/asyncapi-2.0.0/contact-object.d.ts b/dist/schema/asyncapi-2.0.0/contact-object.d.ts new file mode 100644 index 0000000..f3ad9a9 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/contact-object.d.ts @@ -0,0 +1,8 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface ContactObject { + readonly name: Option; + readonly url: Option; + readonly email: Option; +} +export declare const ContactObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/contact-object.js b/dist/schema/asyncapi-2.0.0/contact-object.js new file mode 100644 index 0000000..2bdce42 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/contact-object.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ContactObjectCodec = io_ts_1.type({ + name: optionFromNullable_1.optionFromNullable(io_ts_1.string), + url: optionFromNullable_1.optionFromNullable(io_ts_1.string), + email: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}, 'ContactObject'); diff --git a/dist/schema/asyncapi-2.0.0/correlation-id-object.d.ts b/dist/schema/asyncapi-2.0.0/correlation-id-object.d.ts new file mode 100644 index 0000000..6faa8bb --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/correlation-id-object.d.ts @@ -0,0 +1,7 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface CorrelationIdObject { + readonly description: Option; + readonly location: string; +} +export declare const CorrelationIdObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/correlation-id-object.js b/dist/schema/asyncapi-2.0.0/correlation-id-object.js new file mode 100644 index 0000000..fb309cc --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/correlation-id-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.CorrelationIdObjectCodec = io_ts_1.type({ + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + location: io_ts_1.string, +}, 'CorrelationIdObject'); diff --git a/dist/schema/asyncapi-2.0.0/external-documentation-object.d.ts b/dist/schema/asyncapi-2.0.0/external-documentation-object.d.ts new file mode 100644 index 0000000..d487d03 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/external-documentation-object.d.ts @@ -0,0 +1,7 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface ExternalDocumentationObject { + readonly description: Option; + readonly url: string; +} +export declare const ExternalDocumentationObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/external-documentation-object.js b/dist/schema/asyncapi-2.0.0/external-documentation-object.js new file mode 100644 index 0000000..f273794 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/external-documentation-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ExternalDocumentationObjectCodec = io_ts_1.type({ + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + url: io_ts_1.string, +}, 'ExternalDocumentationObject'); diff --git a/dist/schema/asyncapi-2.0.0/info-object.d.ts b/dist/schema/asyncapi-2.0.0/info-object.d.ts new file mode 100644 index 0000000..033fe11 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/info-object.d.ts @@ -0,0 +1,13 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ContactObject } from './contact-object'; +import { LicenseObject } from './license-object'; +import { Codec } from '../../utils/io-ts'; +export interface InfoObject { + readonly title: string; + readonly version: string; + readonly description: Option; + readonly termsOfService: Option; + readonly contact: Option; + readonly license: Option; +} +export declare const InfoObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/info-object.js b/dist/schema/asyncapi-2.0.0/info-object.js new file mode 100644 index 0000000..c756f82 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/info-object.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const contact_object_1 = require("./contact-object"); +const license_object_1 = require("./license-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.InfoObjectCodec = io_ts_1.type({ + title: io_ts_1.string, + version: io_ts_1.string, + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + termsOfService: optionFromNullable_1.optionFromNullable(io_ts_1.string), + contact: optionFromNullable_1.optionFromNullable(contact_object_1.ContactObjectCodec), + license: optionFromNullable_1.optionFromNullable(license_object_1.LicenseObjectCodec), +}, 'InfoObject'); diff --git a/dist/schema/asyncapi-2.0.0/license-object.d.ts b/dist/schema/asyncapi-2.0.0/license-object.d.ts new file mode 100644 index 0000000..6b9d204 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/license-object.d.ts @@ -0,0 +1,7 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface LicenseObject { + readonly name: string; + readonly url: Option; +} +export declare const LicenseObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/license-object.js b/dist/schema/asyncapi-2.0.0/license-object.js new file mode 100644 index 0000000..d613ad6 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/license-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.LicenseObjectCodec = io_ts_1.type({ + name: io_ts_1.string, + url: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}, 'LicenseObject'); diff --git a/dist/schema/asyncapi-2.0.0/message-object.d.ts b/dist/schema/asyncapi-2.0.0/message-object.d.ts new file mode 100644 index 0000000..b5de3b3 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/message-object.d.ts @@ -0,0 +1,24 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ReferenceObject } from './reference-object'; +import { CorrelationIdObject } from './correlation-id-object'; +import { TagsObject } from './tags-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { MessageTraitObject } from './message-trait-object'; +import { ObjectSchemaObject, SchemaObject } from './schema-object'; +import { Codec } from '../../utils/io-ts'; +export interface MessageObject { + readonly headers: Option; + readonly payload: ReferenceObject | SchemaObject; + readonly correlationId: Option; + readonly schemaFormat: Option; + readonly contentType: Option; + readonly name: Option; + readonly title: Option; + readonly summary: Option; + readonly description: Option; + readonly tags: Option; + readonly externalDocs: Option; + readonly examples: Option[]>; + readonly traits: Option; +} +export declare const MessageObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/message-object.js b/dist/schema/asyncapi-2.0.0/message-object.js new file mode 100644 index 0000000..7a21b8b --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/message-object.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reference_object_1 = require("./reference-object"); +const correlation_id_object_1 = require("./correlation-id-object"); +const tags_object_1 = require("./tags-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +const message_trait_object_1 = require("./message-trait-object"); +const schema_object_1 = require("./schema-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.MessageObjectCodec = io_ts_1.type({ + headers: optionFromNullable_1.optionFromNullable(schema_object_1.ObjectSchemaObjectCodec), + payload: io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.SchemaObjectCodec]), + correlationId: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, correlation_id_object_1.CorrelationIdObjectCodec])), + schemaFormat: optionFromNullable_1.optionFromNullable(io_ts_1.string), + contentType: optionFromNullable_1.optionFromNullable(io_ts_1.string), + name: optionFromNullable_1.optionFromNullable(io_ts_1.string), + title: optionFromNullable_1.optionFromNullable(io_ts_1.string), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + tags: optionFromNullable_1.optionFromNullable(tags_object_1.TagsObjectCodec), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), + examples: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.record(io_ts_1.string, io_ts_1.unknown))), + traits: optionFromNullable_1.optionFromNullable(io_ts_1.array(message_trait_object_1.MessageTraitObjectCodec)), +}, 'MessageObject'); diff --git a/dist/schema/asyncapi-2.0.0/message-trait-object.d.ts b/dist/schema/asyncapi-2.0.0/message-trait-object.d.ts new file mode 100644 index 0000000..ac73f6a --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/message-trait-object.d.ts @@ -0,0 +1,21 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ReferenceObject } from './reference-object'; +import { CorrelationIdObject } from './correlation-id-object'; +import { TagsObject } from './tags-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { Codec } from '../../utils/io-ts'; +import { ObjectSchemaObject } from './schema-object'; +export interface MessageTraitObject { + readonly headers: Option; + readonly correlationId: Option; + readonly schemaFormat: Option; + readonly contentType: Option; + readonly name: Option; + readonly title: Option; + readonly summary: Option; + readonly description: Option; + readonly tags: Option; + readonly externalDocs: Option; + readonly examples: Option>; +} +export declare const MessageTraitObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/message-trait-object.js b/dist/schema/asyncapi-2.0.0/message-trait-object.js new file mode 100644 index 0000000..17de397 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/message-trait-object.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const reference_object_1 = require("./reference-object"); +const correlation_id_object_1 = require("./correlation-id-object"); +const tags_object_1 = require("./tags-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const schema_object_1 = require("./schema-object"); +exports.MessageTraitObjectCodec = io_ts_1.type({ + headers: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, schema_object_1.ObjectSchemaObjectCodec])), + correlationId: optionFromNullable_1.optionFromNullable(io_ts_1.union([reference_object_1.ReferenceObjectCodec, correlation_id_object_1.CorrelationIdObjectCodec])), + schemaFormat: optionFromNullable_1.optionFromNullable(io_ts_1.string), + contentType: optionFromNullable_1.optionFromNullable(io_ts_1.string), + name: optionFromNullable_1.optionFromNullable(io_ts_1.string), + title: optionFromNullable_1.optionFromNullable(io_ts_1.string), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + tags: optionFromNullable_1.optionFromNullable(tags_object_1.TagsObjectCodec), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), + examples: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, io_ts_1.unknown)), +}, 'MessageTraitObject'); diff --git a/dist/schema/asyncapi-2.0.0/operation-object.d.ts b/dist/schema/asyncapi-2.0.0/operation-object.d.ts new file mode 100644 index 0000000..2d33924 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/operation-object.d.ts @@ -0,0 +1,22 @@ +import { Option } from 'fp-ts/lib/Option'; +import { TagsObject } from './tags-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { Codec } from '../../utils/io-ts'; +import { OperationTraitObject } from './operation-trait-object'; +import { MessageObject } from './message-object'; +import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; +import { ReferenceObject } from './reference-object'; +export interface OperationObjectOneOfMessage { + readonly oneOf: NonEmptyArray; +} +export declare const OperationObjectOneOfMessageCodec: Codec; +export interface OperationObject { + readonly operationId: Option; + readonly summary: Option; + readonly description: Option; + readonly tags: Option; + readonly externalDocs: Option; + readonly traits: Option; + readonly message: ReferenceObject | MessageObject | OperationObjectOneOfMessage; +} +export declare const OperationObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/operation-object.js b/dist/schema/asyncapi-2.0.0/operation-object.js new file mode 100644 index 0000000..d6184dc --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/operation-object.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tags_object_1 = require("./tags-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const operation_trait_object_1 = require("./operation-trait-object"); +const message_object_1 = require("./message-object"); +const reference_object_1 = require("./reference-object"); +const nonEmptyArray_1 = require("io-ts-types/lib/nonEmptyArray"); +exports.OperationObjectOneOfMessageCodec = io_ts_1.type({ + oneOf: nonEmptyArray_1.nonEmptyArray(io_ts_1.union([reference_object_1.ReferenceObjectCodec, message_object_1.MessageObjectCodec])), +}, 'OperationObjectOneOfMessage'); +exports.OperationObjectCodec = io_ts_1.type({ + operationId: optionFromNullable_1.optionFromNullable(io_ts_1.string), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + tags: optionFromNullable_1.optionFromNullable(tags_object_1.TagsObjectCodec), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), + traits: optionFromNullable_1.optionFromNullable(io_ts_1.array(operation_trait_object_1.OperationTraitObjectCodec)), + message: io_ts_1.union([reference_object_1.ReferenceObjectCodec, message_object_1.MessageObjectCodec, exports.OperationObjectOneOfMessageCodec]), +}, 'OperationObject'); diff --git a/dist/schema/asyncapi-2.0.0/operation-trait-object.d.ts b/dist/schema/asyncapi-2.0.0/operation-trait-object.d.ts new file mode 100644 index 0000000..bc2046e --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/operation-trait-object.d.ts @@ -0,0 +1,12 @@ +import { Option } from 'fp-ts/lib/Option'; +import { TagsObject } from './tags-object'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { Codec } from '../../utils/io-ts'; +export interface OperationTraitObject { + readonly operationId: Option; + readonly summary: Option; + readonly description: Option; + readonly tags: Option; + readonly externalDocs: Option; +} +export declare const OperationTraitObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/operation-trait-object.js b/dist/schema/asyncapi-2.0.0/operation-trait-object.js new file mode 100644 index 0000000..5ba1116 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/operation-trait-object.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tags_object_1 = require("./tags-object"); +const external_documentation_object_1 = require("./external-documentation-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.OperationTraitObjectCodec = io_ts_1.type({ + operationId: optionFromNullable_1.optionFromNullable(io_ts_1.string), + summary: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + tags: optionFromNullable_1.optionFromNullable(tags_object_1.TagsObjectCodec), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), +}, 'OperationTraitObject'); diff --git a/dist/schema/asyncapi-2.0.0/parameter-object.d.ts b/dist/schema/asyncapi-2.0.0/parameter-object.d.ts new file mode 100644 index 0000000..6717d0e --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/parameter-object.d.ts @@ -0,0 +1,9 @@ +import { Option } from 'fp-ts/lib/Option'; +import { SchemaObject } from './schema-object'; +import { Codec } from '../../utils/io-ts'; +export interface ParameterObject { + readonly description: Option; + readonly schema: Option; + readonly location: Option; +} +export declare const ParameterObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/parameter-object.js b/dist/schema/asyncapi-2.0.0/parameter-object.js new file mode 100644 index 0000000..22320df --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/parameter-object.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const schema_object_1 = require("./schema-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ParameterObjectCodec = io_ts_1.type({ + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + schema: optionFromNullable_1.optionFromNullable(schema_object_1.SchemaObjectCodec), + location: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}, 'ParameterObject'); diff --git a/dist/schema/asyncapi-2.0.0/parameters-object.d.ts b/dist/schema/asyncapi-2.0.0/parameters-object.d.ts new file mode 100644 index 0000000..10e7e13 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/parameters-object.d.ts @@ -0,0 +1,11 @@ +import { Branded } from 'io-ts'; +import { Codec } from '../../utils/io-ts'; +import { ReferenceObject } from './reference-object'; +import { ParameterObject } from './parameter-object'; +export interface ParametersObjectFieldPatternBrand { + readonly ParametersObjectFieldPattern: unique symbol; +} +export declare type ParametersObjectPattern = Branded; +export interface ParametersObject extends Record { +} +export declare const ParametersObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/parameters-object.js b/dist/schema/asyncapi-2.0.0/parameters-object.js new file mode 100644 index 0000000..5e9ad8f --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/parameters-object.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const reference_object_1 = require("./reference-object"); +const parameter_object_1 = require("./parameter-object"); +const pattern = /^[A-Za-z0-9_\-]+$/; +const ParametersObjectFieldPatternCodec = io_ts_1.brand(io_ts_1.string, (v) => pattern.test(v), 'ParametersObjectFieldPattern'); +exports.ParametersObjectCodec = io_ts_1.record(ParametersObjectFieldPatternCodec, io_ts_1.union([reference_object_1.ReferenceObjectCodec, parameter_object_1.ParameterObjectCodec]), 'ParametersObject'); diff --git a/dist/schema/asyncapi-2.0.0/reference-object.d.ts b/dist/schema/asyncapi-2.0.0/reference-object.d.ts new file mode 100644 index 0000000..be703fa --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/reference-object.d.ts @@ -0,0 +1,5 @@ +import { Codec } from '../../utils/io-ts'; +export interface ReferenceObject { + readonly $ref: string; +} +export declare const ReferenceObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/reference-object.js b/dist/schema/asyncapi-2.0.0/reference-object.js new file mode 100644 index 0000000..6755230 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/reference-object.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.ReferenceObjectCodec = io_ts_1.type({ + $ref: io_ts_1.string, +}, 'ReferenceObject'); diff --git a/dist/schema/asyncapi-2.0.0/schema-object.d.ts b/dist/schema/asyncapi-2.0.0/schema-object.d.ts new file mode 100644 index 0000000..3923c19 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/schema-object.d.ts @@ -0,0 +1,70 @@ +import { Codec, Natural, NonEmptySet, Positive, JSONPrimitive } from '../../utils/io-ts'; +import { Option } from 'fp-ts/lib/Option'; +import { ReferenceObject } from './reference-object'; +import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; +import { ExternalDocumentationObject } from './external-documentation-object'; +export interface BaseSchemaObject { + externalDocs: Option; + deprecated: Option; +} +export declare const BaseSchemaObjectCodec: Codec; +export interface EnumSchemaObject extends BaseSchemaObject { + readonly enum: NonEmptyArray; +} +export declare const EnumSchemaObjectCodec: Codec; +export interface ConstSchemaObject extends BaseSchemaObject { + readonly const: JSONPrimitive; +} +export declare const ConstSchemaObjectCodec: Codec; +export interface AllOfSchemaObject extends BaseSchemaObject { + readonly allOf: NonEmptyArray; +} +export declare const AllOfSchemaObjectCodec: Codec; +export interface OneOfSchemaObject extends BaseSchemaObject { + readonly oneOf: NonEmptyArray; +} +export declare const OneOfSchemaObjectCodec: Codec; +export interface BasePrimitiveSchemaObject extends BaseSchemaObject { + readonly format: Option; +} +export declare const BasePrimitiveSchemaObjectCodec: Codec; +export interface NullSchemaObject extends BasePrimitiveSchemaObject { + readonly type: 'null'; +} +export interface BooleanSchemaObject extends BasePrimitiveSchemaObject { + readonly type: 'boolean'; +} +export interface BaseNumericSchemaObject extends BasePrimitiveSchemaObject { + readonly multipleOf: Option; + readonly maximum: Option; + readonly exclusiveMaximum: Option; + readonly minimum: Option; + readonly exclusiveMinimum: Option; +} +export interface NumberSchemaObject extends BaseNumericSchemaObject { + readonly type: 'number'; +} +export interface IntegerSchemaObject extends BaseNumericSchemaObject { + readonly type: 'integer'; +} +export interface StringSchemaObject extends BasePrimitiveSchemaObject { + readonly type: 'string'; + readonly maxLength: Option; + readonly minLength: Option; + readonly pattern: Option; +} +export interface ArraySchemaObject extends BaseSchemaObject { + readonly type: 'array'; + readonly items: ReferenceObject | SchemaObject; + readonly maxItems: Option; + readonly minItems: Option; +} +export interface ObjectSchemaObject extends BaseSchemaObject { + readonly type: 'object'; + readonly properties: Option>; + readonly additionalProperties: Option; + readonly required: Option>; +} +export declare const ObjectSchemaObjectCodec: Codec; +export declare type SchemaObject = EnumSchemaObject | ConstSchemaObject | AllOfSchemaObject | OneOfSchemaObject | NullSchemaObject | BooleanSchemaObject | NumberSchemaObject | IntegerSchemaObject | StringSchemaObject | ArraySchemaObject | ObjectSchemaObject; +export declare const SchemaObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/schema-object.js b/dist/schema/asyncapi-2.0.0/schema-object.js new file mode 100644 index 0000000..955593b --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/schema-object.js @@ -0,0 +1,117 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const reference_object_1 = require("./reference-object"); +const Ord_1 = require("fp-ts/lib/Ord"); +const nonEmptyArray_1 = require("io-ts-types/lib/nonEmptyArray"); +const external_documentation_object_1 = require("./external-documentation-object"); +exports.BaseSchemaObjectCodec = io_ts_2.type({ + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), + deprecated: optionFromNullable_1.optionFromNullable(io_ts_2.boolean), +}, 'BaseSchemaObject'); +exports.EnumSchemaObjectCodec = io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + enum: nonEmptyArray_1.nonEmptyArray(io_ts_1.JSONPrimitiveCodec), + }), +], 'EnumSchemaObject'); +exports.ConstSchemaObjectCodec = io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + const: io_ts_1.JSONPrimitiveCodec, + }), +], 'ConstSchemaObject'); +exports.AllOfSchemaObjectCodec = io_ts_2.recursion('AllOfSchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + allOf: nonEmptyArray_1.nonEmptyArray(io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + }), +])); +exports.OneOfSchemaObjectCodec = io_ts_2.recursion('OneOfSchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + oneOf: nonEmptyArray_1.nonEmptyArray(io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + }), +])); +exports.BasePrimitiveSchemaObjectCodec = io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + format: optionFromNullable_1.optionFromNullable(io_ts_2.string), + }), +], 'BasePrimitiveSchemaObject'); +const NullSchemaObjectCodec = io_ts_2.intersection([ + exports.BasePrimitiveSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('null'), + }), +], 'NullSchemaObject'); +const BooleanSchemaObjectCodec = io_ts_2.intersection([ + exports.BasePrimitiveSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('boolean'), + }), +], 'BooleanSchemaObject'); +const BaseNumericSchemaObjectCodec = io_ts_2.intersection([ + exports.BasePrimitiveSchemaObjectCodec, + io_ts_2.type({ + multipleOf: optionFromNullable_1.optionFromNullable(io_ts_1.positive), + maximum: optionFromNullable_1.optionFromNullable(io_ts_2.number), + exclusiveMaximum: optionFromNullable_1.optionFromNullable(io_ts_2.number), + minimum: optionFromNullable_1.optionFromNullable(io_ts_2.number), + exclusiveMinimum: optionFromNullable_1.optionFromNullable(io_ts_2.number), + }), +], 'BaseNumericSchemaObject'); +const NumberSchemaObjectCodec = io_ts_2.intersection([ + BaseNumericSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('number'), + }), +], 'NumberSchemaObject'); +const IntegerSchemaObjectCodec = io_ts_2.intersection([ + BaseNumericSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('integer'), + }), +], 'IntegerSchemaObject'); +const StringSchemaObjectCodec = io_ts_2.intersection([ + exports.BasePrimitiveSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('string'), + maxLength: optionFromNullable_1.optionFromNullable(io_ts_1.natural), + minLength: optionFromNullable_1.optionFromNullable(io_ts_1.natural), + pattern: optionFromNullable_1.optionFromNullable(io_ts_2.string), + }), +], 'StringSchemaObject'); +const ArraySchemaObjectCodec = io_ts_2.recursion('ArraySchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('array'), + items: io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec]), + maxItems: optionFromNullable_1.optionFromNullable(io_ts_1.natural), + minItems: optionFromNullable_1.optionFromNullable(io_ts_1.natural), + }), +])); +exports.ObjectSchemaObjectCodec = io_ts_2.recursion('ObjectSchemaObject', () => io_ts_2.intersection([ + exports.BaseSchemaObjectCodec, + io_ts_2.type({ + type: io_ts_2.literal('object'), + properties: optionFromNullable_1.optionFromNullable(io_ts_2.record(io_ts_2.string, io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec]))), + additionalProperties: optionFromNullable_1.optionFromNullable(io_ts_2.union([reference_object_1.ReferenceObjectCodec, exports.SchemaObjectCodec])), + required: optionFromNullable_1.optionFromNullable(io_ts_1.nonEmptySetFromArray(io_ts_2.string, Ord_1.ordString)), + }), +])); +exports.SchemaObjectCodec = io_ts_2.recursion('SchemaObject', () => io_ts_2.union([ + exports.EnumSchemaObjectCodec, + exports.ConstSchemaObjectCodec, + exports.AllOfSchemaObjectCodec, + exports.OneOfSchemaObjectCodec, + NullSchemaObjectCodec, + BooleanSchemaObjectCodec, + NumberSchemaObjectCodec, + IntegerSchemaObjectCodec, + StringSchemaObjectCodec, + ArraySchemaObjectCodec, + exports.ObjectSchemaObjectCodec, +])); diff --git a/dist/schema/asyncapi-2.0.0/security-requirement-object.d.ts b/dist/schema/asyncapi-2.0.0/security-requirement-object.d.ts new file mode 100644 index 0000000..df9d106 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/security-requirement-object.d.ts @@ -0,0 +1,4 @@ +import { Codec } from '../../utils/io-ts'; +export interface SecurityRequirementObject extends Record { +} +export declare const SecurityRequirementObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/security-requirement-object.js b/dist/schema/asyncapi-2.0.0/security-requirement-object.js new file mode 100644 index 0000000..7d232f9 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/security-requirement-object.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.SecurityRequirementObjectCodec = io_ts_1.record(io_ts_1.string, io_ts_1.string, 'SecurityRequirementObject'); diff --git a/dist/schema/asyncapi-2.0.0/security-scheme-object.d.ts b/dist/schema/asyncapi-2.0.0/security-scheme-object.d.ts new file mode 100644 index 0000000..4a069bc --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/security-scheme-object.d.ts @@ -0,0 +1,43 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface BaseSecuritySchemeObject { + readonly description: Option; +} +export interface UserPasswordSecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'userPassword'; +} +export declare const UserPasswordSecuritySchemeObjectCodec: Codec; +export interface APIKeySecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'apiKey'; +} +export declare const APIKeySecuritySchemeObjectCodec: Codec; +export interface X509SecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'X509'; +} +export declare const X509SecuritySchemeObjectCodec: Codec; +export interface SymmetricEncryptionSecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'symmetricEncryption'; +} +export declare const SymmetricEncryptionSecuritySchemeObjectCodec: Codec; +export interface AssymmetricEncryptionSecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'asymmetricEncryption'; +} +export declare const AssymmetricEncryptionSecuritySchemeObjectCodec: Codec; +export interface HTTPAPIKeySecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'httpApiKey'; +} +export declare const HTTPAPIKeySecuritySchemeObjectCodec: Codec; +export interface HTTPSecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'http'; +} +export declare const HTTPSecuritySchemeObjectCodec: Codec; +export interface OAuth2SecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'oauth2'; +} +export declare const OAuth2SecuritySchemeObjectCodec: Codec; +export interface OpenIdConnectSecuritySchemeObject extends BaseSecuritySchemeObject { + readonly type: 'openIdConnect'; +} +export declare const OpenIdConnectSecuritySchemeObjectCodec: Codec; +export declare type SecuritySchemeObject = UserPasswordSecuritySchemeObject | APIKeySecuritySchemeObject | X509SecuritySchemeObject | SymmetricEncryptionSecuritySchemeObject | AssymmetricEncryptionSecuritySchemeObject | HTTPAPIKeySecuritySchemeObject | OAuth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject; +export declare const SecuritySchemeObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/security-scheme-object.js b/dist/schema/asyncapi-2.0.0/security-scheme-object.js new file mode 100644 index 0000000..e541543 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/security-scheme-object.js @@ -0,0 +1,71 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const BaseSecuritySchemeObjectCodec = io_ts_1.type({ + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}); +exports.UserPasswordSecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('userPassword'), + }), +], 'UserPasswordSecuritySchemeObject'); +exports.APIKeySecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('apiKey'), + }), +]); +exports.X509SecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('X509'), + }), +]); +exports.SymmetricEncryptionSecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('symmetricEncryption'), + }), +]); +exports.AssymmetricEncryptionSecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('asymmetricEncryption'), + }), +]); +exports.HTTPAPIKeySecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('httpApiKey'), + }), +]); +exports.HTTPSecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('http'), + }), +]); +exports.OAuth2SecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('oauth2'), + }), +]); +exports.OpenIdConnectSecuritySchemeObjectCodec = io_ts_1.intersection([ + BaseSecuritySchemeObjectCodec, + io_ts_1.type({ + type: io_ts_1.literal('openIdConnect'), + }), +]); +exports.SecuritySchemeObjectCodec = io_ts_1.union([ + exports.UserPasswordSecuritySchemeObjectCodec, + exports.APIKeySecuritySchemeObjectCodec, + exports.X509SecuritySchemeObjectCodec, + exports.SymmetricEncryptionSecuritySchemeObjectCodec, + exports.AssymmetricEncryptionSecuritySchemeObjectCodec, + exports.HTTPAPIKeySecuritySchemeObjectCodec, + exports.OAuth2SecuritySchemeObjectCodec, + exports.OpenIdConnectSecuritySchemeObjectCodec, +], 'SecuritySchemeObjectCodec'); diff --git a/dist/schema/asyncapi-2.0.0/server-object.d.ts b/dist/schema/asyncapi-2.0.0/server-object.d.ts new file mode 100644 index 0000000..6ea3072 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/server-object.d.ts @@ -0,0 +1,13 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ServerVariableObject } from './server-variable-object'; +import { SecurityRequirementObject } from './security-requirement-object'; +import { Codec } from '../../utils/io-ts'; +export interface ServerObject { + readonly url: string; + readonly protocol: string; + readonly protocolVersion: Option; + readonly description: Option; + readonly variables: Option>; + readonly security: Option; +} +export declare const ServerObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/server-object.js b/dist/schema/asyncapi-2.0.0/server-object.js new file mode 100644 index 0000000..7df720d --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/server-object.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const server_variable_object_1 = require("./server-variable-object"); +const security_requirement_object_1 = require("./security-requirement-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ServerObjectCodec = io_ts_1.type({ + url: io_ts_1.string, + protocol: io_ts_1.string, + protocolVersion: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + variables: optionFromNullable_1.optionFromNullable(io_ts_1.record(io_ts_1.string, server_variable_object_1.ServerVariableObjectCodec)), + security: optionFromNullable_1.optionFromNullable(io_ts_1.array(security_requirement_object_1.SecurityRequirementObjectCodec)), +}, 'ServerObject'); diff --git a/dist/schema/asyncapi-2.0.0/server-variable-object.d.ts b/dist/schema/asyncapi-2.0.0/server-variable-object.d.ts new file mode 100644 index 0000000..9211045 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/server-variable-object.d.ts @@ -0,0 +1,9 @@ +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../utils/io-ts'; +export interface ServerVariableObject { + readonly enum: Option; + readonly default: Option; + readonly description: Option; + readonly examples: Option; +} +export declare const ServerVariableObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/server-variable-object.js b/dist/schema/asyncapi-2.0.0/server-variable-object.js new file mode 100644 index 0000000..d39031e --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/server-variable-object.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ServerVariableObjectCodec = io_ts_1.type({ + enum: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.string)), + default: optionFromNullable_1.optionFromNullable(io_ts_1.string), + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + examples: optionFromNullable_1.optionFromNullable(io_ts_1.array(io_ts_1.string)), +}, 'ServerVariableObject'); diff --git a/dist/schema/asyncapi-2.0.0/servers-object.d.ts b/dist/schema/asyncapi-2.0.0/servers-object.d.ts new file mode 100644 index 0000000..ff82f03 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/servers-object.d.ts @@ -0,0 +1,10 @@ +import { Branded } from 'io-ts'; +import { ServerObject } from './server-object'; +import { Codec } from '../../utils/io-ts'; +export interface ServersObjectFieldPatternBrand { + readonly ServersObjectFieldPattern: unique symbol; +} +export declare type ServersObjectPattern = Branded; +export interface ServersObject extends Record { +} +export declare const ServersObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/servers-object.js b/dist/schema/asyncapi-2.0.0/servers-object.js new file mode 100644 index 0000000..5c018f3 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/servers-object.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const server_object_1 = require("./server-object"); +const pattern = /^[A-Za-z0-9_\-]+$/; +const ServersObjectFieldPatternCodec = io_ts_1.brand(io_ts_1.string, (v) => pattern.test(v), 'ServersObjectFieldPattern'); +exports.ServersObjectCodec = io_ts_1.record(ServersObjectFieldPatternCodec, server_object_1.ServerObjectCodec, 'ServersObject'); diff --git a/dist/schema/asyncapi-2.0.0/tag-object.d.ts b/dist/schema/asyncapi-2.0.0/tag-object.d.ts new file mode 100644 index 0000000..2b341d9 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/tag-object.d.ts @@ -0,0 +1,9 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ExternalDocumentationObject } from './external-documentation-object'; +import { Codec } from '../../utils/io-ts'; +export interface TagObject { + readonly name: string; + readonly description: Option; + readonly externalDocs: Option; +} +export declare const TagObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/tag-object.js b/dist/schema/asyncapi-2.0.0/tag-object.js new file mode 100644 index 0000000..1fe2356 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/tag-object.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const external_documentation_object_1 = require("./external-documentation-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.TagObjectCodec = io_ts_1.type({ + name: io_ts_1.string, + description: optionFromNullable_1.optionFromNullable(io_ts_1.string), + externalDocs: optionFromNullable_1.optionFromNullable(external_documentation_object_1.ExternalDocumentationObjectCodec), +}, 'TagObject'); diff --git a/dist/schema/asyncapi-2.0.0/tags-object.d.ts b/dist/schema/asyncapi-2.0.0/tags-object.d.ts new file mode 100644 index 0000000..2504e2b --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/tags-object.d.ts @@ -0,0 +1,5 @@ +import { TagObject } from './tag-object'; +import { Codec } from '../../utils/io-ts'; +export interface TagsObject extends Array { +} +export declare const TagsObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/tags-object.js b/dist/schema/asyncapi-2.0.0/tags-object.js new file mode 100644 index 0000000..80c9d2b --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/tags-object.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tag_object_1 = require("./tag-object"); +const io_ts_1 = require("io-ts"); +exports.TagsObjectCodec = io_ts_1.array(tag_object_1.TagObjectCodec, 'TagsObject'); diff --git a/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.d.ts b/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.d.ts new file mode 100644 index 0000000..0716613 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.d.ts @@ -0,0 +1,10 @@ +import { Option } from 'fp-ts/lib/Option'; +import { ObjectSchemaObject } from './schema-object'; +import { Codec } from '../../utils/io-ts'; +export interface WebsocketsChannelBindingObject { + readonly method: Option<'GET' | 'POST'>; + readonly query: Option; + readonly headers: Option; + readonly bindingVersion: Option; +} +export declare const WebsocketsChannelBindingObjectCodec: Codec; diff --git a/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.js b/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.js new file mode 100644 index 0000000..39c9f00 --- /dev/null +++ b/dist/schema/asyncapi-2.0.0/websockets-channel-binding-object.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const schema_object_1 = require("./schema-object"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.WebsocketsChannelBindingObjectCodec = io_ts_1.type({ + method: optionFromNullable_1.optionFromNullable(io_ts_1.union([io_ts_1.literal('GET'), io_ts_1.literal('POST')])), + query: optionFromNullable_1.optionFromNullable(schema_object_1.ObjectSchemaObjectCodec), + headers: optionFromNullable_1.optionFromNullable(schema_object_1.ObjectSchemaObjectCodec), + bindingVersion: optionFromNullable_1.optionFromNullable(io_ts_1.string), +}, 'WebsocketsChannelBindingObject'); diff --git a/dist/schema/sketch-121/abstract-document.d.ts b/dist/schema/sketch-121/abstract-document.d.ts new file mode 100644 index 0000000..31f8af1 --- /dev/null +++ b/dist/schema/sketch-121/abstract-document.d.ts @@ -0,0 +1,18 @@ +import { SharedStyleContainer } from './objects/shared-style-container'; +import { Codec } from '../../utils/io-ts'; +import { SharedTextStyleContainer } from './objects/shared-text-style-container'; +import { ForeignLayerStyle } from './objects/foreign-layer-style'; +import { ForeignTextStyle } from './objects/foreign-text-style'; +import { AssetCollection } from './objects/asset-collection'; +import { ObjectID } from './objects/object-id'; +import { ForeignSymbol } from './objects/foreign-symbol'; +export interface AbstractDocument { + readonly do_objectID: ObjectID; + readonly assets: AssetCollection; + readonly foreignLayerStyles: ForeignLayerStyle[]; + readonly foreignTextStyles: ForeignTextStyle[]; + readonly foreignSymbols: ForeignSymbol[]; + readonly layerTextStyles: SharedTextStyleContainer; + readonly layerStyles: SharedStyleContainer; +} +export declare const AbstractDocumentCodec: Codec; diff --git a/dist/schema/sketch-121/abstract-document.js b/dist/schema/sketch-121/abstract-document.js new file mode 100644 index 0000000..b841c4d --- /dev/null +++ b/dist/schema/sketch-121/abstract-document.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const shared_style_container_1 = require("./objects/shared-style-container"); +const io_ts_1 = require("io-ts"); +const shared_text_style_container_1 = require("./objects/shared-text-style-container"); +const foreign_layer_style_1 = require("./objects/foreign-layer-style"); +const foreign_text_style_1 = require("./objects/foreign-text-style"); +const asset_collection_1 = require("./objects/asset-collection"); +const object_id_1 = require("./objects/object-id"); +const foreign_symbol_1 = require("./objects/foreign-symbol"); +exports.AbstractDocumentCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + assets: asset_collection_1.AssetCollectionCodec, + foreignLayerStyles: io_ts_1.array(foreign_layer_style_1.ForeignLayerStyleCodec), + foreignTextStyles: io_ts_1.array(foreign_text_style_1.ForeignTextStyleCodec), + foreignSymbols: io_ts_1.array(foreign_symbol_1.ForeignSymbolCodec), + layerTextStyles: shared_text_style_container_1.SharedTextStyleContainerCodec, + layerStyles: shared_style_container_1.SharedStyleContainerCodec, +}); diff --git a/dist/schema/sketch-121/document.d.ts b/dist/schema/sketch-121/document.d.ts new file mode 100644 index 0000000..9836a57 --- /dev/null +++ b/dist/schema/sketch-121/document.d.ts @@ -0,0 +1,7 @@ +import { Codec } from '../../utils/io-ts'; +import { AbstractDocument } from './abstract-document'; +import { Page } from './objects/page'; +export interface Document extends AbstractDocument { + readonly pages: Page[]; +} +export declare const DocumentCodec: Codec; diff --git a/dist/schema/sketch-121/document.js b/dist/schema/sketch-121/document.js new file mode 100644 index 0000000..b50c851 --- /dev/null +++ b/dist/schema/sketch-121/document.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const abstract_document_1 = require("./abstract-document"); +const page_1 = require("./objects/page"); +exports.DocumentCodec = io_ts_1.intersection([ + abstract_document_1.AbstractDocumentCodec, + io_ts_1.type({ + pages: io_ts_1.array(page_1.PageCodec), + }), +], 'Document'); diff --git a/dist/schema/sketch-121/enums/blend-mode.d.ts b/dist/schema/sketch-121/enums/blend-mode.d.ts new file mode 100644 index 0000000..ff14e54 --- /dev/null +++ b/dist/schema/sketch-121/enums/blend-mode.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type BlendMode = 'Normal' | 'Darken' | 'Multiply' | 'Color burn' | 'Lighten' | 'Screen' | 'Color dodge' | 'Overlay' | 'Soft light' | 'Hard light' | 'Difference' | 'Exclusion' | 'Hue' | 'Saturation' | 'Color' | 'Luminosity' | 'Plus darker' | 'Plus lighter'; +export declare const BlendModeCodec: Codec; diff --git a/dist/schema/sketch-121/enums/blend-mode.js b/dist/schema/sketch-121/enums/blend-mode.js new file mode 100644 index 0000000..f846ec4 --- /dev/null +++ b/dist/schema/sketch-121/enums/blend-mode.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.BlendModeCodec = io_ts_2.union([ + io_ts_1.mapper('Normal', 0), + io_ts_1.mapper('Darken', 1), + io_ts_1.mapper('Multiply', 2), + io_ts_1.mapper('Color burn', 3), + io_ts_1.mapper('Lighten', 4), + io_ts_1.mapper('Screen', 5), + io_ts_1.mapper('Color dodge', 6), + io_ts_1.mapper('Overlay', 7), + io_ts_1.mapper('Soft light', 8), + io_ts_1.mapper('Hard light', 9), + io_ts_1.mapper('Difference', 10), + io_ts_1.mapper('Exclusion', 11), + io_ts_1.mapper('Hue', 12), + io_ts_1.mapper('Saturation', 13), + io_ts_1.mapper('Color', 14), + io_ts_1.mapper('Luminosity', 15), + io_ts_1.mapper('Plus darker', 16), + io_ts_1.mapper('Plus lighter', 17), +], 'BlendMode'); diff --git a/dist/schema/sketch-121/enums/border-position.d.ts b/dist/schema/sketch-121/enums/border-position.d.ts new file mode 100644 index 0000000..39c53cf --- /dev/null +++ b/dist/schema/sketch-121/enums/border-position.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type BorderPosition = 'Center' | 'Inside' | 'Outside'; +export declare const BorderPositionCodec: Codec; diff --git a/dist/schema/sketch-121/enums/border-position.js b/dist/schema/sketch-121/enums/border-position.js new file mode 100644 index 0000000..bd06b16 --- /dev/null +++ b/dist/schema/sketch-121/enums/border-position.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.BorderPositionCodec = io_ts_2.union([io_ts_1.mapper('Center', 0), io_ts_1.mapper('Inside', 1), io_ts_1.mapper('Outside', 2)], 'BorderPosition'); diff --git a/dist/schema/sketch-121/enums/fill-type.d.ts b/dist/schema/sketch-121/enums/fill-type.d.ts new file mode 100644 index 0000000..114c9c0 --- /dev/null +++ b/dist/schema/sketch-121/enums/fill-type.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type FillType = 'Color' | 'Gradient' | 'Pattern'; +export declare const FillTypeCodec: Codec; diff --git a/dist/schema/sketch-121/enums/fill-type.js b/dist/schema/sketch-121/enums/fill-type.js new file mode 100644 index 0000000..360bac3 --- /dev/null +++ b/dist/schema/sketch-121/enums/fill-type.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.FillTypeCodec = io_ts_2.union([io_ts_1.mapper('Color', 0), io_ts_1.mapper('Gradient', 1), io_ts_1.mapper('Pattern', 2)], 'FillType'); diff --git a/dist/schema/sketch-121/enums/gradient-type.d.ts b/dist/schema/sketch-121/enums/gradient-type.d.ts new file mode 100644 index 0000000..cb40467 --- /dev/null +++ b/dist/schema/sketch-121/enums/gradient-type.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type GradientType = 0 | 1 | 2; +export declare const GradientTypeCodec: Codec; diff --git a/dist/schema/sketch-121/enums/gradient-type.js b/dist/schema/sketch-121/enums/gradient-type.js new file mode 100644 index 0000000..2bf5223 --- /dev/null +++ b/dist/schema/sketch-121/enums/gradient-type.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.GradientTypeCodec = io_ts_1.union([io_ts_1.literal(0, 'Linear'), io_ts_1.literal(1, 'Radial'), io_ts_1.literal(2, 'Angular')], 'GradientType'); diff --git a/dist/schema/sketch-121/enums/layer-class.d.ts b/dist/schema/sketch-121/enums/layer-class.d.ts new file mode 100644 index 0000000..8a74946 --- /dev/null +++ b/dist/schema/sketch-121/enums/layer-class.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type LayerClass = 'symbolInstance' | 'symbolMaster' | 'group' | 'oval' | 'text' | 'rectangle' | 'shapePath' | 'shapeGroup' | 'artboard'; +export declare const LayerClassCodec: Codec; diff --git a/dist/schema/sketch-121/enums/layer-class.js b/dist/schema/sketch-121/enums/layer-class.js new file mode 100644 index 0000000..95f7b62 --- /dev/null +++ b/dist/schema/sketch-121/enums/layer-class.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.LayerClassCodec = io_ts_1.union([ + io_ts_1.literal('symbolInstance'), + io_ts_1.literal('symbolMaster'), + io_ts_1.literal('group'), + io_ts_1.literal('oval'), + io_ts_1.literal('text'), + io_ts_1.literal('rectangle'), + io_ts_1.literal('shapePath'), + io_ts_1.literal('shapeGroup'), + io_ts_1.literal('artboard'), +], 'LayerClass'); diff --git a/dist/schema/sketch-121/enums/text-horizontal-alignment.d.ts b/dist/schema/sketch-121/enums/text-horizontal-alignment.d.ts new file mode 100644 index 0000000..6e9f1c7 --- /dev/null +++ b/dist/schema/sketch-121/enums/text-horizontal-alignment.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type TextHorizontalAlignment = 'Left' | 'Right' | 'Centered' | 'Justified' | 'Natural'; +export declare const TextHorizontalAlignmentCodec: Codec; diff --git a/dist/schema/sketch-121/enums/text-horizontal-alignment.js b/dist/schema/sketch-121/enums/text-horizontal-alignment.js new file mode 100644 index 0000000..b8be147 --- /dev/null +++ b/dist/schema/sketch-121/enums/text-horizontal-alignment.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.TextHorizontalAlignmentCodec = io_ts_2.union([io_ts_1.mapper('Left', 0), io_ts_1.mapper('Right', 1), io_ts_1.mapper('Centered', 2), io_ts_1.mapper('Justified', 3), io_ts_1.mapper('Natural', 4)], 'TextHorizontalAlignment'); diff --git a/dist/schema/sketch-121/enums/text-transform.d.ts b/dist/schema/sketch-121/enums/text-transform.d.ts new file mode 100644 index 0000000..1b241fb --- /dev/null +++ b/dist/schema/sketch-121/enums/text-transform.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type TextTransform = 'None' | 'Uppercase' | 'Lowercase'; +export declare const TextTransformCodec: Codec; diff --git a/dist/schema/sketch-121/enums/text-transform.js b/dist/schema/sketch-121/enums/text-transform.js new file mode 100644 index 0000000..e27a80e --- /dev/null +++ b/dist/schema/sketch-121/enums/text-transform.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.TextTransformCodec = io_ts_2.union([io_ts_1.mapper('None', 0), io_ts_1.mapper('Uppercase', 1), io_ts_1.mapper('Lowercase', 2)], 'TextTransform'); diff --git a/dist/schema/sketch-121/enums/text-vertical-alignment.d.ts b/dist/schema/sketch-121/enums/text-vertical-alignment.d.ts new file mode 100644 index 0000000..df13df3 --- /dev/null +++ b/dist/schema/sketch-121/enums/text-vertical-alignment.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type TextVerticalAlignment = 'Top' | 'Middle' | 'Bottom'; +export declare const TextVerticalAlignmentCodec: Codec; diff --git a/dist/schema/sketch-121/enums/text-vertical-alignment.js b/dist/schema/sketch-121/enums/text-vertical-alignment.js new file mode 100644 index 0000000..a65a5e6 --- /dev/null +++ b/dist/schema/sketch-121/enums/text-vertical-alignment.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.TextVerticalAlignmentCodec = io_ts_2.union([io_ts_1.mapper('Top', 0), io_ts_1.mapper('Middle', 1), io_ts_1.mapper('Bottom', 2)], 'TextVerticalAlignment'); diff --git a/dist/schema/sketch-121/enums/underline-style.d.ts b/dist/schema/sketch-121/enums/underline-style.d.ts new file mode 100644 index 0000000..9ceac5b --- /dev/null +++ b/dist/schema/sketch-121/enums/underline-style.d.ts @@ -0,0 +1,3 @@ +import { Codec } from '../../../utils/io-ts'; +export declare type UnderlineStyle = 'None' | 'Underlined'; +export declare const UnderlineStyleCodec: Codec; diff --git a/dist/schema/sketch-121/enums/underline-style.js b/dist/schema/sketch-121/enums/underline-style.js new file mode 100644 index 0000000..46593e2 --- /dev/null +++ b/dist/schema/sketch-121/enums/underline-style.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +exports.UnderlineStyleCodec = io_ts_2.union([io_ts_1.mapper('None', 0), io_ts_1.mapper('Underlined', 1)], 'UnderlineStyle'); diff --git a/dist/schema/sketch-121/file-format.d.ts b/dist/schema/sketch-121/file-format.d.ts new file mode 100644 index 0000000..ddd96cf --- /dev/null +++ b/dist/schema/sketch-121/file-format.d.ts @@ -0,0 +1,10 @@ +import { Meta } from './meta'; +import { User } from './user'; +import { Codec } from '../../utils/io-ts'; +import { Document } from './document'; +export interface FileFormat { + readonly document: Document; + readonly meta: Meta; + readonly user: User; +} +export declare const FileFormatCodec: Codec; diff --git a/dist/schema/sketch-121/file-format.js b/dist/schema/sketch-121/file-format.js new file mode 100644 index 0000000..0df41f8 --- /dev/null +++ b/dist/schema/sketch-121/file-format.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const meta_1 = require("./meta"); +const user_1 = require("./user"); +const io_ts_1 = require("io-ts"); +const document_1 = require("./document"); +exports.FileFormatCodec = io_ts_1.type({ + document: document_1.DocumentCodec, + meta: meta_1.MetaCodec, + user: user_1.UserCodec, +}); diff --git a/dist/schema/sketch-121/meta.d.ts b/dist/schema/sketch-121/meta.d.ts new file mode 100644 index 0000000..5c741a3 --- /dev/null +++ b/dist/schema/sketch-121/meta.d.ts @@ -0,0 +1,5 @@ +import { Codec } from '../../utils/io-ts'; +export interface Meta { + readonly version: 121 | 122 | 123; +} +export declare const MetaCodec: Codec; diff --git a/dist/schema/sketch-121/meta.js b/dist/schema/sketch-121/meta.js new file mode 100644 index 0000000..f561f73 --- /dev/null +++ b/dist/schema/sketch-121/meta.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.MetaCodec = io_ts_1.type({ + version: io_ts_1.union([io_ts_1.literal(121), io_ts_1.literal(122), io_ts_1.literal(123)]), +}, 'Meta'); diff --git a/dist/schema/sketch-121/objects/asset-collection.d.ts b/dist/schema/sketch-121/objects/asset-collection.d.ts new file mode 100644 index 0000000..8d005e3 --- /dev/null +++ b/dist/schema/sketch-121/objects/asset-collection.d.ts @@ -0,0 +1,14 @@ +import { ColorAsset } from './color-asset'; +import { Codec } from '../../../utils/io-ts'; +import { Color } from './color'; +import { Gradient } from './gradient'; +import { GradientAsset } from './gradient-asset'; +import { ObjectID } from './object-id'; +export interface AssetCollection { + readonly do_objectID: ObjectID; + readonly colorAssets: ColorAsset[]; + readonly gradientAssets: GradientAsset[]; + readonly colors: Color[]; + readonly gradients: Gradient[]; +} +export declare const AssetCollectionCodec: Codec; diff --git a/dist/schema/sketch-121/objects/asset-collection.js b/dist/schema/sketch-121/objects/asset-collection.js new file mode 100644 index 0000000..d2c3975 --- /dev/null +++ b/dist/schema/sketch-121/objects/asset-collection.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_asset_1 = require("./color-asset"); +const io_ts_1 = require("io-ts"); +const color_1 = require("./color"); +const gradient_1 = require("./gradient"); +const gradient_asset_1 = require("./gradient-asset"); +const object_id_1 = require("./object-id"); +exports.AssetCollectionCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + colorAssets: io_ts_1.array(color_asset_1.ColorAssetCodec), + gradientAssets: io_ts_1.array(gradient_asset_1.GradientAssetCodec), + colors: io_ts_1.array(color_1.ColorCodec), + gradients: io_ts_1.array(gradient_1.GradientCodec), +}); diff --git a/dist/schema/sketch-121/objects/border-options.d.ts b/dist/schema/sketch-121/objects/border-options.d.ts new file mode 100644 index 0000000..1ec7ccb --- /dev/null +++ b/dist/schema/sketch-121/objects/border-options.d.ts @@ -0,0 +1,6 @@ +import { Codec } from '../../../utils/io-ts'; +export interface BorderOptions { + readonly isEnabled: boolean; + readonly dashPattern: number[]; +} +export declare const BorderOptionsCodec: Codec; diff --git a/dist/schema/sketch-121/objects/border-options.js b/dist/schema/sketch-121/objects/border-options.js new file mode 100644 index 0000000..d79b7f9 --- /dev/null +++ b/dist/schema/sketch-121/objects/border-options.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.BorderOptionsCodec = io_ts_1.type({ + isEnabled: io_ts_1.boolean, + dashPattern: io_ts_1.array(io_ts_1.number), +}); diff --git a/dist/schema/sketch-121/objects/border.d.ts b/dist/schema/sketch-121/objects/border.d.ts new file mode 100644 index 0000000..299a9dd --- /dev/null +++ b/dist/schema/sketch-121/objects/border.d.ts @@ -0,0 +1,16 @@ +import { Codec, NonNegative } from '../../../utils/io-ts'; +import { Color } from './color'; +import { FillType } from '../enums/fill-type'; +import { BorderPosition } from '../enums/border-position'; +import { GraphicsContextSettings } from './graphics-context-settings'; +import { Gradient } from './gradient'; +export interface Border { + readonly isEnabled: boolean; + readonly color: Color; + readonly fillType: FillType; + readonly position: BorderPosition; + readonly thickness: NonNegative; + readonly contextSettings: GraphicsContextSettings; + readonly gradient: Gradient; +} +export declare const BorderCodec: Codec; diff --git a/dist/schema/sketch-121/objects/border.js b/dist/schema/sketch-121/objects/border.js new file mode 100644 index 0000000..6ef60c7 --- /dev/null +++ b/dist/schema/sketch-121/objects/border.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("../../../utils/io-ts"); +const io_ts_2 = require("io-ts"); +const color_1 = require("./color"); +const fill_type_1 = require("../enums/fill-type"); +const border_position_1 = require("../enums/border-position"); +const graphics_context_settings_1 = require("./graphics-context-settings"); +const gradient_1 = require("./gradient"); +exports.BorderCodec = io_ts_2.type({ + isEnabled: io_ts_2.boolean, + color: color_1.ColorCodec, + fillType: fill_type_1.FillTypeCodec, + position: border_position_1.BorderPositionCodec, + thickness: io_ts_1.nonNegative, + contextSettings: graphics_context_settings_1.GraphicsContextSettingsCodec, + gradient: gradient_1.GradientCodec, +}, 'Border'); diff --git a/dist/schema/sketch-121/objects/color-asset.d.ts b/dist/schema/sketch-121/objects/color-asset.d.ts new file mode 100644 index 0000000..626d9ca --- /dev/null +++ b/dist/schema/sketch-121/objects/color-asset.d.ts @@ -0,0 +1,9 @@ +import { Color } from './color'; +import { Codec } from '../../../utils/io-ts'; +import { ObjectID } from './object-id'; +export interface ColorAsset { + readonly do_objectID: ObjectID; + readonly name: string; + readonly color: Color; +} +export declare const ColorAssetCodec: Codec; diff --git a/dist/schema/sketch-121/objects/color-asset.js b/dist/schema/sketch-121/objects/color-asset.js new file mode 100644 index 0000000..f477d80 --- /dev/null +++ b/dist/schema/sketch-121/objects/color-asset.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +const io_ts_1 = require("io-ts"); +const object_id_1 = require("./object-id"); +exports.ColorAssetCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + name: io_ts_1.string, + color: color_1.ColorCodec, +}, 'ColorAsset'); diff --git a/dist/schema/sketch-121/objects/color.d.ts b/dist/schema/sketch-121/objects/color.d.ts new file mode 100644 index 0000000..9aad5d8 --- /dev/null +++ b/dist/schema/sketch-121/objects/color.d.ts @@ -0,0 +1,9 @@ +import { UnitInterval } from '../utils/unit-interval'; +import { Codec } from '../../../utils/io-ts'; +export interface Color { + readonly alpha: UnitInterval; + readonly red: UnitInterval; + readonly green: UnitInterval; + readonly blue: UnitInterval; +} +export declare const ColorCodec: Codec; diff --git a/dist/schema/sketch-121/objects/color.js b/dist/schema/sketch-121/objects/color.js new file mode 100644 index 0000000..95a2f45 --- /dev/null +++ b/dist/schema/sketch-121/objects/color.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const unit_interval_1 = require("../utils/unit-interval"); +const io_ts_1 = require("io-ts"); +exports.ColorCodec = io_ts_1.type({ + alpha: unit_interval_1.UnitIntervalCodec, + red: unit_interval_1.UnitIntervalCodec, + green: unit_interval_1.UnitIntervalCodec, + blue: unit_interval_1.UnitIntervalCodec, +}, 'Color'); diff --git a/dist/schema/sketch-121/objects/fill.d.ts b/dist/schema/sketch-121/objects/fill.d.ts new file mode 100644 index 0000000..6f37cb5 --- /dev/null +++ b/dist/schema/sketch-121/objects/fill.d.ts @@ -0,0 +1,13 @@ +import { Codec } from '../../../utils/io-ts'; +import { Color } from './color'; +import { Gradient } from './gradient'; +import { FillType } from '../enums/fill-type'; +import { GraphicsContextSettings } from './graphics-context-settings'; +export interface Fill { + readonly isEnabled: boolean; + readonly color: Color; + readonly fillType: FillType; + readonly contextSettings: GraphicsContextSettings; + readonly gradient: Gradient; +} +export declare const FillCodec: Codec; diff --git a/dist/schema/sketch-121/objects/fill.js b/dist/schema/sketch-121/objects/fill.js new file mode 100644 index 0000000..8bcfe5e --- /dev/null +++ b/dist/schema/sketch-121/objects/fill.js @@ -0,0 +1,14 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const color_1 = require("./color"); +const gradient_1 = require("./gradient"); +const fill_type_1 = require("../enums/fill-type"); +const graphics_context_settings_1 = require("./graphics-context-settings"); +exports.FillCodec = io_ts_1.type({ + isEnabled: io_ts_1.boolean, + color: color_1.ColorCodec, + fillType: fill_type_1.FillTypeCodec, + contextSettings: graphics_context_settings_1.GraphicsContextSettingsCodec, + gradient: gradient_1.GradientCodec, +}, 'Fill'); diff --git a/dist/schema/sketch-121/objects/font-descriptor.d.ts b/dist/schema/sketch-121/objects/font-descriptor.d.ts new file mode 100644 index 0000000..f8cc3fa --- /dev/null +++ b/dist/schema/sketch-121/objects/font-descriptor.d.ts @@ -0,0 +1,8 @@ +import { Codec } from '../../../utils/io-ts'; +export interface FontDescriptor { + readonly attributes: { + readonly name: string; + readonly size: number; + }; +} +export declare const FontDescriptorCodec: Codec; diff --git a/dist/schema/sketch-121/objects/font-descriptor.js b/dist/schema/sketch-121/objects/font-descriptor.js new file mode 100644 index 0000000..2430220 --- /dev/null +++ b/dist/schema/sketch-121/objects/font-descriptor.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.FontDescriptorCodec = io_ts_1.type({ + attributes: io_ts_1.type({ + name: io_ts_1.string, + size: io_ts_1.number, + }), +}); diff --git a/dist/schema/sketch-121/objects/foreign-layer-style.d.ts b/dist/schema/sketch-121/objects/foreign-layer-style.d.ts new file mode 100644 index 0000000..7dded30 --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-layer-style.d.ts @@ -0,0 +1,7 @@ +import { Codec } from '../../../utils/io-ts'; +import { SharedStyle } from './shared-style'; +export interface ForeignLayerStyle { + readonly sourceLibraryName: string; + readonly localSharedStyle: SharedStyle; +} +export declare const ForeignLayerStyleCodec: Codec; diff --git a/dist/schema/sketch-121/objects/foreign-layer-style.js b/dist/schema/sketch-121/objects/foreign-layer-style.js new file mode 100644 index 0000000..75a0780 --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-layer-style.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const shared_style_1 = require("./shared-style"); +exports.ForeignLayerStyleCodec = io_ts_1.type({ + sourceLibraryName: io_ts_1.string, + localSharedStyle: shared_style_1.SharedStyleCodec, +}, 'ForeignLayerStyle'); diff --git a/dist/schema/sketch-121/objects/foreign-symbol.d.ts b/dist/schema/sketch-121/objects/foreign-symbol.d.ts new file mode 100644 index 0000000..817bb96 --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-symbol.d.ts @@ -0,0 +1,9 @@ +import { Layer } from './layer'; +import { ObjectID } from './object-id'; +import { Codec } from '../../../utils/io-ts'; +export interface ForeignSymbol { + do_objectID: ObjectID; + originalMaster: Layer; + symbolMaster: Layer; +} +export declare const ForeignSymbolCodec: Codec; diff --git a/dist/schema/sketch-121/objects/foreign-symbol.js b/dist/schema/sketch-121/objects/foreign-symbol.js new file mode 100644 index 0000000..1b27777 --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-symbol.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const layer_1 = require("./layer"); +const object_id_1 = require("./object-id"); +exports.ForeignSymbolCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + originalMaster: layer_1.LayerCodec, + symbolMaster: layer_1.LayerCodec, +}, 'ForeignSymbol'); diff --git a/dist/schema/sketch-121/objects/foreign-text-style.d.ts b/dist/schema/sketch-121/objects/foreign-text-style.d.ts new file mode 100644 index 0000000..4151074 --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-text-style.d.ts @@ -0,0 +1,7 @@ +import { Codec } from '../../../utils/io-ts'; +import { SharedStyle } from './shared-style'; +export interface ForeignTextStyle { + readonly sourceLibraryName: string; + readonly localSharedStyle: SharedStyle; +} +export declare const ForeignTextStyleCodec: Codec; diff --git a/dist/schema/sketch-121/objects/foreign-text-style.js b/dist/schema/sketch-121/objects/foreign-text-style.js new file mode 100644 index 0000000..0b25d4f --- /dev/null +++ b/dist/schema/sketch-121/objects/foreign-text-style.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const shared_style_1 = require("./shared-style"); +exports.ForeignTextStyleCodec = io_ts_1.type({ + sourceLibraryName: io_ts_1.string, + localSharedStyle: shared_style_1.SharedStyleCodec, +}, 'ForeignTextStyle'); diff --git a/dist/schema/sketch-121/objects/gradient-asset.d.ts b/dist/schema/sketch-121/objects/gradient-asset.d.ts new file mode 100644 index 0000000..8213c2b --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient-asset.d.ts @@ -0,0 +1,9 @@ +import { Gradient } from './gradient'; +import { Codec } from '../../../utils/io-ts'; +import { ObjectID } from './object-id'; +export interface GradientAsset { + readonly do_objectID: ObjectID; + readonly name: string; + readonly gradient: Gradient; +} +export declare const GradientAssetCodec: Codec; diff --git a/dist/schema/sketch-121/objects/gradient-asset.js b/dist/schema/sketch-121/objects/gradient-asset.js new file mode 100644 index 0000000..34b3d3c --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient-asset.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gradient_1 = require("./gradient"); +const io_ts_1 = require("io-ts"); +const object_id_1 = require("./object-id"); +exports.GradientAssetCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + name: io_ts_1.string, + gradient: gradient_1.GradientCodec, +}); diff --git a/dist/schema/sketch-121/objects/gradient-stop.d.ts b/dist/schema/sketch-121/objects/gradient-stop.d.ts new file mode 100644 index 0000000..f672937 --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient-stop.d.ts @@ -0,0 +1,8 @@ +import { Color } from './color'; +import { UnitInterval } from '../utils/unit-interval'; +import { Codec } from '../../../utils/io-ts'; +export interface GradientStop { + readonly color: Color; + readonly position: UnitInterval; +} +export declare const GradientStopCodec: Codec; diff --git a/dist/schema/sketch-121/objects/gradient-stop.js b/dist/schema/sketch-121/objects/gradient-stop.js new file mode 100644 index 0000000..871d6ce --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient-stop.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +const unit_interval_1 = require("../utils/unit-interval"); +const io_ts_1 = require("io-ts"); +exports.GradientStopCodec = io_ts_1.type({ + color: color_1.ColorCodec, + position: unit_interval_1.UnitIntervalCodec, +}, 'GradientStopCodec'); diff --git a/dist/schema/sketch-121/objects/gradient.d.ts b/dist/schema/sketch-121/objects/gradient.d.ts new file mode 100644 index 0000000..c61f858 --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient.d.ts @@ -0,0 +1,11 @@ +import { GradientType } from '../enums/gradient-type'; +import { Codec } from '../../../utils/io-ts'; +import { PointString } from '../utils/point-string'; +import { GradientStop } from './gradient-stop'; +export interface Gradient { + readonly gradientType: GradientType; + readonly from: PointString; + readonly to: PointString; + readonly stops: GradientStop[]; +} +export declare const GradientCodec: Codec; diff --git a/dist/schema/sketch-121/objects/gradient.js b/dist/schema/sketch-121/objects/gradient.js new file mode 100644 index 0000000..520e6d2 --- /dev/null +++ b/dist/schema/sketch-121/objects/gradient.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const gradient_type_1 = require("../enums/gradient-type"); +const io_ts_1 = require("io-ts"); +const point_string_1 = require("../utils/point-string"); +const gradient_stop_1 = require("./gradient-stop"); +exports.GradientCodec = io_ts_1.type({ + gradientType: gradient_type_1.GradientTypeCodec, + from: point_string_1.PointStringCodec, + to: point_string_1.PointStringCodec, + stops: io_ts_1.array(gradient_stop_1.GradientStopCodec), +}, 'Gradient'); diff --git a/dist/schema/sketch-121/objects/graphics-context-settings.d.ts b/dist/schema/sketch-121/objects/graphics-context-settings.d.ts new file mode 100644 index 0000000..094194e --- /dev/null +++ b/dist/schema/sketch-121/objects/graphics-context-settings.d.ts @@ -0,0 +1,7 @@ +import { BlendMode } from '../enums/blend-mode'; +import { Codec } from '../../../utils/io-ts'; +export interface GraphicsContextSettings { + readonly blendMode: BlendMode; + readonly opacity: number; +} +export declare const GraphicsContextSettingsCodec: Codec; diff --git a/dist/schema/sketch-121/objects/graphics-context-settings.js b/dist/schema/sketch-121/objects/graphics-context-settings.js new file mode 100644 index 0000000..d6e3183 --- /dev/null +++ b/dist/schema/sketch-121/objects/graphics-context-settings.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const blend_mode_1 = require("../enums/blend-mode"); +const io_ts_1 = require("io-ts"); +exports.GraphicsContextSettingsCodec = io_ts_1.type({ + blendMode: blend_mode_1.BlendModeCodec, + opacity: io_ts_1.number, +}, 'GraphicsContextSettings'); diff --git a/dist/schema/sketch-121/objects/inner-shadow.d.ts b/dist/schema/sketch-121/objects/inner-shadow.d.ts new file mode 100644 index 0000000..a02e557 --- /dev/null +++ b/dist/schema/sketch-121/objects/inner-shadow.d.ts @@ -0,0 +1,11 @@ +import { Color } from './color'; +import { Codec } from '../../../utils/io-ts'; +export interface InnerShadow { + readonly isEnabled: boolean; + readonly blurRadius: number; + readonly color: Color; + readonly offsetX: number; + readonly offsetY: number; + readonly spread: number; +} +export declare const InnerShadowCodec: Codec; diff --git a/dist/schema/sketch-121/objects/inner-shadow.js b/dist/schema/sketch-121/objects/inner-shadow.js new file mode 100644 index 0000000..8f892c2 --- /dev/null +++ b/dist/schema/sketch-121/objects/inner-shadow.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const color_1 = require("./color"); +const io_ts_1 = require("io-ts"); +exports.InnerShadowCodec = io_ts_1.type({ + isEnabled: io_ts_1.boolean, + blurRadius: io_ts_1.number, + color: color_1.ColorCodec, + offsetX: io_ts_1.number, + offsetY: io_ts_1.number, + spread: io_ts_1.number, +}, 'InnerShadow'); diff --git a/dist/schema/sketch-121/objects/layer.d.ts b/dist/schema/sketch-121/objects/layer.d.ts new file mode 100644 index 0000000..1757f4f --- /dev/null +++ b/dist/schema/sketch-121/objects/layer.d.ts @@ -0,0 +1,18 @@ +import { Codec } from '../../../utils/io-ts'; +import { Style } from './style'; +import { ObjectID } from './object-id'; +import { Option } from 'fp-ts/lib/Option'; +import { OverrideValue } from './override-value'; +import { LayerClass } from '../enums/layer-class'; +export interface Layer { + readonly _class: LayerClass; + readonly do_objectID: ObjectID; + readonly name: string; + readonly style: Style; + readonly layers: Option; + readonly isVisible: boolean; + readonly overrideValues: Option; + readonly sharedStyleID: Option; + readonly symbolID: Option; +} +export declare const LayerCodec: Codec; diff --git a/dist/schema/sketch-121/objects/layer.js b/dist/schema/sketch-121/objects/layer.js new file mode 100644 index 0000000..aac62ee --- /dev/null +++ b/dist/schema/sketch-121/objects/layer.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const style_1 = require("./style"); +const object_id_1 = require("./object-id"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +const override_value_1 = require("./override-value"); +const layer_class_1 = require("../enums/layer-class"); +exports.LayerCodec = io_ts_1.recursion('Layer', () => io_ts_1.type({ + _class: layer_class_1.LayerClassCodec, + do_objectID: object_id_1.ObjectIDCodec, + name: io_ts_1.string, + style: style_1.StyleCodec, + isVisible: io_ts_1.boolean, + layers: optionFromNullable_1.optionFromNullable(io_ts_1.array(exports.LayerCodec)), + overrideValues: optionFromNullable_1.optionFromNullable(io_ts_1.array(override_value_1.OverrideValueCodec)), + sharedStyleID: optionFromNullable_1.optionFromNullable(object_id_1.ObjectIDCodec), + symbolID: optionFromNullable_1.optionFromNullable(object_id_1.ObjectIDCodec), +}, 'Layer')); diff --git a/dist/schema/sketch-121/objects/object-id.d.ts b/dist/schema/sketch-121/objects/object-id.d.ts new file mode 100644 index 0000000..d6b6277 --- /dev/null +++ b/dist/schema/sketch-121/objects/object-id.d.ts @@ -0,0 +1,7 @@ +import { Branded } from 'io-ts'; +interface ObjectIDBrand { + readonly ObjectID: unique symbol; +} +export declare type ObjectID = Branded; +export declare const ObjectIDCodec: import("io-ts").BrandC; +export {}; diff --git a/dist/schema/sketch-121/objects/object-id.js b/dist/schema/sketch-121/objects/object-id.js new file mode 100644 index 0000000..08df1cb --- /dev/null +++ b/dist/schema/sketch-121/objects/object-id.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const UUIDReg = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/; +const ObjectIDReg = new RegExp(`${UUIDReg.source}(\\[${UUIDReg.source}\\])?`, 'i'); +exports.ObjectIDCodec = io_ts_1.brand(io_ts_1.string, (n) => ObjectIDReg.test(n), 'ObjectID'); diff --git a/dist/schema/sketch-121/objects/override-value.d.ts b/dist/schema/sketch-121/objects/override-value.d.ts new file mode 100644 index 0000000..96638b3 --- /dev/null +++ b/dist/schema/sketch-121/objects/override-value.d.ts @@ -0,0 +1,7 @@ +import { Codec } from '../../../utils/io-ts'; +export interface OverrideValue { + readonly _class: string; + readonly overrideName: string; + readonly value: string; +} +export declare const OverrideValueCodec: Codec; diff --git a/dist/schema/sketch-121/objects/override-value.js b/dist/schema/sketch-121/objects/override-value.js new file mode 100644 index 0000000..dd40ead --- /dev/null +++ b/dist/schema/sketch-121/objects/override-value.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +exports.OverrideValueCodec = io_ts_1.type({ + _class: io_ts_1.string, + value: io_ts_1.string, + overrideName: io_ts_1.string, +}, 'OverrideValue'); diff --git a/dist/schema/sketch-121/objects/page.d.ts b/dist/schema/sketch-121/objects/page.d.ts new file mode 100644 index 0000000..3967ab8 --- /dev/null +++ b/dist/schema/sketch-121/objects/page.d.ts @@ -0,0 +1,11 @@ +import { Codec } from '../../../utils/io-ts'; +import { Style } from './style'; +import { ObjectID } from './object-id'; +import { Layer } from './layer'; +export interface Page { + do_objectID: ObjectID; + name: string; + style: Style; + layers: Layer[]; +} +export declare const PageCodec: Codec; diff --git a/dist/schema/sketch-121/objects/page.js b/dist/schema/sketch-121/objects/page.js new file mode 100644 index 0000000..bbb1f20 --- /dev/null +++ b/dist/schema/sketch-121/objects/page.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const style_1 = require("./style"); +const object_id_1 = require("./object-id"); +const io_ts_1 = require("io-ts"); +const layer_1 = require("./layer"); +exports.PageCodec = io_ts_1.type({ + do_objectID: object_id_1.ObjectIDCodec, + name: io_ts_1.string, + style: style_1.StyleCodec, + layers: io_ts_1.array(layer_1.LayerCodec), +}, 'Page'); diff --git a/dist/schema/sketch-121/objects/paragraph-style.d.ts b/dist/schema/sketch-121/objects/paragraph-style.d.ts new file mode 100644 index 0000000..706fdab --- /dev/null +++ b/dist/schema/sketch-121/objects/paragraph-style.d.ts @@ -0,0 +1,9 @@ +import { TextHorizontalAlignment } from '../enums/text-horizontal-alignment'; +import { Option } from 'fp-ts/lib/Option'; +import { Codec } from '../../../utils/io-ts'; +export interface ParagraphStyle { + readonly alignment: Option; + readonly maximumLineHeight: Option; + readonly minimumLineHeight: Option; +} +export declare const ParagraphStyleCodec: Codec; diff --git a/dist/schema/sketch-121/objects/paragraph-style.js b/dist/schema/sketch-121/objects/paragraph-style.js new file mode 100644 index 0000000..9460fa1 --- /dev/null +++ b/dist/schema/sketch-121/objects/paragraph-style.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const text_horizontal_alignment_1 = require("../enums/text-horizontal-alignment"); +const io_ts_1 = require("io-ts"); +const optionFromNullable_1 = require("io-ts-types/lib/optionFromNullable"); +exports.ParagraphStyleCodec = io_ts_1.type({ + alignment: optionFromNullable_1.optionFromNullable(text_horizontal_alignment_1.TextHorizontalAlignmentCodec), + maximumLineHeight: optionFromNullable_1.optionFromNullable(io_ts_1.number), + minimumLineHeight: optionFromNullable_1.optionFromNullable(io_ts_1.number), +}); diff --git a/dist/schema/sketch-121/objects/shadow.d.ts b/dist/schema/sketch-121/objects/shadow.d.ts new file mode 100644 index 0000000..83741b0 --- /dev/null +++ b/dist/schema/sketch-121/objects/shadow.d.ts @@ -0,0 +1,11 @@ +import { Codec } from '../../../utils/io-ts'; +import { Color } from './color'; +export interface Shadow { + readonly isEnabled: boolean; + readonly blurRadius: number; + readonly color: Color; + readonly offsetX: number; + readonly offsetY: number; + readonly spread: number; +} +export declare const ShadowCodec: Codec; diff --git a/dist/schema/sketch-121/objects/shadow.js b/dist/schema/sketch-121/objects/shadow.js new file mode 100644 index 0000000..b1d750c --- /dev/null +++ b/dist/schema/sketch-121/objects/shadow.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const color_1 = require("./color"); +exports.ShadowCodec = io_ts_1.type({ + isEnabled: io_ts_1.boolean, + blurRadius: io_ts_1.number, + color: color_1.ColorCodec, + offsetX: io_ts_1.number, + offsetY: io_ts_1.number, + spread: io_ts_1.number, +}, 'Shadow'); diff --git a/dist/schema/sketch-121/objects/shared-style-container.d.ts b/dist/schema/sketch-121/objects/shared-style-container.d.ts new file mode 100644 index 0000000..d3d732b --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-style-container.d.ts @@ -0,0 +1,6 @@ +import { Codec } from '../../../utils/io-ts'; +import { SharedStyle } from './shared-style'; +export interface SharedStyleContainer { + readonly objects: SharedStyle[]; +} +export declare const SharedStyleContainerCodec: Codec; diff --git a/dist/schema/sketch-121/objects/shared-style-container.js b/dist/schema/sketch-121/objects/shared-style-container.js new file mode 100644 index 0000000..9f7b9f6 --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-style-container.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const shared_style_1 = require("./shared-style"); +exports.SharedStyleContainerCodec = io_ts_1.type({ + objects: io_ts_1.array(shared_style_1.SharedStyleCodec), +}, 'SharedStyleContainer'); diff --git a/dist/schema/sketch-121/objects/shared-style.d.ts b/dist/schema/sketch-121/objects/shared-style.d.ts new file mode 100644 index 0000000..e57af80 --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-style.d.ts @@ -0,0 +1,9 @@ +import { Codec } from '../../../utils/io-ts'; +import { Style } from './style'; +import { ObjectID } from './object-id'; +export interface SharedStyle { + readonly do_objectID: ObjectID; + readonly name: string; + readonly value: Style; +} +export declare const SharedStyleCodec: Codec; diff --git a/dist/schema/sketch-121/objects/shared-style.js b/dist/schema/sketch-121/objects/shared-style.js new file mode 100644 index 0000000..ca0aeef --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-style.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const style_1 = require("./style"); +const object_id_1 = require("./object-id"); +exports.SharedStyleCodec = io_ts_1.type({ + name: io_ts_1.string, + do_objectID: object_id_1.ObjectIDCodec, + value: style_1.StyleCodec, +}, 'SharedStyle'); diff --git a/dist/schema/sketch-121/objects/shared-text-style-container.d.ts b/dist/schema/sketch-121/objects/shared-text-style-container.d.ts new file mode 100644 index 0000000..e471cb2 --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-text-style-container.d.ts @@ -0,0 +1,6 @@ +import { Codec } from '../../../utils/io-ts'; +import { SharedStyle } from './shared-style'; +export interface SharedTextStyleContainer { + readonly objects: SharedStyle[]; +} +export declare const SharedTextStyleContainerCodec: Codec; diff --git a/dist/schema/sketch-121/objects/shared-text-style-container.js b/dist/schema/sketch-121/objects/shared-text-style-container.js new file mode 100644 index 0000000..ff5f479 --- /dev/null +++ b/dist/schema/sketch-121/objects/shared-text-style-container.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const io_ts_1 = require("io-ts"); +const shared_style_1 = require("./shared-style"); +exports.SharedTextStyleContainerCodec = io_ts_1.type({ + objects: io_ts_1.array(shared_style_1.SharedStyleCodec), +}, 'SharedTextStyleContainer'); diff --git a/dist/schema/sketch-121/objects/style.d.ts b/dist/schema/sketch-121/objects/style.d.ts new file mode 100644 index 0000000..601c57e --- /dev/null +++ b/dist/schema/sketch-121/objects/style.d.ts @@ -0,0 +1,21 @@ +import { Codec } from '../../../utils/io-ts'; +import { Option } from 'fp-ts/lib/Option'; +import { Fill } from './fill'; +import { GraphicsContextSettings } from './graphics-context-settings'; +import { Border } from './border'; +import { BorderOptions } from './border-options'; +import { InnerShadow } from './inner-shadow'; +import { Shadow } from './shadow'; +import { TextStyle } from './text-style'; +import { ObjectID } from './object-id'; +export interface Style { + readonly do_objectID: ObjectID; + readonly borders: Option; + readonly borderOptions: BorderOptions; + readonly fills: Option; + readonly textStyle: Option; + readonly shadows: Option; + readonly innerShadows: InnerShadow[]; + readonly contextSettings: Option; +} +export declare const StyleCodec: Codec