@plugmatica/plugin-sdk 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/externalNavigation.ts","../src/runtime.tsx"],"names":[],"mappings":";;;;;;AAMO,SAAS,4BAA4B,WAAA,EAA6B;AACvE,EAAA,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,WAAA,CAAY,SAAS,IAAA,EAAM;AAChE,IAAA,MAAM,IAAI,MAAM,qCAAqC,CAAA;AAAA,EACvD;AACA,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,IAAI,IAAI,WAAW,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,MAAM,qCAAqC,CAAA;AAAA,EACvD;AACA,EAAA,IAAI,GAAA,CAAI,QAAA,KAAa,QAAA,IAAY,CAAC,GAAA,CAAI,YAAY,GAAA,CAAI,IAAA,IAAQ,GAAA,CAAI,IAAA,KAAS,KAAA,IACpE,GAAA,CAAI,YAAY,GAAA,CAAI,QAAA,IAAY,GAAA,CAAI,IAAA,IACpC,CAAC,GAAA,CAAI,QAAA,CAAS,QAAA,CAAS,GAAG,CAAA,IAAK,GAAA,CAAI,QAAA,KAAa,WAAA,EAAa;AAClE,IAAA,MAAM,IAAI,MAAM,mFAAmF,CAAA;AAAA,EACrG;AACA,EAAA,OAAO,IAAI,QAAA,EAAS;AACtB;ACwCA,IAAM,iBAAA,GAAyC;AAAA,EAC7C,QAAA,CAAS,IAAI,OAAA,EAAS;AACpB,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAEA,IAAA,IAAI,SAAS,OAAA,EAAS;AACpB,MAAA,MAAA,CAAO,QAAA,CAAS,QAAQ,EAAE,CAAA;AAAA,IAC5B,CAA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AAS,aAAA,CAAc,EAAE,EAAA,EAAI,MAAA,EAAO,EAAuB;AAChE,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,aAAA,EAAc;AAC5B,EAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAG,QAAA,EAAA,CAAA,CAAE,EAAA,EAAI,MAAM,CAAA,EAAE,CAAA;AAC1B;AAOO,IAAM,gBAAA,GAAmB,MAAM,gBAAA,EAAiB,CAAE;AAMlD,IAAM,qBAAA,GAAwB,MAAM,gBAAA,EAAiB,CAAE","file":"chunk-ACHELRPS.js","sourcesContent":["/**\n * Validate an explicit, full-document external navigation destination.\n * SPA navigation must continue to use PluginNavigationApi.navigate().\n * Only secure browser destinations, never javascript:/data:/relative URLs,\n * may cross this host-managed boundary.\n */\nexport function assertExternalNavigationUrl(destination: string): string {\n if (typeof destination !== \"string\" || destination.length > 4096) {\n throw new Error(\"External navigation URL is invalid.\");\n }\n let url: URL;\n try {\n url = new URL(destination);\n } catch {\n throw new Error(\"External navigation URL is invalid.\");\n }\n if (url.protocol !== \"https:\" || !url.hostname || url.port && url.port !== \"443\"\n || url.username || url.password || url.hash\n || !url.hostname.includes(\".\") || url.hostname === \"localhost\") {\n throw new Error(\"External navigation requires a public HTTPS URL without credentials or fragments.\");\n }\n return url.toString();\n}\n","import { useScopedI18n, type TranslationValues } from \"@plugmatica/i18n\";\nimport {\n UiExtensionRuntimeProvider,\n type UiExtensionRuntime,\n} from \"@plugmatica/ui-kit/host\";\nimport * as React from \"react\";\n\nimport { assertExternalNavigationUrl } from \"./externalNavigation\";\n\nimport type {\n PluginApiClient,\n PluginExtensionsApi,\n PluginGuestSessionApi,\n PluginI18nApi,\n PluginNavigationApi,\n PluginManagedResourceApi,\n PluginRenderContext,\n PluginSession,\n PluginWorkflowManagementApi,\n PluginWorkflowRealtimeApi,\n} from \"./types\";\n\n/**\n * Public type contract for plugin runtime.\n */\nexport type PluginRuntime = {\n /**\n * Scoped plugin render context.\n */\n context: PluginRenderContext;\n /**\n * Plugin-scoped API client.\n */\n api: PluginApiClient;\n /**\n * Plugin-scoped internationalization API.\n */\n i18n: PluginI18nApi;\n /**\n * Current runtime session.\n */\n session: PluginSession;\n /**\n * Guest-session lifecycle API when running in guest mode.\n */\n guest?: PluginGuestSessionApi;\n /**\n * Host navigation capability.\n */\n navigation: PluginNavigationApi;\n /** Narrow host-mediated workflow management capability when granted by the host. */\n workflows?: PluginWorkflowManagementApi;\n /** Resource-scoped workflow realtime subscriptions, only when granted by the host. */\n workflowRealtime?: PluginWorkflowRealtimeApi;\n /** Host-mediated managed-resource capability when granted by the host. */\n managedResources?: PluginManagedResourceApi;\n /**\n * Extension-runtime capability set.\n */\n extensions: PluginExtensionsApi;\n};\n\nconst defaultNavigation: PluginNavigationApi = {\n navigate(to, options) {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"Plugin navigation is unavailable outside a browser host.\",\n );\n }\n\n if (options?.replace) {\n window.location.replace(to);\n } else {\n window.location.assign(to);\n }\n },\n navigateExternal(url) {\n if (typeof window === \"undefined\") {\n throw new Error(\"External navigation is unavailable outside a browser host.\");\n }\n window.location.assign(assertExternalNavigationUrl(url));\n },\n currentPath() {\n return typeof window === \"undefined\"\n ? \"/\"\n : `${window.location.pathname}${window.location.search}${window.location.hash}`;\n },\n subscribe(listener) {\n if (typeof window === \"undefined\") return () => undefined;\n window.addEventListener(\"popstate\", listener);\n window.addEventListener(\"hashchange\", listener);\n return () => {\n window.removeEventListener(\"popstate\", listener);\n window.removeEventListener(\"hashchange\", listener);\n };\n },\n};\n\nconst defaultExtensions: PluginExtensionsApi = {\n registerSurface: () => undefined,\n renderUi: ({ emptyFallback }) => emptyFallback ?? null,\n resolveUi: async () => [],\n runOperation: async ({ payload, execute }) => ({\n status: \"completed\",\n execution: \"owner\",\n result: await execute(payload),\n }),\n emitEvent: async () => undefined,\n resolveProviders: async () => [],\n reportDiagnostic: () => undefined,\n};\n\nfunction missingApiMethod(method: string): never {\n throw new Error(\n `Plugin API method '${method}' is not configured. Ensure PluginRenderer receives a scoped API client.`,\n );\n}\n\nconst defaultApi: PluginApiClient = {\n get: async () => missingApiMethod(\"GET\"),\n getBlob: async () => missingApiMethod(\"GET Blob\"),\n getTransferBlob: async () => missingApiMethod(\"GET Blob Transfer\"),\n uploadTransfer: async () => missingApiMethod(\"PUT Blob Transfer\"),\n getArrayBuffer: async () => missingApiMethod(\"GET ArrayBuffer\"),\n post: async () => missingApiMethod(\"POST\"),\n put: async () => missingApiMethod(\"PUT\"),\n patch: async () => missingApiMethod(\"PATCH\"),\n delete: async () => missingApiMethod(\"DELETE\"),\n getWithMeta: async () => missingApiMethod(\"GET metadata\"),\n postWithMeta: async () => missingApiMethod(\"POST metadata\"),\n putWithMeta: async () => missingApiMethod(\"PUT metadata\"),\n patchWithMeta: async () => missingApiMethod(\"PATCH metadata\"),\n deleteWithMeta: async () => missingApiMethod(\"DELETE metadata\"),\n};\n\n/**\n * Create the normalized runtime capabilities consumed by plugin hooks and providers.\n *\n * @param context Scoped runtime context for this callback/operation.\n * @returns Normalized runtime used by `PluginRuntimeProvider` and SDK hooks.\n */\nexport function createPluginRuntime(\n context: PluginRenderContext,\n): PluginRuntime {\n return {\n context,\n api: context.api ?? defaultApi,\n i18n: context.i18n,\n session: context.session,\n guest: context.guest,\n navigation: context.navigation ?? defaultNavigation,\n workflows: context.workflows,\n workflowRealtime: context.workflowRealtime,\n managedResources: context.managedResources,\n extensions: context.extensions ?? defaultExtensions,\n };\n}\n\nconst PluginRuntimeContext = React.createContext<PluginRuntime | null>(null);\n\n/**\n * Provide one normalized plugin runtime to SDK hooks and the UI extension runtime.\n *\n * @param props Component/provider properties.\n * @returns React provider element that makes the supplied plugin runtime available to descendant SDK hooks.\n */\nexport function PluginRuntimeProvider({\n value,\n children,\n}: {\n value: PluginRuntime;\n children: React.ReactNode;\n}) {\n const extensions = value.extensions;\n const extensionEnvironmentKey = value.navigation.currentPath();\n\n const uiRuntime = React.useMemo<UiExtensionRuntime>(\n () => ({\n ownerPluginIdentifier: value.context.plugin.identifier,\n registerSurface: extensions.registerSurface,\n renderUi: extensions.renderUi,\n resolveUi: extensions.resolveUi,\n runOperation: extensions.runOperation,\n emitEvent: extensions.emitEvent,\n resolveProviders: extensions.resolveProviders,\n reportDiagnostic: extensions.reportDiagnostic,\n }),\n [\n value.context.plugin.identifier,\n extensions.registerSurface,\n extensions.renderUi,\n extensions.resolveUi,\n extensions.runOperation,\n extensions.emitEvent,\n extensions.resolveProviders,\n extensions.reportDiagnostic,\n ],\n );\n return (\n <PluginRuntimeContext.Provider value={value}>\n <UiExtensionRuntimeProvider\n runtime={uiRuntime}\n environmentKey={extensionEnvironmentKey}\n >\n {children}\n </UiExtensionRuntimeProvider>\n </PluginRuntimeContext.Provider>\n );\n}\n\nfunction usePluginRuntime(): PluginRuntime {\n const runtime = React.useContext(PluginRuntimeContext);\n if (!runtime) {\n throw new Error(\n \"Plugin runtime is unavailable. Render plugin content through PluginRenderer or PluginRuntimeProvider.\",\n );\n }\n return runtime;\n}\n\n/**\n * Return the host-supplied render context for the current plugin.\n *\n * @returns Current plugin render context.\n */\nexport const usePluginContext = () => usePluginRuntime().context;\n/**\n * Return the plugin-scoped API client for the current plugin.\n *\n * @returns Current plugin-scoped API client.\n *\n * @example\n * ```tsx\n * const api = usePluginApi();\n * const customer = await api.get<Customer>(`/customers/${customerPid}`);\n * ```\n */\nexport const usePluginApi = () => usePluginRuntime().api;\n/**\n * Return extension-runtime capabilities scoped to the current plugin.\n *\n * @returns Current plugin extension-runtime API.\n */\nexport const usePluginExtensions = () => usePluginRuntime().extensions;\n/**\n * Return the host navigation capability for the current plugin.\n *\n * @returns Current host navigation API.\n *\n * @example\n * ```tsx\n * const navigation = usePluginNavigation();\n * await navigation.navigate(`/customers/${customerPid}`);\n * ```\n */\nexport const usePluginNavigation = () => usePluginRuntime().navigation;\n/** Return workflow management when the host explicitly grants it to this plugin. */\nexport const usePluginWorkflows = (): PluginWorkflowManagementApi => {\n const workflows = usePluginRuntime().workflows;\n if (!workflows)\n throw new Error(\n \"Workflow management capability is unavailable for this plugin.\",\n );\n return workflows;\n};\n\n/** Optional realtime feature. Missing means the existing REST path stays active. */\nexport const usePluginWorkflowRealtime = (): PluginWorkflowRealtimeApi | undefined =>\n usePluginRuntime().workflowRealtime;\n\n/** Return managed-resource administration when the host explicitly grants it to this plugin. */\nexport const usePluginManagedResources = (): PluginManagedResourceApi => {\n const managedResources = usePluginRuntime().managedResources;\n if (!managedResources)\n throw new Error(\n \"Managed resource capability is unavailable for this plugin.\",\n );\n return managedResources;\n};\n\n/**\n * Return the translation API scoped to the current plugin namespace.\n * Shared platform vocabulary remains available through `$common` and `$terms`.\n *\n * @returns Scoped translation API for the current plugin.\n *\n * @example\n * ```tsx\n * const { t } = usePluginI18n();\n * return <Button>{t(\"actions.save\")}</Button>;\n * ```\n */\nexport function usePluginI18n(): PluginI18nApi {\n return useScopedI18n(usePluginRuntime().i18n);\n}\n\n/**\n * Props for {@link PluginMessage}.\n *\n * `id` uses the same plugin-local/shared translation-reference rules as\n * {@link usePluginI18n}. Values are forwarded to ICU message formatting.\n */\nexport type PluginMessageProps = {\n /** Static plugin-local or shared translation reference. */\n id: string;\n /** Optional ICU interpolation/pluralisation values. */\n values?: TranslationValues;\n};\n\n/**\n * Render one translated message at the point a static descriptor is rendered.\n *\n * This is intentionally a render-boundary component, not a second translation\n * API. Normal components should continue to call {@link usePluginI18n}. Use\n * `PluginMessage` when a module-level/static descriptor needs translated React\n * content without moving that descriptor into a hook-owning component.\n *\n * The plugin build scanner recognises static `id` values here exactly like\n * `t(\"...\")`, so local and shared catalogue dependencies remain build-time\n * discoverable.\n *\n * @example\n * ```tsx\n * const columns = [\n * {\n * accessorKey: \"name\",\n * header: () => <PluginMessage id=\"customers.name\" />,\n * },\n * ];\n * ```\n */\nexport function PluginMessage({ id, values }: PluginMessageProps) {\n const { t } = usePluginI18n();\n return <>{t(id, values)}</>;\n}\n\n/**\n * Return the current plugin session.\n *\n * @returns Current runtime session.\n */\nexport const usePluginSession = () => usePluginRuntime().session;\n/**\n * Return guest-session lifecycle controls when the plugin is running in public or kiosk mode.\n *\n * @returns Guest-session API, or `undefined` for authenticated runtimes.\n */\nexport const usePluginGuestSession = () => usePluginRuntime().guest;\n"]}
@@ -0,0 +1,256 @@
1
+ // src/ExtensionIndex.ts
2
+ var EMPTY_UI = Object.freeze([]);
3
+ var EMPTY_OPERATION_HOOKS = Object.freeze(
4
+ []
5
+ );
6
+ var EMPTY_EVENTS = Object.freeze(
7
+ []
8
+ );
9
+ var EMPTY_PROVIDERS = Object.freeze(
10
+ []
11
+ );
12
+ var ExtensionIndex = class {
13
+ #ui;
14
+ #uiBySurface;
15
+ #operationHooks;
16
+ #operationHooksBySurface;
17
+ #events;
18
+ #providers;
19
+ /**
20
+ * Return every indexed extension in deterministic order.
21
+ */
22
+ all;
23
+ /**
24
+ * Return counts for the indexed extension set.
25
+ */
26
+ stats;
27
+ constructor(extensions) {
28
+ const ui = /* @__PURE__ */ new Map();
29
+ const uiBySurface = /* @__PURE__ */ new Map();
30
+ const operationHooks = /* @__PURE__ */ new Map();
31
+ const operationHooksBySurface = /* @__PURE__ */ new Map();
32
+ const events = /* @__PURE__ */ new Map();
33
+ const providers = /* @__PURE__ */ new Map();
34
+ let uiCount = 0;
35
+ let operationHookCount = 0;
36
+ let eventCount = 0;
37
+ let providerCount = 0;
38
+ for (const extension of extensions) {
39
+ switch (extension.kind) {
40
+ case "ui": {
41
+ uiCount += 1;
42
+ addBucket(
43
+ ui,
44
+ uiTargetKey(
45
+ extension.targetPluginIdentifier,
46
+ extension.target.surface,
47
+ extension.target.key,
48
+ extension.target.point
49
+ ),
50
+ extension
51
+ );
52
+ addBucket(
53
+ uiBySurface,
54
+ surfaceTargetKey(
55
+ extension.targetPluginIdentifier,
56
+ extension.target.surface,
57
+ extension.target.key
58
+ ),
59
+ extension
60
+ );
61
+ break;
62
+ }
63
+ case "operation_hook": {
64
+ operationHookCount += 1;
65
+ addBucket(
66
+ operationHooks,
67
+ operationTargetKey(
68
+ extension.targetPluginIdentifier,
69
+ extension.target.surface,
70
+ extension.target.key,
71
+ extension.target.operation
72
+ ),
73
+ extension
74
+ );
75
+ addBucket(
76
+ operationHooksBySurface,
77
+ surfaceTargetKey(
78
+ extension.targetPluginIdentifier,
79
+ extension.target.surface,
80
+ extension.target.key
81
+ ),
82
+ extension
83
+ );
84
+ break;
85
+ }
86
+ case "event_handler": {
87
+ eventCount += 1;
88
+ addBucket(
89
+ events,
90
+ namedTargetKey(
91
+ extension.targetPluginIdentifier,
92
+ extension.target.event
93
+ ),
94
+ extension
95
+ );
96
+ break;
97
+ }
98
+ case "provider": {
99
+ providerCount += 1;
100
+ addBucket(
101
+ providers,
102
+ namedTargetKey(
103
+ extension.targetPluginIdentifier,
104
+ extension.target.provider
105
+ ),
106
+ extension
107
+ );
108
+ break;
109
+ }
110
+ }
111
+ }
112
+ this.#ui = freezeBuckets(ui);
113
+ this.#uiBySurface = freezeBuckets(uiBySurface);
114
+ this.#operationHooks = freezeBuckets(operationHooks);
115
+ this.#operationHooksBySurface = freezeBuckets(operationHooksBySurface);
116
+ this.#events = freezeBuckets(events);
117
+ this.#providers = freezeBuckets(providers);
118
+ this.all = Object.freeze([...extensions].sort(compareExtensions));
119
+ this.stats = Object.freeze({
120
+ total: extensions.length,
121
+ ui: uiCount,
122
+ operationHooks: operationHookCount,
123
+ events: eventCount,
124
+ providers: providerCount,
125
+ uiBuckets: this.#ui.size,
126
+ operationBuckets: this.#operationHooks.size,
127
+ eventBuckets: this.#events.size,
128
+ providerBuckets: this.#providers.size
129
+ });
130
+ }
131
+ /**
132
+ * Return UI extensions matching a target plugin/surface/key/point.
133
+ *
134
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
135
+ * @param surface Semantic UI extension surface.
136
+ * @param surfaceKey Stable semantic surface key.
137
+ * @param point Extension point within the surface.
138
+ * @returns Result returned by ui.
139
+ */
140
+ ui(targetPluginIdentifier, surface, surfaceKey, point) {
141
+ return this.#ui.get(
142
+ uiTargetKey(targetPluginIdentifier, surface, surfaceKey, point)
143
+ ) ?? EMPTY_UI;
144
+ }
145
+ /**
146
+ * Return operation hooks matching a target operation.
147
+ *
148
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
149
+ * @param surface Extension surface to query.
150
+ * @param surfaceKey Stable semantic key for the target surface.
151
+ * @param operation Operation contract name.
152
+ * @returns Result returned by operationHooks.
153
+ */
154
+ operationHooks(targetPluginIdentifier, surface, surfaceKey, operation) {
155
+ return this.#operationHooks.get(
156
+ operationTargetKey(
157
+ targetPluginIdentifier,
158
+ surface,
159
+ surfaceKey,
160
+ operation
161
+ )
162
+ ) ?? EMPTY_OPERATION_HOOKS;
163
+ }
164
+ /**
165
+ * Return event handlers matching a target event.
166
+ *
167
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
168
+ * @param event Event contract name.
169
+ * @returns Result returned by events.
170
+ */
171
+ events(targetPluginIdentifier, event) {
172
+ return this.#events.get(namedTargetKey(targetPluginIdentifier, event)) ?? EMPTY_EVENTS;
173
+ }
174
+ /**
175
+ * Return providers matching a target provider contract.
176
+ *
177
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
178
+ * @param provider Provider contract name.
179
+ * @returns Result returned by providers.
180
+ */
181
+ providers(targetPluginIdentifier, provider) {
182
+ return this.#providers.get(namedTargetKey(targetPluginIdentifier, provider)) ?? EMPTY_PROVIDERS;
183
+ }
184
+ /**
185
+ * Return all UI extensions registered for one semantic surface instance.
186
+ *
187
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
188
+ * @param surface Extension surface to query.
189
+ * @param surfaceKey Stable semantic key for the target surface.
190
+ * @returns Result returned by uiForSurface.
191
+ */
192
+ uiForSurface(targetPluginIdentifier, surface, surfaceKey) {
193
+ return this.#uiBySurface.get(
194
+ surfaceTargetKey(targetPluginIdentifier, surface, surfaceKey)
195
+ ) ?? EMPTY_UI;
196
+ }
197
+ /**
198
+ * Return all operation hooks registered for one semantic surface.
199
+ *
200
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
201
+ * @param surface Extension surface to query.
202
+ * @param surfaceKey Stable semantic key for the target surface.
203
+ * @returns Result returned by operationHooksForSurface.
204
+ */
205
+ operationHooksForSurface(targetPluginIdentifier, surface, surfaceKey) {
206
+ return this.#operationHooksBySurface.get(
207
+ surfaceTargetKey(targetPluginIdentifier, surface, surfaceKey)
208
+ ) ?? EMPTY_OPERATION_HOOKS;
209
+ }
210
+ };
211
+ function createExtensionIndex(extensions) {
212
+ return new ExtensionIndex(extensions);
213
+ }
214
+ function compareRuntimeExtensions(left, right) {
215
+ return left.order - right.order || left.id.localeCompare(right.id);
216
+ }
217
+ function extensionTargetPart(value) {
218
+ return `${value.length}:${value}`;
219
+ }
220
+ function surfaceTargetKey(targetPluginIdentifier, surface, surfaceKey) {
221
+ return joinTarget(targetPluginIdentifier, surface, surfaceKey);
222
+ }
223
+ function uiTargetKey(targetPluginIdentifier, surface, surfaceKey, point) {
224
+ return joinTarget(targetPluginIdentifier, surface, surfaceKey, point);
225
+ }
226
+ function operationTargetKey(targetPluginIdentifier, surface, surfaceKey, operation) {
227
+ return joinTarget(targetPluginIdentifier, surface, surfaceKey, operation);
228
+ }
229
+ function namedTargetKey(targetPluginIdentifier, name) {
230
+ return joinTarget(targetPluginIdentifier, name);
231
+ }
232
+ function joinTarget(...parts) {
233
+ return parts.map(extensionTargetPart).join("");
234
+ }
235
+ function addBucket(buckets, key, extension) {
236
+ const existing = buckets.get(key);
237
+ if (existing) {
238
+ existing.push(extension);
239
+ } else {
240
+ buckets.set(key, [extension]);
241
+ }
242
+ }
243
+ function freezeBuckets(buckets) {
244
+ const result = /* @__PURE__ */ new Map();
245
+ for (const [key, values] of buckets) {
246
+ result.set(key, Object.freeze(values.sort(compareExtensions)));
247
+ }
248
+ return result;
249
+ }
250
+ function compareExtensions(left, right) {
251
+ return compareRuntimeExtensions(left, right);
252
+ }
253
+
254
+ export { ExtensionIndex, compareRuntimeExtensions, createExtensionIndex, extensionTargetPart };
255
+ //# sourceMappingURL=chunk-AFVR6B2A.js.map
256
+ //# sourceMappingURL=chunk-AFVR6B2A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ExtensionIndex.ts"],"names":[],"mappings":";AA6HA,IAAM,QAAA,GAAW,MAAA,CAAO,MAAA,CAAO,EAAE,CAAA;AACjC,IAAM,wBAAwB,MAAA,CAAO,MAAA;AAAA,EACnC;AACF,CAAA;AACA,IAAM,eAAe,MAAA,CAAO,MAAA;AAAA,EAC1B;AACF,CAAA;AACA,IAAM,kBAAkB,MAAA,CAAO,MAAA;AAAA,EAC7B;AACF,CAAA;AAKO,IAAM,iBAAN,MAAuD;AAAA,EACnD,GAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA;AAAA,EACA,wBAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA;AAAA,EAKA,GAAA;AAAA;AAAA;AAAA;AAAA,EAIA,KAAA;AAAA,EAET,YAAY,UAAA,EAAyC;AACnD,IAAA,MAAM,EAAA,uBAAS,GAAA,EAAkC;AACjD,IAAA,MAAM,WAAA,uBAAkB,GAAA,EAAkC;AAC1D,IAAA,MAAM,cAAA,uBAAqB,GAAA,EAA6C;AACxE,IAAA,MAAM,uBAAA,uBAA8B,GAAA,EAGlC;AACF,IAAA,MAAM,MAAA,uBAAa,GAAA,EAA4C;AAC/D,IAAA,MAAM,SAAA,uBAAgB,GAAA,EAAwC;AAE9D,IAAA,IAAI,OAAA,GAAU,CAAA;AACd,IAAA,IAAI,kBAAA,GAAqB,CAAA;AACzB,IAAA,IAAI,UAAA,GAAa,CAAA;AACjB,IAAA,IAAI,aAAA,GAAgB,CAAA;AAEpB,IAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,MAAA,QAAQ,UAAU,IAAA;AAAM,QACtB,KAAK,IAAA,EAAM;AACT,UAAA,OAAA,IAAW,CAAA;AACX,UAAA,S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;AACL,IAAA,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,CAAC,SAAS,CAAC,CAAA;AAAA,EAC9B;AACF;AAEA,SAAS,cACP,OAAA,EACkB;AAClB,EAAA,MAAM,MAAA,uBAAa,GAAA,EAA0B;AAC7C,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,MAAM,CAAA,IAAK,OAAA,EAAS;AACnC,IAAA,MAAA,CAAO,GAAA,CAAI,KAAK,MAAA,CAAO,MAAA,CAAO,OAAO,IAAA,CAAK,iBAAiB,CAAC,CAAC,CAAA;AAAA,EAC/D;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,iBAAA,CACP,MACA,KAAA,EACQ;AACR,EAAA,OAAO,wBAAA,CAAyB,MAAM,KAAK,CAAA;AAC7C","file":"chunk-AFVR6B2A.js","sourcesContent":["import type {\n ExtensionSurface,\n RuntimeEventHandlerExtension,\n RuntimeExtension,\n RuntimeOperationHookExtension,\n RuntimeProviderExtension,\n RuntimeUiExtension,\n} from \"@plugmatica/core-sdk\";\n\n/**\n * Counts describing the immutable runtime extension index.\n */\nexport type ExtensionIndexStats = Readonly<{\n total: number;\n ui: number;\n operationHooks: number;\n events: number;\n providers: number;\n uiBuckets: number;\n operationBuckets: number;\n eventBuckets: number;\n providerBuckets: number;\n}>;\n\n/**\n * Read-only query surface shared by the runtime and developer tooling.\n * Bucket internals are intentionally not exposed so bootstrap refresh can\n * replace the complete index atomically instead of supporting mutation.\n */\nexport interface ExtensionIndexReadOnly {\n /**\n * Stats associated with this extension index read only.\n */\n readonly stats: ExtensionIndexStats;\n /**\n * Return every indexed runtime extension in deterministic order.\n */\n readonly all: readonly RuntimeExtension[];\n\n /**\n * Ui associated with this extension index read only.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @param point Extension point within the surface.\n * @returns Result returned by ui.\n */\n ui(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n point: string,\n ): readonly RuntimeUiExtension[];\n\n /**\n * Operation hooks associated with this extension index read only.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @param operation Operation contract name.\n * @returns Result returned by operationHooks.\n */\n operationHooks(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n operation: string,\n ): readonly RuntimeOperationHookExtension[];\n\n /**\n * Events associated with this extension index read only.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param event Event contract name.\n * @returns Result returned by events.\n */\n events(\n targetPluginIdentifier: string,\n event: string,\n ): readonly RuntimeEventHandlerExtension[];\n\n /**\n * Providers associated with this extension index read only.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param provider Provider contract name.\n * @returns Result returned by providers.\n */\n providers(\n targetPluginIdentifier: string,\n provider: string,\n ): readonly RuntimeProviderExtension[];\n\n /** All UI contributions targeting a mounted surface, regardless of point. */\n /**\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @returns Result returned by uiForSurface.\n */\n uiForSurface(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n ): readonly RuntimeUiExtension[];\n\n /** All operation hooks targeting a mounted surface, regardless of operation. */\n /**\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @returns Result returned by operationHooksForSurface.\n */\n operationHooksForSurface(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n ): readonly RuntimeOperationHookExtension[];\n}\n\ntype MutableBuckets<T extends RuntimeExtension> = Map<string, T[]>;\ntype FrozenBuckets<T extends RuntimeExtension> = Map<string, readonly T[]>;\n\nconst EMPTY_UI = Object.freeze([]) as readonly RuntimeUiExtension[];\nconst EMPTY_OPERATION_HOOKS = Object.freeze(\n [],\n) as readonly RuntimeOperationHookExtension[];\nconst EMPTY_EVENTS = Object.freeze(\n [],\n) as readonly RuntimeEventHandlerExtension[];\nconst EMPTY_PROVIDERS = Object.freeze(\n [],\n) as readonly RuntimeProviderExtension[];\n\n/**\n * Indexed view of normalized runtime extension descriptors used by host resolution.\n */\nexport class ExtensionIndex implements ExtensionIndexReadOnly {\n readonly #ui: FrozenBuckets<RuntimeUiExtension>;\n readonly #uiBySurface: FrozenBuckets<RuntimeUiExtension>;\n readonly #operationHooks: FrozenBuckets<RuntimeOperationHookExtension>;\n readonly #operationHooksBySurface: FrozenBuckets<RuntimeOperationHookExtension>;\n readonly #events: FrozenBuckets<RuntimeEventHandlerExtension>;\n readonly #providers: FrozenBuckets<RuntimeProviderExtension>;\n\n /**\n * Return every indexed extension in deterministic order.\n */\n readonly all: readonly RuntimeExtension[];\n /**\n * Return counts for the indexed extension set.\n */\n readonly stats: ExtensionIndexStats;\n\n constructor(extensions: readonly RuntimeExtension[]) {\n const ui = new Map<string, RuntimeUiExtension[]>();\n const uiBySurface = new Map<string, RuntimeUiExtension[]>();\n const operationHooks = new Map<string, RuntimeOperationHookExtension[]>();\n const operationHooksBySurface = new Map<\n string,\n RuntimeOperationHookExtension[]\n >();\n const events = new Map<string, RuntimeEventHandlerExtension[]>();\n const providers = new Map<string, RuntimeProviderExtension[]>();\n\n let uiCount = 0;\n let operationHookCount = 0;\n let eventCount = 0;\n let providerCount = 0;\n\n for (const extension of extensions) {\n switch (extension.kind) {\n case \"ui\": {\n uiCount += 1;\n addBucket(\n ui,\n uiTargetKey(\n extension.targetPluginIdentifier,\n extension.target.surface,\n extension.target.key,\n extension.target.point,\n ),\n extension,\n );\n addBucket(\n uiBySurface,\n surfaceTargetKey(\n extension.targetPluginIdentifier,\n extension.target.surface,\n extension.target.key,\n ),\n extension,\n );\n break;\n }\n case \"operation_hook\": {\n operationHookCount += 1;\n addBucket(\n operationHooks,\n operationTargetKey(\n extension.targetPluginIdentifier,\n extension.target.surface,\n extension.target.key,\n extension.target.operation,\n ),\n extension,\n );\n addBucket(\n operationHooksBySurface,\n surfaceTargetKey(\n extension.targetPluginIdentifier,\n extension.target.surface,\n extension.target.key,\n ),\n extension,\n );\n break;\n }\n case \"event_handler\": {\n eventCount += 1;\n addBucket(\n events,\n namedTargetKey(\n extension.targetPluginIdentifier,\n extension.target.event,\n ),\n extension,\n );\n break;\n }\n case \"provider\": {\n providerCount += 1;\n addBucket(\n providers,\n namedTargetKey(\n extension.targetPluginIdentifier,\n extension.target.provider,\n ),\n extension,\n );\n break;\n }\n }\n }\n\n this.#ui = freezeBuckets(ui);\n this.#uiBySurface = freezeBuckets(uiBySurface);\n this.#operationHooks = freezeBuckets(operationHooks);\n this.#operationHooksBySurface = freezeBuckets(operationHooksBySurface);\n this.#events = freezeBuckets(events);\n this.#providers = freezeBuckets(providers);\n\n this.all = Object.freeze([...extensions].sort(compareExtensions));\n this.stats = Object.freeze({\n total: extensions.length,\n ui: uiCount,\n operationHooks: operationHookCount,\n events: eventCount,\n providers: providerCount,\n uiBuckets: this.#ui.size,\n operationBuckets: this.#operationHooks.size,\n eventBuckets: this.#events.size,\n providerBuckets: this.#providers.size,\n });\n }\n\n /**\n * Return UI extensions matching a target plugin/surface/key/point.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Semantic UI extension surface.\n * @param surfaceKey Stable semantic surface key.\n * @param point Extension point within the surface.\n * @returns Result returned by ui.\n */\n ui(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n point: string,\n ): readonly RuntimeUiExtension[] {\n return (\n this.#ui.get(\n uiTargetKey(targetPluginIdentifier, surface, surfaceKey, point),\n ) ?? EMPTY_UI\n );\n }\n\n /**\n * Return operation hooks matching a target operation.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @param operation Operation contract name.\n * @returns Result returned by operationHooks.\n */\n operationHooks(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n operation: string,\n ): readonly RuntimeOperationHookExtension[] {\n return (\n this.#operationHooks.get(\n operationTargetKey(\n targetPluginIdentifier,\n surface,\n surfaceKey,\n operation,\n ),\n ) ?? EMPTY_OPERATION_HOOKS\n );\n }\n\n /**\n * Return event handlers matching a target event.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param event Event contract name.\n * @returns Result returned by events.\n */\n events(\n targetPluginIdentifier: string,\n event: string,\n ): readonly RuntimeEventHandlerExtension[] {\n return (\n this.#events.get(namedTargetKey(targetPluginIdentifier, event)) ??\n EMPTY_EVENTS\n );\n }\n\n /**\n * Return providers matching a target provider contract.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param provider Provider contract name.\n * @returns Result returned by providers.\n */\n providers(\n targetPluginIdentifier: string,\n provider: string,\n ): readonly RuntimeProviderExtension[] {\n return (\n this.#providers.get(namedTargetKey(targetPluginIdentifier, provider)) ??\n EMPTY_PROVIDERS\n );\n }\n\n /**\n * Return all UI extensions registered for one semantic surface instance.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @returns Result returned by uiForSurface.\n */\n uiForSurface(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n ): readonly RuntimeUiExtension[] {\n return (\n this.#uiBySurface.get(\n surfaceTargetKey(targetPluginIdentifier, surface, surfaceKey),\n ) ?? EMPTY_UI\n );\n }\n\n /**\n * Return all operation hooks registered for one semantic surface.\n *\n * @param targetPluginIdentifier Identifier of the plugin owning the target surface.\n * @param surface Extension surface to query.\n * @param surfaceKey Stable semantic key for the target surface.\n * @returns Result returned by operationHooksForSurface.\n */\n operationHooksForSurface(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n ): readonly RuntimeOperationHookExtension[] {\n return (\n this.#operationHooksBySurface.get(\n surfaceTargetKey(targetPluginIdentifier, surface, surfaceKey),\n ) ?? EMPTY_OPERATION_HOOKS\n );\n }\n}\n\n/**\n * Create an immutable query index from normalized runtime extension descriptors.\n *\n * @param extensions Normalized runtime extension descriptors to index.\n * @returns Result returned by createExtensionIndex.\n */\nexport function createExtensionIndex(\n extensions: readonly RuntimeExtension[],\n): ExtensionIndexReadOnly {\n return new ExtensionIndex(extensions);\n}\n\n/** Canonical deterministic ordering used by every extension bucket. */\n/**\n * @param left Left extension descriptor to compare.\n * @param right Right extension descriptor to compare.\n * @returns Result returned by compareRuntimeExtensions.\n */\nexport function compareRuntimeExtensions(\n left: Pick<RuntimeExtension, \"order\" | \"id\">,\n right: Pick<RuntimeExtension, \"order\" | \"id\">,\n): number {\n return left.order - right.order || left.id.localeCompare(right.id);\n}\n\n/**\n * Canonical target equivalence encoding. Length-prefixing avoids delimiter\n * collisions while keeping key construction allocation small and predictable.\n */\n/**\n * @param value Input value to normalize/convert.\n * @returns Result returned by extensionTargetPart.\n */\nexport function extensionTargetPart(value: string): string {\n return `${value.length}:${value}`;\n}\n\nfunction surfaceTargetKey(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n): string {\n return joinTarget(targetPluginIdentifier, surface, surfaceKey);\n}\n\nfunction uiTargetKey(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n point: string,\n): string {\n return joinTarget(targetPluginIdentifier, surface, surfaceKey, point);\n}\n\nfunction operationTargetKey(\n targetPluginIdentifier: string,\n surface: ExtensionSurface,\n surfaceKey: string,\n operation: string,\n): string {\n return joinTarget(targetPluginIdentifier, surface, surfaceKey, operation);\n}\n\nfunction namedTargetKey(targetPluginIdentifier: string, name: string): string {\n return joinTarget(targetPluginIdentifier, name);\n}\n\nfunction joinTarget(...parts: readonly string[]): string {\n return parts.map(extensionTargetPart).join(\"\");\n}\n\nfunction addBucket<T extends RuntimeExtension>(\n buckets: MutableBuckets<T>,\n key: string,\n extension: T,\n): void {\n const existing = buckets.get(key);\n if (existing) {\n existing.push(extension);\n } else {\n buckets.set(key, [extension]);\n }\n}\n\nfunction freezeBuckets<T extends RuntimeExtension>(\n buckets: MutableBuckets<T>,\n): FrozenBuckets<T> {\n const result = new Map<string, readonly T[]>();\n for (const [key, values] of buckets) {\n result.set(key, Object.freeze(values.sort(compareExtensions)));\n }\n return result;\n}\n\nfunction compareExtensions(\n left: Pick<RuntimeExtension, \"order\" | \"id\">,\n right: Pick<RuntimeExtension, \"order\" | \"id\">,\n): number {\n return compareRuntimeExtensions(left, right);\n}\n"]}
@@ -0,0 +1,84 @@
1
+ // src/definitions.ts
2
+ function defineActions(actions) {
3
+ return actions;
4
+ }
5
+ function defineRepeatedInstances(items) {
6
+ return items;
7
+ }
8
+ var extensionTarget = {
9
+ ui(target) {
10
+ return {
11
+ __pmTarget: "ui",
12
+ resolution: "capability",
13
+ required: target.required ?? true,
14
+ surface: target.surface,
15
+ key: target.key,
16
+ point: target.point,
17
+ contract: target.contract
18
+ };
19
+ },
20
+ operation(target) {
21
+ return {
22
+ __pmTarget: "operation",
23
+ resolution: "capability",
24
+ required: target.required ?? true,
25
+ surface: target.surface,
26
+ key: target.key,
27
+ operation: target.operation,
28
+ contract: target.contract
29
+ };
30
+ },
31
+ event(target) {
32
+ return {
33
+ __pmTarget: "event",
34
+ resolution: "capability",
35
+ required: target.required ?? true,
36
+ event: target.event,
37
+ contract: target.contract
38
+ };
39
+ },
40
+ provider(target) {
41
+ return {
42
+ __pmTarget: "provider",
43
+ resolution: "capability",
44
+ required: target.required ?? true,
45
+ provider: target.provider,
46
+ contract: target.contract
47
+ };
48
+ }
49
+ };
50
+ function defineExtension(definition) {
51
+ if ("component" in definition) return definition.component;
52
+ const {
53
+ target: _target,
54
+ module: _module,
55
+ contribution: _contribution,
56
+ label: _label,
57
+ labelKey: _labelKey,
58
+ requiredScope: _requiredScope,
59
+ metadata: _metadata,
60
+ contribute,
61
+ visible,
62
+ lifecycle
63
+ } = definition;
64
+ return {
65
+ contribute,
66
+ ...visible ? {
67
+ visible
68
+ } : {},
69
+ ...lifecycle ? { lifecycle } : {}
70
+ };
71
+ }
72
+ function defineProvider(definition) {
73
+ return definition;
74
+ }
75
+ function defineEventHandler(definition) {
76
+ return definition;
77
+ }
78
+ function defineOperationHook(definition) {
79
+ return definition;
80
+ }
81
+
82
+ export { defineActions, defineEventHandler, defineExtension, defineOperationHook, defineProvider, defineRepeatedInstances, extensionTarget };
83
+ //# sourceMappingURL=chunk-YY4H56JF.js.map
84
+ //# sourceMappingURL=chunk-YY4H56JF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/definitions.ts"],"names":[],"mappings":";AA+CO,SAAS,cACd,OAAA,EACU;AACV,EAAA,OAAO,OAAA;AACT;AAQO,SAAS,wBAEd,KAAA,EAAuB;AACvB,EAAA,OAAO,KAAA;AACT;AAoBO,IAAM,eAAA,GAAkB;AAAA,EAC7B,GAOE,MAAA,EAOmC;AACnC,IAAA,OAAO;AAAA,MACL,UAAA,EAAY,IAAA;AAAA,MACZ,UAAA,EAAY,YAAA;AAAA,MACZ,QAAA,EAAU,OAAO,QAAA,IAAY,IAAA;AAAA,MAC7B,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,UAAU,MAAA,CAAO;AAAA,KACnB;AAAA,EAUF,CAAA;AAAA,EACA,UAOE,MAAA,EAcmC;AACnC,IAAA,OAAO;AAAA,MACL,UAAA,EAAY,WAAA;AAAA,MACZ,UAAA,EAAY,YAAA;AAAA,MACZ,QAAA,EAAU,OAAO,QAAA,IAAY,IAAA;AAAA,MAC7B,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,WAAW,MAAA,CAAO,SAAA;AAAA,MAClB,UAAU,MA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Gd,UAAA,EACkC;AAClC,EAAA,OAAO,UAAA;AACT","file":"chunk-YY4H56JF.js","sourcesContent":["import type {\n EventExtensionTargetToken,\n ExtensionContractRequirement,\n ExtensionSurface,\n OperationExtensionPhase,\n OperationExtensionTargetToken,\n PluginKey,\n ProviderExtensionTargetToken,\n UiExtensionTargetToken,\n} from \"@plugmatica/core-sdk\";\nimport type { ComponentType } from \"react\";\n\nimport type {\n EventHandlerModule,\n ExtensionLifecycleHooks,\n OperationHookModule,\n ProviderModule,\n StructuredUiExtensionModule,\n} from \"./types\";\n\n/**\n * Callable action exposed through a semantic `defineActions()` collection.\n *\n * @param args Arguments accepted by the concrete action implementation.\n * @returns Value returned by the concrete action implementation.\n */\nexport type PluginAction = (...args: any[]) => any;\n/**\n * Read-only map of semantic action keys to plugin action implementations.\n */\nexport type PluginActionMap = Readonly<Record<string, PluginAction>>;\n\n/**\n * Declare semantic actions while preserving their static keys for the frontend compiler.\n * The helper is a runtime no-op and returns the exact object passed to it.\n *\n * @param actions Action implementations keyed by their stable semantic action name.\n * @returns The unchanged action map with literal keys/types preserved.\n *\n * @example\n * ```ts\n * const actions = defineActions({\n * save: async () => saveCustomer(),\n * refresh: async () => reloadCustomer(),\n * });\n * ```\n */\nexport function defineActions<const TActions extends PluginActionMap>(\n actions: TActions,\n): TActions {\n return actions;\n}\n\n/**\n * Mark a compile-time collection as intentional repeated instances of one semantic surface.\n *\n * @param items Static items that deliberately share one extension identity and use `instanceKey` at runtime.\n * @returns The unchanged collection with literal tuple/array types preserved.\n */\nexport function defineRepeatedInstances<\n const TItems extends readonly unknown[],\n>(items: TItems): TItems {\n return items;\n}\n\ntype CapabilityResolvedTarget<TTarget> = Extract<\n TTarget,\n { readonly resolution: \"capability\" }\n>;\n\ntype CapabilityTargetBase<\n TContract extends ExtensionContractRequirement,\n TRequired extends boolean,\n> = {\n readonly contract: TContract;\n readonly required?: TRequired;\n};\n\n/**\n * Declare an extension target by public runtime capability rather than by a\n * concrete provider plugin package. The runtime resolves exactly one compatible\n * installed provider before exposing the contribution.\n */\nexport const extensionTarget = {\n ui<\n const TSurface extends ExtensionSurface,\n const TKey extends string,\n const TPoint extends string,\n const TContract extends ExtensionContractRequirement,\n const TRequired extends boolean = true,\n >(\n target: CapabilityTargetBase<TContract, TRequired> & {\n readonly surface: TSurface;\n readonly key: TKey;\n readonly point: TPoint;\n },\n ): CapabilityResolvedTarget<\n UiExtensionTargetToken<PluginKey, string, TSurface, TKey, TPoint, TContract>\n > & { readonly required: TRequired } {\n return {\n __pmTarget: \"ui\",\n resolution: \"capability\",\n required: target.required ?? true,\n surface: target.surface,\n key: target.key,\n point: target.point,\n contract: target.contract,\n } as CapabilityResolvedTarget<\n UiExtensionTargetToken<\n PluginKey,\n string,\n TSurface,\n TKey,\n TPoint,\n TContract\n >\n > & { readonly required: TRequired };\n },\n operation<\n const TSurface extends ExtensionSurface,\n const TKey extends string,\n const TOperation extends string,\n const TContract extends ExtensionContractRequirement,\n const TRequired extends boolean = true,\n >(\n target: CapabilityTargetBase<TContract, TRequired> & {\n readonly surface: TSurface;\n readonly key: TKey;\n readonly operation: TOperation;\n },\n ): CapabilityResolvedTarget<\n OperationExtensionTargetToken<\n PluginKey,\n string,\n TSurface,\n TKey,\n TOperation,\n TContract\n >\n > & { readonly required: TRequired } {\n return {\n __pmTarget: \"operation\",\n resolution: \"capability\",\n required: target.required ?? true,\n surface: target.surface,\n key: target.key,\n operation: target.operation,\n contract: target.contract,\n } as CapabilityResolvedTarget<\n OperationExtensionTargetToken<\n PluginKey,\n string,\n TSurface,\n TKey,\n TOperation,\n TContract\n >\n > & { readonly required: TRequired };\n },\n event<\n const TEvent extends string,\n const TContract extends ExtensionContractRequirement,\n const TRequired extends boolean = true,\n >(\n target: CapabilityTargetBase<TContract, TRequired> & {\n readonly event: TEvent;\n },\n ): CapabilityResolvedTarget<\n EventExtensionTargetToken<unknown, PluginKey, string, TEvent, TContract>\n > & { readonly required: TRequired } {\n return {\n __pmTarget: \"event\",\n resolution: \"capability\",\n required: target.required ?? true,\n event: target.event,\n contract: target.contract,\n } as CapabilityResolvedTarget<\n EventExtensionTargetToken<unknown, PluginKey, string, TEvent, TContract>\n > & { readonly required: TRequired };\n },\n provider<\n const TProvider extends string,\n const TContract extends ExtensionContractRequirement,\n const TRequired extends boolean = true,\n >(\n target: CapabilityTargetBase<TContract, TRequired> & {\n readonly provider: TProvider;\n },\n ): CapabilityResolvedTarget<\n ProviderExtensionTargetToken<\n unknown,\n unknown,\n PluginKey,\n string,\n TProvider,\n TContract\n >\n > & { readonly required: TRequired } {\n return {\n __pmTarget: \"provider\",\n resolution: \"capability\",\n required: target.required ?? true,\n provider: target.provider,\n contract: target.contract,\n } as CapabilityResolvedTarget<\n ProviderExtensionTargetToken<\n unknown,\n unknown,\n PluginKey,\n string,\n TProvider,\n TContract\n >\n > & { readonly required: TRequired };\n },\n} as const;\n\n/** Public UI target accepted from either a generated direct target or a capability selector. */\nexport type UiExtensionTarget = UiExtensionTargetToken;\n/**\n * Infer the structured contribution value carried by a generated UI target token.\n */\nexport type UiContributionOf<TTarget> = TTarget extends {\n readonly __contribution?: infer TContribution;\n}\n ? TContribution\n : unknown;\n/**\n * Generated provider target token carrying provider request and value types.\n */\nexport type ProviderTarget<\n TRequest = unknown,\n TValue = unknown,\n> = ProviderExtensionTargetToken<TRequest, TValue>;\n/**\n * Generated event target token carrying the event payload type.\n */\nexport type EventHandlerTarget<TPayload = unknown> =\n EventExtensionTargetToken<TPayload>;\n/**\n * Generated operation target token carrying operation payload and result types.\n */\nexport type OperationHookTarget<\n TPayload = unknown,\n TResult = unknown,\n> = OperationExtensionTargetToken & {\n /** Type-only operation payload/result carriers for specialised target packages. */\n readonly __payload?: TPayload;\n /**\n * Type-only operation result carrier for specialised target packages.\n */\n readonly __result?: TResult;\n};\n\n/**\n * React component type accepted by a renderable Plugmatica UI extension.\n */\nexport type DefinedExtensionComponent = ComponentType;\n\n/**\n * Optional compiler-owned contribution metadata. `module` is the stable Module\n * Federation expose name; target protocol fields come exclusively from the\n * generated token. `contribution` is an escape hatch for preserving the\n * contribution key when a module expose is renamed.\n */\nexport type ExtensionContributionDefinition = {\n /**\n * Module Federation expose name or generated contribution module path.\n */\n readonly module?: `./${string}`;\n /**\n * Optional stable contribution key retained when a module expose is renamed.\n */\n readonly contribution?: string;\n /**\n * Resolved ordering value used to sort contributions.\n */\n readonly order?: number;\n /**\n * Optional human-readable contribution label.\n */\n readonly label?: string | null;\n /**\n * Optional translation key for the contribution label.\n */\n readonly labelKey?: string | null;\n /**\n * Optional permission scope required before the contribution is activated.\n */\n readonly requiredScope?: string | null;\n /**\n * Optional compiler/runtime metadata associated with the contribution.\n */\n readonly metadata?: Readonly<Record<string, unknown>> | null;\n};\n\n/**\n * Definition for a UI extension implemented by rendering a React component.\n */\nexport type RenderableUiExtensionDefinition<\n TTarget extends UiExtensionTarget = UiExtensionTarget,\n TComponent extends DefinedExtensionComponent = DefinedExtensionComponent,\n> = ExtensionContributionDefinition & {\n /**\n * Generated/normalized target identifying what this extension or augmentation applies to.\n */\n target: TTarget;\n /**\n * React component rendered by a renderable UI extension.\n */\n component: TComponent;\n};\n\n/**\n * Structured standard-surface contribution. Use this shape for collection\n * points such as Form.fields, Form.actions, DataTable.columns and Tabs.items.\n * The contribution value is ordinary UI-kit data; target protocol metadata is\n * still supplied entirely by the generated target token.\n */\nexport type StructuredUiExtensionDefinition<\n TTarget extends UiExtensionTarget = UiExtensionTarget,\n TContribution = UiContributionOf<TTarget>,\n TPayload = unknown,\n> = ExtensionContributionDefinition & {\n /**\n * Generated/normalized target identifying what this extension or augmentation applies to.\n */\n target: TTarget;\n /**\n * Produce structured contribution data for the target collection point.\n *\n * @param context Scoped runtime context for this callback/operation.\n * @returns Structured contribution value, or a promise resolving to it.\n */\n contribute: StructuredUiExtensionModule<\n TContribution,\n TPayload\n >[\"contribute\"];\n /**\n * Decide whether this extension participates for the current runtime context.\n *\n * @param context Scoped runtime context for this callback/operation.\n * @returns Whether visible condition is satisfied.\n */\n visible?: StructuredUiExtensionModule<TContribution, TPayload>[\"visible\"];\n /**\n * Optional lifecycle hooks for this extension module.\n */\n lifecycle?: ExtensionLifecycleHooks;\n};\n\n/**\n * Union of renderable and structured UI extension definition shapes.\n */\nexport type UiExtensionDefinition<\n TTarget extends UiExtensionTarget = UiExtensionTarget,\n TComponent extends DefinedExtensionComponent = DefinedExtensionComponent,\n TContribution = unknown,\n TPayload = unknown,\n> =\n | RenderableUiExtensionDefinition<TTarget, TComponent>\n | StructuredUiExtensionDefinition<TTarget, TContribution, TPayload>;\n\n/** Define a renderable UI contribution whose runtime value is the supplied React component. */\nexport function defineExtension<\n const TTarget extends UiExtensionTarget,\n TComponent extends DefinedExtensionComponent,\n>(definition: RenderableUiExtensionDefinition<TTarget, TComponent>): TComponent;\n\n/** Define a structured contribution for a generated semantic collection point. */\nexport function defineExtension<\n const TTarget extends UiExtensionTarget,\n TPayload = unknown,\n>(\n definition: StructuredUiExtensionDefinition<\n TTarget,\n UiContributionOf<TTarget>,\n TPayload\n >,\n): StructuredUiExtensionModule<UiContributionOf<TTarget>, TPayload>;\n\n/**\n * Define a renderable or structured UI extension for a generated target token.\n *\n * Compiler-only target/module metadata is consumed by `plugin-build`; runtime receives\n * the component or structured module expected by the extension host.\n *\n * @param definition Renderable or structured extension definition.\n * @returns Runtime component/module shape consumed by the extension host.\n *\n * @example\n * ```tsx\n * export default defineExtension({\n * target: customer.detail.tabs.$points.items,\n * module: \"./CustomerDocuments\",\n * component: CustomerDocuments,\n * });\n * ```\n */\nexport function defineExtension(\n definition: UiExtensionDefinition<\n UiExtensionTarget,\n DefinedExtensionComponent,\n unknown,\n unknown\n >,\n): DefinedExtensionComponent | StructuredUiExtensionModule<unknown, unknown> {\n if (\"component\" in definition) return definition.component;\n\n const {\n target: _target,\n module: _module,\n contribution: _contribution,\n label: _label,\n labelKey: _labelKey,\n requiredScope: _requiredScope,\n metadata: _metadata,\n contribute,\n visible,\n lifecycle,\n } = definition;\n\n return {\n contribute: contribute as StructuredUiExtensionModule<\n unknown,\n unknown\n >[\"contribute\"],\n ...(visible\n ? {\n visible: visible as StructuredUiExtensionModule<\n unknown,\n unknown\n >[\"visible\"],\n }\n : {}),\n ...(lifecycle ? { lifecycle } : {}),\n };\n}\n\n/**\n * Infer the request type carried by a generated provider target token.\n */\nexport type ProviderRequestOf<TTarget> =\n TTarget extends ProviderExtensionTargetToken<infer TRequest, any>\n ? TRequest\n : unknown;\n/**\n * Infer the provided value type carried by a generated provider target token.\n */\nexport type ProviderValueOf<TTarget> =\n TTarget extends ProviderExtensionTargetToken<any, infer TValue>\n ? TValue\n : unknown;\n/**\n * Infer the event payload type carried by a generated event target token.\n */\nexport type EventPayloadOf<TTarget> =\n TTarget extends EventExtensionTargetToken<infer TPayload>\n ? TPayload\n : unknown;\n/**\n * Infer the operation payload type carried by a generated operation target token.\n */\nexport type OperationPayloadOf<TTarget> = TTarget extends {\n readonly __payload?: infer TPayload;\n}\n ? TPayload\n : unknown;\n/**\n * Infer the operation result type carried by a generated operation target token.\n */\nexport type OperationResultOf<TTarget> = TTarget extends {\n readonly __result?: infer TResult;\n}\n ? TResult\n : unknown;\n\n/**\n * Definition of a provider extension for a generated provider target.\n */\nexport type ProviderDefinition<\n TTarget extends ProviderTarget<any, any> = ProviderTarget,\n> = ExtensionContributionDefinition & {\n /**\n * Generated/normalized target identifying what this extension or augmentation applies to.\n */\n target: TTarget;\n /**\n * Resolve a value for the targeted provider request.\n *\n * @param context Scoped runtime context for this callback/operation.\n * @returns Provider value for the current request, or a promise resolving to it.\n */\n provide: ProviderModule<\n ProviderRequestOf<TTarget>,\n ProviderValueOf<TTarget>\n >[\"provide\"];\n};\n\n/**\n * Define a provider extension using a generated provider target.\n *\n * @param definition Provider target, implementation and optional contribution metadata.\n * @returns The unchanged provider definition consumed by build/runtime tooling.\n *\n * @example\n * ```ts\n * export default defineProvider({\n * target: customer.$providers.displayName,\n * module: \"./CustomerDisplayName\",\n * provide: ({ request }) => `Customer ${request.customerId}`,\n * });\n * ```\n */\nexport function defineProvider<const TTarget extends ProviderTarget<any, any>>(\n definition: ProviderDefinition<TTarget>,\n): ProviderDefinition<TTarget> {\n return definition;\n}\n\n/**\n * Definition of an event-handler extension for a generated event target.\n */\nexport type EventHandlerDefinition<\n TTarget extends EventHandlerTarget<any> = EventHandlerTarget,\n> = ExtensionContributionDefinition & {\n /**\n * Generated/normalized target identifying what this extension or augmentation applies to.\n */\n target: TTarget;\n /**\n * Handle one event emitted by the targeted event contract.\n *\n * @param context Scoped runtime context for this callback/operation.\n * @returns Completes when the operation finishes.\n */\n handle: EventHandlerModule<EventPayloadOf<TTarget>>[\"handle\"];\n};\n\n/**\n * Define an event-handler extension using a generated event target.\n *\n * @param definition Event target, handler and optional contribution metadata.\n * @returns The unchanged event-handler definition consumed by build/runtime tooling.\n *\n * @example\n * ```ts\n * export const audit = defineEventHandler({\n * target: customer.$events.saved,\n * module: \"./CustomerSavedAudit\",\n * handle: async ({ payload }) => auditCustomer(payload),\n * });\n * ```\n */\nexport function defineEventHandler<\n const TTarget extends EventHandlerTarget<any>,\n>(\n definition: EventHandlerDefinition<TTarget>,\n): EventHandlerDefinition<TTarget> {\n return definition;\n}\n\n/**\n * Definition of an operation-hook extension for a generated operation target.\n */\nexport type OperationHookDefinition<\n TTarget extends OperationHookTarget<any, any> = OperationHookTarget,\n> = ExtensionContributionDefinition & {\n /**\n * Generated/normalized target identifying what this extension or augmentation applies to.\n */\n target: TTarget;\n /** Optional explicit phase intent; handler presence remains authoritative. */\n phases?: readonly OperationExtensionPhase[];\n} & OperationHookModule<\n OperationPayloadOf<TTarget>,\n OperationResultOf<TTarget>\n >;\n\n/**\n * Define an operation-hook extension using a generated operation target.\n *\n * @param definition Operation target, phase handlers and optional contribution metadata.\n * @returns The unchanged operation-hook definition consumed by build/runtime tooling.\n *\n * @example\n * ```ts\n * export const guard = defineOperationHook({\n * target: customer.detail.form.$operations.submit,\n * module: \"./CustomerSubmitGuard\",\n * before: async ({ payload }) => ({ kind: \"continue\", payload }),\n * });\n * ```\n */\nexport function defineOperationHook<\n const TTarget extends OperationHookTarget<any, any>,\n>(\n definition: OperationHookDefinition<TTarget>,\n): OperationHookDefinition<TTarget> {\n return definition;\n}\n"]}
@@ -0,0 +1,178 @@
1
+ import { RuntimeExtension, ExtensionSurface, RuntimeUiExtension, RuntimeOperationHookExtension, RuntimeEventHandlerExtension, RuntimeProviderExtension } from '@plugmatica/core-sdk';
2
+
3
+ /**
4
+ * Counts describing the immutable runtime extension index.
5
+ */
6
+ type ExtensionIndexStats = Readonly<{
7
+ total: number;
8
+ ui: number;
9
+ operationHooks: number;
10
+ events: number;
11
+ providers: number;
12
+ uiBuckets: number;
13
+ operationBuckets: number;
14
+ eventBuckets: number;
15
+ providerBuckets: number;
16
+ }>;
17
+ /**
18
+ * Read-only query surface shared by the runtime and developer tooling.
19
+ * Bucket internals are intentionally not exposed so bootstrap refresh can
20
+ * replace the complete index atomically instead of supporting mutation.
21
+ */
22
+ interface ExtensionIndexReadOnly {
23
+ /**
24
+ * Stats associated with this extension index read only.
25
+ */
26
+ readonly stats: ExtensionIndexStats;
27
+ /**
28
+ * Return every indexed runtime extension in deterministic order.
29
+ */
30
+ readonly all: readonly RuntimeExtension[];
31
+ /**
32
+ * Ui associated with this extension index read only.
33
+ *
34
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
35
+ * @param surface Extension surface to query.
36
+ * @param surfaceKey Stable semantic key for the target surface.
37
+ * @param point Extension point within the surface.
38
+ * @returns Result returned by ui.
39
+ */
40
+ ui(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string, point: string): readonly RuntimeUiExtension[];
41
+ /**
42
+ * Operation hooks associated with this extension index read only.
43
+ *
44
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
45
+ * @param surface Extension surface to query.
46
+ * @param surfaceKey Stable semantic key for the target surface.
47
+ * @param operation Operation contract name.
48
+ * @returns Result returned by operationHooks.
49
+ */
50
+ operationHooks(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string, operation: string): readonly RuntimeOperationHookExtension[];
51
+ /**
52
+ * Events associated with this extension index read only.
53
+ *
54
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
55
+ * @param event Event contract name.
56
+ * @returns Result returned by events.
57
+ */
58
+ events(targetPluginIdentifier: string, event: string): readonly RuntimeEventHandlerExtension[];
59
+ /**
60
+ * Providers associated with this extension index read only.
61
+ *
62
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
63
+ * @param provider Provider contract name.
64
+ * @returns Result returned by providers.
65
+ */
66
+ providers(targetPluginIdentifier: string, provider: string): readonly RuntimeProviderExtension[];
67
+ /** All UI contributions targeting a mounted surface, regardless of point. */
68
+ /**
69
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
70
+ * @param surface Extension surface to query.
71
+ * @param surfaceKey Stable semantic key for the target surface.
72
+ * @returns Result returned by uiForSurface.
73
+ */
74
+ uiForSurface(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string): readonly RuntimeUiExtension[];
75
+ /** All operation hooks targeting a mounted surface, regardless of operation. */
76
+ /**
77
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
78
+ * @param surface Extension surface to query.
79
+ * @param surfaceKey Stable semantic key for the target surface.
80
+ * @returns Result returned by operationHooksForSurface.
81
+ */
82
+ operationHooksForSurface(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string): readonly RuntimeOperationHookExtension[];
83
+ }
84
+ /**
85
+ * Indexed view of normalized runtime extension descriptors used by host resolution.
86
+ */
87
+ declare class ExtensionIndex implements ExtensionIndexReadOnly {
88
+ #private;
89
+ /**
90
+ * Return every indexed extension in deterministic order.
91
+ */
92
+ readonly all: readonly RuntimeExtension[];
93
+ /**
94
+ * Return counts for the indexed extension set.
95
+ */
96
+ readonly stats: ExtensionIndexStats;
97
+ constructor(extensions: readonly RuntimeExtension[]);
98
+ /**
99
+ * Return UI extensions matching a target plugin/surface/key/point.
100
+ *
101
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
102
+ * @param surface Semantic UI extension surface.
103
+ * @param surfaceKey Stable semantic surface key.
104
+ * @param point Extension point within the surface.
105
+ * @returns Result returned by ui.
106
+ */
107
+ ui(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string, point: string): readonly RuntimeUiExtension[];
108
+ /**
109
+ * Return operation hooks matching a target operation.
110
+ *
111
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
112
+ * @param surface Extension surface to query.
113
+ * @param surfaceKey Stable semantic key for the target surface.
114
+ * @param operation Operation contract name.
115
+ * @returns Result returned by operationHooks.
116
+ */
117
+ operationHooks(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string, operation: string): readonly RuntimeOperationHookExtension[];
118
+ /**
119
+ * Return event handlers matching a target event.
120
+ *
121
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
122
+ * @param event Event contract name.
123
+ * @returns Result returned by events.
124
+ */
125
+ events(targetPluginIdentifier: string, event: string): readonly RuntimeEventHandlerExtension[];
126
+ /**
127
+ * Return providers matching a target provider contract.
128
+ *
129
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
130
+ * @param provider Provider contract name.
131
+ * @returns Result returned by providers.
132
+ */
133
+ providers(targetPluginIdentifier: string, provider: string): readonly RuntimeProviderExtension[];
134
+ /**
135
+ * Return all UI extensions registered for one semantic surface instance.
136
+ *
137
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
138
+ * @param surface Extension surface to query.
139
+ * @param surfaceKey Stable semantic key for the target surface.
140
+ * @returns Result returned by uiForSurface.
141
+ */
142
+ uiForSurface(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string): readonly RuntimeUiExtension[];
143
+ /**
144
+ * Return all operation hooks registered for one semantic surface.
145
+ *
146
+ * @param targetPluginIdentifier Identifier of the plugin owning the target surface.
147
+ * @param surface Extension surface to query.
148
+ * @param surfaceKey Stable semantic key for the target surface.
149
+ * @returns Result returned by operationHooksForSurface.
150
+ */
151
+ operationHooksForSurface(targetPluginIdentifier: string, surface: ExtensionSurface, surfaceKey: string): readonly RuntimeOperationHookExtension[];
152
+ }
153
+ /**
154
+ * Create an immutable query index from normalized runtime extension descriptors.
155
+ *
156
+ * @param extensions Normalized runtime extension descriptors to index.
157
+ * @returns Result returned by createExtensionIndex.
158
+ */
159
+ declare function createExtensionIndex(extensions: readonly RuntimeExtension[]): ExtensionIndexReadOnly;
160
+ /** Canonical deterministic ordering used by every extension bucket. */
161
+ /**
162
+ * @param left Left extension descriptor to compare.
163
+ * @param right Right extension descriptor to compare.
164
+ * @returns Result returned by compareRuntimeExtensions.
165
+ */
166
+ declare function compareRuntimeExtensions(left: Pick<RuntimeExtension, "order" | "id">, right: Pick<RuntimeExtension, "order" | "id">): number;
167
+ /**
168
+ * Canonical target equivalence encoding. Length-prefixing avoids delimiter
169
+ * collisions while keeping key construction allocation small and predictable.
170
+ */
171
+ /**
172
+ * @param value Input value to normalize/convert.
173
+ * @returns Result returned by extensionTargetPart.
174
+ */
175
+ declare function extensionTargetPart(value: string): string;
176
+
177
+ export { ExtensionIndex, compareRuntimeExtensions, createExtensionIndex, extensionTargetPart };
178
+ export type { ExtensionIndexReadOnly, ExtensionIndexStats };
@@ -0,0 +1,3 @@
1
+ export { ExtensionIndex, compareRuntimeExtensions, createExtensionIndex, extensionTargetPart } from './chunk-AFVR6B2A.js';
2
+ //# sourceMappingURL=extension-index.js.map
3
+ //# sourceMappingURL=extension-index.js.map