@longlast/function-provenance 0.1.0 → 0.1.1

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.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
@@ -9,3 +9,24 @@ export function getBoundArguments(f) {
9
9
  export function getUnapplied(f) {
10
10
  return f[$unapplied] ?? f;
11
11
  }
12
+ /**
13
+ * Transfers provenance information from the `source` function to `dest`, which
14
+ * is assumed to be a partial application of `source`.
15
+ *
16
+ * @param args the arguments that were applied to create `dest` from `source`.
17
+ */
18
+ export function trackProvenance(source, args, dest) {
19
+ unsafeNarrow(dest);
20
+ dest.displayName = getName(source);
21
+ dest[$getBoundArguments] = () => getBoundArguments(source).concat(args);
22
+ dest[$unapplied] = getUnapplied(source);
23
+ return dest;
24
+ }
25
+ // TODO: unsafeNarrow is duplicated in equals.
26
+ function unsafeNarrow(value) {
27
+ value;
28
+ }
29
+ // TODO: getName is duplicated.
30
+ function getName(f) {
31
+ return f.displayName ?? f.name;
32
+ }
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.1",
4
4
  "description": "Imbues partially-applied functions with knowledge of their origins",
5
5
  "homepage": "https://longlast.js.org/",
6
6
  "license": "MIT",