@layerzerolabs/function-pointer 0.2.68 → 0.2.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +23 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-lint.log +0 -8
- package/.turbo/turbo-test.log +0 -16
- package/src/index.ts +0 -71
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -2,22 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
var curryFunctionPointer = /* @__PURE__ */ __name((pointer) => (args) => ({
|
|
5
|
+
var curryFunctionPointer = /* @__PURE__ */ __name((pointer) => (...args) => ({
|
|
6
6
|
...pointer,
|
|
7
7
|
args: [
|
|
8
8
|
...pointer.args,
|
|
9
9
|
...args
|
|
10
10
|
]
|
|
11
11
|
}), "curryFunctionPointer");
|
|
12
|
-
var curryDimensionlessFunctionPointer = /* @__PURE__ */ __name((pointer) => (args) => ({
|
|
12
|
+
var curryDimensionlessFunctionPointer = /* @__PURE__ */ __name((pointer) => (...args) => ({
|
|
13
13
|
...pointer,
|
|
14
14
|
args: [
|
|
15
15
|
...pointer.args,
|
|
16
16
|
...args
|
|
17
17
|
]
|
|
18
18
|
}), "curryDimensionlessFunctionPointer");
|
|
19
|
+
var isFunctionPointer = /* @__PURE__ */ __name((o) => o.args && o.dimKey && o.factoryName && o.methodName, "isFunctionPointer");
|
|
20
|
+
var deeplyResolveDeepFunctionPointers = /* @__PURE__ */ __name(async (deepFunctionPointers, resolveFunctionPointer) => Object.fromEntries(await Promise.all(Object.entries(deepFunctionPointers).map(async ([k, v]) => {
|
|
21
|
+
if (v === null) {
|
|
22
|
+
return [
|
|
23
|
+
k,
|
|
24
|
+
v
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
if (isFunctionPointer(v)) {
|
|
28
|
+
return [
|
|
29
|
+
k,
|
|
30
|
+
await resolveFunctionPointer(v)
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
k,
|
|
35
|
+
await deeplyResolveDeepFunctionPointers(v, resolveFunctionPointer)
|
|
36
|
+
];
|
|
37
|
+
}))), "deeplyResolveDeepFunctionPointers");
|
|
19
38
|
|
|
20
39
|
exports.curryDimensionlessFunctionPointer = curryDimensionlessFunctionPointer;
|
|
21
40
|
exports.curryFunctionPointer = curryFunctionPointer;
|
|
41
|
+
exports.deeplyResolveDeepFunctionPointers = deeplyResolveDeepFunctionPointers;
|
|
42
|
+
exports.isFunctionPointer = isFunctionPointer;
|
|
22
43
|
//# sourceMappingURL=index.cjs.map
|
|
23
44
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["curryFunctionPointer","pointer","args","curryDimensionlessFunctionPointer"],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["curryFunctionPointer","pointer","args","curryDimensionlessFunctionPointer","isFunctionPointer","o","dimKey","factoryName","methodName","deeplyResolveDeepFunctionPointers","deepFunctionPointers","resolveFunctionPointer","Object","fromEntries","Promise","all","entries","map","k","v"],"mappings":";;;;AAgDO,IAAMA,oBAAAA,mBACT,MAAA,CAAA,CAAwCC,OAAAA,KACxC,CAAA,GAAwEC,IAAAA,MACnE;EACG,GAAGD,OAAAA;EACHC,IAAAA,EAAM;OAAID,OAAAA,CAAQC,IAAAA;AAASA,IAAAA,GAAAA;;AAC/B,CAAA,CAAA,EALJ,sBAAA;AAWG,IAAMC,iCAAAA,mBACT,MAAA,CAAA,CAAqDF,OAAAA,KACrD,CAAA,GAAwEC,IAAAA,MACnE;EACG,GAAGD,OAAAA;EACHC,IAAAA,EAAM;OAAID,OAAAA,CAAQC,IAAAA;AAASA,IAAAA,GAAAA;;AAC/B,CAAA,CAAA,EALJ,mCAAA;AAWG,IAAME,iBAAAA,mBAAoB,MAAA,CAAA,CAACC,CAAAA,KAC9BA,CAAAA,CAAEH,IAAAA,IAAQG,EAAEC,MAAAA,IAAUD,CAAAA,CAAEE,WAAAA,IAAeF,CAAAA,CAAEG,UAAAA,EADZ,mBAAA;AAmB1B,IAAMC,oDAAoC,MAAA,CAAA,OAG7CC,oBAAAA,EACAC,2BAEAC,MAAAA,CAAOC,WAAAA,CACH,MAAMC,OAAAA,CAAQC,GAAAA,CACVH,MAAAA,CAAOI,OAAAA,CAAQN,oBAAAA,CAAAA,CAAsBO,GAAAA,CAAI,OAAO,CAACC,CAAAA,EAAGC,CAAAA,CAAAA,KAAE;AAClD,EAAA,IAAIA,MAAM,IAAA,EAAM;AACZ,IAAA,OAAO;AAACD,MAAAA,CAAAA;AAAGC,MAAAA;;AACf,EAAA;AAEA,EAAA,IAAIf,iBAAAA,CAAkBe,CAAAA,CAAAA,EAAI;AACtB,IAAA,OAAO;AAACD,MAAAA,CAAAA;AAAG,MAAA,MAAMP,uBAAuBQ,CAAAA;;AAC5C,EAAA;AAEA,EAAA,OAAO;AACHD,IAAAA,CAAAA;IACA,MAAMT,iCAAAA,CACFU,GACAR,sBAAAA;;AAGZ,CAAA,CAAA,CAAA,CAAA,EAxBqC,mCAAA","file":"index.cjs","sourcesContent":["import type { SubtractTuple } from '@layerzerolabs/typescript-utils';\nimport { type TuplePrefixUnion } from '@layerzerolabs/typescript-utils';\n\nconst fpSym = Symbol('_fp_tag');\nconst dimSym = Symbol('_dim_tag');\n\nexport type FunctionPointer<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n> = {\n factoryName: string;\n dimKey: string;\n methodName: string;\n // an improper subset of the arguments expected by the method this points to\n args: any[];\n} & {\n // we do it this way to preserve contravariance of the input type\n // AND to brand the pointer\n [fpSym]: Fn;\n};\n\nexport type DimensionlessFunctionPointer<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n Dim = any,\n> = {\n factoryName: string;\n methodName: string;\n args: any[];\n} & {\n [fpSym]: Fn;\n [dimSym]: Dim;\n};\n\nexport type FunctionPointerUnderlying<\n Pointer extends FunctionPointer | DimensionlessFunctionPointer,\n> =\n Pointer extends FunctionPointer<infer Fn>\n ? Fn\n : Pointer extends DimensionlessFunctionPointer<infer Fn>\n ? Fn\n : never;\n\nexport type FunctionPointerInput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =\n Parameters<FunctionPointerUnderlying<Pointer>>;\n\nexport type FunctionPointerOutput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =\n ReturnType<FunctionPointerUnderlying<Pointer>>;\n\n// Does not and cannot preserve generic functions\nexport const curryFunctionPointer =\n <const Pointer extends FunctionPointer>(pointer: Pointer) =>\n <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) =>\n ({\n ...pointer,\n args: [...pointer.args, ...args],\n }) as unknown as FunctionPointer<\n (\n ...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>\n ) => FunctionPointerOutput<Pointer>\n >;\n\nexport const curryDimensionlessFunctionPointer =\n <const Pointer extends DimensionlessFunctionPointer>(pointer: Pointer) =>\n <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) =>\n ({\n ...pointer,\n args: [...pointer.args, ...args],\n }) as unknown as DimensionlessFunctionPointer<\n (\n ...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>\n ) => FunctionPointerOutput<Pointer>\n >;\n\nexport const isFunctionPointer = (o: any): o is FunctionPointer =>\n o.args && o.dimKey && o.factoryName && o.methodName;\n\nexport type DeepFunctionPointers<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n> = {\n [key: string]: DeepFunctionPointers<Fn> | FunctionPointer<Fn> | null;\n};\n\nexport type DeeplyResolvedDeepFunctionPointers<Pointers extends DeepFunctionPointers> = {\n [K in keyof Pointers]: Pointers[K] extends FunctionPointer\n ? Awaited<FunctionPointerOutput<Pointers[K]>>\n : Pointers[K] extends DeepFunctionPointers\n ? DeeplyResolvedDeepFunctionPointers<Pointers[K]>\n : Pointers[K] extends null\n ? null\n : never;\n};\n\nexport const deeplyResolveDeepFunctionPointers = async <\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n>(\n deepFunctionPointers: DeepFunctionPointers<Fn>,\n resolveFunctionPointer: (pointer: FunctionPointer<Fn>) => ReturnType<Fn>,\n) =>\n Object.fromEntries(\n await Promise.all(\n Object.entries(deepFunctionPointers).map(async ([k, v]): Promise<any> => {\n if (v === null) {\n return [k, v];\n }\n // this is kind of hacky but if this case occurs we have bigger problems\n if (isFunctionPointer(v)) {\n return [k, await resolveFunctionPointer(v as FunctionPointer<Fn>)];\n }\n\n return [\n k,\n await deeplyResolveDeepFunctionPointers(\n v as DeepFunctionPointers<Fn>,\n resolveFunctionPointer,\n ),\n ];\n }),\n ),\n ) as Promise<DeeplyResolvedDeepFunctionPointers<DeepFunctionPointers<Fn>>>;\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,28 +2,34 @@ import type { SubtractTuple } from '@layerzerolabs/typescript-utils';
|
|
|
2
2
|
import { type TuplePrefixUnion } from '@layerzerolabs/typescript-utils';
|
|
3
3
|
declare const fpSym: unique symbol;
|
|
4
4
|
declare const dimSym: unique symbol;
|
|
5
|
-
|
|
6
|
-
* <!-- anchor:FunctionPointer -->
|
|
7
|
-
*/
|
|
8
|
-
export type FunctionPointer<Input extends any[] = any[], Output extends Promise<any> = Promise<any>> = {
|
|
5
|
+
export type FunctionPointer<Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>> = {
|
|
9
6
|
factoryName: string;
|
|
10
7
|
dimKey: string;
|
|
11
8
|
methodName: string;
|
|
12
9
|
args: any[];
|
|
13
10
|
} & {
|
|
14
|
-
[fpSym]:
|
|
11
|
+
[fpSym]: Fn;
|
|
15
12
|
};
|
|
16
|
-
export type DimensionlessFunctionPointer<
|
|
13
|
+
export type DimensionlessFunctionPointer<Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>, Dim = any> = {
|
|
17
14
|
factoryName: string;
|
|
18
15
|
methodName: string;
|
|
19
16
|
args: any[];
|
|
20
17
|
} & {
|
|
21
|
-
[fpSym]:
|
|
18
|
+
[fpSym]: Fn;
|
|
22
19
|
[dimSym]: Dim;
|
|
23
20
|
};
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
26
|
-
export
|
|
27
|
-
export declare const
|
|
21
|
+
export type FunctionPointerUnderlying<Pointer extends FunctionPointer | DimensionlessFunctionPointer> = Pointer extends FunctionPointer<infer Fn> ? Fn : Pointer extends DimensionlessFunctionPointer<infer Fn> ? Fn : never;
|
|
22
|
+
export type FunctionPointerInput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> = Parameters<FunctionPointerUnderlying<Pointer>>;
|
|
23
|
+
export type FunctionPointerOutput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> = ReturnType<FunctionPointerUnderlying<Pointer>>;
|
|
24
|
+
export declare const curryFunctionPointer: <const Pointer extends FunctionPointer>(pointer: Pointer) => <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) => FunctionPointer<(...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>) => FunctionPointerOutput<Pointer>>;
|
|
25
|
+
export declare const curryDimensionlessFunctionPointer: <const Pointer extends DimensionlessFunctionPointer>(pointer: Pointer) => <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) => DimensionlessFunctionPointer<(...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>) => FunctionPointerOutput<Pointer>>;
|
|
26
|
+
export declare const isFunctionPointer: (o: any) => o is FunctionPointer;
|
|
27
|
+
export type DeepFunctionPointers<Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>> = {
|
|
28
|
+
[key: string]: DeepFunctionPointers<Fn> | FunctionPointer<Fn> | null;
|
|
29
|
+
};
|
|
30
|
+
export type DeeplyResolvedDeepFunctionPointers<Pointers extends DeepFunctionPointers> = {
|
|
31
|
+
[K in keyof Pointers]: Pointers[K] extends FunctionPointer ? Awaited<FunctionPointerOutput<Pointers[K]>> : Pointers[K] extends DeepFunctionPointers ? DeeplyResolvedDeepFunctionPointers<Pointers[K]> : Pointers[K] extends null ? null : never;
|
|
32
|
+
};
|
|
33
|
+
export declare const deeplyResolveDeepFunctionPointers: <Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>>(deepFunctionPointers: DeepFunctionPointers<Fn>, resolveFunctionPointer: (pointer: FunctionPointer<Fn>) => ReturnType<Fn>) => Promise<DeeplyResolvedDeepFunctionPointers<DeepFunctionPointers<Fn>>>;
|
|
28
34
|
export {};
|
|
29
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,QAAA,MAAM,KAAK,eAAoB,CAAC;AAChC,QAAA,MAAM,MAAM,eAAqB,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,QAAA,MAAM,KAAK,eAAoB,CAAC;AAChC,QAAA,MAAM,MAAM,eAAqB,CAAC;AAElC,MAAM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CAAC,CAAC,CAAC,GAC3C,QAAQ,CAAC,CAAC,CAAC,SAAS,oBAAoB,GACtC,kCAAkC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAC/C,QAAQ,CAAC,CAAC,CAAC,SAAS,IAAI,GACtB,IAAI,GACJ,KAAK;CAClB,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC1C,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAE9E,sBAAsB,oBAAoB,CAAC,EAAE,CAAC,EAC9C,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,CAAC,KAAK,UAAU,CAAC,EAAE,CAAC,0EAsBE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
var curryFunctionPointer = /* @__PURE__ */ __name((pointer) => (args) => ({
|
|
3
|
+
var curryFunctionPointer = /* @__PURE__ */ __name((pointer) => (...args) => ({
|
|
4
4
|
...pointer,
|
|
5
5
|
args: [
|
|
6
6
|
...pointer.args,
|
|
7
7
|
...args
|
|
8
8
|
]
|
|
9
9
|
}), "curryFunctionPointer");
|
|
10
|
-
var curryDimensionlessFunctionPointer = /* @__PURE__ */ __name((pointer) => (args) => ({
|
|
10
|
+
var curryDimensionlessFunctionPointer = /* @__PURE__ */ __name((pointer) => (...args) => ({
|
|
11
11
|
...pointer,
|
|
12
12
|
args: [
|
|
13
13
|
...pointer.args,
|
|
14
14
|
...args
|
|
15
15
|
]
|
|
16
16
|
}), "curryDimensionlessFunctionPointer");
|
|
17
|
+
var isFunctionPointer = /* @__PURE__ */ __name((o) => o.args && o.dimKey && o.factoryName && o.methodName, "isFunctionPointer");
|
|
18
|
+
var deeplyResolveDeepFunctionPointers = /* @__PURE__ */ __name(async (deepFunctionPointers, resolveFunctionPointer) => Object.fromEntries(await Promise.all(Object.entries(deepFunctionPointers).map(async ([k, v]) => {
|
|
19
|
+
if (v === null) {
|
|
20
|
+
return [
|
|
21
|
+
k,
|
|
22
|
+
v
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
if (isFunctionPointer(v)) {
|
|
26
|
+
return [
|
|
27
|
+
k,
|
|
28
|
+
await resolveFunctionPointer(v)
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
k,
|
|
33
|
+
await deeplyResolveDeepFunctionPointers(v, resolveFunctionPointer)
|
|
34
|
+
];
|
|
35
|
+
}))), "deeplyResolveDeepFunctionPointers");
|
|
17
36
|
|
|
18
|
-
export { curryDimensionlessFunctionPointer, curryFunctionPointer };
|
|
37
|
+
export { curryDimensionlessFunctionPointer, curryFunctionPointer, deeplyResolveDeepFunctionPointers, isFunctionPointer };
|
|
19
38
|
//# sourceMappingURL=index.js.map
|
|
20
39
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["curryFunctionPointer","pointer","args","curryDimensionlessFunctionPointer"],"mappings":";;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["curryFunctionPointer","pointer","args","curryDimensionlessFunctionPointer","isFunctionPointer","o","dimKey","factoryName","methodName","deeplyResolveDeepFunctionPointers","deepFunctionPointers","resolveFunctionPointer","Object","fromEntries","Promise","all","entries","map","k","v"],"mappings":";;AAgDO,IAAMA,oBAAAA,mBACT,MAAA,CAAA,CAAwCC,OAAAA,KACxC,CAAA,GAAwEC,IAAAA,MACnE;EACG,GAAGD,OAAAA;EACHC,IAAAA,EAAM;OAAID,OAAAA,CAAQC,IAAAA;AAASA,IAAAA,GAAAA;;AAC/B,CAAA,CAAA,EALJ,sBAAA;AAWG,IAAMC,iCAAAA,mBACT,MAAA,CAAA,CAAqDF,OAAAA,KACrD,CAAA,GAAwEC,IAAAA,MACnE;EACG,GAAGD,OAAAA;EACHC,IAAAA,EAAM;OAAID,OAAAA,CAAQC,IAAAA;AAASA,IAAAA,GAAAA;;AAC/B,CAAA,CAAA,EALJ,mCAAA;AAWG,IAAME,iBAAAA,mBAAoB,MAAA,CAAA,CAACC,CAAAA,KAC9BA,CAAAA,CAAEH,IAAAA,IAAQG,EAAEC,MAAAA,IAAUD,CAAAA,CAAEE,WAAAA,IAAeF,CAAAA,CAAEG,UAAAA,EADZ,mBAAA;AAmB1B,IAAMC,oDAAoC,MAAA,CAAA,OAG7CC,oBAAAA,EACAC,2BAEAC,MAAAA,CAAOC,WAAAA,CACH,MAAMC,OAAAA,CAAQC,GAAAA,CACVH,MAAAA,CAAOI,OAAAA,CAAQN,oBAAAA,CAAAA,CAAsBO,GAAAA,CAAI,OAAO,CAACC,CAAAA,EAAGC,CAAAA,CAAAA,KAAE;AAClD,EAAA,IAAIA,MAAM,IAAA,EAAM;AACZ,IAAA,OAAO;AAACD,MAAAA,CAAAA;AAAGC,MAAAA;;AACf,EAAA;AAEA,EAAA,IAAIf,iBAAAA,CAAkBe,CAAAA,CAAAA,EAAI;AACtB,IAAA,OAAO;AAACD,MAAAA,CAAAA;AAAG,MAAA,MAAMP,uBAAuBQ,CAAAA;;AAC5C,EAAA;AAEA,EAAA,OAAO;AACHD,IAAAA,CAAAA;IACA,MAAMT,iCAAAA,CACFU,GACAR,sBAAAA;;AAGZ,CAAA,CAAA,CAAA,CAAA,EAxBqC,mCAAA","file":"index.js","sourcesContent":["import type { SubtractTuple } from '@layerzerolabs/typescript-utils';\nimport { type TuplePrefixUnion } from '@layerzerolabs/typescript-utils';\n\nconst fpSym = Symbol('_fp_tag');\nconst dimSym = Symbol('_dim_tag');\n\nexport type FunctionPointer<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n> = {\n factoryName: string;\n dimKey: string;\n methodName: string;\n // an improper subset of the arguments expected by the method this points to\n args: any[];\n} & {\n // we do it this way to preserve contravariance of the input type\n // AND to brand the pointer\n [fpSym]: Fn;\n};\n\nexport type DimensionlessFunctionPointer<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n Dim = any,\n> = {\n factoryName: string;\n methodName: string;\n args: any[];\n} & {\n [fpSym]: Fn;\n [dimSym]: Dim;\n};\n\nexport type FunctionPointerUnderlying<\n Pointer extends FunctionPointer | DimensionlessFunctionPointer,\n> =\n Pointer extends FunctionPointer<infer Fn>\n ? Fn\n : Pointer extends DimensionlessFunctionPointer<infer Fn>\n ? Fn\n : never;\n\nexport type FunctionPointerInput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =\n Parameters<FunctionPointerUnderlying<Pointer>>;\n\nexport type FunctionPointerOutput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =\n ReturnType<FunctionPointerUnderlying<Pointer>>;\n\n// Does not and cannot preserve generic functions\nexport const curryFunctionPointer =\n <const Pointer extends FunctionPointer>(pointer: Pointer) =>\n <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) =>\n ({\n ...pointer,\n args: [...pointer.args, ...args],\n }) as unknown as FunctionPointer<\n (\n ...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>\n ) => FunctionPointerOutput<Pointer>\n >;\n\nexport const curryDimensionlessFunctionPointer =\n <const Pointer extends DimensionlessFunctionPointer>(pointer: Pointer) =>\n <const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(...args: Args) =>\n ({\n ...pointer,\n args: [...pointer.args, ...args],\n }) as unknown as DimensionlessFunctionPointer<\n (\n ...args: SubtractTuple<FunctionPointerInput<Pointer>, Args>\n ) => FunctionPointerOutput<Pointer>\n >;\n\nexport const isFunctionPointer = (o: any): o is FunctionPointer =>\n o.args && o.dimKey && o.factoryName && o.methodName;\n\nexport type DeepFunctionPointers<\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n> = {\n [key: string]: DeepFunctionPointers<Fn> | FunctionPointer<Fn> | null;\n};\n\nexport type DeeplyResolvedDeepFunctionPointers<Pointers extends DeepFunctionPointers> = {\n [K in keyof Pointers]: Pointers[K] extends FunctionPointer\n ? Awaited<FunctionPointerOutput<Pointers[K]>>\n : Pointers[K] extends DeepFunctionPointers\n ? DeeplyResolvedDeepFunctionPointers<Pointers[K]>\n : Pointers[K] extends null\n ? null\n : never;\n};\n\nexport const deeplyResolveDeepFunctionPointers = async <\n Fn extends (...args: any[]) => Promise<any> = (...args: any[]) => Promise<any>,\n>(\n deepFunctionPointers: DeepFunctionPointers<Fn>,\n resolveFunctionPointer: (pointer: FunctionPointer<Fn>) => ReturnType<Fn>,\n) =>\n Object.fromEntries(\n await Promise.all(\n Object.entries(deepFunctionPointers).map(async ([k, v]): Promise<any> => {\n if (v === null) {\n return [k, v];\n }\n // this is kind of hacky but if this case occurs we have bigger problems\n if (isFunctionPointer(v)) {\n return [k, await resolveFunctionPointer(v as FunctionPointer<Fn>)];\n }\n\n return [\n k,\n await deeplyResolveDeepFunctionPointers(\n v as DeepFunctionPointers<Fn>,\n resolveFunctionPointer,\n ),\n ];\n }),\n ),\n ) as Promise<DeeplyResolvedDeepFunctionPointers<DeepFunctionPointers<Fn>>>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/function-pointer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.70",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,14 +13,17 @@
|
|
|
13
13
|
"main": "./dist/index.cjs",
|
|
14
14
|
"module": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*"
|
|
18
|
+
],
|
|
16
19
|
"dependencies": {
|
|
17
|
-
"@layerzerolabs/typescript-utils": "0.2.
|
|
20
|
+
"@layerzerolabs/typescript-utils": "0.2.70"
|
|
18
21
|
},
|
|
19
22
|
"devDependencies": {
|
|
20
23
|
"tsup": "^8.4.0",
|
|
21
24
|
"vitest": "^3.2.3",
|
|
22
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
23
|
-
"@layerzerolabs/typescript-configuration": "0.2.
|
|
25
|
+
"@layerzerolabs/tsup-configuration": "0.2.70",
|
|
26
|
+
"@layerzerolabs/typescript-configuration": "0.2.70"
|
|
24
27
|
},
|
|
25
28
|
"publishConfig": {
|
|
26
29
|
"access": "public",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
WARN Issue while reading "/home/runner/work/monorepo-internal/monorepo-internal/.npmrc". Failed to replace env in config: ${NPM_TOKEN}
|
|
2
|
-
|
|
3
|
-
> @layerzerolabs/function-pointer@0.0.0 build /home/runner/work/monorepo-internal/monorepo-internal/packages/framework/definitions/function-pointer
|
|
4
|
-
> tsup
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
-
[34mCLI[39m tsup v8.5.1
|
|
9
|
-
[34mCLI[39m Using tsup config: /home/runner/work/monorepo-internal/monorepo-internal/packages/framework/definitions/function-pointer/tsup.config.ts
|
|
10
|
-
[34mCLI[39m Target: ES2023
|
|
11
|
-
[34mCLI[39m Cleaning output folder
|
|
12
|
-
[34mCJS[39m Build start
|
|
13
|
-
[34mESM[39m Build start
|
|
14
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m704.00 B[39m
|
|
15
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m2.90 KB[39m
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in 101ms
|
|
17
|
-
[32mESM[39m [1mdist/index.js [22m[32m623.00 B[39m
|
|
18
|
-
[32mESM[39m [1mdist/index.js.map [22m[32m2.90 KB[39m
|
|
19
|
-
[32mESM[39m ⚡️ Build success in 100ms
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @layerzerolabs/function-pointer@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/framework/definitions/function-pointer
|
|
3
|
-
> eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
|
|
4
|
-
|
|
5
|
-
(node:72533) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1775694520701 is not specified and it doesn't parse as CommonJS.
|
|
6
|
-
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
|
|
7
|
-
To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
|
|
8
|
-
(Use `node --trace-warnings ...` to show where the warning was created)
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @layerzerolabs/function-pointer@0.0.0 test /home/runner/work/monorepo-internal/monorepo-internal/packages/framework/definitions/function-pointer
|
|
3
|
-
> vitest --run --pass-with-no-tests --typecheck
|
|
4
|
-
|
|
5
|
-
[33mTesting types with tsc and vue-tsc is an experimental feature.
|
|
6
|
-
Breaking changes might not follow SemVer, please pin Vitest's version when using it.[39m
|
|
7
|
-
|
|
8
|
-
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/home/runner/work/monorepo-internal/monorepo-internal/packages/framework/definitions/function-pointer[39m
|
|
9
|
-
|
|
10
|
-
No test files found, exiting with code 0
|
|
11
|
-
|
|
12
|
-
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
13
|
-
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
14
|
-
[2mtypecheck include: [22m[33m**/*.{test,spec}-d.?(c|m)[jt]s?(x)[39m
|
|
15
|
-
[2mtypecheck exclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
16
|
-
|
package/src/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { SubtractTuple } from '@layerzerolabs/typescript-utils';
|
|
2
|
-
import { type TuplePrefixUnion } from '@layerzerolabs/typescript-utils';
|
|
3
|
-
|
|
4
|
-
const fpSym = Symbol('_fp_tag');
|
|
5
|
-
const dimSym = Symbol('_dim_tag');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* <!-- anchor:FunctionPointer -->
|
|
9
|
-
*/
|
|
10
|
-
export type FunctionPointer<
|
|
11
|
-
Input extends any[] = any[],
|
|
12
|
-
Output extends Promise<any> = Promise<any>,
|
|
13
|
-
> = {
|
|
14
|
-
factoryName: string;
|
|
15
|
-
dimKey: string;
|
|
16
|
-
methodName: string;
|
|
17
|
-
// an improper subset of the arguments expected by the method this points to
|
|
18
|
-
args: any[];
|
|
19
|
-
} & {
|
|
20
|
-
// we do it this way to preserve contravariance of the input type
|
|
21
|
-
[fpSym]: (...args: Input) => Output;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type DimensionlessFunctionPointer<
|
|
25
|
-
Input extends any[] = any[],
|
|
26
|
-
Output extends Promise<any> = Promise<any>,
|
|
27
|
-
Dim = any,
|
|
28
|
-
> = {
|
|
29
|
-
factoryName: string;
|
|
30
|
-
methodName: string;
|
|
31
|
-
args: any[];
|
|
32
|
-
} & {
|
|
33
|
-
[fpSym]: (...args: Input) => Output;
|
|
34
|
-
[dimSym]: Dim;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type FunctionPointerInput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =
|
|
38
|
-
Pointer extends FunctionPointer<infer M>
|
|
39
|
-
? M
|
|
40
|
-
: Pointer extends DimensionlessFunctionPointer<infer M>
|
|
41
|
-
? M
|
|
42
|
-
: never;
|
|
43
|
-
|
|
44
|
-
export type FunctionPointerOutput<Pointer extends FunctionPointer | DimensionlessFunctionPointer> =
|
|
45
|
-
Pointer extends FunctionPointer<any, infer A>
|
|
46
|
-
? A
|
|
47
|
-
: Pointer extends DimensionlessFunctionPointer<any, infer A>
|
|
48
|
-
? A
|
|
49
|
-
: never;
|
|
50
|
-
|
|
51
|
-
export const curryFunctionPointer =
|
|
52
|
-
<const Pointer extends FunctionPointer>(pointer: Pointer) =>
|
|
53
|
-
<const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(args: Args) =>
|
|
54
|
-
({
|
|
55
|
-
...pointer,
|
|
56
|
-
args: [...pointer.args, ...args],
|
|
57
|
-
}) as unknown as FunctionPointer<
|
|
58
|
-
SubtractTuple<FunctionPointerInput<Pointer>, Args>,
|
|
59
|
-
FunctionPointerOutput<Pointer>
|
|
60
|
-
>;
|
|
61
|
-
|
|
62
|
-
export const curryDimensionlessFunctionPointer =
|
|
63
|
-
<const Pointer extends DimensionlessFunctionPointer>(pointer: Pointer) =>
|
|
64
|
-
<const Args extends TuplePrefixUnion<FunctionPointerInput<Pointer>>>(args: Args) =>
|
|
65
|
-
({
|
|
66
|
-
...pointer,
|
|
67
|
-
args: [...pointer.args, ...args],
|
|
68
|
-
}) as unknown as DimensionlessFunctionPointer<
|
|
69
|
-
SubtractTuple<FunctionPointerInput<Pointer>, Args>,
|
|
70
|
-
FunctionPointerOutput<Pointer>
|
|
71
|
-
>;
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"strictPropertyInitialization": false,
|
|
7
|
-
"noUnusedLocals": false,
|
|
8
|
-
"noUnusedParameters": false,
|
|
9
|
-
"jsx": "react-jsx"
|
|
10
|
-
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"**/__mocks__/*",
|
|
14
|
-
"**/__tests__/*",
|
|
15
|
-
"**/*.spec.ts",
|
|
16
|
-
"**/*.test.ts",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
"include": ["src/**/*"]
|
|
20
|
-
}
|