@cosmology/utils
Advanced tools
Comparing version 1.8.6 to 1.8.7
@@ -180,12 +180,11 @@ "use strict"; | ||
* @param methodKey e.g. "balance" | ||
* @param mapper | ||
* @param mappers a list of mappers to apply. An earlier one will override a later one. | ||
*/ | ||
function getHelperFuncName(packagePath, methodKey, mapper, defaultFuncBodyFn) { | ||
mapper = mapper ?? {}; | ||
const { funcBody, creatorPrefix, hookPrefix } = mapper; | ||
function getHelperFuncName(packagePath, methodKey, mappers, defaultFuncBodyFn) { | ||
let rule; | ||
const methodKeyWithPkg = `${packagePath}.${methodKey}`; | ||
let funcBodyFn; | ||
if (funcBody) { | ||
for (const pattern in funcBody) { | ||
let isMatching = false; | ||
for (const m of mappers) { | ||
let mapper = m ?? {}; | ||
let isMatching = false; | ||
for (const pattern in mapper) { | ||
if (!globPattern.test(pattern)) { | ||
@@ -196,8 +195,16 @@ isMatching = methodKeyWithPkg === pattern; | ||
if (isMatching) { | ||
funcBodyFn = funcBody[pattern]; | ||
rule = mapper[pattern]; | ||
break; | ||
} | ||
} | ||
if (isMatching) { | ||
break; | ||
} | ||
} | ||
funcBodyFn = funcBodyFn ?? defaultFuncBodyFn; | ||
let { funcBody: funcBodyFn, creatorPrefix, hookPrefix, } = { | ||
funcBody: defaultFuncBodyFn, | ||
creatorPrefix: "create", | ||
hookPrefix: "use", | ||
...rule, | ||
}; | ||
funcBodyFn = | ||
@@ -210,6 +217,6 @@ funcBodyFn === "unchanged" | ||
return { | ||
creator: (0, _1.camel)(`${creatorPrefix || "create"}_${(0, _1.camel)(funcBodyFn(methodKey))}`), | ||
hook: (0, _1.camel)(`${hookPrefix || "use"}_${(0, _1.camel)(funcBodyFn(methodKey))}`), | ||
creator: (0, _1.camel)(`${creatorPrefix}_${(0, _1.camel)(funcBodyFn(methodKey))}`), | ||
hook: (0, _1.camel)(`${hookPrefix}_${(0, _1.camel)(funcBodyFn(methodKey))}`), | ||
}; | ||
} | ||
exports.getHelperFuncName = getHelperFuncName; |
@@ -160,12 +160,11 @@ import { camel, variableSlug } from "."; | ||
* @param methodKey e.g. "balance" | ||
* @param mapper | ||
* @param mappers a list of mappers to apply. An earlier one will override a later one. | ||
*/ | ||
export function getHelperFuncName(packagePath, methodKey, mapper, defaultFuncBodyFn) { | ||
mapper = mapper ?? {}; | ||
const { funcBody, creatorPrefix, hookPrefix } = mapper; | ||
export function getHelperFuncName(packagePath, methodKey, mappers, defaultFuncBodyFn) { | ||
let rule; | ||
const methodKeyWithPkg = `${packagePath}.${methodKey}`; | ||
let funcBodyFn; | ||
if (funcBody) { | ||
for (const pattern in funcBody) { | ||
let isMatching = false; | ||
for (const m of mappers) { | ||
let mapper = m ?? {}; | ||
let isMatching = false; | ||
for (const pattern in mapper) { | ||
if (!globPattern.test(pattern)) { | ||
@@ -176,8 +175,16 @@ isMatching = methodKeyWithPkg === pattern; | ||
if (isMatching) { | ||
funcBodyFn = funcBody[pattern]; | ||
rule = mapper[pattern]; | ||
break; | ||
} | ||
} | ||
if (isMatching) { | ||
break; | ||
} | ||
} | ||
funcBodyFn = funcBodyFn ?? defaultFuncBodyFn; | ||
let { funcBody: funcBodyFn, creatorPrefix, hookPrefix, } = { | ||
funcBody: defaultFuncBodyFn, | ||
creatorPrefix: "create", | ||
hookPrefix: "use", | ||
...rule, | ||
}; | ||
funcBodyFn = | ||
@@ -190,5 +197,5 @@ funcBodyFn === "unchanged" | ||
return { | ||
creator: camel(`${creatorPrefix || "create"}_${camel(funcBodyFn(methodKey))}`), | ||
hook: camel(`${hookPrefix || "use"}_${camel(funcBodyFn(methodKey))}`), | ||
creator: camel(`${creatorPrefix}_${camel(funcBodyFn(methodKey))}`), | ||
hook: camel(`${hookPrefix}_${camel(funcBodyFn(methodKey))}`), | ||
}; | ||
} |
{ | ||
"name": "@cosmology/utils", | ||
"version": "1.8.6", | ||
"version": "1.8.7", | ||
"description": "Telescope utils", | ||
@@ -77,6 +77,6 @@ "author": "Dan Lynch <pyramation@gmail.com>", | ||
"dependencies": { | ||
"@cosmology/types": "^1.10.2", | ||
"@cosmology/types": "^1.10.3", | ||
"dotty": "0.1.2" | ||
}, | ||
"gitHead": "3d4a33c988d687c82922e3577c6c1f64e82f107f" | ||
"gitHead": "47da72d3d7a71b7b3c9ff236eaabccdfffa717c6" | ||
} |
import { camel, variableSlug } from "."; | ||
import { pascal, snake } from "case"; | ||
import minimatch from "minimatch"; | ||
import { ProtoField, ProtoRef, ProtoRoot } from "@cosmology/types"; | ||
import { | ||
ProtoField, | ||
ProtoRef, | ||
ProtoRoot, | ||
HelperFuncNameMappers, | ||
HelperFuncNameMappersRule, | ||
} from "@cosmology/types"; | ||
import dotty from "dotty"; | ||
@@ -87,2 +93,3 @@ | ||
} | ||
return minimatch(methodNameWithPkg, pattern); | ||
@@ -218,3 +225,3 @@ }); | ||
* @param methodKey e.g. "balance" | ||
* @param mapper | ||
* @param mappers a list of mappers to apply. An earlier one will override a later one. | ||
*/ | ||
@@ -224,9 +231,3 @@ export function getHelperFuncName( | ||
methodKey: string, | ||
mapper: { | ||
funcBody?: { | ||
[key: string]: "unchanged" | "get" | ((name: string) => string); | ||
}; | ||
creatorPrefix?: string; | ||
hookPrefix?: string; | ||
}, | ||
mappers: HelperFuncNameMappers[], | ||
defaultFuncBodyFn: "unchanged" | "get" | ((name: string) => string) | ||
@@ -237,11 +238,10 @@ ): { | ||
} { | ||
mapper = mapper ?? {}; | ||
const { funcBody, creatorPrefix, hookPrefix } = mapper; | ||
let rule: HelperFuncNameMappersRule; | ||
const methodKeyWithPkg = `${packagePath}.${methodKey}`; | ||
let funcBodyFn: "unchanged" | "get" | ((name: string) => string); | ||
if (funcBody) { | ||
for (const pattern in funcBody) { | ||
let isMatching = false; | ||
for (const m of mappers) { | ||
let mapper = m ?? {}; | ||
let isMatching = false; | ||
for (const pattern in mapper) { | ||
if (!globPattern.test(pattern)) { | ||
@@ -254,9 +254,23 @@ isMatching = methodKeyWithPkg === pattern; | ||
if (isMatching) { | ||
funcBodyFn = funcBody[pattern]; | ||
rule = mapper[pattern]; | ||
break; | ||
} | ||
} | ||
if (isMatching) { | ||
break; | ||
} | ||
} | ||
funcBodyFn = funcBodyFn ?? defaultFuncBodyFn; | ||
let { | ||
funcBody: funcBodyFn, | ||
creatorPrefix, | ||
hookPrefix, | ||
} = { | ||
funcBody: defaultFuncBodyFn, | ||
creatorPrefix: "create", | ||
hookPrefix: "use", | ||
...rule, | ||
}; | ||
funcBodyFn = | ||
@@ -270,5 +284,5 @@ funcBodyFn === "unchanged" | ||
return { | ||
creator: camel(`${creatorPrefix || "create"}_${camel(funcBodyFn(methodKey))}`), | ||
hook: camel(`${hookPrefix || "use"}_${camel(funcBodyFn(methodKey))}`), | ||
creator: camel(`${creatorPrefix}_${camel(funcBodyFn(methodKey))}`), | ||
hook: camel(`${hookPrefix}_${camel(funcBodyFn(methodKey))}`), | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ProtoRef, ProtoRoot } from "@cosmology/types"; | ||
import { ProtoRef, ProtoRoot, HelperFuncNameMappers } from "@cosmology/types"; | ||
export declare const getNestedProto: (root: ProtoRoot) => any; | ||
@@ -55,13 +55,7 @@ export declare const getNestedProtoGeneric: (root: ProtoRoot, path: string[]) => any; | ||
* @param methodKey e.g. "balance" | ||
* @param mapper | ||
* @param mappers a list of mappers to apply. An earlier one will override a later one. | ||
*/ | ||
export declare function getHelperFuncName(packagePath: string, methodKey: string, mapper: { | ||
funcBody?: { | ||
[key: string]: "unchanged" | "get" | ((name: string) => string); | ||
}; | ||
creatorPrefix?: string; | ||
hookPrefix?: string; | ||
}, defaultFuncBodyFn: "unchanged" | "get" | ((name: string) => string)): { | ||
export declare function getHelperFuncName(packagePath: string, methodKey: string, mappers: HelperFuncNameMappers[], defaultFuncBodyFn: "unchanged" | "get" | ((name: string) => string)): { | ||
creator: string; | ||
hook: string; | ||
}; |
95979
2611
Updated@cosmology/types@^1.10.3