当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript collection-utils.definedMap函数代码示例

本文整理汇总了TypeScript中collection-utils.definedMap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript definedMap函数的具体用法?TypeScript definedMap怎么用?TypeScript definedMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了definedMap函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: definedMap

    reconstitute<T extends BaseGraphRewriteBuilder>(builder: TypeReconstituter<T>, canonicalOrder: boolean): void {
        const sortedProperties = this.getSortedProperties();
        const propertiesInNewOrder = canonicalOrder ? sortedProperties : this.getProperties();
        const maybePropertyTypes = builder.lookupMap(mapMap(sortedProperties, cp => cp.typeRef));
        const maybeAdditionalProperties = definedMap(this._additionalPropertiesRef, r => builder.lookup(r));

        if (
            maybePropertyTypes !== undefined &&
            (maybeAdditionalProperties !== undefined || this._additionalPropertiesRef === undefined)
        ) {
            const properties = mapMap(propertiesInNewOrder, (cp, n) =>
                builder.makeClassProperty(defined(maybePropertyTypes.get(n)), cp.isOptional)
            );

            switch (this.kind) {
                case "object":
                    assert(this.isFixed);
                    builder.getObjectType(properties, maybeAdditionalProperties);
                    break;
                case "map":
                    builder.getMapType(defined(maybeAdditionalProperties));
                    break;
                case "class":
                    if (this.isFixed) {
                        builder.getUniqueClassType(true, properties);
                    } else {
                        builder.getClassType(properties);
                    }
                    break;
                default:
                    return panic(`Invalid object type kind ${this.kind}`);
            }
        } else {
            switch (this.kind) {
                case "object":
                    assert(this.isFixed);
                    builder.getUniqueObjectType(undefined, undefined);
                    break;
                case "map":
                    builder.getUniqueMapType();
                    break;
                case "class":
                    builder.getUniqueClassType(this.isFixed, undefined);
                    break;
                default:
                    return panic(`Invalid object type kind ${this.kind}`);
            }

            const reconstitutedTypes = mapMap(sortedProperties, cp => builder.reconstitute(cp.typeRef));
            const properties = mapMap(propertiesInNewOrder, (cp, n) =>
                builder.makeClassProperty(defined(reconstitutedTypes.get(n)), cp.isOptional)
            );
            const additionalProperties = definedMap(this._additionalPropertiesRef, r => builder.reconstitute(r));
            builder.setObjectProperties(properties, additionalProperties);
        }
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:56,代码来源:Type.ts

示例2: singularize

 singularize(): TypeNames {
     return TypeNames.makeWithDistance(
         setMap(this.names, pluralize.singular),
         definedMap(this._alternativeNames, an => setMap(an, pluralize.singular)),
         this.distance + 1
     );
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:7,代码来源:TypeNames.ts

示例3: StringifyTransformer

 reconstitute<TBuilder extends BaseGraphRewriteBuilder>(builder: TBuilder): Transformer {
     return new StringifyTransformer(
         builder.typeGraph,
         builder.reconstituteTypeRef(this.sourceTypeRef),
         definedMap(this.consumer, xfer => xfer.reconstitute(builder))
     );
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:7,代码来源:Transformers.ts

示例4: ArrayDecodingTransformer

 reconstitute<TBuilder extends BaseGraphRewriteBuilder>(builder: TBuilder): Transformer {
     return new ArrayDecodingTransformer(
         builder.typeGraph,
         builder.reconstituteTypeRef(this.sourceTypeRef),
         definedMap(this.consumer, xfer => xfer.reconstitute(builder)),
         builder.reconstituteTypeRef(this._itemTargetTypeRef),
         this.itemTransformer.reconstitute(builder)
     );
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:9,代码来源:Transformers.ts

示例5: add

    add(namesArray: TypeNames[], startIndex: number = 0): TypeNames {
        let newNames = new Set(this.names);
        let newDistance = this.distance;
        let newAlternativeNames = definedMap(this._alternativeNames, s => new Set(s));

        for (let i = startIndex; i < namesArray.length; i++) {
            const other = namesArray[i];

            if (other instanceof RegularTypeNames && other._alternativeNames !== undefined) {
                if (newAlternativeNames === undefined) {
                    newAlternativeNames = new Set();
                }
                setUnionInto(newAlternativeNames, other._alternativeNames);
            }

            if (other.distance > newDistance) continue;

            if (!(other instanceof RegularTypeNames)) {
                assert(other instanceof TooManyTypeNames, "Unknown TypeNames instance");
                // The other one is at most our distance, so let it sort it out
                return other.add(namesArray, i + 1);
            }

            if (other.distance < newDistance) {
                // The other one is closer, so take its names
                newNames = new Set(other.names);
                newDistance = other.distance;
                newAlternativeNames = definedMap(other._alternativeNames, s => new Set(s));
            } else {
                // Same distance, merge them
                assert(other.distance === newDistance, "This should be the only case left");
                setUnionInto(newNames, other.names);
            }
        }
        return TypeNames.makeWithDistance(newNames, newAlternativeNames, newDistance);
    }
开发者ID:nrkn,项目名称:quicktype,代码行数:36,代码来源:TypeNames.ts

示例6: makeQuicktypeOptions

export async function makeQuicktypeOptions(
    options: CLIOptions,
    targetLanguages?: TargetLanguage[]
): Promise<Partial<Options> | undefined> {
    if (options.help) {
        usage(targetLanguages === undefined ? defaultTargetLanguages : targetLanguages);
        return undefined;
    }
    if (options.version) {
        console.log(`quicktype version ${packageJSON.version}`);
        console.log("Visit quicktype.io for more info.");
        return undefined;
    }
    if (options.buildMarkovChain !== undefined) {
        const contents = fs.readFileSync(options.buildMarkovChain).toString();
        const lines = contents.split("\n");
        const mc = trainMarkovChain(lines, 3);
        console.log(JSON.stringify(mc));
        return undefined;
    }

    let sources: TypeSource[] = [];
    let leadingComments: string[] | undefined = undefined;
    let fixedTopLevels: boolean = false;
    switch (options.srcLang) {
        case "graphql":
            let schemaString: string | undefined = undefined;
            let wroteSchemaToFile = false;
            if (options.graphqlIntrospect !== undefined) {
                schemaString = await introspectServer(
                    options.graphqlIntrospect,
                    withDefault(options.httpMethod, "GET"),
                    withDefault<string[]>(options.httpHeader, [])
                );
                if (options.graphqlSchema !== undefined) {
                    fs.writeFileSync(options.graphqlSchema, schemaString);
                    wroteSchemaToFile = true;
                }
            }
            const numSources = options.src.length;
            if (numSources !== 1) {
                if (wroteSchemaToFile) {
                    // We're done.
                    return undefined;
                }
                if (numSources === 0) {
                    if (schemaString !== undefined) {
                        console.log(schemaString);
                        return undefined;
                    }
                    return messageError("DriverNoGraphQLQueryGiven", {});
                }
            }
            const gqlSources: GraphQLTypeSource[] = [];
            for (const queryFile of options.src) {
                let schemaFileName: string | undefined = undefined;
                if (schemaString === undefined) {
                    schemaFileName = defined(options.graphqlSchema);
                    schemaString = fs.readFileSync(schemaFileName, "utf8");
                }
                const schema = parseJSON(schemaString, "GraphQL schema", schemaFileName);
                const query = await getStream(await readableFromFileOrURL(queryFile));
                const name = numSources === 1 ? options.topLevel : typeNameFromFilename(queryFile);
                gqlSources.push({ kind: "graphql", name, schema, query });
            }
            sources = gqlSources;
            break;
        case "json":
        case "schema":
            sources = await getSources(options);
            break;
        case "typescript":
            sources = [makeTypeScriptSource(options.src)];
            break;
        case "postman":
            for (const collectionFile of options.src) {
                const collectionJSON = fs.readFileSync(collectionFile, "utf8");
                const { sources: postmanSources, description } = sourcesFromPostmanCollection(
                    collectionJSON,
                    collectionFile
                );
                for (const src of postmanSources) {
                    sources.push(Object.assign(
                        { kind: "json" },
                        stringSourceDataToStreamSourceData(src)
                    ) as JSONTypeSource);
                }
                if (postmanSources.length > 1) {
                    fixedTopLevels = true;
                }
                if (description !== undefined) {
                    leadingComments = wordWrap(description).split("\n");
                }
            }
            break;
        default:
            return messageError("DriverUnknownSourceLanguage", { lang: options.srcLang });
    }

    const components = definedMap(options.debug, d => d.split(","));
//.........这里部分代码省略.........
开发者ID:nrkn,项目名称:quicktype,代码行数:101,代码来源:index.ts

示例7: constructor

 constructor(typeRef: TypeRef, graph: TypeGraph, valuesRef: TypeRef | undefined) {
     super(typeRef, graph, "map", false, definedMap(valuesRef, () => new Map()), valuesRef);
 }
开发者ID:nrkn,项目名称:quicktype,代码行数:3,代码来源:Type.ts


注:本文中的collection-utils.definedMap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。