@plugmatica/semantic-contracts 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.
- package/LICENSE +21 -0
- package/README.md +62 -2
- package/dist/index.d.ts +2534 -0
- package/dist/index.js +1194 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1194 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/generated/protocol.ts
|
|
6
|
+
var EXTENSION_KINDS = [
|
|
7
|
+
"ui",
|
|
8
|
+
"operation_hook",
|
|
9
|
+
"event_handler",
|
|
10
|
+
"provider"
|
|
11
|
+
];
|
|
12
|
+
var EXTENSION_SURFACES = [
|
|
13
|
+
"page",
|
|
14
|
+
"page_header",
|
|
15
|
+
"grid",
|
|
16
|
+
"nav_menu",
|
|
17
|
+
"form",
|
|
18
|
+
"field",
|
|
19
|
+
"card",
|
|
20
|
+
"tabs",
|
|
21
|
+
"panel",
|
|
22
|
+
"dialog",
|
|
23
|
+
"table",
|
|
24
|
+
"chart",
|
|
25
|
+
"metric",
|
|
26
|
+
"action",
|
|
27
|
+
"settings_section",
|
|
28
|
+
"wizard",
|
|
29
|
+
"slot",
|
|
30
|
+
"slot_frame",
|
|
31
|
+
"slot_container",
|
|
32
|
+
"custom"
|
|
33
|
+
];
|
|
34
|
+
var OPERATION_EXTENSION_PHASES = [
|
|
35
|
+
"before",
|
|
36
|
+
"after",
|
|
37
|
+
"error",
|
|
38
|
+
"finally"
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// src/extensions/identity.ts
|
|
42
|
+
var ExtensionIdentityError = class extends Error {
|
|
43
|
+
constructor(code, message, value) {
|
|
44
|
+
super(message);
|
|
45
|
+
/** Stable machine-readable reason for the identity failure. */
|
|
46
|
+
__publicField(this, "code");
|
|
47
|
+
/** Optional offending identity value or expression. */
|
|
48
|
+
__publicField(this, "value");
|
|
49
|
+
this.name = "ExtensionIdentityError";
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.value = value;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var absentExtensionIdentity = {
|
|
55
|
+
state: "absent"
|
|
56
|
+
};
|
|
57
|
+
function staticExtensionIdentity(value) {
|
|
58
|
+
return { state: "static", value };
|
|
59
|
+
}
|
|
60
|
+
function dynamicExtensionIdentity(expression) {
|
|
61
|
+
return expression ? { state: "dynamic", expression } : { state: "dynamic" };
|
|
62
|
+
}
|
|
63
|
+
function createExtensionScope(input) {
|
|
64
|
+
if (input == null || input === "") {
|
|
65
|
+
return { segments: [] };
|
|
66
|
+
}
|
|
67
|
+
const raw = typeof input === "string" ? [input] : input;
|
|
68
|
+
const segments = raw.flatMap((part) => splitIdentity(part));
|
|
69
|
+
return { segments };
|
|
70
|
+
}
|
|
71
|
+
function composeExtensionPublicKey(scope, identity) {
|
|
72
|
+
const parent = createExtensionScope(scope);
|
|
73
|
+
const local = splitIdentity(identity);
|
|
74
|
+
return asSurfaceKey([...parent.segments, ...local].join("."));
|
|
75
|
+
}
|
|
76
|
+
function resolveQualifiedExtensionPublicKey(scope, key) {
|
|
77
|
+
const normalized = normalizePublicIdentity(key);
|
|
78
|
+
if (normalized.includes(".")) {
|
|
79
|
+
return asSurfaceKey(normalized);
|
|
80
|
+
}
|
|
81
|
+
return composeExtensionPublicKey(scope, normalized);
|
|
82
|
+
}
|
|
83
|
+
function derivePublicExtensionIdentity(request) {
|
|
84
|
+
const scope = createExtensionScope(request.scope);
|
|
85
|
+
const explicit = request.explicit ?? absentExtensionIdentity;
|
|
86
|
+
const semantic = request.semantic ?? absentExtensionIdentity;
|
|
87
|
+
if (explicit.state === "dynamic") {
|
|
88
|
+
throw new ExtensionIdentityError(
|
|
89
|
+
"dynamic_explicit_identity",
|
|
90
|
+
"The public `extension` override must be statically resolvable at build time.",
|
|
91
|
+
explicit.expression
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (explicit.state === "static") {
|
|
95
|
+
const local = normalizeExplicitExtensionName(explicit.value);
|
|
96
|
+
return {
|
|
97
|
+
key: composeExtensionPublicKey(scope.segments, local),
|
|
98
|
+
scope,
|
|
99
|
+
source: "explicit",
|
|
100
|
+
localIdentity: local
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (semantic.state === "dynamic") {
|
|
104
|
+
throw new ExtensionIdentityError(
|
|
105
|
+
"dynamic_semantic_identity",
|
|
106
|
+
"A semantic public extension identity must be statically resolvable at build time.",
|
|
107
|
+
semantic.expression
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (semantic.state === "static") {
|
|
111
|
+
const local = normalizePublicIdentity(semantic.value);
|
|
112
|
+
return {
|
|
113
|
+
key: composeExtensionPublicKey(scope.segments, local),
|
|
114
|
+
scope,
|
|
115
|
+
source: "semantic",
|
|
116
|
+
localIdentity: local
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (request.allowEnclosingScope && scope.segments.length > 0) {
|
|
120
|
+
return {
|
|
121
|
+
key: asSurfaceKey(scope.segments.join(".")),
|
|
122
|
+
scope,
|
|
123
|
+
source: "scope",
|
|
124
|
+
localIdentity: null
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
throw new ExtensionIdentityError(
|
|
128
|
+
"ambiguous_identity",
|
|
129
|
+
"A stable public extension identity cannot be inferred. Provide semantic source identity or a static `extension` override."
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function deriveUniquePublicExtensionIdentities(requests) {
|
|
133
|
+
const result = requests.map(derivePublicExtensionIdentity);
|
|
134
|
+
const seen = /* @__PURE__ */ new Set();
|
|
135
|
+
for (const identity of result) {
|
|
136
|
+
if (seen.has(identity.key)) {
|
|
137
|
+
throw new ExtensionIdentityError(
|
|
138
|
+
"duplicate_identity",
|
|
139
|
+
`Public extension identity '${identity.key}' is declared more than once. Add stable semantic identity or an explicit extension override instead of relying on generated suffixes.`,
|
|
140
|
+
identity.key
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
seen.add(identity.key);
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
function createCurrentExtensionContract(input) {
|
|
148
|
+
const surfaces = (input.surfaces ?? []).map((surface) => ({
|
|
149
|
+
surface: surface.surface,
|
|
150
|
+
key: asSurfaceKey(surface.key),
|
|
151
|
+
contract: { ...surface.contract },
|
|
152
|
+
points: surface.points.map((point2) => ({
|
|
153
|
+
key: asPointKey(point2.key),
|
|
154
|
+
multiple: point2.multiple,
|
|
155
|
+
...point2.ownerAnchors && point2.ownerAnchors.length > 0 ? {
|
|
156
|
+
ownerAnchors: [...new Set(point2.ownerAnchors)].sort(
|
|
157
|
+
(left, right) => left.localeCompare(right)
|
|
158
|
+
)
|
|
159
|
+
} : {},
|
|
160
|
+
...point2.ownerAnchorsComplete ? { ownerAnchorsComplete: true } : {}
|
|
161
|
+
})).sort((left, right) => left.key.localeCompare(right.key)),
|
|
162
|
+
operations: surface.operations.map(asOperationKey).sort((left, right) => left.localeCompare(right))
|
|
163
|
+
}));
|
|
164
|
+
assertUniqueSurfaceContracts(surfaces);
|
|
165
|
+
const events = (input.events ?? []).map((event) => ({
|
|
166
|
+
key: asSurfaceKey(event.key),
|
|
167
|
+
contract: { ...event.contract },
|
|
168
|
+
multiple: event.multiple
|
|
169
|
+
})).sort((left, right) => left.key.localeCompare(right.key));
|
|
170
|
+
assertUniqueKeys(events, "event");
|
|
171
|
+
const providers = (input.providers ?? []).map((provider) => ({
|
|
172
|
+
key: asSurfaceKey(provider.key),
|
|
173
|
+
contract: { ...provider.contract },
|
|
174
|
+
multiple: provider.multiple
|
|
175
|
+
})).sort((left, right) => left.key.localeCompare(right.key));
|
|
176
|
+
assertUniqueKeys(providers, "provider");
|
|
177
|
+
surfaces.sort(
|
|
178
|
+
(left, right) => left.surface.localeCompare(right.surface) || left.key.localeCompare(right.key)
|
|
179
|
+
);
|
|
180
|
+
return { surfaces, events, providers };
|
|
181
|
+
}
|
|
182
|
+
function normalizePublicIdentity(value) {
|
|
183
|
+
return splitIdentity(value).join(".");
|
|
184
|
+
}
|
|
185
|
+
function normalizeExplicitExtensionName(value) {
|
|
186
|
+
const normalized = normalizePublicIdentity(value);
|
|
187
|
+
for (const segment of normalized.split(".")) {
|
|
188
|
+
if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(segment)) {
|
|
189
|
+
throw new ExtensionIdentityError(
|
|
190
|
+
"invalid_identity",
|
|
191
|
+
`Explicit extension name '${value}' is invalid. Use lower-kebab segments such as 'summary' or 'billing-summary'.`,
|
|
192
|
+
value
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return normalized;
|
|
197
|
+
}
|
|
198
|
+
function splitIdentity(value) {
|
|
199
|
+
const normalized = value.trim();
|
|
200
|
+
if (!normalized) {
|
|
201
|
+
throw invalidIdentity(value, "identity cannot be empty");
|
|
202
|
+
}
|
|
203
|
+
if (/\s/.test(normalized) || /[\u0000-\u001f\u007f]/.test(normalized)) {
|
|
204
|
+
throw invalidIdentity(
|
|
205
|
+
value,
|
|
206
|
+
"whitespace and control characters are not allowed"
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const segments = normalized.split(".");
|
|
210
|
+
for (const segment of segments) {
|
|
211
|
+
if (!segment) {
|
|
212
|
+
throw invalidIdentity(
|
|
213
|
+
value,
|
|
214
|
+
"empty dot-separated segments are not allowed"
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(segment)) {
|
|
218
|
+
throw invalidIdentity(
|
|
219
|
+
value,
|
|
220
|
+
`segment '${segment}' must contain only letters, digits, '_' or '-' and start with a letter or digit`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return segments;
|
|
225
|
+
}
|
|
226
|
+
function invalidIdentity(value, reason) {
|
|
227
|
+
return new ExtensionIdentityError(
|
|
228
|
+
"invalid_identity",
|
|
229
|
+
`Invalid public extension identity '${value}': ${reason}.`,
|
|
230
|
+
value
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
function asSurfaceKey(value) {
|
|
234
|
+
return normalizePublicIdentity(value);
|
|
235
|
+
}
|
|
236
|
+
function asPointKey(value) {
|
|
237
|
+
return normalizePublicIdentity(value);
|
|
238
|
+
}
|
|
239
|
+
function asOperationKey(value) {
|
|
240
|
+
return normalizePublicIdentity(value);
|
|
241
|
+
}
|
|
242
|
+
function assertUniqueSurfaceContracts(surfaces) {
|
|
243
|
+
const seen = /* @__PURE__ */ new Set();
|
|
244
|
+
for (const surface of surfaces) {
|
|
245
|
+
const identity = `${surface.surface}:${surface.key}`;
|
|
246
|
+
if (seen.has(identity)) {
|
|
247
|
+
throw new ExtensionIdentityError(
|
|
248
|
+
"duplicate_identity",
|
|
249
|
+
`Current Extension Contract contains duplicate surface '${identity}'.`,
|
|
250
|
+
identity
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
seen.add(identity);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function assertUniqueKeys(values, kind) {
|
|
257
|
+
const seen = /* @__PURE__ */ new Set();
|
|
258
|
+
for (const value of values) {
|
|
259
|
+
if (seen.has(value.key)) {
|
|
260
|
+
throw new ExtensionIdentityError(
|
|
261
|
+
"duplicate_identity",
|
|
262
|
+
`Current Extension Contract contains duplicate ${kind} '${value.key}'.`,
|
|
263
|
+
value.key
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
seen.add(value.key);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/extensions/standardSurfaces.ts
|
|
271
|
+
function point(key, label, description, group, importance = "primary", multiple = true, contributionSchema) {
|
|
272
|
+
return {
|
|
273
|
+
key,
|
|
274
|
+
label,
|
|
275
|
+
description,
|
|
276
|
+
group,
|
|
277
|
+
importance,
|
|
278
|
+
multiple,
|
|
279
|
+
...contributionSchema ? { contributionSchema } : {}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
var orderedRenderContribution = {
|
|
283
|
+
kind: "object",
|
|
284
|
+
required: { key: "string", render: "function" },
|
|
285
|
+
optional: { order: "number", placement: "object" }
|
|
286
|
+
};
|
|
287
|
+
var orderedItemContribution = {
|
|
288
|
+
kind: "object",
|
|
289
|
+
required: { key: "string", item: "object" },
|
|
290
|
+
optional: { order: "number", placement: "object" }
|
|
291
|
+
};
|
|
292
|
+
function spatialPoints(surface) {
|
|
293
|
+
return [
|
|
294
|
+
point("top.left", "Top left", `Adds content to the ${surface}'s top-left zone.`, "Spatial"),
|
|
295
|
+
point("top.center", "Top center", `Adds content to the ${surface}'s top-center/title zone.`, "Spatial"),
|
|
296
|
+
point("top.right", "Top right", `Adds content to the ${surface}'s top-right/action zone.`, "Spatial"),
|
|
297
|
+
point("middle.left", "Middle left", `Adds content to the ${surface}'s middle-left zone.`, "Spatial"),
|
|
298
|
+
point("middle.center", "Middle center", `Adds content to the ${surface}'s main content zone.`, "Spatial"),
|
|
299
|
+
point("middle.right", "Middle right", `Adds content to the ${surface}'s middle-right zone.`, "Spatial"),
|
|
300
|
+
point("bottom.left", "Bottom left", `Adds content to the ${surface}'s bottom-left zone.`, "Spatial"),
|
|
301
|
+
point("bottom.center", "Bottom center", `Adds content to the ${surface}'s footer zone.`, "Spatial"),
|
|
302
|
+
point("bottom.right", "Bottom right", `Adds content to the ${surface}'s bottom-right zone.`, "Spatial")
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
var standardExtensionSurfaces = {
|
|
306
|
+
page: {
|
|
307
|
+
surface: "page",
|
|
308
|
+
component: "Page",
|
|
309
|
+
contract: { id: "plugmatica.ui.page", version: "1.0.0" },
|
|
310
|
+
points: [
|
|
311
|
+
point(
|
|
312
|
+
"before",
|
|
313
|
+
"Before page",
|
|
314
|
+
"Renders before owner page items.",
|
|
315
|
+
"Page",
|
|
316
|
+
"advanced"
|
|
317
|
+
),
|
|
318
|
+
point(
|
|
319
|
+
"items",
|
|
320
|
+
"Page items",
|
|
321
|
+
"Adds ordered top-level page sections.",
|
|
322
|
+
"Page",
|
|
323
|
+
"primary",
|
|
324
|
+
true,
|
|
325
|
+
orderedRenderContribution
|
|
326
|
+
),
|
|
327
|
+
point(
|
|
328
|
+
"after",
|
|
329
|
+
"After page",
|
|
330
|
+
"Renders after owner page items.",
|
|
331
|
+
"Page",
|
|
332
|
+
"advanced"
|
|
333
|
+
)
|
|
334
|
+
],
|
|
335
|
+
operations: []
|
|
336
|
+
},
|
|
337
|
+
page_header: {
|
|
338
|
+
surface: "page_header",
|
|
339
|
+
component: "PageHeader",
|
|
340
|
+
contract: { id: "plugmatica.ui.page-header", version: "1.0.0" },
|
|
341
|
+
points: [
|
|
342
|
+
point(
|
|
343
|
+
"title.before",
|
|
344
|
+
"Before title",
|
|
345
|
+
"Renders before the page title block.",
|
|
346
|
+
"Title",
|
|
347
|
+
"advanced"
|
|
348
|
+
),
|
|
349
|
+
point(
|
|
350
|
+
"title.after",
|
|
351
|
+
"After title",
|
|
352
|
+
"Renders after the page title block.",
|
|
353
|
+
"Title",
|
|
354
|
+
"advanced"
|
|
355
|
+
),
|
|
356
|
+
point(
|
|
357
|
+
"actions",
|
|
358
|
+
"Header actions",
|
|
359
|
+
"Adds ordered actions to the page header.",
|
|
360
|
+
"Actions",
|
|
361
|
+
"primary",
|
|
362
|
+
true,
|
|
363
|
+
orderedRenderContribution
|
|
364
|
+
)
|
|
365
|
+
],
|
|
366
|
+
operations: []
|
|
367
|
+
},
|
|
368
|
+
dialog: {
|
|
369
|
+
surface: "dialog",
|
|
370
|
+
component: "Dialog",
|
|
371
|
+
contract: { id: "plugmatica.ui.dialog", version: "1.0.0" },
|
|
372
|
+
points: [
|
|
373
|
+
point(
|
|
374
|
+
"actions",
|
|
375
|
+
"Dialog actions",
|
|
376
|
+
"Adds ordered footer actions relative to the dialog owner\u2019s stable action keys.",
|
|
377
|
+
"Actions",
|
|
378
|
+
"primary",
|
|
379
|
+
true,
|
|
380
|
+
orderedRenderContribution
|
|
381
|
+
)
|
|
382
|
+
],
|
|
383
|
+
operations: []
|
|
384
|
+
},
|
|
385
|
+
grid: {
|
|
386
|
+
surface: "grid",
|
|
387
|
+
component: "Grid",
|
|
388
|
+
contract: { id: "plugmatica.ui.grid", version: "1.0.0" },
|
|
389
|
+
points: [
|
|
390
|
+
point(
|
|
391
|
+
"items",
|
|
392
|
+
"Grid items",
|
|
393
|
+
"Adds ordered grid items relative to stable owner item keys.",
|
|
394
|
+
"Items",
|
|
395
|
+
"primary",
|
|
396
|
+
true,
|
|
397
|
+
{
|
|
398
|
+
...orderedRenderContribution,
|
|
399
|
+
optional: {
|
|
400
|
+
...orderedRenderContribution.optional,
|
|
401
|
+
span: "unknown",
|
|
402
|
+
className: "string"
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
)
|
|
406
|
+
],
|
|
407
|
+
operations: []
|
|
408
|
+
},
|
|
409
|
+
nav_menu: {
|
|
410
|
+
surface: "nav_menu",
|
|
411
|
+
component: "NavMenu",
|
|
412
|
+
contract: { id: "plugmatica.ui.nav-menu", version: "1.0.0" },
|
|
413
|
+
points: [
|
|
414
|
+
point(
|
|
415
|
+
"items",
|
|
416
|
+
"Navigation items",
|
|
417
|
+
"Adds ordered navigation items.",
|
|
418
|
+
"Navigation",
|
|
419
|
+
"primary",
|
|
420
|
+
true,
|
|
421
|
+
orderedItemContribution
|
|
422
|
+
),
|
|
423
|
+
point(
|
|
424
|
+
"footer.items",
|
|
425
|
+
"Footer navigation items",
|
|
426
|
+
"Adds ordered footer navigation items.",
|
|
427
|
+
"Navigation",
|
|
428
|
+
"advanced",
|
|
429
|
+
true,
|
|
430
|
+
orderedItemContribution
|
|
431
|
+
)
|
|
432
|
+
],
|
|
433
|
+
operations: ["select"]
|
|
434
|
+
},
|
|
435
|
+
form: {
|
|
436
|
+
surface: "form",
|
|
437
|
+
component: "Form",
|
|
438
|
+
contract: { id: "plugmatica.ui.form", version: "1.0.0" },
|
|
439
|
+
points: [
|
|
440
|
+
point(
|
|
441
|
+
"header.before",
|
|
442
|
+
"Before header",
|
|
443
|
+
"Renders immediately before the form header.",
|
|
444
|
+
"Header",
|
|
445
|
+
"advanced"
|
|
446
|
+
),
|
|
447
|
+
point(
|
|
448
|
+
"header.after",
|
|
449
|
+
"After header",
|
|
450
|
+
"Renders immediately after the form header.",
|
|
451
|
+
"Header",
|
|
452
|
+
"advanced"
|
|
453
|
+
),
|
|
454
|
+
point(
|
|
455
|
+
"fields.before",
|
|
456
|
+
"Before fields",
|
|
457
|
+
"Renders above the form field collection.",
|
|
458
|
+
"Fields"
|
|
459
|
+
),
|
|
460
|
+
point(
|
|
461
|
+
"fields",
|
|
462
|
+
"Form fields",
|
|
463
|
+
"Adds fields to the form field collection.",
|
|
464
|
+
"Fields",
|
|
465
|
+
"primary",
|
|
466
|
+
true,
|
|
467
|
+
orderedRenderContribution
|
|
468
|
+
),
|
|
469
|
+
point(
|
|
470
|
+
"fields.after",
|
|
471
|
+
"After fields",
|
|
472
|
+
"Renders below the form field collection.",
|
|
473
|
+
"Fields"
|
|
474
|
+
),
|
|
475
|
+
point(
|
|
476
|
+
"actions.before",
|
|
477
|
+
"Before actions",
|
|
478
|
+
"Renders immediately before the form actions.",
|
|
479
|
+
"Actions",
|
|
480
|
+
"advanced"
|
|
481
|
+
),
|
|
482
|
+
point(
|
|
483
|
+
"actions",
|
|
484
|
+
"Form actions",
|
|
485
|
+
"Adds actions to the form action area.",
|
|
486
|
+
"Actions",
|
|
487
|
+
"primary",
|
|
488
|
+
true,
|
|
489
|
+
orderedRenderContribution
|
|
490
|
+
),
|
|
491
|
+
point(
|
|
492
|
+
"actions.after",
|
|
493
|
+
"After actions",
|
|
494
|
+
"Renders immediately after the form actions.",
|
|
495
|
+
"Actions",
|
|
496
|
+
"advanced"
|
|
497
|
+
),
|
|
498
|
+
point(
|
|
499
|
+
"footer.before",
|
|
500
|
+
"Before footer",
|
|
501
|
+
"Renders immediately before the form footer.",
|
|
502
|
+
"Footer",
|
|
503
|
+
"advanced"
|
|
504
|
+
),
|
|
505
|
+
point(
|
|
506
|
+
"footer.after",
|
|
507
|
+
"After footer",
|
|
508
|
+
"Renders immediately after the form footer.",
|
|
509
|
+
"Footer",
|
|
510
|
+
"advanced"
|
|
511
|
+
)
|
|
512
|
+
],
|
|
513
|
+
operations: ["submit", "reset"]
|
|
514
|
+
},
|
|
515
|
+
field: {
|
|
516
|
+
surface: "field",
|
|
517
|
+
component: "FormField",
|
|
518
|
+
contract: { id: "plugmatica.ui.form-field", version: "1.0.0" },
|
|
519
|
+
points: [
|
|
520
|
+
point(
|
|
521
|
+
"label.before",
|
|
522
|
+
"Before label",
|
|
523
|
+
"Renders before the field label.",
|
|
524
|
+
"Label",
|
|
525
|
+
"advanced"
|
|
526
|
+
),
|
|
527
|
+
point(
|
|
528
|
+
"label.after",
|
|
529
|
+
"After label",
|
|
530
|
+
"Renders after the field label.",
|
|
531
|
+
"Label"
|
|
532
|
+
),
|
|
533
|
+
point(
|
|
534
|
+
"control.before",
|
|
535
|
+
"Before control",
|
|
536
|
+
"Renders before the input control.",
|
|
537
|
+
"Control"
|
|
538
|
+
),
|
|
539
|
+
point(
|
|
540
|
+
"control.after",
|
|
541
|
+
"After control",
|
|
542
|
+
"Renders after the input control.",
|
|
543
|
+
"Control"
|
|
544
|
+
),
|
|
545
|
+
point(
|
|
546
|
+
"description.before",
|
|
547
|
+
"Before description",
|
|
548
|
+
"Renders before help or description text.",
|
|
549
|
+
"Description",
|
|
550
|
+
"advanced"
|
|
551
|
+
),
|
|
552
|
+
point(
|
|
553
|
+
"description.after",
|
|
554
|
+
"After description",
|
|
555
|
+
"Renders after help or description text.",
|
|
556
|
+
"Description"
|
|
557
|
+
),
|
|
558
|
+
point(
|
|
559
|
+
"message.before",
|
|
560
|
+
"Before validation message",
|
|
561
|
+
"Renders before validation feedback.",
|
|
562
|
+
"Validation",
|
|
563
|
+
"advanced"
|
|
564
|
+
),
|
|
565
|
+
point(
|
|
566
|
+
"message.after",
|
|
567
|
+
"After validation message",
|
|
568
|
+
"Renders after validation feedback.",
|
|
569
|
+
"Validation"
|
|
570
|
+
)
|
|
571
|
+
],
|
|
572
|
+
operations: ["change", "blur"]
|
|
573
|
+
},
|
|
574
|
+
card: {
|
|
575
|
+
surface: "card",
|
|
576
|
+
component: "Card",
|
|
577
|
+
contract: { id: "plugmatica.ui.card", version: "1.0.0" },
|
|
578
|
+
points: spatialPoints("card"),
|
|
579
|
+
operations: []
|
|
580
|
+
},
|
|
581
|
+
action: {
|
|
582
|
+
surface: "action",
|
|
583
|
+
component: "Button",
|
|
584
|
+
contract: { id: "plugmatica.ui.action", version: "1.0.0" },
|
|
585
|
+
points: [
|
|
586
|
+
point(
|
|
587
|
+
"content.before",
|
|
588
|
+
"Before button content",
|
|
589
|
+
"Renders before the button label or icon.",
|
|
590
|
+
"Content"
|
|
591
|
+
),
|
|
592
|
+
point(
|
|
593
|
+
"content.after",
|
|
594
|
+
"After button content",
|
|
595
|
+
"Renders after the button label or icon.",
|
|
596
|
+
"Content"
|
|
597
|
+
)
|
|
598
|
+
],
|
|
599
|
+
operations: ["click"]
|
|
600
|
+
},
|
|
601
|
+
table: {
|
|
602
|
+
surface: "table",
|
|
603
|
+
component: "DataTable",
|
|
604
|
+
contract: { id: "plugmatica.ui.table", version: "1.0.0" },
|
|
605
|
+
points: [
|
|
606
|
+
point(
|
|
607
|
+
"toolbar.before",
|
|
608
|
+
"Before toolbar",
|
|
609
|
+
"Renders before the table toolbar.",
|
|
610
|
+
"Toolbar",
|
|
611
|
+
"advanced"
|
|
612
|
+
),
|
|
613
|
+
point(
|
|
614
|
+
"toolbar.actions",
|
|
615
|
+
"Toolbar actions",
|
|
616
|
+
"Adds actions to the table toolbar.",
|
|
617
|
+
"Toolbar"
|
|
618
|
+
),
|
|
619
|
+
point(
|
|
620
|
+
"toolbar.after",
|
|
621
|
+
"After toolbar",
|
|
622
|
+
"Renders after the table toolbar.",
|
|
623
|
+
"Toolbar",
|
|
624
|
+
"advanced"
|
|
625
|
+
),
|
|
626
|
+
point(
|
|
627
|
+
"columns",
|
|
628
|
+
"Table columns",
|
|
629
|
+
"Adds columns to the table.",
|
|
630
|
+
"Table",
|
|
631
|
+
"primary",
|
|
632
|
+
true,
|
|
633
|
+
{
|
|
634
|
+
kind: "object",
|
|
635
|
+
required: {
|
|
636
|
+
key: "string",
|
|
637
|
+
header: "unknown",
|
|
638
|
+
renderCell: "function"
|
|
639
|
+
},
|
|
640
|
+
optional: { order: "number", placement: "object" }
|
|
641
|
+
}
|
|
642
|
+
),
|
|
643
|
+
point(
|
|
644
|
+
"row.actions",
|
|
645
|
+
"Row actions",
|
|
646
|
+
"Adds actions to each table row.",
|
|
647
|
+
"Rows"
|
|
648
|
+
),
|
|
649
|
+
point(
|
|
650
|
+
"selection.actions",
|
|
651
|
+
"Selection actions",
|
|
652
|
+
"Adds actions for the current selected-row set.",
|
|
653
|
+
"Selection"
|
|
654
|
+
),
|
|
655
|
+
point(
|
|
656
|
+
"empty.before",
|
|
657
|
+
"Before empty state",
|
|
658
|
+
"Renders before the empty-state content.",
|
|
659
|
+
"Empty state",
|
|
660
|
+
"advanced"
|
|
661
|
+
),
|
|
662
|
+
point(
|
|
663
|
+
"empty.after",
|
|
664
|
+
"After empty state",
|
|
665
|
+
"Renders after the empty-state content.",
|
|
666
|
+
"Empty state",
|
|
667
|
+
"advanced"
|
|
668
|
+
),
|
|
669
|
+
point(
|
|
670
|
+
"footer.before",
|
|
671
|
+
"Before footer",
|
|
672
|
+
"Renders before the table footer.",
|
|
673
|
+
"Footer",
|
|
674
|
+
"advanced"
|
|
675
|
+
),
|
|
676
|
+
point(
|
|
677
|
+
"footer.after",
|
|
678
|
+
"After footer",
|
|
679
|
+
"Renders after the table footer.",
|
|
680
|
+
"Footer",
|
|
681
|
+
"advanced"
|
|
682
|
+
)
|
|
683
|
+
],
|
|
684
|
+
// Loading remains owner/query state rather than an operation. Semantic
|
|
685
|
+
// table state transitions are operations because extensions may validate,
|
|
686
|
+
// cancel or rewrite sorting/filter/pagination requests before owner state
|
|
687
|
+
// is mutated.
|
|
688
|
+
operations: [
|
|
689
|
+
"refresh",
|
|
690
|
+
"export",
|
|
691
|
+
"row.select",
|
|
692
|
+
"sort.change",
|
|
693
|
+
"filter.change",
|
|
694
|
+
"pagination.change"
|
|
695
|
+
]
|
|
696
|
+
},
|
|
697
|
+
chart: {
|
|
698
|
+
surface: "chart",
|
|
699
|
+
component: "Chart",
|
|
700
|
+
contract: { id: "plugmatica.ui.chart", version: "1.0.0" },
|
|
701
|
+
// V1 permits contextual content around the visualization, but deliberately
|
|
702
|
+
// does not allow cross-plugin mutation of datasets, axes, series or raw
|
|
703
|
+
// renderer options. Those require a future declarative contribution model.
|
|
704
|
+
points: [
|
|
705
|
+
point(
|
|
706
|
+
"before",
|
|
707
|
+
"Before visualization",
|
|
708
|
+
"Renders contextual content immediately before the chart.",
|
|
709
|
+
"Context"
|
|
710
|
+
),
|
|
711
|
+
point(
|
|
712
|
+
"after",
|
|
713
|
+
"After visualization",
|
|
714
|
+
"Renders contextual content immediately after the chart.",
|
|
715
|
+
"Context"
|
|
716
|
+
)
|
|
717
|
+
],
|
|
718
|
+
operations: []
|
|
719
|
+
},
|
|
720
|
+
metric: {
|
|
721
|
+
surface: "metric",
|
|
722
|
+
component: "Stat",
|
|
723
|
+
contract: { id: "plugmatica.ui.metric", version: "1.0.0" },
|
|
724
|
+
points: [
|
|
725
|
+
point(
|
|
726
|
+
"before",
|
|
727
|
+
"Before metric",
|
|
728
|
+
"Renders contextual content immediately before the metric.",
|
|
729
|
+
"Context"
|
|
730
|
+
),
|
|
731
|
+
point(
|
|
732
|
+
"after",
|
|
733
|
+
"After metric",
|
|
734
|
+
"Renders contextual content immediately after the metric.",
|
|
735
|
+
"Context"
|
|
736
|
+
)
|
|
737
|
+
],
|
|
738
|
+
operations: []
|
|
739
|
+
},
|
|
740
|
+
tabs: {
|
|
741
|
+
surface: "tabs",
|
|
742
|
+
component: "Tabs",
|
|
743
|
+
contract: { id: "plugmatica.ui.tabs", version: "1.0.0" },
|
|
744
|
+
points: [
|
|
745
|
+
point("items", "Tabs", "Adds selectable tabs.", "Tabs", "primary", true, {
|
|
746
|
+
...orderedRenderContribution,
|
|
747
|
+
optional: {
|
|
748
|
+
...orderedRenderContribution.optional,
|
|
749
|
+
label: "unknown",
|
|
750
|
+
disabled: "boolean"
|
|
751
|
+
}
|
|
752
|
+
}),
|
|
753
|
+
point(
|
|
754
|
+
"content.before",
|
|
755
|
+
"Above tab content",
|
|
756
|
+
"Renders above the selected tab content.",
|
|
757
|
+
"Content"
|
|
758
|
+
),
|
|
759
|
+
point(
|
|
760
|
+
"content.after",
|
|
761
|
+
"Below tab content",
|
|
762
|
+
"Renders below the selected tab content.",
|
|
763
|
+
"Content"
|
|
764
|
+
),
|
|
765
|
+
point(
|
|
766
|
+
"actions",
|
|
767
|
+
"Tab actions",
|
|
768
|
+
"Adds actions beside the tab list.",
|
|
769
|
+
"Actions"
|
|
770
|
+
)
|
|
771
|
+
],
|
|
772
|
+
operations: ["change"]
|
|
773
|
+
},
|
|
774
|
+
panel: {
|
|
775
|
+
surface: "panel",
|
|
776
|
+
component: "Panel",
|
|
777
|
+
contract: { id: "plugmatica.ui.panel", version: "1.0.0" },
|
|
778
|
+
points: spatialPoints("panel"),
|
|
779
|
+
operations: ["open", "close"]
|
|
780
|
+
},
|
|
781
|
+
settings_section: {
|
|
782
|
+
surface: "settings_section",
|
|
783
|
+
component: "SettingsSection",
|
|
784
|
+
contract: { id: "plugmatica.ui.settings-section", version: "1.0.0" },
|
|
785
|
+
points: [
|
|
786
|
+
point(
|
|
787
|
+
"items.before",
|
|
788
|
+
"Before settings",
|
|
789
|
+
"Renders before the setting items.",
|
|
790
|
+
"Settings"
|
|
791
|
+
),
|
|
792
|
+
point(
|
|
793
|
+
"items",
|
|
794
|
+
"Setting items",
|
|
795
|
+
"Adds settings to the section.",
|
|
796
|
+
"Settings"
|
|
797
|
+
),
|
|
798
|
+
point(
|
|
799
|
+
"items.after",
|
|
800
|
+
"After settings",
|
|
801
|
+
"Renders after the setting items.",
|
|
802
|
+
"Settings"
|
|
803
|
+
),
|
|
804
|
+
point(
|
|
805
|
+
"actions",
|
|
806
|
+
"Section actions",
|
|
807
|
+
"Adds actions to the settings section.",
|
|
808
|
+
"Actions"
|
|
809
|
+
)
|
|
810
|
+
],
|
|
811
|
+
operations: ["save", "reset"]
|
|
812
|
+
},
|
|
813
|
+
wizard: {
|
|
814
|
+
surface: "wizard",
|
|
815
|
+
component: "Wizard",
|
|
816
|
+
contract: { id: "plugmatica.ui.wizard", version: "1.0.0" },
|
|
817
|
+
points: [
|
|
818
|
+
point(
|
|
819
|
+
"steps",
|
|
820
|
+
"Wizard steps",
|
|
821
|
+
"Adds steps to the wizard.",
|
|
822
|
+
"Steps",
|
|
823
|
+
"primary",
|
|
824
|
+
true,
|
|
825
|
+
{
|
|
826
|
+
...orderedRenderContribution,
|
|
827
|
+
required: { ...orderedRenderContribution.required, title: "string" },
|
|
828
|
+
optional: {
|
|
829
|
+
...orderedRenderContribution.optional,
|
|
830
|
+
validationFields: "string[]"
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
),
|
|
834
|
+
point(
|
|
835
|
+
"header.before",
|
|
836
|
+
"Before header",
|
|
837
|
+
"Renders before the wizard header.",
|
|
838
|
+
"Header",
|
|
839
|
+
"advanced"
|
|
840
|
+
),
|
|
841
|
+
point(
|
|
842
|
+
"content.before",
|
|
843
|
+
"Above step content",
|
|
844
|
+
"Renders above the active step.",
|
|
845
|
+
"Content"
|
|
846
|
+
),
|
|
847
|
+
point(
|
|
848
|
+
"content.after",
|
|
849
|
+
"Below step content",
|
|
850
|
+
"Renders below the active step.",
|
|
851
|
+
"Content"
|
|
852
|
+
),
|
|
853
|
+
point(
|
|
854
|
+
"footer.before",
|
|
855
|
+
"Before footer",
|
|
856
|
+
"Renders before wizard navigation.",
|
|
857
|
+
"Footer",
|
|
858
|
+
"advanced"
|
|
859
|
+
),
|
|
860
|
+
point(
|
|
861
|
+
"footer.actions",
|
|
862
|
+
"Footer actions",
|
|
863
|
+
"Adds actions to wizard navigation.",
|
|
864
|
+
"Footer"
|
|
865
|
+
),
|
|
866
|
+
point(
|
|
867
|
+
"footer.after",
|
|
868
|
+
"After footer",
|
|
869
|
+
"Renders after wizard navigation.",
|
|
870
|
+
"Footer",
|
|
871
|
+
"advanced"
|
|
872
|
+
)
|
|
873
|
+
],
|
|
874
|
+
operations: ["next", "previous", "finish", "cancel"]
|
|
875
|
+
},
|
|
876
|
+
slot: {
|
|
877
|
+
surface: "slot",
|
|
878
|
+
component: "ExtensionSlot",
|
|
879
|
+
contract: { id: "plugmatica.ui.slot", version: "1.0.0" },
|
|
880
|
+
points: [
|
|
881
|
+
point("content", "Content", "Adds content to the slot.", "Content")
|
|
882
|
+
],
|
|
883
|
+
operations: []
|
|
884
|
+
},
|
|
885
|
+
slot_frame: {
|
|
886
|
+
surface: "slot_frame",
|
|
887
|
+
component: "SlotFrame",
|
|
888
|
+
contract: { id: "plugmatica.ui.slot-frame", version: "1.0.0" },
|
|
889
|
+
points: [
|
|
890
|
+
point(
|
|
891
|
+
"header.before",
|
|
892
|
+
"Before header",
|
|
893
|
+
"Renders immediately before the frame header.",
|
|
894
|
+
"Header",
|
|
895
|
+
"advanced"
|
|
896
|
+
),
|
|
897
|
+
point(
|
|
898
|
+
"header.actions",
|
|
899
|
+
"Header actions",
|
|
900
|
+
"Adds actions to the right side of the frame header.",
|
|
901
|
+
"Header"
|
|
902
|
+
),
|
|
903
|
+
point(
|
|
904
|
+
"content.before",
|
|
905
|
+
"Above content",
|
|
906
|
+
"Renders between the header and the main frame content.",
|
|
907
|
+
"Content"
|
|
908
|
+
),
|
|
909
|
+
point(
|
|
910
|
+
"content",
|
|
911
|
+
"Main content",
|
|
912
|
+
"Adds content inside the main frame body.",
|
|
913
|
+
"Content"
|
|
914
|
+
),
|
|
915
|
+
point(
|
|
916
|
+
"content.after",
|
|
917
|
+
"Below content",
|
|
918
|
+
"Renders after the main content and before the footer.",
|
|
919
|
+
"Content"
|
|
920
|
+
),
|
|
921
|
+
point(
|
|
922
|
+
"footer.before",
|
|
923
|
+
"Before footer",
|
|
924
|
+
"Renders immediately before the frame footer.",
|
|
925
|
+
"Footer",
|
|
926
|
+
"advanced"
|
|
927
|
+
),
|
|
928
|
+
point(
|
|
929
|
+
"footer.actions",
|
|
930
|
+
"Footer actions",
|
|
931
|
+
"Adds actions to the frame footer.",
|
|
932
|
+
"Footer"
|
|
933
|
+
),
|
|
934
|
+
point(
|
|
935
|
+
"footer.after",
|
|
936
|
+
"After footer",
|
|
937
|
+
"Renders immediately after the frame footer.",
|
|
938
|
+
"Footer",
|
|
939
|
+
"advanced"
|
|
940
|
+
)
|
|
941
|
+
],
|
|
942
|
+
operations: []
|
|
943
|
+
},
|
|
944
|
+
slot_container: {
|
|
945
|
+
surface: "slot_container",
|
|
946
|
+
component: "ExtensionSlotContainer",
|
|
947
|
+
contract: { id: "plugmatica.ui.slot-container", version: "1.0.0" },
|
|
948
|
+
points: [
|
|
949
|
+
point("content", "Content", "Adds content to the container.", "Content")
|
|
950
|
+
],
|
|
951
|
+
operations: []
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
function standardSurfaceContract(surface) {
|
|
955
|
+
return standardExtensionSurfaces[surface].contract;
|
|
956
|
+
}
|
|
957
|
+
function standardSurfaceContractRequirement(surface) {
|
|
958
|
+
const contract = standardExtensionSurfaces[surface].contract;
|
|
959
|
+
return { id: contract.id, version: `^${contract.version}` };
|
|
960
|
+
}
|
|
961
|
+
function standardSurfaceDefinition(surface, key, metadata = {}) {
|
|
962
|
+
const standard = standardExtensionSurfaces[surface];
|
|
963
|
+
return {
|
|
964
|
+
key,
|
|
965
|
+
surface: standard.surface,
|
|
966
|
+
contract: { ...standard.contract },
|
|
967
|
+
points: standard.points.map(({ key: pointKey, multiple }) => ({
|
|
968
|
+
key: pointKey,
|
|
969
|
+
multiple
|
|
970
|
+
})),
|
|
971
|
+
operations: [...standard.operations],
|
|
972
|
+
metadata: {
|
|
973
|
+
...metadata,
|
|
974
|
+
pointDefinitions: standard.points.map((definition) => ({
|
|
975
|
+
...definition
|
|
976
|
+
}))
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
function standardContributionSchema(surface, pointKey) {
|
|
981
|
+
const definition = standardExtensionSurfaces[surface].points.find(
|
|
982
|
+
(candidate) => candidate.key === pointKey
|
|
983
|
+
);
|
|
984
|
+
return definition?.contributionSchema ?? null;
|
|
985
|
+
}
|
|
986
|
+
function validateStandardContribution(surface, pointKey, value) {
|
|
987
|
+
const schema = standardContributionSchema(surface, pointKey);
|
|
988
|
+
if (!schema) return [];
|
|
989
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
990
|
+
return [`${surface}:${pointKey} contribution must be an object.`];
|
|
991
|
+
}
|
|
992
|
+
const record = value;
|
|
993
|
+
const issues = [];
|
|
994
|
+
for (const [field, fieldType] of Object.entries(schema.required)) {
|
|
995
|
+
if (!(field in record)) {
|
|
996
|
+
issues.push(
|
|
997
|
+
`${surface}:${pointKey} contribution is missing required field '${field}'.`
|
|
998
|
+
);
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
if (!matchesContributionFieldType(record[field], fieldType)) {
|
|
1002
|
+
issues.push(
|
|
1003
|
+
`${surface}:${pointKey} contribution field '${field}' must be ${describeContributionFieldType(fieldType)}.`
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
for (const [field, fieldType] of Object.entries(schema.optional ?? {})) {
|
|
1008
|
+
if (record[field] === void 0) continue;
|
|
1009
|
+
if (!matchesContributionFieldType(record[field], fieldType)) {
|
|
1010
|
+
issues.push(
|
|
1011
|
+
`${surface}:${pointKey} contribution field '${field}' must be ${describeContributionFieldType(fieldType)} when provided.`
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (!schema.allowUnknownFields) {
|
|
1016
|
+
const known = /* @__PURE__ */ new Set([
|
|
1017
|
+
...Object.keys(schema.required),
|
|
1018
|
+
...Object.keys(schema.optional ?? {})
|
|
1019
|
+
]);
|
|
1020
|
+
for (const field of Object.keys(record)) {
|
|
1021
|
+
if (!known.has(field)) {
|
|
1022
|
+
issues.push(
|
|
1023
|
+
`${surface}:${pointKey} contribution contains unknown field '${field}'.`
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return issues;
|
|
1029
|
+
}
|
|
1030
|
+
function matchesContributionFieldType(value, fieldType) {
|
|
1031
|
+
switch (fieldType) {
|
|
1032
|
+
case "unknown":
|
|
1033
|
+
return true;
|
|
1034
|
+
case "string":
|
|
1035
|
+
case "number":
|
|
1036
|
+
case "boolean":
|
|
1037
|
+
case "function":
|
|
1038
|
+
return typeof value === fieldType;
|
|
1039
|
+
case "object":
|
|
1040
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1041
|
+
case "string[]":
|
|
1042
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
function describeContributionFieldType(fieldType) {
|
|
1046
|
+
if (fieldType === "string[]") return "an array of strings";
|
|
1047
|
+
if (fieldType === "unknown") return "present";
|
|
1048
|
+
return `a ${fieldType}`;
|
|
1049
|
+
}
|
|
1050
|
+
function isStandardExtensionSurface(value) {
|
|
1051
|
+
return Object.prototype.hasOwnProperty.call(standardExtensionSurfaces, value);
|
|
1052
|
+
}
|
|
1053
|
+
function isStandardExtensionContractId(value) {
|
|
1054
|
+
return Object.values(standardExtensionSurfaces).some(
|
|
1055
|
+
(definition) => definition.contract.id === value
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
function standardSurfaceForContractId(contractId) {
|
|
1059
|
+
for (const [surface, definition] of Object.entries(
|
|
1060
|
+
standardExtensionSurfaces
|
|
1061
|
+
)) {
|
|
1062
|
+
if (definition.contract.id === contractId) {
|
|
1063
|
+
return surface;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
function validateStandardSurfaceDefinition(candidate) {
|
|
1069
|
+
if (candidate.surface === "custom") {
|
|
1070
|
+
if (isStandardExtensionContractId(candidate.contract.id)) {
|
|
1071
|
+
return [
|
|
1072
|
+
{
|
|
1073
|
+
field: "contract",
|
|
1074
|
+
message: `Contract id '${candidate.contract.id}' is reserved for the canonical Plugmatica standard surface '${standardSurfaceForContractId(candidate.contract.id)}'. Use a distinct contract id for a genuinely custom protocol.`
|
|
1075
|
+
}
|
|
1076
|
+
];
|
|
1077
|
+
}
|
|
1078
|
+
return [];
|
|
1079
|
+
}
|
|
1080
|
+
if (!isStandardExtensionSurface(candidate.surface)) {
|
|
1081
|
+
return [
|
|
1082
|
+
{
|
|
1083
|
+
field: "surface",
|
|
1084
|
+
message: `Unknown standard extension surface '${candidate.surface}'.`
|
|
1085
|
+
}
|
|
1086
|
+
];
|
|
1087
|
+
}
|
|
1088
|
+
const expected = standardExtensionSurfaces[candidate.surface];
|
|
1089
|
+
const issues = [];
|
|
1090
|
+
if (candidate.contract.id !== expected.contract.id || candidate.contract.version !== expected.contract.version) {
|
|
1091
|
+
issues.push({
|
|
1092
|
+
field: "contract",
|
|
1093
|
+
message: `Standard surface '${candidate.surface}' must provide canonical contract '${expected.contract.id}@${expected.contract.version}', received '${candidate.contract.id}@${candidate.contract.version}'. Use surface 'custom' for a genuinely custom protocol.`
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
const expectedPoints = expected.points.map(({ key, multiple }) => ({
|
|
1097
|
+
key,
|
|
1098
|
+
multiple
|
|
1099
|
+
}));
|
|
1100
|
+
if (!samePoints(candidate.points, expectedPoints)) {
|
|
1101
|
+
issues.push({
|
|
1102
|
+
field: "points",
|
|
1103
|
+
message: `Standard surface '${candidate.surface}' must use canonical points [${expectedPoints.map((item) => item.key).join(", ")}].`
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
if (!sameStrings(candidate.operations, expected.operations)) {
|
|
1107
|
+
issues.push({
|
|
1108
|
+
field: "operations",
|
|
1109
|
+
message: `Standard surface '${candidate.surface}' must use canonical operations [${expected.operations.join(", ")}].`
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
return issues;
|
|
1113
|
+
}
|
|
1114
|
+
function assertStandardSurfaceDefinition(candidate) {
|
|
1115
|
+
const issues = validateStandardSurfaceDefinition(candidate);
|
|
1116
|
+
if (issues.length === 0) return;
|
|
1117
|
+
throw new Error(issues.map((issue) => issue.message).join("\n"));
|
|
1118
|
+
}
|
|
1119
|
+
function samePoints(actual, expected) {
|
|
1120
|
+
if (actual.length !== expected.length) return false;
|
|
1121
|
+
const actualMap = new Map(actual.map((point2) => [point2.key, point2.multiple]));
|
|
1122
|
+
return expected.every((point2) => actualMap.get(point2.key) === point2.multiple);
|
|
1123
|
+
}
|
|
1124
|
+
function sameStrings(actual, expected) {
|
|
1125
|
+
if (actual.length !== expected.length) return false;
|
|
1126
|
+
const actualSet = new Set(actual);
|
|
1127
|
+
return expected.every((value) => actualSet.has(value));
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// src/extensions/targets.ts
|
|
1131
|
+
var EXTENSION_TARGET_REFERENCE_VERSION = 1;
|
|
1132
|
+
var EXTENSION_TARGET_PACKAGE_SUBPATH = "./extensions";
|
|
1133
|
+
function compatibleExtensionContractRequirement(contract, surface) {
|
|
1134
|
+
if (surface && isStandardExtensionSurface(surface)) {
|
|
1135
|
+
return standardSurfaceContractRequirement(surface);
|
|
1136
|
+
}
|
|
1137
|
+
return {
|
|
1138
|
+
id: contract.id,
|
|
1139
|
+
version: contract.version.startsWith("^") ? contract.version : `^${contract.version}`
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
function isCapabilityResolvedExtensionTargetToken(value) {
|
|
1143
|
+
return value.resolution === "capability";
|
|
1144
|
+
}
|
|
1145
|
+
function isDirectExtensionTargetToken(value) {
|
|
1146
|
+
return value.resolution !== "capability";
|
|
1147
|
+
}
|
|
1148
|
+
function isExtensionTargetToken(value) {
|
|
1149
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
const record = value;
|
|
1153
|
+
if (record.__pmTarget !== "ui" && record.__pmTarget !== "operation" && record.__pmTarget !== "event" && record.__pmTarget !== "provider") {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
if (record.resolution !== void 0 && record.resolution !== "plugin" && record.resolution !== "capability") {
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
const capabilityResolved = record.resolution === "capability";
|
|
1160
|
+
if (capabilityResolved) {
|
|
1161
|
+
if (typeof record.required !== "boolean" || record.plugin !== void 0 || record.pluginVersion !== void 0) {
|
|
1162
|
+
return false;
|
|
1163
|
+
}
|
|
1164
|
+
} else if (typeof record.plugin !== "string" || !record.plugin || typeof record.pluginVersion !== "string" || !record.pluginVersion || record.required !== void 0) {
|
|
1165
|
+
return false;
|
|
1166
|
+
}
|
|
1167
|
+
if (!record.contract || typeof record.contract !== "object") {
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1170
|
+
const contract = record.contract;
|
|
1171
|
+
if (typeof contract.id !== "string" || typeof contract.version !== "string") {
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
switch (record.__pmTarget) {
|
|
1175
|
+
case "ui": {
|
|
1176
|
+
const anchors = record.ownerAnchors;
|
|
1177
|
+
const anchorsValid = anchors === void 0 || Array.isArray(anchors) && anchors.every(
|
|
1178
|
+
(anchor) => typeof anchor === "string" && anchor.length > 0
|
|
1179
|
+
);
|
|
1180
|
+
const completenessValid = record.ownerAnchorsComplete === void 0 || typeof record.ownerAnchorsComplete === "boolean";
|
|
1181
|
+
return typeof record.surface === "string" && typeof record.key === "string" && typeof record.point === "string" && anchorsValid && completenessValid;
|
|
1182
|
+
}
|
|
1183
|
+
case "operation":
|
|
1184
|
+
return typeof record.surface === "string" && typeof record.key === "string" && typeof record.operation === "string";
|
|
1185
|
+
case "event":
|
|
1186
|
+
return typeof record.event === "string";
|
|
1187
|
+
case "provider":
|
|
1188
|
+
return typeof record.provider === "string";
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
export { EXTENSION_KINDS, EXTENSION_SURFACES, EXTENSION_TARGET_PACKAGE_SUBPATH, EXTENSION_TARGET_REFERENCE_VERSION, ExtensionIdentityError, OPERATION_EXTENSION_PHASES, absentExtensionIdentity, assertStandardSurfaceDefinition, compatibleExtensionContractRequirement, composeExtensionPublicKey, createCurrentExtensionContract, createExtensionScope, derivePublicExtensionIdentity, deriveUniquePublicExtensionIdentities, dynamicExtensionIdentity, isCapabilityResolvedExtensionTargetToken, isDirectExtensionTargetToken, isExtensionTargetToken, isStandardExtensionContractId, isStandardExtensionSurface, normalizeExplicitExtensionName, normalizePublicIdentity, resolveQualifiedExtensionPublicKey, standardContributionSchema, standardExtensionSurfaces, standardSurfaceContract, standardSurfaceContractRequirement, standardSurfaceDefinition, standardSurfaceForContractId, staticExtensionIdentity, validateStandardContribution, validateStandardSurfaceDefinition };
|
|
1193
|
+
//# sourceMappingURL=index.js.map
|
|
1194
|
+
//# sourceMappingURL=index.js.map
|