@longlast/function-provenance 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -15,10 +15,6 @@ pnpm add @longlast/function-provenance
15
15
  yarn add @longlast/function-provenance
16
16
  ```
17
17
 
18
- ## Use
19
-
20
- TODO
21
-
22
18
  ## Documentation
23
19
 
24
20
  [Browse the docs on longlast.js.org][docs].
package/dist/index.d.ts CHANGED
@@ -11,7 +11,14 @@ export interface FunctionProvenance {
11
11
  displayName: string;
12
12
  [$nonUserConstructible]: true;
13
13
  }
14
+ type UnknownFunction = (...args: never) => unknown;
14
15
  export declare function getBoundArguments(f: AnyFunction): unknown[];
15
16
  export declare function getUnapplied(f: AnyFunction): UnknownFunction;
16
- type UnknownFunction = (...args: never) => unknown;
17
+ /**
18
+ * Transfers provenance information from the `source` function to `dest`, which
19
+ * is assumed to be a partial application of `source`.
20
+ *
21
+ * @param args the arguments that were applied to create `dest` from `source`.
22
+ */
23
+ export declare function trackProvenance<F extends AnyFunction>(source: UnknownFunction, args: readonly unknown[], dest: F): F;
17
24
  export {};
package/dist/index.js CHANGED
@@ -3,9 +3,27 @@
3
3
  * @hidden
4
4
  */
5
5
  import { $getBoundArguments, $unapplied } from "@longlast/symbols";
6
+ import { getFunctionName } from "@longlast/function-name";
6
7
  export function getBoundArguments(f) {
7
8
  return f[$getBoundArguments]?.() ?? [];
8
9
  }
9
10
  export function getUnapplied(f) {
10
11
  return f[$unapplied] ?? f;
11
12
  }
13
+ /**
14
+ * Transfers provenance information from the `source` function to `dest`, which
15
+ * is assumed to be a partial application of `source`.
16
+ *
17
+ * @param args the arguments that were applied to create `dest` from `source`.
18
+ */
19
+ export function trackProvenance(source, args, dest) {
20
+ unsafeNarrow(dest);
21
+ dest.displayName = getFunctionName(source);
22
+ dest[$getBoundArguments] = () => getBoundArguments(source).concat(args);
23
+ dest[$unapplied] = getUnapplied(source);
24
+ return dest;
25
+ }
26
+ // TODO: unsafeNarrow is duplicated in equals.
27
+ function unsafeNarrow(value) {
28
+ value;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longlast/function-provenance",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Imbues partially-applied functions with knowledge of their origins",
5
5
  "homepage": "https://longlast.js.org/",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@longlast/any-function": "^0.0.1",
21
+ "@longlast/function-name": "^0.0.1",
21
22
  "@longlast/symbols": "^1.1.0"
22
23
  }
23
24
  }