@lorion-org/react 1.0.0-beta.1 → 1.0.0-beta.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 +51 -10
- package/dist/chunk-5FUI4JPB.js +38 -0
- package/dist/index.cjs +55 -4
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +24 -4
- package/dist/vite.cjs +111 -7
- package/dist/vite.d.cts +7 -3
- package/dist/vite.d.ts +7 -3
- package/dist/vite.js +76 -8
- package/package.json +17 -7
- package/src/index.ts +222 -0
- package/src/relations.ts +37 -0
- package/src/vite.ts +445 -0
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@ Use this package when a React application is assembled from local capability pac
|
|
|
10
10
|
pnpm add @lorion-org/react react
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
Host configs that import selection helpers from `@lorion-org/composition-graph`
|
|
14
|
+
should declare that package directly too.
|
|
15
|
+
|
|
13
16
|
Add Vite, TanStack Router, or another router in the host application as needed.
|
|
14
17
|
The runtime helpers do not own routing; the Vite entry point only prepares
|
|
15
18
|
capability discovery and TanStack-compatible virtual route config.
|
|
@@ -117,13 +120,10 @@ import { lorionReact } from '@lorion-org/react/vite';
|
|
|
117
120
|
The Vite helper discovers `capabilities/*/capability.json`, validates the descriptor shape with LORION, resolves selected descriptors through the LORION composition graph, resolves each package `./capability` export, and exposes `virtual:capabilities`.
|
|
118
121
|
|
|
119
122
|
```ts
|
|
120
|
-
const capabilityComposition = {
|
|
121
|
-
selected: ['default'],
|
|
122
|
-
};
|
|
123
123
|
const lorion = lorionReact({
|
|
124
124
|
workspaceRoot,
|
|
125
125
|
routesDirectory,
|
|
126
|
-
|
|
126
|
+
defaultSelection: ['default'],
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
export default defineConfig({
|
|
@@ -138,32 +138,59 @@ export default defineConfig({
|
|
|
138
138
|
});
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
By default the Vite helper reads the shared capability seed from
|
|
142
|
+
`--capabilities`, `npm_config_capabilities`, and `LORION_CAPABILITIES` before it
|
|
143
|
+
falls back to `defaultSelection`. No `selectionSeed.key` option is required for
|
|
144
|
+
that default. Pass `selectionSeed` only to override the seed names, inject custom
|
|
145
|
+
`argv`/`env` for tests, or set `selectionSeed: false` to disable CLI/env lookup.
|
|
146
|
+
|
|
147
|
+
Route config generation stays TanStack-focused and only includes enabled,
|
|
148
|
+
selected capability route directories. If no `selected`, seed value,
|
|
149
|
+
`defaultSelection`, or `baseDescriptors` are provided, every enabled local
|
|
150
|
+
capability remains active.
|
|
151
|
+
Use `indexRouteFile: false` when `/` is owned by a capability route.
|
|
152
|
+
|
|
153
|
+
The virtual module exports `capabilityModules`, `selectedCapabilityIds`, and
|
|
154
|
+
`resolvedCapabilityIds` so host code can distinguish the seed from the final
|
|
155
|
+
graph resolution.
|
|
142
156
|
|
|
143
157
|
## Provider Selection
|
|
144
158
|
|
|
145
|
-
Capabilities that implement another capability can declare `providesFor
|
|
159
|
+
Capabilities that implement another capability can declare `providesFor`.
|
|
160
|
+
Provider-owned defaults use `defaultFor` on the provider descriptor:
|
|
146
161
|
|
|
147
162
|
```json
|
|
148
163
|
{
|
|
149
164
|
"id": "payment-provider-stripe",
|
|
150
165
|
"version": "1.0.0",
|
|
151
|
-
"providesFor": "
|
|
166
|
+
"providesFor": "checkout",
|
|
167
|
+
"defaultFor": "checkout"
|
|
152
168
|
}
|
|
153
169
|
```
|
|
154
170
|
|
|
155
|
-
|
|
171
|
+
`providesFor` and `defaultFor` both accept a string or string array. If a
|
|
172
|
+
capability descriptor exists, `defaultFor` also creates the composition relation
|
|
173
|
+
from that capability to the default provider.
|
|
174
|
+
|
|
175
|
+
Profiles can still declare descriptor preferences with `providerPreferences`.
|
|
176
|
+
Use this when the profile, not the provider package, owns the default choice:
|
|
156
177
|
|
|
157
178
|
```json
|
|
158
179
|
{
|
|
159
180
|
"id": "web",
|
|
160
181
|
"version": "1.0.0",
|
|
161
182
|
"providerPreferences": {
|
|
162
|
-
"
|
|
183
|
+
"checkout": "payment-provider-stripe"
|
|
163
184
|
}
|
|
164
185
|
}
|
|
165
186
|
```
|
|
166
187
|
|
|
188
|
+
When a provider capability is explicitly selected through the normal selection
|
|
189
|
+
seed, the Vite helper removes lower-priority `defaultFor` and
|
|
190
|
+
`providerPreferences` relations for that capability before graph resolution.
|
|
191
|
+
That selected provider wins over descriptor defaults and preferences. A losing
|
|
192
|
+
provider is only present if another hard dependency still requires it.
|
|
193
|
+
|
|
167
194
|
Read the resolved provider selection from the runtime:
|
|
168
195
|
|
|
169
196
|
```ts
|
|
@@ -172,7 +199,16 @@ import { getCapabilityProviderSelection } from '@lorion-org/react';
|
|
|
172
199
|
const selection = getCapabilityProviderSelection(capabilityRuntime);
|
|
173
200
|
```
|
|
174
201
|
|
|
175
|
-
Explicit `configuredProviders` passed to `getCapabilityProviderSelection()`
|
|
202
|
+
Explicit `configuredProviders` passed to `getCapabilityProviderSelection()`
|
|
203
|
+
override selected providers, provider-owned defaults, and descriptor
|
|
204
|
+
preferences. `selectedProviders` can mirror the descriptor seed at runtime, and
|
|
205
|
+
`fallbackProviders` are merged with descriptor defaults and only used when no
|
|
206
|
+
configured or selected provider exists.
|
|
207
|
+
|
|
208
|
+
The React playground uses the first variant by default: Stripe declares
|
|
209
|
+
`defaultFor: "checkout"` and is selected as the fallback provider. Selecting
|
|
210
|
+
`web payment-provider-invoice` through the seed switches checkout to Invoice and
|
|
211
|
+
leaves Stripe out of the resolved capabilities.
|
|
176
212
|
|
|
177
213
|
## API
|
|
178
214
|
|
|
@@ -189,7 +225,12 @@ The package includes a React playground that mirrors the Nuxt package playground
|
|
|
189
225
|
pnpm --filter @lorion-org/react dev:playground
|
|
190
226
|
```
|
|
191
227
|
|
|
228
|
+
The playground scripts run with Lorion's `lorion-source` export condition so
|
|
229
|
+
local workspace package imports resolve to `src` instead of stale `dist` output.
|
|
230
|
+
|
|
192
231
|
The playground runs on `http://localhost:3200` and uses local demo capabilities under `playground/capabilities`.
|
|
232
|
+
Select a different profile or provider with `--capabilities=admin`,
|
|
233
|
+
`--capabilities=web,payment-provider-invoice`, or `LORION_CAPABILITIES="web payment-provider-invoice"`.
|
|
193
234
|
|
|
194
235
|
## Local Commands
|
|
195
236
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/relations.ts
|
|
2
|
+
var defaultCapabilityResolutionRelations = [
|
|
3
|
+
"dependencies",
|
|
4
|
+
"defaultProviders",
|
|
5
|
+
"providerPreferences"
|
|
6
|
+
];
|
|
7
|
+
var defaultCapabilityRelationDescriptors = [
|
|
8
|
+
{
|
|
9
|
+
direction: "incoming",
|
|
10
|
+
field: "defaultFor",
|
|
11
|
+
id: "defaultProviders"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
field: "providerPreferences",
|
|
15
|
+
id: "providerPreferences",
|
|
16
|
+
targetMode: "values"
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
function createCapabilityCompositionPolicy(policy) {
|
|
20
|
+
return {
|
|
21
|
+
...policy,
|
|
22
|
+
inspectionRelationIds: policy?.inspectionRelationIds ?? [
|
|
23
|
+
...defaultCapabilityResolutionRelations
|
|
24
|
+
],
|
|
25
|
+
provenanceRelationIds: policy?.provenanceRelationIds ?? [
|
|
26
|
+
...defaultCapabilityResolutionRelations
|
|
27
|
+
],
|
|
28
|
+
resolutionRelationIds: policy?.resolutionRelationIds ?? [
|
|
29
|
+
...defaultCapabilityResolutionRelations
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
defaultCapabilityResolutionRelations,
|
|
36
|
+
defaultCapabilityRelationDescriptors,
|
|
37
|
+
createCapabilityCompositionPolicy
|
|
38
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -21,8 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CapabilityRuntimeProvider: () => CapabilityRuntimeProvider,
|
|
24
|
+
createCapabilityCompositionPolicy: () => createCapabilityCompositionPolicy,
|
|
24
25
|
createCapabilityRuntime: () => createCapabilityRuntime,
|
|
25
26
|
createContributionContract: () => createContributionContract,
|
|
27
|
+
defaultCapabilityRelationDescriptors: () => defaultCapabilityRelationDescriptors,
|
|
28
|
+
defaultCapabilityResolutionRelations: () => defaultCapabilityResolutionRelations,
|
|
26
29
|
defineCapability: () => defineCapability,
|
|
27
30
|
defineContribution: () => defineContribution,
|
|
28
31
|
defineExtensionPoint: () => defineExtensionPoint,
|
|
@@ -33,6 +36,41 @@ module.exports = __toCommonJS(index_exports);
|
|
|
33
36
|
var import_react = require("react");
|
|
34
37
|
var import_composition_graph = require("@lorion-org/composition-graph");
|
|
35
38
|
var import_provider_selection = require("@lorion-org/provider-selection");
|
|
39
|
+
|
|
40
|
+
// src/relations.ts
|
|
41
|
+
var defaultCapabilityResolutionRelations = [
|
|
42
|
+
"dependencies",
|
|
43
|
+
"defaultProviders",
|
|
44
|
+
"providerPreferences"
|
|
45
|
+
];
|
|
46
|
+
var defaultCapabilityRelationDescriptors = [
|
|
47
|
+
{
|
|
48
|
+
direction: "incoming",
|
|
49
|
+
field: "defaultFor",
|
|
50
|
+
id: "defaultProviders"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
field: "providerPreferences",
|
|
54
|
+
id: "providerPreferences",
|
|
55
|
+
targetMode: "values"
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
function createCapabilityCompositionPolicy(policy) {
|
|
59
|
+
return {
|
|
60
|
+
...policy,
|
|
61
|
+
inspectionRelationIds: policy?.inspectionRelationIds ?? [
|
|
62
|
+
...defaultCapabilityResolutionRelations
|
|
63
|
+
],
|
|
64
|
+
provenanceRelationIds: policy?.provenanceRelationIds ?? [
|
|
65
|
+
...defaultCapabilityResolutionRelations
|
|
66
|
+
],
|
|
67
|
+
resolutionRelationIds: policy?.resolutionRelationIds ?? [
|
|
68
|
+
...defaultCapabilityResolutionRelations
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/index.ts
|
|
36
74
|
function defineExtensionPoint(id) {
|
|
37
75
|
return { id };
|
|
38
76
|
}
|
|
@@ -54,16 +92,25 @@ function getCapabilityProviderSelection(runtime, options = {}) {
|
|
|
54
92
|
items: descriptors,
|
|
55
93
|
getProviderPreferences: (descriptor) => descriptor.providerPreferences
|
|
56
94
|
});
|
|
57
|
-
const
|
|
95
|
+
const providerDefaults = (0, import_provider_selection.collectProviderDefaults)({
|
|
96
|
+
items: descriptors,
|
|
97
|
+
getDefaultFor: (descriptor) => descriptor.defaultFor,
|
|
98
|
+
getProviderId: (descriptor) => descriptor.id
|
|
99
|
+
});
|
|
100
|
+
const configuredProviders = options.configuredProviders ?? {};
|
|
101
|
+
const selectedProviders = options.selectedProviders ?? {};
|
|
102
|
+
const fallbackProviders = {
|
|
103
|
+
...providerDefaults,
|
|
58
104
|
...descriptorPreferences,
|
|
59
|
-
...options.
|
|
105
|
+
...options.fallbackProviders ?? {}
|
|
60
106
|
};
|
|
61
107
|
const resolution = (0, import_provider_selection.resolveItemProviderSelection)({
|
|
62
108
|
items: descriptors,
|
|
63
109
|
getCapabilityId: (descriptor) => descriptor.providesFor,
|
|
64
110
|
getProviderId: (descriptor) => descriptor.id,
|
|
65
111
|
configuredProviders,
|
|
66
|
-
|
|
112
|
+
fallbackProviders,
|
|
113
|
+
selectedProviders
|
|
67
114
|
});
|
|
68
115
|
return {
|
|
69
116
|
excludedProviderIds: resolution.excludedProviderIds,
|
|
@@ -138,14 +185,18 @@ function collectContributions(capabilities) {
|
|
|
138
185
|
}
|
|
139
186
|
function createCapabilityCatalog(capabilities) {
|
|
140
187
|
return (0, import_composition_graph.createDescriptorCatalog)({
|
|
141
|
-
descriptors: capabilities.map((capability) => capability.manifest)
|
|
188
|
+
descriptors: capabilities.map((capability) => capability.manifest),
|
|
189
|
+
relationDescriptors: defaultCapabilityRelationDescriptors
|
|
142
190
|
});
|
|
143
191
|
}
|
|
144
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
193
|
0 && (module.exports = {
|
|
146
194
|
CapabilityRuntimeProvider,
|
|
195
|
+
createCapabilityCompositionPolicy,
|
|
147
196
|
createCapabilityRuntime,
|
|
148
197
|
createContributionContract,
|
|
198
|
+
defaultCapabilityRelationDescriptors,
|
|
199
|
+
defaultCapabilityResolutionRelations,
|
|
149
200
|
defineCapability,
|
|
150
201
|
defineContribution,
|
|
151
202
|
defineExtensionPoint,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { Descriptor, DescriptorCatalog } from '@lorion-org/composition-graph';
|
|
2
|
+
import { CompositionPolicy, RelationDescriptor, Descriptor, DescriptorCatalog } from '@lorion-org/composition-graph';
|
|
3
3
|
import { ProviderPreferenceMap, ProviderSelectionResolution } from '@lorion-org/provider-selection';
|
|
4
4
|
|
|
5
|
+
declare const defaultCapabilityResolutionRelations: readonly ["dependencies", "defaultProviders", "providerPreferences"];
|
|
6
|
+
declare const defaultCapabilityRelationDescriptors: RelationDescriptor[];
|
|
7
|
+
declare function createCapabilityCompositionPolicy(policy?: Partial<CompositionPolicy>): Partial<CompositionPolicy>;
|
|
8
|
+
|
|
5
9
|
type CapabilityManifest = Descriptor & {
|
|
10
|
+
defaultFor?: string | string[];
|
|
6
11
|
description?: string;
|
|
7
12
|
providerPreferences?: ProviderPreferenceMap;
|
|
8
13
|
};
|
|
@@ -36,6 +41,7 @@ declare function createContributionContract<T>(id: string): ContributionContract
|
|
|
36
41
|
type CapabilityProviderSelectionOptions = {
|
|
37
42
|
configuredProviders?: ProviderPreferenceMap;
|
|
38
43
|
fallbackProviders?: ProviderPreferenceMap;
|
|
44
|
+
selectedProviders?: ProviderPreferenceMap;
|
|
39
45
|
};
|
|
40
46
|
declare function getCapabilityProviderSelection(runtime: CapabilityRuntime, options?: CapabilityProviderSelectionOptions): ProviderSelectionResolution;
|
|
41
47
|
declare function defineCapability(capability: RuntimeCapability): RuntimeCapability;
|
|
@@ -47,4 +53,4 @@ type CapabilityRuntimeProviderProps = {
|
|
|
47
53
|
declare function CapabilityRuntimeProvider({ children, runtime, }: CapabilityRuntimeProviderProps): ReactElement;
|
|
48
54
|
declare function useCapabilityRuntime(): CapabilityRuntime;
|
|
49
55
|
|
|
50
|
-
export { type CapabilityContribution, type CapabilityManifest, type CapabilityProviderSelectionOptions, type CapabilityRuntime, CapabilityRuntimeProvider, type CapabilityRuntimeProviderProps, type ContributionContract, type ExtensionPoint, type RuntimeCapability, createCapabilityRuntime, createContributionContract, defineCapability, defineContribution, defineExtensionPoint, getCapabilityProviderSelection, useCapabilityRuntime };
|
|
56
|
+
export { type CapabilityContribution, type CapabilityManifest, type CapabilityProviderSelectionOptions, type CapabilityRuntime, CapabilityRuntimeProvider, type CapabilityRuntimeProviderProps, type ContributionContract, type ExtensionPoint, type RuntimeCapability, createCapabilityCompositionPolicy, createCapabilityRuntime, createContributionContract, defaultCapabilityRelationDescriptors, defaultCapabilityResolutionRelations, defineCapability, defineContribution, defineExtensionPoint, getCapabilityProviderSelection, useCapabilityRuntime };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { Descriptor, DescriptorCatalog } from '@lorion-org/composition-graph';
|
|
2
|
+
import { CompositionPolicy, RelationDescriptor, Descriptor, DescriptorCatalog } from '@lorion-org/composition-graph';
|
|
3
3
|
import { ProviderPreferenceMap, ProviderSelectionResolution } from '@lorion-org/provider-selection';
|
|
4
4
|
|
|
5
|
+
declare const defaultCapabilityResolutionRelations: readonly ["dependencies", "defaultProviders", "providerPreferences"];
|
|
6
|
+
declare const defaultCapabilityRelationDescriptors: RelationDescriptor[];
|
|
7
|
+
declare function createCapabilityCompositionPolicy(policy?: Partial<CompositionPolicy>): Partial<CompositionPolicy>;
|
|
8
|
+
|
|
5
9
|
type CapabilityManifest = Descriptor & {
|
|
10
|
+
defaultFor?: string | string[];
|
|
6
11
|
description?: string;
|
|
7
12
|
providerPreferences?: ProviderPreferenceMap;
|
|
8
13
|
};
|
|
@@ -36,6 +41,7 @@ declare function createContributionContract<T>(id: string): ContributionContract
|
|
|
36
41
|
type CapabilityProviderSelectionOptions = {
|
|
37
42
|
configuredProviders?: ProviderPreferenceMap;
|
|
38
43
|
fallbackProviders?: ProviderPreferenceMap;
|
|
44
|
+
selectedProviders?: ProviderPreferenceMap;
|
|
39
45
|
};
|
|
40
46
|
declare function getCapabilityProviderSelection(runtime: CapabilityRuntime, options?: CapabilityProviderSelectionOptions): ProviderSelectionResolution;
|
|
41
47
|
declare function defineCapability(capability: RuntimeCapability): RuntimeCapability;
|
|
@@ -47,4 +53,4 @@ type CapabilityRuntimeProviderProps = {
|
|
|
47
53
|
declare function CapabilityRuntimeProvider({ children, runtime, }: CapabilityRuntimeProviderProps): ReactElement;
|
|
48
54
|
declare function useCapabilityRuntime(): CapabilityRuntime;
|
|
49
55
|
|
|
50
|
-
export { type CapabilityContribution, type CapabilityManifest, type CapabilityProviderSelectionOptions, type CapabilityRuntime, CapabilityRuntimeProvider, type CapabilityRuntimeProviderProps, type ContributionContract, type ExtensionPoint, type RuntimeCapability, createCapabilityRuntime, createContributionContract, defineCapability, defineContribution, defineExtensionPoint, getCapabilityProviderSelection, useCapabilityRuntime };
|
|
56
|
+
export { type CapabilityContribution, type CapabilityManifest, type CapabilityProviderSelectionOptions, type CapabilityRuntime, CapabilityRuntimeProvider, type CapabilityRuntimeProviderProps, type ContributionContract, type ExtensionPoint, type RuntimeCapability, createCapabilityCompositionPolicy, createCapabilityRuntime, createContributionContract, defaultCapabilityRelationDescriptors, defaultCapabilityResolutionRelations, defineCapability, defineContribution, defineExtensionPoint, getCapabilityProviderSelection, useCapabilityRuntime };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCapabilityCompositionPolicy,
|
|
3
|
+
defaultCapabilityRelationDescriptors,
|
|
4
|
+
defaultCapabilityResolutionRelations
|
|
5
|
+
} from "./chunk-5FUI4JPB.js";
|
|
6
|
+
|
|
1
7
|
// src/index.ts
|
|
2
8
|
import { createContext, createElement, useContext } from "react";
|
|
3
9
|
import {
|
|
@@ -5,6 +11,7 @@ import {
|
|
|
5
11
|
createDescriptorCatalog
|
|
6
12
|
} from "@lorion-org/composition-graph";
|
|
7
13
|
import {
|
|
14
|
+
collectProviderDefaults,
|
|
8
15
|
collectProviderPreferences,
|
|
9
16
|
resolveItemProviderSelection
|
|
10
17
|
} from "@lorion-org/provider-selection";
|
|
@@ -29,16 +36,25 @@ function getCapabilityProviderSelection(runtime, options = {}) {
|
|
|
29
36
|
items: descriptors,
|
|
30
37
|
getProviderPreferences: (descriptor) => descriptor.providerPreferences
|
|
31
38
|
});
|
|
32
|
-
const
|
|
39
|
+
const providerDefaults = collectProviderDefaults({
|
|
40
|
+
items: descriptors,
|
|
41
|
+
getDefaultFor: (descriptor) => descriptor.defaultFor,
|
|
42
|
+
getProviderId: (descriptor) => descriptor.id
|
|
43
|
+
});
|
|
44
|
+
const configuredProviders = options.configuredProviders ?? {};
|
|
45
|
+
const selectedProviders = options.selectedProviders ?? {};
|
|
46
|
+
const fallbackProviders = {
|
|
47
|
+
...providerDefaults,
|
|
33
48
|
...descriptorPreferences,
|
|
34
|
-
...options.
|
|
49
|
+
...options.fallbackProviders ?? {}
|
|
35
50
|
};
|
|
36
51
|
const resolution = resolveItemProviderSelection({
|
|
37
52
|
items: descriptors,
|
|
38
53
|
getCapabilityId: (descriptor) => descriptor.providesFor,
|
|
39
54
|
getProviderId: (descriptor) => descriptor.id,
|
|
40
55
|
configuredProviders,
|
|
41
|
-
|
|
56
|
+
fallbackProviders,
|
|
57
|
+
selectedProviders
|
|
42
58
|
});
|
|
43
59
|
return {
|
|
44
60
|
excludedProviderIds: resolution.excludedProviderIds,
|
|
@@ -113,13 +129,17 @@ function collectContributions(capabilities) {
|
|
|
113
129
|
}
|
|
114
130
|
function createCapabilityCatalog(capabilities) {
|
|
115
131
|
return createDescriptorCatalog({
|
|
116
|
-
descriptors: capabilities.map((capability) => capability.manifest)
|
|
132
|
+
descriptors: capabilities.map((capability) => capability.manifest),
|
|
133
|
+
relationDescriptors: defaultCapabilityRelationDescriptors
|
|
117
134
|
});
|
|
118
135
|
}
|
|
119
136
|
export {
|
|
120
137
|
CapabilityRuntimeProvider,
|
|
138
|
+
createCapabilityCompositionPolicy,
|
|
121
139
|
createCapabilityRuntime,
|
|
122
140
|
createContributionContract,
|
|
141
|
+
defaultCapabilityRelationDescriptors,
|
|
142
|
+
defaultCapabilityResolutionRelations,
|
|
123
143
|
defineCapability,
|
|
124
144
|
defineContribution,
|
|
125
145
|
defineExtensionPoint,
|
package/dist/vite.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/vite.ts
|
|
@@ -30,8 +40,45 @@ __export(vite_exports, {
|
|
|
30
40
|
module.exports = __toCommonJS(vite_exports);
|
|
31
41
|
var import_node_fs = require("fs");
|
|
32
42
|
var import_node_path = require("path");
|
|
43
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
33
44
|
var import_composition_graph = require("@lorion-org/composition-graph");
|
|
34
45
|
var import_descriptor_discovery = require("@lorion-org/descriptor-discovery");
|
|
46
|
+
var import_provider_selection = require("@lorion-org/provider-selection");
|
|
47
|
+
|
|
48
|
+
// src/relations.ts
|
|
49
|
+
var defaultCapabilityResolutionRelations = [
|
|
50
|
+
"dependencies",
|
|
51
|
+
"defaultProviders",
|
|
52
|
+
"providerPreferences"
|
|
53
|
+
];
|
|
54
|
+
var defaultCapabilityRelationDescriptors = [
|
|
55
|
+
{
|
|
56
|
+
direction: "incoming",
|
|
57
|
+
field: "defaultFor",
|
|
58
|
+
id: "defaultProviders"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
field: "providerPreferences",
|
|
62
|
+
id: "providerPreferences",
|
|
63
|
+
targetMode: "values"
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
function createCapabilityCompositionPolicy(policy) {
|
|
67
|
+
return {
|
|
68
|
+
...policy,
|
|
69
|
+
inspectionRelationIds: policy?.inspectionRelationIds ?? [
|
|
70
|
+
...defaultCapabilityResolutionRelations
|
|
71
|
+
],
|
|
72
|
+
provenanceRelationIds: policy?.provenanceRelationIds ?? [
|
|
73
|
+
...defaultCapabilityResolutionRelations
|
|
74
|
+
],
|
|
75
|
+
resolutionRelationIds: policy?.resolutionRelationIds ?? [
|
|
76
|
+
...defaultCapabilityResolutionRelations
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/vite.ts
|
|
35
82
|
var virtualModuleId = "virtual:capabilities";
|
|
36
83
|
var resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
37
84
|
function capabilityLoader(options = {}) {
|
|
@@ -53,7 +100,7 @@ function capabilityLoader(options = {}) {
|
|
|
53
100
|
},
|
|
54
101
|
load(id) {
|
|
55
102
|
if (id !== resolvedVirtualModuleId) return null;
|
|
56
|
-
return renderCapabilityModule(capabilities);
|
|
103
|
+
return renderCapabilityModule(capabilities, resolveSelectionSeed(options));
|
|
57
104
|
}
|
|
58
105
|
};
|
|
59
106
|
}
|
|
@@ -75,28 +122,85 @@ function discoverSelectedCapabilities(workspaceRoot, options = {}) {
|
|
|
75
122
|
}
|
|
76
123
|
function selectCapabilities(capabilities, options = {}) {
|
|
77
124
|
const enabledCapabilities = capabilities.filter((capability) => capability.disabled !== true);
|
|
78
|
-
|
|
125
|
+
const selected = resolveCapabilitySelectionSeed(options);
|
|
126
|
+
if (!selected.length && !options.baseDescriptors?.length) {
|
|
79
127
|
return [...enabledCapabilities];
|
|
80
128
|
}
|
|
129
|
+
const selectedProviders = (0, import_provider_selection.collectSelectedProviderPreferences)({
|
|
130
|
+
items: enabledCapabilities,
|
|
131
|
+
getCapabilityId: (capability) => capability.manifest.providesFor,
|
|
132
|
+
getProviderId: (capability) => capability.id,
|
|
133
|
+
selectedProviderIds: selected
|
|
134
|
+
});
|
|
135
|
+
const selectionCapabilities = createProviderSelectionAwareCapabilities(
|
|
136
|
+
enabledCapabilities,
|
|
137
|
+
selectedProviders
|
|
138
|
+
);
|
|
81
139
|
const catalog = (0, import_composition_graph.createDescriptorCatalog)({
|
|
82
|
-
descriptors:
|
|
140
|
+
descriptors: selectionCapabilities.map((capability) => capability.manifest),
|
|
141
|
+
relationDescriptors: [
|
|
142
|
+
...defaultCapabilityRelationDescriptors,
|
|
143
|
+
...options.relationDescriptors ?? []
|
|
144
|
+
]
|
|
83
145
|
});
|
|
84
146
|
const selection = (0, import_composition_graph.createCompositionSelection)({
|
|
85
147
|
catalog,
|
|
86
|
-
selected: [...
|
|
148
|
+
selected: [...selected],
|
|
87
149
|
baseDescriptors: [...options.baseDescriptors ?? []],
|
|
88
|
-
|
|
150
|
+
policy: createCapabilityCompositionPolicy(options.policy)
|
|
89
151
|
});
|
|
90
152
|
const selectedIds = new Set(selection.getResolved());
|
|
91
|
-
return
|
|
153
|
+
return selectionCapabilities.filter((capability) => selectedIds.has(capability.id));
|
|
154
|
+
}
|
|
155
|
+
function createProviderSelectionAwareCapabilities(capabilities, selectedProviders) {
|
|
156
|
+
if (!Object.keys(selectedProviders).length) return [...capabilities];
|
|
157
|
+
return capabilities.map((capability) => {
|
|
158
|
+
const manifest = { ...capability.manifest };
|
|
159
|
+
const preferences = (0, import_provider_selection.resolveSelectedProviderRelationPreferences)({
|
|
160
|
+
providerId: capability.id,
|
|
161
|
+
defaultFor: manifest.defaultFor,
|
|
162
|
+
providerPreferences: manifest.providerPreferences,
|
|
163
|
+
selectedProviders
|
|
164
|
+
});
|
|
165
|
+
delete manifest.defaultFor;
|
|
166
|
+
delete manifest.providerPreferences;
|
|
167
|
+
return {
|
|
168
|
+
...capability,
|
|
169
|
+
manifest: {
|
|
170
|
+
...manifest,
|
|
171
|
+
...preferences
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function resolveSelectionSeed(options) {
|
|
177
|
+
return resolveCapabilitySelectionSeed(options);
|
|
92
178
|
}
|
|
93
|
-
function
|
|
179
|
+
function resolveCapabilitySelectionSeed(options) {
|
|
180
|
+
if (options.selected?.length) return [...options.selected];
|
|
181
|
+
if (options.selectionSeed === false) return [...options.defaultSelection ?? []];
|
|
182
|
+
const seedOptions = options.selectionSeed ?? {};
|
|
183
|
+
const selected = (0, import_composition_graph.resolveDescriptorSelectionSeed)({
|
|
184
|
+
argv: seedOptions.argv ?? import_node_process.default.argv,
|
|
185
|
+
env: seedOptions.env ?? import_node_process.default.env,
|
|
186
|
+
key: seedOptions.key ?? "capability",
|
|
187
|
+
...seedOptions.cliKeys ? { cliKeys: seedOptions.cliKeys } : {},
|
|
188
|
+
...seedOptions.envKeys ? { envKeys: seedOptions.envKeys } : {}
|
|
189
|
+
});
|
|
190
|
+
return selected.length ? selected : [...options.defaultSelection ?? []];
|
|
191
|
+
}
|
|
192
|
+
function renderCapabilityModule(capabilities, selected = []) {
|
|
94
193
|
const imports = capabilities.map(
|
|
95
194
|
(capability) => `import { capability as ${capability.variableName} } from '${capability.importSpecifier}'`
|
|
96
195
|
).join("\n");
|
|
97
196
|
const variables = capabilities.map((capability) => ` ${capability.variableName},`).join("\n");
|
|
197
|
+
const capabilityIds = capabilities.map((capability) => capability.id);
|
|
98
198
|
return `${imports}
|
|
99
199
|
|
|
200
|
+
export const selectedCapabilityIds = ${JSON.stringify([...selected])}
|
|
201
|
+
|
|
202
|
+
export const resolvedCapabilityIds = ${JSON.stringify(capabilityIds)}
|
|
203
|
+
|
|
100
204
|
export const capabilityModules = [
|
|
101
205
|
${variables}
|
|
102
206
|
]
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { DescriptorId, CompositionPolicy, Descriptor } from '@lorion-org/composition-graph';
|
|
1
|
+
import { DescriptorId, CompositionPolicy, RelationDescriptor, DescriptorSelectionSeedInput, Descriptor } from '@lorion-org/composition-graph';
|
|
2
2
|
|
|
3
3
|
type CapabilityLoaderOptions = {
|
|
4
4
|
capabilitiesDir?: string;
|
|
5
5
|
baseDescriptors?: readonly DescriptorId[];
|
|
6
|
+
defaultSelection?: readonly DescriptorId[];
|
|
6
7
|
policy?: Partial<CompositionPolicy>;
|
|
8
|
+
relationDescriptors?: readonly RelationDescriptor[];
|
|
7
9
|
selected?: readonly DescriptorId[];
|
|
10
|
+
selectionSeed?: false | CapabilitySelectionSeedOptions;
|
|
8
11
|
workspaceRoot?: string;
|
|
9
12
|
};
|
|
13
|
+
type CapabilitySelectionSeedOptions = Omit<DescriptorSelectionSeedInput, 'defaultValue'>;
|
|
10
14
|
type CapabilityRouteConfigOptions = CapabilityLoaderOptions & {
|
|
11
15
|
indexRouteFile?: false | string;
|
|
12
16
|
routesDirectory: string;
|
|
@@ -55,7 +59,7 @@ declare function capabilityLoader(options?: CapabilityLoaderOptions): VitePlugin
|
|
|
55
59
|
declare function lorionReact(options: LorionReactViteOptions): LorionReactViteSetup;
|
|
56
60
|
declare function discoverCapabilities(workspaceRoot: string, options?: Pick<CapabilityLoaderOptions, 'capabilitiesDir'>): DiscoveredCapability[];
|
|
57
61
|
declare function discoverSelectedCapabilities(workspaceRoot: string, options?: CapabilityLoaderOptions): DiscoveredCapability[];
|
|
58
|
-
declare function renderCapabilityModule(capabilities: readonly DiscoveredCapability[]): string;
|
|
62
|
+
declare function renderCapabilityModule(capabilities: readonly DiscoveredCapability[], selected?: readonly DescriptorId[]): string;
|
|
59
63
|
declare function createCapabilityRouteConfig(options: CapabilityRouteConfigOptions): VirtualRootRoute;
|
|
60
64
|
|
|
61
|
-
export { type CapabilityLoaderOptions, type CapabilityRouteConfigOptions, type DiscoveredCapability, type LorionReactViteOptions, type LorionReactViteSetup, type VirtualIndexRoute, type VirtualPhysicalRouteSubtree, type VirtualRootRoute, type VitePlugin, type ViteResolvedConfig, capabilityLoader, createCapabilityRouteConfig, discoverCapabilities, discoverSelectedCapabilities, lorionReact, renderCapabilityModule };
|
|
65
|
+
export { type CapabilityLoaderOptions, type CapabilityRouteConfigOptions, type CapabilitySelectionSeedOptions, type DiscoveredCapability, type LorionReactViteOptions, type LorionReactViteSetup, type VirtualIndexRoute, type VirtualPhysicalRouteSubtree, type VirtualRootRoute, type VitePlugin, type ViteResolvedConfig, capabilityLoader, createCapabilityRouteConfig, discoverCapabilities, discoverSelectedCapabilities, lorionReact, renderCapabilityModule };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { DescriptorId, CompositionPolicy, Descriptor } from '@lorion-org/composition-graph';
|
|
1
|
+
import { DescriptorId, CompositionPolicy, RelationDescriptor, DescriptorSelectionSeedInput, Descriptor } from '@lorion-org/composition-graph';
|
|
2
2
|
|
|
3
3
|
type CapabilityLoaderOptions = {
|
|
4
4
|
capabilitiesDir?: string;
|
|
5
5
|
baseDescriptors?: readonly DescriptorId[];
|
|
6
|
+
defaultSelection?: readonly DescriptorId[];
|
|
6
7
|
policy?: Partial<CompositionPolicy>;
|
|
8
|
+
relationDescriptors?: readonly RelationDescriptor[];
|
|
7
9
|
selected?: readonly DescriptorId[];
|
|
10
|
+
selectionSeed?: false | CapabilitySelectionSeedOptions;
|
|
8
11
|
workspaceRoot?: string;
|
|
9
12
|
};
|
|
13
|
+
type CapabilitySelectionSeedOptions = Omit<DescriptorSelectionSeedInput, 'defaultValue'>;
|
|
10
14
|
type CapabilityRouteConfigOptions = CapabilityLoaderOptions & {
|
|
11
15
|
indexRouteFile?: false | string;
|
|
12
16
|
routesDirectory: string;
|
|
@@ -55,7 +59,7 @@ declare function capabilityLoader(options?: CapabilityLoaderOptions): VitePlugin
|
|
|
55
59
|
declare function lorionReact(options: LorionReactViteOptions): LorionReactViteSetup;
|
|
56
60
|
declare function discoverCapabilities(workspaceRoot: string, options?: Pick<CapabilityLoaderOptions, 'capabilitiesDir'>): DiscoveredCapability[];
|
|
57
61
|
declare function discoverSelectedCapabilities(workspaceRoot: string, options?: CapabilityLoaderOptions): DiscoveredCapability[];
|
|
58
|
-
declare function renderCapabilityModule(capabilities: readonly DiscoveredCapability[]): string;
|
|
62
|
+
declare function renderCapabilityModule(capabilities: readonly DiscoveredCapability[], selected?: readonly DescriptorId[]): string;
|
|
59
63
|
declare function createCapabilityRouteConfig(options: CapabilityRouteConfigOptions): VirtualRootRoute;
|
|
60
64
|
|
|
61
|
-
export { type CapabilityLoaderOptions, type CapabilityRouteConfigOptions, type DiscoveredCapability, type LorionReactViteOptions, type LorionReactViteSetup, type VirtualIndexRoute, type VirtualPhysicalRouteSubtree, type VirtualRootRoute, type VitePlugin, type ViteResolvedConfig, capabilityLoader, createCapabilityRouteConfig, discoverCapabilities, discoverSelectedCapabilities, lorionReact, renderCapabilityModule };
|
|
65
|
+
export { type CapabilityLoaderOptions, type CapabilityRouteConfigOptions, type CapabilitySelectionSeedOptions, type DiscoveredCapability, type LorionReactViteOptions, type LorionReactViteSetup, type VirtualIndexRoute, type VirtualPhysicalRouteSubtree, type VirtualRootRoute, type VitePlugin, type ViteResolvedConfig, capabilityLoader, createCapabilityRouteConfig, discoverCapabilities, discoverSelectedCapabilities, lorionReact, renderCapabilityModule };
|