@composurecdk/core 0.3.5 → 0.4.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/compose.d.ts +12 -5
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +28 -23
- package/dist/compose.js.map +1 -1
- package/dist/construct-id.d.ts +45 -0
- package/dist/construct-id.d.ts.map +1 -0
- package/dist/construct-id.js +54 -0
- package/dist/construct-id.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ref.d.ts +1 -1
- package/dist/ref.d.ts.map +1 -1
- package/dist/ref.js +6 -6
- package/dist/ref.js.map +1 -1
- package/package.json +1 -1
package/dist/compose.d.ts
CHANGED
|
@@ -23,10 +23,15 @@ type BuildResult<T extends {
|
|
|
23
23
|
type Dependency<Components extends Record<string, Lifecycle>> = (keyof Components)[];
|
|
24
24
|
/**
|
|
25
25
|
* A callback invoked after all components in a composed system have been
|
|
26
|
-
* built. Receives the scope, system id,
|
|
27
|
-
* of every component
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* built. Receives the top-level scope, system id, the fully-typed build
|
|
27
|
+
* results of every component, and a record mapping each component key to
|
|
28
|
+
* the scope it was built into.
|
|
29
|
+
*
|
|
30
|
+
* `componentScopes` makes per-component scopes visible to hooks so they can
|
|
31
|
+
* attach additional constructs to the same stack a given component was
|
|
32
|
+
* routed to — useful under {@link ComposedSystem.withStacks} or
|
|
33
|
+
* {@link ComposedSystem.withStackStrategy}, where different components may
|
|
34
|
+
* live in different stacks.
|
|
30
35
|
*
|
|
31
36
|
* Domain-specific packages provide helper functions that return hooks. For
|
|
32
37
|
* example, `@composurecdk/cloudformation` exports {@link outputs} which
|
|
@@ -42,7 +47,9 @@ type Dependency<Components extends Record<string, Lifecycle>> = (keyof Component
|
|
|
42
47
|
* };
|
|
43
48
|
* ```
|
|
44
49
|
*/
|
|
45
|
-
export type AfterBuildHook<T extends object> = (scope: IConstruct, id: string, results: T
|
|
50
|
+
export type AfterBuildHook<T extends object> = (scope: IConstruct, id: string, results: T, componentScopes: {
|
|
51
|
+
readonly [K in keyof T]: IConstruct;
|
|
52
|
+
}) => void;
|
|
46
53
|
/**
|
|
47
54
|
* A {@link Lifecycle} produced by {@link compose}, extended with methods
|
|
48
55
|
* for controlling how components are routed to scopes and for registering
|
package/dist/compose.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;GAMG;AACH,KAAK,WAAW,CAAC,CAAC,SAAS;KAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,SAAS;CAAE,IAAI;KAChE,QAAQ,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;GAMG;AACH,KAAK,UAAU,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,EAAE,CAAC;AA+BrF
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;GAMG;AACH,KAAK,WAAW,CAAC,CAAC,SAAS;KAAG,QAAQ,IA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AC,CAAE,SAAQ,SAAS,CAC/F,WAAW,CAAC,UAAU,CAAC,CACxB;IACC;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,cAAc,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;CACzF;AAuGD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAClE,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE;KAAG,QAAQ,IAAI,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;CAAE,GACvE,cAAc,CAAC,UAAU,CAAC,CAE5B"}
|
package/dist/compose.js
CHANGED
|
@@ -24,38 +24,43 @@ function buildDependencyGraph(components, dependencies) {
|
|
|
24
24
|
* built at composition time and traverses it in topological order during build.
|
|
25
25
|
*/
|
|
26
26
|
class ComposedLifecycle {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
#graph;
|
|
28
|
+
#components;
|
|
29
|
+
#dependencies;
|
|
30
30
|
constructor(components, dependencies) {
|
|
31
|
-
this
|
|
32
|
-
this
|
|
33
|
-
this
|
|
31
|
+
this.#components = components;
|
|
32
|
+
this.#dependencies = dependencies;
|
|
33
|
+
this.#graph = buildDependencyGraph(components, dependencies);
|
|
34
34
|
}
|
|
35
35
|
withStacks(stacks) {
|
|
36
|
-
return new ConfiguredLifecycle((scope, id) => this
|
|
36
|
+
return new ConfiguredLifecycle((scope, id) => this.#buildWith(scope, id, stacks));
|
|
37
37
|
}
|
|
38
38
|
withStackStrategy(strategy) {
|
|
39
39
|
return new ConfiguredLifecycle((scope, id) => {
|
|
40
|
-
const stacks = Object.fromEntries(Object.keys(this
|
|
41
|
-
return this
|
|
40
|
+
const stacks = Object.fromEntries(Object.keys(this.#components).map((key) => [key, strategy.resolve(scope, id, key)]));
|
|
41
|
+
return this.#buildWith(scope, id, stacks);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
afterBuild(hook) {
|
|
45
|
-
return new ConfiguredLifecycle((scope, id) => this
|
|
45
|
+
return new ConfiguredLifecycle((scope, id) => this.#buildWith(scope, id)).afterBuild(hook);
|
|
46
46
|
}
|
|
47
47
|
build(scope, id) {
|
|
48
|
-
return this
|
|
48
|
+
return this.#buildWith(scope, id).results;
|
|
49
49
|
}
|
|
50
|
-
buildWith(scope, id, stacks) {
|
|
50
|
+
#buildWith(scope, id, stacks) {
|
|
51
51
|
const results = {};
|
|
52
|
-
|
|
52
|
+
const componentScopes = {};
|
|
53
|
+
for (const key of alg.topsort(this.#graph)) {
|
|
53
54
|
const componentScope = stacks?.[key] ?? scope;
|
|
54
|
-
|
|
55
|
+
componentScopes[key] = componentScope;
|
|
56
|
+
const deps = (this.#dependencies[key] ?? []);
|
|
55
57
|
const context = Object.fromEntries(deps.map((dep) => [dep, results[dep]]));
|
|
56
|
-
results[key] = this
|
|
58
|
+
results[key] = this.#components[key].build(componentScope, `${id}/${key}`, context);
|
|
57
59
|
}
|
|
58
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
results: results,
|
|
62
|
+
componentScopes: componentScopes,
|
|
63
|
+
};
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
@@ -65,19 +70,19 @@ class ComposedLifecycle {
|
|
|
65
70
|
* `afterBuild` methods.
|
|
66
71
|
*/
|
|
67
72
|
class ConfiguredLifecycle {
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
#hooks = [];
|
|
74
|
+
#buildFn;
|
|
70
75
|
constructor(buildFn) {
|
|
71
|
-
this
|
|
76
|
+
this.#buildFn = buildFn;
|
|
72
77
|
}
|
|
73
78
|
afterBuild(hook) {
|
|
74
|
-
this
|
|
79
|
+
this.#hooks.push(hook);
|
|
75
80
|
return this;
|
|
76
81
|
}
|
|
77
82
|
build(scope, id) {
|
|
78
|
-
const results = this
|
|
79
|
-
for (const hook of this
|
|
80
|
-
hook(scope, id, results);
|
|
83
|
+
const { results, componentScopes } = this.#buildFn(scope, id);
|
|
84
|
+
for (const hook of this.#hooks) {
|
|
85
|
+
hook(scope, id, results, componentScopes);
|
|
81
86
|
}
|
|
82
87
|
return results;
|
|
83
88
|
}
|
package/dist/compose.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAwBrE;;;;;GAKG;AACH,SAAS,oBAAoB,CAC3B,UAAsB,EACtB,YAAwE;IAExE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAE1D,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,YAAwC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAC7F,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CACxC,CAAC;IAEF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC3B,KAAK;QACL,KAAK;KACN,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;
|
|
1
|
+
{"version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ACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,OAAO,CACrB,UAAsB,EACtB,YAAwE;IAExE,OAAO,IAAI,iBAAiB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for producing safe CDK construct IDs from arbitrary strings.
|
|
3
|
+
*
|
|
4
|
+
* The `constructs` library uses `/` as the path separator between construct
|
|
5
|
+
* IDs. When user-supplied strings (DNS names, ARNs, filesystem paths) are
|
|
6
|
+
* passed through to a construct ID, any embedded `/` silently gets rewritten
|
|
7
|
+
* to `--`, which produces unreadable CloudFormation logical IDs. Control
|
|
8
|
+
* characters are likewise unsafe.
|
|
9
|
+
*
|
|
10
|
+
* These helpers consolidate that sanitization in one place so every builder
|
|
11
|
+
* in the monorepo applies the same constraints.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Return a construct-ID-safe copy of `raw` by replacing unsafe characters
|
|
15
|
+
* (`/` and control characters) with a single `-`.
|
|
16
|
+
*
|
|
17
|
+
* Does not touch other characters — CDK construct IDs are otherwise
|
|
18
|
+
* permissive, and collapsing further (e.g., to PascalCase) would destroy
|
|
19
|
+
* information a reader expects to see in the synthesised tree.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* sanitizeConstructId("a/b") // "a-b"
|
|
24
|
+
* sanitizeConstructId("_sip._tcp") // "_sip._tcp" (unchanged)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function sanitizeConstructId(raw: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Join the supplied parts into a single construct ID. Falsy parts are
|
|
30
|
+
* dropped; each remaining part is passed through {@link sanitizeConstructId}
|
|
31
|
+
* and the results are joined with `-`.
|
|
32
|
+
*
|
|
33
|
+
* Intended for composing IDs from a mix of static prefixes and user-supplied
|
|
34
|
+
* fragments — the sanitization step means callers don't have to reason about
|
|
35
|
+
* what characters their inputs might contain.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* constructId("records", "a", "api") // "records-a-api"
|
|
40
|
+
* constructId("zone", undefined, "www") // "zone-www"
|
|
41
|
+
* constructId("records", "a/b") // "records-a-b"
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function constructId(...parts: readonly (string | undefined | null | false)[]): string;
|
|
45
|
+
//# sourceMappingURL=construct-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct-id.d.ts","sourceRoot":"","sources":["../src/construct-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,EAAE,GAAG,MAAM,CAK5F"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for producing safe CDK construct IDs from arbitrary strings.
|
|
3
|
+
*
|
|
4
|
+
* The `constructs` library uses `/` as the path separator between construct
|
|
5
|
+
* IDs. When user-supplied strings (DNS names, ARNs, filesystem paths) are
|
|
6
|
+
* passed through to a construct ID, any embedded `/` silently gets rewritten
|
|
7
|
+
* to `--`, which produces unreadable CloudFormation logical IDs. Control
|
|
8
|
+
* characters are likewise unsafe.
|
|
9
|
+
*
|
|
10
|
+
* These helpers consolidate that sanitization in one place so every builder
|
|
11
|
+
* in the monorepo applies the same constraints.
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line no-control-regex
|
|
14
|
+
const UNSAFE = /[/\x00-\x1f\x7f]/g;
|
|
15
|
+
/**
|
|
16
|
+
* Return a construct-ID-safe copy of `raw` by replacing unsafe characters
|
|
17
|
+
* (`/` and control characters) with a single `-`.
|
|
18
|
+
*
|
|
19
|
+
* Does not touch other characters — CDK construct IDs are otherwise
|
|
20
|
+
* permissive, and collapsing further (e.g., to PascalCase) would destroy
|
|
21
|
+
* information a reader expects to see in the synthesised tree.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* sanitizeConstructId("a/b") // "a-b"
|
|
26
|
+
* sanitizeConstructId("_sip._tcp") // "_sip._tcp" (unchanged)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function sanitizeConstructId(raw) {
|
|
30
|
+
return raw.replace(UNSAFE, "-");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Join the supplied parts into a single construct ID. Falsy parts are
|
|
34
|
+
* dropped; each remaining part is passed through {@link sanitizeConstructId}
|
|
35
|
+
* and the results are joined with `-`.
|
|
36
|
+
*
|
|
37
|
+
* Intended for composing IDs from a mix of static prefixes and user-supplied
|
|
38
|
+
* fragments — the sanitization step means callers don't have to reason about
|
|
39
|
+
* what characters their inputs might contain.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* constructId("records", "a", "api") // "records-a-api"
|
|
44
|
+
* constructId("zone", undefined, "www") // "zone-www"
|
|
45
|
+
* constructId("records", "a/b") // "records-a-b"
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function constructId(...parts) {
|
|
49
|
+
return parts
|
|
50
|
+
.filter((p) => typeof p === "string" && p.length > 0)
|
|
51
|
+
.map(sanitizeConstructId)
|
|
52
|
+
.join("-");
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=construct-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct-id.js","sourceRoot":"","sources":["../src/construct-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,GAAG,mBAAmB,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,KAAqD;IAClF,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SACjE,GAAG,CAAC,mBAAmB,CAAC;SACxB,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Builder, type IBuilder } from "./builder.js";
|
|
2
|
+
export { constructId, sanitizeConstructId } from "./construct-id.js";
|
|
2
3
|
export { compose, type ComposedSystem, type ConfiguredSystem, type AfterBuildHook, } from "./compose.js";
|
|
3
4
|
export { CyclicDependencyError } from "./cyclic-dependency-error.js";
|
|
4
5
|
export { type Lifecycle } from "./lifecycle.js";
|
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,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Builder } from "./builder.js";
|
|
2
|
+
export { constructId, sanitizeConstructId } from "./construct-id.js";
|
|
2
3
|
export { compose, } from "./compose.js";
|
|
3
4
|
export { CyclicDependencyError } from "./cyclic-dependency-error.js";
|
|
4
5
|
export { Ref, ref, resolve, isRef } from "./ref.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,OAAO,GAIR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAmB,MAAM,UAAU,CAAC;AACrE,OAAO,EAGL,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACL,OAAO,GAIR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAmB,MAAM,UAAU,CAAC;AACrE,OAAO,EAGL,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
|
package/dist/ref.d.ts
CHANGED
package/dist/ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,GAAG,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,GAAG,CAAC,CAAC;;IAGhB,OAAO;IAIP;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;IAYtD;;;;;OAKG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAIzC;;;;;;;;;OASG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAInC;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;CAG5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAEjE,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAShG;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAEvC;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,CAE9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAEpF"}
|
package/dist/ref.js
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
export class Ref {
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
this
|
|
29
|
+
#resolver;
|
|
30
|
+
constructor(resolver) {
|
|
31
|
+
this.#resolver = resolver;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Creates a `Ref` that resolves to a component's full build output.
|
|
@@ -52,7 +52,7 @@ export class Ref {
|
|
|
52
52
|
* @returns A new `Ref` to the selected property.
|
|
53
53
|
*/
|
|
54
54
|
get(key) {
|
|
55
|
-
return new Ref((context) => this
|
|
55
|
+
return new Ref((context) => this.#resolver(context)[key]);
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Transforms the resolved value using the provided function.
|
|
@@ -65,7 +65,7 @@ export class Ref {
|
|
|
65
65
|
* @returns A new `Ref` whose resolved value is the result of `fn`.
|
|
66
66
|
*/
|
|
67
67
|
map(fn) {
|
|
68
|
-
return new Ref((context) => fn(this
|
|
68
|
+
return new Ref((context) => fn(this.#resolver(context)));
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Resolves this reference against a build context.
|
|
@@ -76,7 +76,7 @@ export class Ref {
|
|
|
76
76
|
* @returns The resolved value.
|
|
77
77
|
*/
|
|
78
78
|
resolve(context) {
|
|
79
|
-
return this
|
|
79
|
+
return this.#resolver(context);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
export function ref(component, transform) {
|
package/dist/ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,GAAG;
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,GAAG;IACL,SAAS,CAAyC;IAE3D,YAAoB,QAAgD;QAClE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAmB,SAAiB;QAC3C,OAAO,IAAI,GAAG,CAAI,CAAC,OAAO,EAAE,EAAE;YAC5B,IAAI,CAAC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