@serene-pub/sdk 0.6.0-pr-5 → 0.6.0-pr-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +52 -2
- package/dist/actions.js +56 -6
- package/dist/annexFields.d.ts +32 -2
- package/dist/annexFields.js +48 -5
- package/dist/announce.d.ts +142 -2
- package/dist/announce.js +198 -2
- package/dist/attributes.d.ts +331 -6
- package/dist/attributes.js +339 -27
- package/dist/bridges.d.ts +61 -0
- package/dist/bridges.js +112 -0
- package/dist/builder.d.ts +278 -51
- package/dist/builder.js +267 -30
- package/dist/cadences.d.ts +585 -0
- package/dist/cadences.js +1118 -0
- package/dist/capabilities.d.ts +106 -17
- package/dist/capabilities.js +85 -7
- package/dist/checkMethods.d.ts +240 -0
- package/dist/checkMethods.js +362 -0
- package/dist/component.d.ts +6 -1
- package/dist/componentClient.d.ts +42 -6
- package/dist/componentWire.js +22 -4
- package/dist/composerStates.d.ts +96 -0
- package/dist/composerStates.js +190 -0
- package/dist/conditions.d.ts +424 -0
- package/dist/conditions.js +521 -0
- package/dist/config.d.ts +42 -6
- package/dist/config.js +48 -20
- package/dist/conversions.d.ts +41 -0
- package/dist/conversions.js +50 -0
- package/dist/declarations.d.ts +40 -2
- package/dist/declarations.js +178 -10
- package/dist/descriptors.d.ts +287 -4
- package/dist/descriptors.js +281 -18
- package/dist/document.d.ts +47 -2
- package/dist/document.js +46 -14
- package/dist/entities.d.ts +156 -0
- package/dist/entities.js +259 -0
- package/dist/events.d.ts +711 -1
- package/dist/events.js +412 -1
- package/dist/executor.d.ts +4 -3
- package/dist/executor.js +22 -8
- package/dist/exposure.d.ts +128 -0
- package/dist/exposure.js +168 -0
- package/dist/extension.d.ts +127 -3
- package/dist/extension.js +43 -0
- package/dist/fit.d.ts +198 -0
- package/dist/fit.js +351 -0
- package/dist/functions.d.ts +554 -0
- package/dist/functions.js +712 -0
- package/dist/genres.d.ts +303 -89
- package/dist/genres.js +335 -100
- package/dist/hookGrants.d.ts +15 -1
- package/dist/hookGrants.js +11 -10
- package/dist/hooks.d.ts +34 -5
- package/dist/hooks.js +5 -2
- package/dist/hostElements.d.ts +7 -1
- package/dist/hostElements.js +20 -1
- package/dist/hostState.d.ts +110 -0
- package/dist/hostState.js +140 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.js +48 -0
- package/dist/jsonSchema.d.ts +178 -0
- package/dist/jsonSchema.js +570 -0
- package/dist/libraryDraft.d.ts +27 -0
- package/dist/libraryDraft.js +25 -0
- package/dist/lorebookFile.d.ts +44 -0
- package/dist/lorebookFile.js +202 -0
- package/dist/media.d.ts +127 -12
- package/dist/media.js +45 -1
- package/dist/messageBlocks.d.ts +179 -5
- package/dist/messageBlocks.js +208 -6
- package/dist/participants.d.ts +32 -9
- package/dist/participants.js +13 -2
- package/dist/pluginHarness.d.ts +63 -33
- package/dist/pluginHarness.js +78 -144
- package/dist/pluginPermissions.d.ts +15 -1
- package/dist/pluginPermissions.js +29 -2
- package/dist/preview.d.ts +45 -4
- package/dist/preview.js +52 -12
- package/dist/primers.d.ts +177 -0
- package/dist/primers.js +265 -0
- package/dist/receipt.d.ts +11 -0
- package/dist/receiverRules.js +9 -0
- package/dist/refs.d.ts +9 -1
- package/dist/refs.js +12 -0
- package/dist/registrations.d.ts +384 -0
- package/dist/registrations.js +625 -0
- package/dist/repertoires.d.ts +502 -0
- package/dist/repertoires.js +666 -0
- package/dist/rulesetDocument.d.ts +116 -0
- package/dist/rulesetDocument.js +252 -0
- package/dist/rulesetSections.d.ts +631 -0
- package/dist/rulesetSections.js +1288 -0
- package/dist/rulesetTemplates.d.ts +161 -0
- package/dist/rulesetTemplates.js +242 -0
- package/dist/rulesets.d.ts +899 -0
- package/dist/rulesets.js +1378 -0
- package/dist/sceneSettings.d.ts +8 -0
- package/dist/sceneSettings.js +10 -2
- package/dist/scope.d.ts +44 -3
- package/dist/scope.js +18 -0
- package/dist/scripts.d.ts +31 -8
- package/dist/scripts.js +45 -8
- package/dist/sessionDossier.d.ts +157 -7
- package/dist/sessionLayout.d.ts +291 -138
- package/dist/sessionLayout.js +504 -211
- package/dist/sessionSettings.d.ts +24 -0
- package/dist/settings.d.ts +95 -4
- package/dist/settings.js +293 -4
- package/dist/shapes.d.ts +80 -1
- package/dist/shapes.js +100 -5
- package/dist/speech.d.ts +333 -0
- package/dist/speech.js +199 -0
- package/dist/statShapes.d.ts +8 -1
- package/dist/statShapes.js +8 -1
- package/dist/status.d.ts +14 -0
- package/dist/status.js +12 -0
- package/dist/storage.d.ts +53 -66
- package/dist/storage.js +7 -12
- package/dist/storyTime.d.ts +25 -1
- package/dist/storyTime.js +42 -2
- package/dist/surfaces.d.ts +15 -2
- package/dist/template.d.ts +19 -1
- package/dist/template.js +25 -11
- package/dist/templateScopeAt.d.ts +1 -1
- package/dist/templateScopeAt.js +11 -8
- package/dist/ties.d.ts +211 -0
- package/dist/ties.js +301 -0
- package/dist/turnOrder.d.ts +25 -14
- package/dist/turnOrder.js +21 -8
- package/dist/userAnnex.d.ts +126 -0
- package/dist/userAnnex.js +214 -0
- package/dist/validate.js +114 -19
- package/dist/values.js +6 -0
- package/dist/vocabularies.d.ts +192 -0
- package/dist/vocabularies.js +326 -0
- package/dist/widgetDecls.d.ts +12 -0
- package/dist/widgetDecls.js +2 -0
- package/dist/widgets.d.ts +1062 -29
- package/dist/widgets.js +218 -3
- package/host-elements.d.ts +90 -0
- package/package.json +1 -1
package/dist/attributes.js
CHANGED
|
@@ -71,10 +71,11 @@
|
|
|
71
71
|
* functions, so they cannot be mistaken at a call site.
|
|
72
72
|
* @ruling entries plan Part 3
|
|
73
73
|
*/
|
|
74
|
-
import { i18nFindings } from './i18n.js';
|
|
74
|
+
import { i18nFindings, i18nText } from './i18n.js';
|
|
75
75
|
import { refuseUnlessIdentical } from './hash.js';
|
|
76
76
|
import { getStatShape, statShapeKindOf } from './statShapes.js';
|
|
77
77
|
import { parseStoryTime } from './storyTime.js';
|
|
78
|
+
import { _repertoireTimeUnit, checkPiece, getRepertoire, RULESET_ID_PATTERN } from './repertoires.js';
|
|
78
79
|
const SLOT_ID = /^[a-z0-9]+(?:[.-][a-z0-9]+)*:slot\/[a-z0-9]+(?:-[a-z0-9]+)*@\d+$/;
|
|
79
80
|
/** @experimental */
|
|
80
81
|
export function assertSlotId(id) {
|
|
@@ -168,13 +169,46 @@ export const derivations = Object.freeze({
|
|
|
168
169
|
requiresFrom: false,
|
|
169
170
|
description: 'A LiquidJS expression on the declaration, evaluated over the state pinned at run start.',
|
|
170
171
|
}),
|
|
172
|
+
/**
|
|
173
|
+
* The clock's part of the day, by the book's own calendar `periods` (default
|
|
174
|
+
* morning 5 · day 12 · dusk 18 · night 22). Absent when the clock has no hour.
|
|
175
|
+
*/
|
|
176
|
+
dayPeriod: Object.freeze({
|
|
177
|
+
id: 'core:derive/day-period@1',
|
|
178
|
+
requiresFrom: false,
|
|
179
|
+
description: "The part of the day the story clock is in, by the calendar's periods.",
|
|
180
|
+
}),
|
|
181
|
+
/**
|
|
182
|
+
* The clock's season, by the book's own calendar `seasons`. Absent without
|
|
183
|
+
* seasons, months, or a clock with a month and day.
|
|
184
|
+
*/
|
|
185
|
+
season: Object.freeze({
|
|
186
|
+
id: 'core:derive/season@1',
|
|
187
|
+
requiresFrom: false,
|
|
188
|
+
description: "The season the story clock is in, by the calendar's seasons.",
|
|
189
|
+
}),
|
|
190
|
+
/**
|
|
191
|
+
* The clock's part of the day over the default periods always (morning, day,
|
|
192
|
+
* dusk, night), whatever the calendar declares.
|
|
193
|
+
*/
|
|
194
|
+
timeOfDay: Object.freeze({
|
|
195
|
+
id: 'core:derive/time-of-day@1',
|
|
196
|
+
requiresFrom: false,
|
|
197
|
+
description: "The default part of the day (morning, day, dusk, night) the story clock is in.",
|
|
198
|
+
}),
|
|
171
199
|
});
|
|
172
200
|
/** @experimental */
|
|
173
201
|
export const getDerivation = (id) => Object.values(derivations).find((d) => d.id === id);
|
|
202
|
+
/** 🚧 Is this list item a piece? @experimental */
|
|
203
|
+
export const isSlotPiece = (item) => !!item &&
|
|
204
|
+
typeof item === 'object' &&
|
|
205
|
+
!Array.isArray(item) &&
|
|
206
|
+
(item.kind === 'inline' || item.kind === 'lore' || item.kind === 'compendium');
|
|
174
207
|
/** Is this list item a lore reference? @experimental */
|
|
175
208
|
export const isSlotLoreRef = (item) => !!item &&
|
|
176
209
|
typeof item === 'object' &&
|
|
177
210
|
!Array.isArray(item) &&
|
|
211
|
+
!('kind' in item) &&
|
|
178
212
|
Number.isInteger(item.entryId) &&
|
|
179
213
|
item.entryId > 0;
|
|
180
214
|
/** 🚧 How many of its entry a reference holds: its `count`, or one when it states none. @experimental */
|
|
@@ -191,8 +225,8 @@ export function heldCountIn(value, entryId) {
|
|
|
191
225
|
return 0;
|
|
192
226
|
let held = 0;
|
|
193
227
|
for (const item of value)
|
|
194
|
-
if (isSlotLoreRef(item) && item.entryId === entryId)
|
|
195
|
-
held +=
|
|
228
|
+
if ((isSlotLoreRef(item) || (isSlotPiece(item) && item.kind === 'lore')) && item.entryId === entryId)
|
|
229
|
+
held += typeof item.count === 'number' ? item.count : 1;
|
|
196
230
|
return held;
|
|
197
231
|
}
|
|
198
232
|
/**
|
|
@@ -204,6 +238,17 @@ export function heldCountIn(value, entryId) {
|
|
|
204
238
|
* @experimental
|
|
205
239
|
*/
|
|
206
240
|
export function slotListItemText(item) {
|
|
241
|
+
if (isSlotPiece(item)) {
|
|
242
|
+
const named = item.kind === 'inline' ? undefined : item.overrides?.name;
|
|
243
|
+
const overridden = typeof named === 'string' ? named : undefined;
|
|
244
|
+
const title = item.kind === 'inline'
|
|
245
|
+
? item.name
|
|
246
|
+
: overridden?.trim() ||
|
|
247
|
+
item.name?.trim() ||
|
|
248
|
+
(item.kind === 'lore' ? `entry ${item.entryId}` : item.pieceId);
|
|
249
|
+
const count = typeof item.count === 'number' ? item.count : 1;
|
|
250
|
+
return count > 1 ? `${title} ×${count}` : title;
|
|
251
|
+
}
|
|
207
252
|
if (isSlotLoreRef(item)) {
|
|
208
253
|
const title = item.name?.trim() || `entry ${item.entryId}`;
|
|
209
254
|
const count = slotLoreRefCount(item);
|
|
@@ -227,22 +272,119 @@ export function slotValueForStorage(value) {
|
|
|
227
272
|
return { entryId: value.entryId };
|
|
228
273
|
if (!Array.isArray(value))
|
|
229
274
|
return value;
|
|
230
|
-
return value.map((item) =>
|
|
231
|
-
?
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
275
|
+
return value.map((item) => isSlotPiece(item)
|
|
276
|
+
? pieceForStorage(item)
|
|
277
|
+
: isSlotLoreRef(item)
|
|
278
|
+
? // One held is stored bare (phase 4): `count: 1` and no count are
|
|
279
|
+
// one value, and it has one spelling on disk.
|
|
280
|
+
item.count === undefined || item.count === 1
|
|
281
|
+
? { entryId: item.entryId }
|
|
282
|
+
: { entryId: item.entryId, count: item.count }
|
|
283
|
+
: item);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* 🚧 The words a value reads at a table that keeps no numbers: the first
|
|
287
|
+
* band its share of `max` fits (`max` absent or 0: a value above none is the
|
|
288
|
+
* whole), or `null` when the slot declares none.
|
|
289
|
+
* @experimental
|
|
290
|
+
*/
|
|
291
|
+
export function slotWordsFor(bands, value, max) {
|
|
292
|
+
if (!bands?.length || typeof value !== 'number' || !Number.isFinite(value))
|
|
293
|
+
return null;
|
|
294
|
+
const top = typeof max === 'number' && max > 0 ? max : null;
|
|
295
|
+
const share = top === null ? (value > 0 ? 1 : 0) : Math.max(0, Math.min(1, value / top));
|
|
296
|
+
for (const b of bands)
|
|
297
|
+
if (share <= b.upTo)
|
|
298
|
+
return b.label;
|
|
299
|
+
return bands[bands.length - 1].label;
|
|
300
|
+
}
|
|
301
|
+
/** A piece as stored: the host-filled `name` and `resolved` of a reference dropped, a count of one spelled bare. */
|
|
302
|
+
function pieceForStorage(item) {
|
|
303
|
+
const { count, ...rest } = item;
|
|
304
|
+
const kept = { ...rest };
|
|
305
|
+
if (item.kind !== 'inline') {
|
|
306
|
+
delete kept.name;
|
|
307
|
+
delete kept.resolved;
|
|
308
|
+
}
|
|
309
|
+
return (count === undefined || count === 1 ? kept : { ...kept, count });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The identity two list items are "the same item" by: a word by its text, a
|
|
313
|
+
* reference (or a lore piece) by its entry, a compendium piece by its row, an
|
|
314
|
+
* inline piece by its name.
|
|
315
|
+
*/
|
|
316
|
+
const listItemKey = (item) => isSlotPiece(item)
|
|
317
|
+
? item.kind === 'lore'
|
|
318
|
+
? `entry:${item.entryId}`
|
|
319
|
+
: item.kind === 'compendium'
|
|
320
|
+
? `compendium:${item.compendiumId}/${item.pieceId}`
|
|
321
|
+
: `piece:${String(item.name).trim().toLowerCase()}`
|
|
322
|
+
: isSlotLoreRef(item)
|
|
323
|
+
? `entry:${item.entryId}`
|
|
324
|
+
: `${typeof item}:${String(item)}`;
|
|
240
325
|
/** 🚧 The earshots a slot may declare. @experimental */
|
|
241
326
|
export const SLOT_EARSHOTS = Object.freeze(['all', 'holder']);
|
|
242
327
|
/** 🚧 A slot's earshot, the default read in: `'holder'` only when it says so. @experimental */
|
|
243
328
|
export const slotEarshot = (decl) => decl.earshot === 'holder' ? 'holder' : 'all';
|
|
244
329
|
/** 🚧 May a session pick this slot as an attribute of its own or carry it in from its world? @experimental */
|
|
245
330
|
export const slotPickable = (decl) => decl.pickable !== false;
|
|
331
|
+
/**
|
|
332
|
+
* Which rulesets own each slot by listing it under their `stats` (not
|
|
333
|
+
* `borrowed`) — filled by `rulesets.ts` as each ruleset registers, so a
|
|
334
|
+
* ruleset's own slots need not spell `rulesetOwned` 20 times over.
|
|
335
|
+
*/
|
|
336
|
+
const listedOwners = new Map();
|
|
337
|
+
/** Record the slots a registering ruleset owns. Called by `rulesets.ts` only. @internal */
|
|
338
|
+
export function _registerRulesetStats(rulesetId, slotIds) {
|
|
339
|
+
for (const id of slotIds) {
|
|
340
|
+
let owners = listedOwners.get(id);
|
|
341
|
+
if (!owners)
|
|
342
|
+
listedOwners.set(id, (owners = new Set()));
|
|
343
|
+
owners.add(rulesetId);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** @internal */
|
|
347
|
+
export function _clearRulesetStats() {
|
|
348
|
+
listedOwners.clear();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 🚧 Forget that one ruleset lists any slot (`_registerRulesetStats`'s
|
|
352
|
+
* inverse); a slot nobody lists any more is dropped from the index.
|
|
353
|
+
* @internal
|
|
354
|
+
*/
|
|
355
|
+
export function _withdrawRulesetStats(rulesetId) {
|
|
356
|
+
for (const [id, owners] of [...listedOwners]) {
|
|
357
|
+
owners.delete(rulesetId);
|
|
358
|
+
if (!owners.size)
|
|
359
|
+
listedOwners.delete(id);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 🚧 The rulesets that own a slot: every registered ruleset that lists it
|
|
364
|
+
* under its `stats` (not `borrowed`), with the slot's own `rulesetOwned` if
|
|
365
|
+
* it spells one. Empty: no ruleset's — pickable in every session.
|
|
366
|
+
* @experimental
|
|
367
|
+
*/
|
|
368
|
+
export function slotRulesetOwners(decl) {
|
|
369
|
+
const owners = new Set(decl.id !== undefined ? (listedOwners.get(decl.id) ?? []) : []);
|
|
370
|
+
if (decl.rulesetOwned !== undefined)
|
|
371
|
+
owners.add(decl.rulesetOwned);
|
|
372
|
+
return [...owners];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 🚧 May a session whose ruleset is `sessionRuleset` pick this slot? A slot a
|
|
376
|
+
* ruleset owns (`slotRulesetOwners`: listed under its `stats`, or spelled
|
|
377
|
+
* `rulesetOwned`) is pickable only in the sessions of a ruleset that owns
|
|
378
|
+
* it; every other slot answers as `slotPickable` does. Pass the declaration
|
|
379
|
+
* with its `id`, so the derived owners are read.
|
|
380
|
+
* @experimental
|
|
381
|
+
*/
|
|
382
|
+
export const slotPickableIn = (decl, sessionRuleset) => {
|
|
383
|
+
if (!slotPickable(decl))
|
|
384
|
+
return false;
|
|
385
|
+
const owners = slotRulesetOwners(decl);
|
|
386
|
+
return !owners.length || (typeof sessionRuleset === 'string' && owners.includes(sessionRuleset));
|
|
387
|
+
};
|
|
246
388
|
const registry = new Map();
|
|
247
389
|
/**
|
|
248
390
|
* What is kept out of this registry's content hash beyond `i18n`/`description`.
|
|
@@ -313,6 +455,16 @@ function register(id, rawProps, origin, authorUserId) {
|
|
|
313
455
|
export function defineAttributeSlot(id, props) {
|
|
314
456
|
return register(id, props, 'code');
|
|
315
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* 🚧 The rulesets' door: the slot a ruleset's own attribute files its values
|
|
460
|
+
* under (`rulesetAttributeSlotDecls`, `<owner>.<ruleset>:slot/<attribute>@N`),
|
|
461
|
+
* registered by `defineRuleset` with the ruleset and withdrawn with it. A
|
|
462
|
+
* code declaration, so an identical re-declaration is a no-op.
|
|
463
|
+
* @internal
|
|
464
|
+
*/
|
|
465
|
+
export function _defineRulesetAttributeSlot(id, props) {
|
|
466
|
+
return register(id, props, 'code');
|
|
467
|
+
}
|
|
316
468
|
/**
|
|
317
469
|
* The plugin-facing door — same registration, minus the ability to claim core's
|
|
318
470
|
* namespace. A plugin that could redefine `core:slot/hp@1` would change what
|
|
@@ -502,7 +654,7 @@ export function slotField(decl) {
|
|
|
502
654
|
/** The catalogue shape a slot names, when it names one (an inline `FieldDecl` names none). @experimental */
|
|
503
655
|
export const slotStatShapeId = (decl) => typeof decl.shape === 'string' ? decl.shape : undefined;
|
|
504
656
|
/** Which kind of stat a slot is; `undefined` for a derived slot, which is computed rather than kept. @experimental */
|
|
505
|
-
export const slotStatShapeKind = (decl) => statShapeKindOf(slotField(decl));
|
|
657
|
+
export const slotStatShapeKind = (decl) => statShapeKindOf(slotField(decl), { repertoire: decl.config?.repertoire });
|
|
506
658
|
/**
|
|
507
659
|
* What a field bounds, as the configuration keys a layer deviates from: a
|
|
508
660
|
* number's `min`/`max`; a choice's options (`of`, or its `members`' keys); a
|
|
@@ -549,6 +701,82 @@ export function fieldSlotConfig(field) {
|
|
|
549
701
|
}
|
|
550
702
|
return out;
|
|
551
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* 🚧 The configuration keys an owner may set on this slot: what its stat
|
|
706
|
+
* shape bounds (`fieldSlotConfig`'s keys) — a number's `min` and `max`; a
|
|
707
|
+
* choice's `of`; a list's `maxItems` and, by its item, `of` or
|
|
708
|
+
* `maxLength`; a line's `maxLength` — and, on every kept slot, the
|
|
709
|
+
* `descriptor` (the model-facing sentence in this world, R5). A derived
|
|
710
|
+
* slot takes none. Nothing else is stored per owner: a key outside these
|
|
711
|
+
* would be kept and read by nobody.
|
|
712
|
+
* @experimental
|
|
713
|
+
*/
|
|
714
|
+
export function statConfigKeys(decl) {
|
|
715
|
+
const field = slotField(decl);
|
|
716
|
+
if (!field)
|
|
717
|
+
return [];
|
|
718
|
+
switch (statShapeKindOf(field)) {
|
|
719
|
+
case 'number':
|
|
720
|
+
return ['min', 'max', 'descriptor'];
|
|
721
|
+
case 'choice':
|
|
722
|
+
return ['of', 'descriptor'];
|
|
723
|
+
case 'list':
|
|
724
|
+
return field.item?.type === 'enum' ? ['maxItems', 'of', 'descriptor'] : ['maxItems', 'maxLength', 'descriptor'];
|
|
725
|
+
case 'text':
|
|
726
|
+
return ['maxLength', 'descriptor'];
|
|
727
|
+
default:
|
|
728
|
+
return ['descriptor'];
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* 🚧 Why this owner configuration may not be stored for this slot — one
|
|
733
|
+
* sentence per fault, empty when it may. Asked of the document's `config`
|
|
734
|
+
* alone; whether its `min` still sits under the owner's `max` once merged
|
|
735
|
+
* with what is in force is the writer's to ask (it holds the layers).
|
|
736
|
+
* @experimental
|
|
737
|
+
*/
|
|
738
|
+
export function statConfigRefusals(decl, config) {
|
|
739
|
+
const label = i18nText(decl.label) ?? decl.id;
|
|
740
|
+
if (!config || typeof config !== 'object' || Array.isArray(config))
|
|
741
|
+
return [`a stat configuration is an object of the keys to change, such as { max: 30 }.`];
|
|
742
|
+
if (decl.type === 'derived')
|
|
743
|
+
return [`${label} is derived, so there is nothing to configure: it is computed every time it is read.`];
|
|
744
|
+
const keys = statConfigKeys(decl);
|
|
745
|
+
const out = [];
|
|
746
|
+
const entries = Object.entries(config);
|
|
747
|
+
if (!entries.length)
|
|
748
|
+
out.push(`the configuration for ${label} changes nothing; name a key: ${keys.join(', ')}.`);
|
|
749
|
+
for (const [key, value] of entries) {
|
|
750
|
+
if (!keys.includes(key)) {
|
|
751
|
+
out.push(`${label} has no '${key}' to configure; it takes ${keys.join(', ')}.`);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
switch (key) {
|
|
755
|
+
case 'min':
|
|
756
|
+
case 'max':
|
|
757
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
758
|
+
out.push(`${label}'s ${key} is a number; '${String(value)}' is not one.`);
|
|
759
|
+
break;
|
|
760
|
+
case 'maxItems':
|
|
761
|
+
case 'maxLength':
|
|
762
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1)
|
|
763
|
+
out.push(`${label}'s ${key} is a whole number above zero; '${String(value)}' is not one.`);
|
|
764
|
+
break;
|
|
765
|
+
case 'of':
|
|
766
|
+
if (!Array.isArray(value) || !value.length || value.some((v) => typeof v !== 'string' || !v.trim()))
|
|
767
|
+
out.push(`${label}'s options are a list of words; '${JSON.stringify(value)}' is not one.`);
|
|
768
|
+
break;
|
|
769
|
+
case 'descriptor':
|
|
770
|
+
if (typeof value !== 'string' || !value.trim())
|
|
771
|
+
out.push(`${label} cannot be described as nothing here; leave 'descriptor' out to keep the declaration's own.`);
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const { min, max } = config;
|
|
776
|
+
if (typeof min === 'number' && typeof max === 'number' && min > max)
|
|
777
|
+
out.push(`${label}'s min (${min}) is above its max (${max}).`);
|
|
778
|
+
return out;
|
|
779
|
+
}
|
|
552
780
|
/**
|
|
553
781
|
* The type a declaration is, from what it said: `type`, `shape`, or both
|
|
554
782
|
* agreeing. Refused with a sentence when neither is said, when the shape is
|
|
@@ -573,7 +801,7 @@ function typeOfDeclaration(id, props) {
|
|
|
573
801
|
}
|
|
574
802
|
else
|
|
575
803
|
field = props.shape;
|
|
576
|
-
const kind = statShapeKindOf(field);
|
|
804
|
+
const kind = statShapeKindOf(field, { repertoire: props.config?.repertoire });
|
|
577
805
|
if (!kind)
|
|
578
806
|
throw new Error(`${id} is shaped as a '${field?.type}' field, which is not a value core can keep as a stat. ` +
|
|
579
807
|
`A stat is a number, a choice, a list of text, a story time, a line of text or a switch.`);
|
|
@@ -587,6 +815,45 @@ function typeOfDeclaration(id, props) {
|
|
|
587
815
|
function checkSlotDeclaration(id, props) {
|
|
588
816
|
if (props.pickable !== undefined && props.pickable !== false)
|
|
589
817
|
throw new Error(`${id}.pickable: only \`false\` is said — a slot is pickable unless it says otherwise.`);
|
|
818
|
+
if (props.rulesetOwned !== undefined && !(typeof props.rulesetOwned === 'string' && RULESET_ID_PATTERN.test(props.rulesetOwned)))
|
|
819
|
+
throw new Error(`${id}.rulesetOwned is '${String(props.rulesetOwned)}'. Name the ruleset that declares the slot — ` +
|
|
820
|
+
`'owner:ruleset/name@N', 'core:ruleset/vis-itineris@1'.`);
|
|
821
|
+
if (props.minSeats !== undefined && !(Number.isInteger(props.minSeats) && props.minSeats >= 1))
|
|
822
|
+
throw new Error(`${id}.minSeats is ${String(props.minSeats)}. Say how many active player seats a session needs ` +
|
|
823
|
+
`before this slot is tracked — a whole number from 1 — or leave it out.`);
|
|
824
|
+
if (props.whenRulesetSetting !== undefined) {
|
|
825
|
+
const w = props.whenRulesetSetting;
|
|
826
|
+
const ok = !!w &&
|
|
827
|
+
typeof w === 'object' &&
|
|
828
|
+
typeof w.ruleset === 'string' &&
|
|
829
|
+
RULESET_ID_PATTERN.test(w.ruleset) &&
|
|
830
|
+
typeof w.setting === 'string' &&
|
|
831
|
+
w.setting.trim() !== '' &&
|
|
832
|
+
Array.isArray(w.is) &&
|
|
833
|
+
w.is.length > 0 &&
|
|
834
|
+
w.is.every((c) => typeof c === 'string' && c.trim() !== '');
|
|
835
|
+
if (!ok)
|
|
836
|
+
throw new Error(`${id}.whenRulesetSetting is { ruleset, setting, is }: the ruleset ('owner:ruleset/name@N'), ` +
|
|
837
|
+
`the name of one of its settings, and the choices under which the slot is tracked — ` +
|
|
838
|
+
`{ ruleset: 'core:ruleset/vis-itineris@1', setting: 'casting', is: ['points'] } — or leave it out.`);
|
|
839
|
+
}
|
|
840
|
+
if (props.shownWhenSet !== undefined && props.shownWhenSet !== true)
|
|
841
|
+
throw new Error(`${id}.shownWhenSet is true or left out: a stat drawn only while it holds something.`);
|
|
842
|
+
if (props.words !== undefined) {
|
|
843
|
+
const bands = props.words;
|
|
844
|
+
const ok = Array.isArray(bands) &&
|
|
845
|
+
bands.length > 0 &&
|
|
846
|
+
bands.every((b, i) => !!b &&
|
|
847
|
+
typeof b === 'object' &&
|
|
848
|
+
typeof b.upTo === 'number' &&
|
|
849
|
+
b.upTo >= 0 &&
|
|
850
|
+
b.upTo <= 1 &&
|
|
851
|
+
(i === 0 || b.upTo > bands[i - 1].upTo) &&
|
|
852
|
+
!!b.label);
|
|
853
|
+
if (!ok)
|
|
854
|
+
throw new Error(`${id}.words is a list of bands, first fitting first — each { upTo, label }, upTo a share of the ` +
|
|
855
|
+
`stat's maximum from 0 to 1 and rising — [{ upTo: 0, label: { en: "at death's door" } }, …] — or leave it out.`);
|
|
856
|
+
}
|
|
590
857
|
if (props.earshot !== undefined && !SLOT_EARSHOTS.includes(props.earshot))
|
|
591
858
|
throw new Error(`${id}.earshot is '${String(props.earshot)}'. A slot is heard by 'all' (the default) or ` +
|
|
592
859
|
`by its 'holder' alone.`);
|
|
@@ -601,6 +868,10 @@ function checkSlotDeclaration(id, props) {
|
|
|
601
868
|
if (!props.appliesTo?.length)
|
|
602
869
|
throw new Error(`${id} declares no appliesTo. Say whether it attaches to 'cast', to 'world', to ` +
|
|
603
870
|
`'location', or to several — a slot nothing may carry can never hold a value.`);
|
|
871
|
+
if (props.scope !== undefined && props.scope !== 'session' && props.scope !== 'world')
|
|
872
|
+
throw new Error(`${id} declares scope '${String(props.scope)}'. Say 'session' — its values end with the session — or 'world' — they live on the book.`);
|
|
873
|
+
if (props.nextChapter !== undefined && props.nextChapter !== true)
|
|
874
|
+
throw new Error(`${id}: \`nextChapter\` is true or absent — the value follows the player into the next chapter.`);
|
|
604
875
|
if (props.type === 'enum' && !(props.config?.of ?? fieldSlotConfig(slotField(props)).of)?.length)
|
|
605
876
|
throw new Error(`${id} is an enum with no options. Declare config.of — the closed set is what ` +
|
|
606
877
|
`makes it a chip rather than a text field.`);
|
|
@@ -745,6 +1016,26 @@ export function checkSlotValue(decl, value, config = resolveSlotConfig(decl)) {
|
|
|
745
1016
|
const unique = config.unique !== false;
|
|
746
1017
|
const seen = new Set();
|
|
747
1018
|
for (const item of items) {
|
|
1019
|
+
// 🚧 A piece — legal only where the slot names a repertoire,
|
|
1020
|
+
// and checked against that repertoire's piece shape.
|
|
1021
|
+
if (isSlotPiece(item)) {
|
|
1022
|
+
if (!config.repertoire)
|
|
1023
|
+
return `${decl.id} holds words and lore references; a piece belongs in a list whose config names a repertoire.`;
|
|
1024
|
+
if (of)
|
|
1025
|
+
return `${decl.id} holds items from ${of.join(', ') || '(nothing declared)'}; a piece is not one of them.`;
|
|
1026
|
+
const rep = getRepertoire(String(config.repertoire));
|
|
1027
|
+
if (!rep)
|
|
1028
|
+
return `${decl.id} names the repertoire '${String(config.repertoire)}', which no installed ruleset declares — nothing new is written to it until one does.`;
|
|
1029
|
+
const why = checkPiece(rep, item, { timeUnit: _repertoireTimeUnit(String(config.repertoire)) });
|
|
1030
|
+
if (why)
|
|
1031
|
+
return `${decl.id}: ${why}`;
|
|
1032
|
+
const key = listItemKey(item);
|
|
1033
|
+
// A reference is held once whatever `unique` says — its count is its multiplicity.
|
|
1034
|
+
if ((item.kind !== 'inline' || unique) && seen.has(key))
|
|
1035
|
+
return `${decl.id} holds each piece once${item.kind === 'inline' ? '' : ', with a count'}; '${slotListItemText(item)}' is in it twice.`;
|
|
1036
|
+
seen.add(key);
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
748
1039
|
// A lore reference is an item in its own right — unless the
|
|
749
1040
|
// list is closed over words, where only those words are.
|
|
750
1041
|
if (isSlotLoreRef(item)) {
|
|
@@ -826,6 +1117,22 @@ export function applyListOp(current, op, items, config = {}) {
|
|
|
826
1117
|
...(count === 1 ? {} : { count }),
|
|
827
1118
|
...(ref.name === undefined ? {} : { name: ref.name }),
|
|
828
1119
|
});
|
|
1120
|
+
// 🚧 A piece that references something — a lore entry or a compendium
|
|
1121
|
+
// row — holds a count the same way a lore reference does: the same
|
|
1122
|
+
// reference twice is one holding with a count, never two items. An inline
|
|
1123
|
+
// piece is its own thing and is never merged. @experimental
|
|
1124
|
+
const isCountedPiece = (item) => isSlotPiece(item) && (item.kind === 'lore' || item.kind === 'compendium');
|
|
1125
|
+
const isCounted = (item) => isSlotLoreRef(item) || isCountedPiece(item);
|
|
1126
|
+
const countOf = (item) => isSlotLoreRef(item) ? slotLoreRefCount(item) : isCountedPiece(item) ? (item.count ?? 1) : 1;
|
|
1127
|
+
const statedCount = (item) => isSlotLoreRef(item) || isCountedPiece(item) ? item.count : undefined;
|
|
1128
|
+
const recount = (item, count) => {
|
|
1129
|
+
if (isSlotLoreRef(item))
|
|
1130
|
+
return withCount(item, count);
|
|
1131
|
+
if (!isCountedPiece(item))
|
|
1132
|
+
return item;
|
|
1133
|
+
const { count: _was, ...rest } = item;
|
|
1134
|
+
return count === 1 ? rest : { ...rest, count };
|
|
1135
|
+
};
|
|
829
1136
|
let next;
|
|
830
1137
|
switch (op) {
|
|
831
1138
|
case 'set':
|
|
@@ -838,15 +1145,17 @@ export function applyListOp(current, op, items, config = {}) {
|
|
|
838
1145
|
const out = [...held];
|
|
839
1146
|
const rest = [];
|
|
840
1147
|
for (const item of items) {
|
|
841
|
-
|
|
1148
|
+
const stated = statedCount(item);
|
|
1149
|
+
if (!isCounted(item) || stated === undefined) {
|
|
842
1150
|
rest.push(item);
|
|
843
1151
|
continue;
|
|
844
1152
|
}
|
|
845
|
-
const
|
|
1153
|
+
const key = listItemKey(item);
|
|
1154
|
+
const at = out.findIndex((h) => isCounted(h) && listItemKey(h) === key);
|
|
846
1155
|
if (at < 0)
|
|
847
|
-
out.push(
|
|
1156
|
+
out.push(recount(item, stated));
|
|
848
1157
|
else
|
|
849
|
-
out[at] =
|
|
1158
|
+
out[at] = recount(out[at], countOf(out[at]) + stated);
|
|
850
1159
|
}
|
|
851
1160
|
next = dedup([...out, ...rest]);
|
|
852
1161
|
break;
|
|
@@ -854,18 +1163,21 @@ export function applyListOp(current, op, items, config = {}) {
|
|
|
854
1163
|
case 'remove': {
|
|
855
1164
|
// A counted reference takes that many and drops the item at zero;
|
|
856
1165
|
// an uncounted one (and every word) takes the item out entirely.
|
|
857
|
-
const out = new Set(items.filter((item) => !
|
|
1166
|
+
const out = new Set(items.filter((item) => !isCounted(item) || statedCount(item) === undefined).map(listItemKey));
|
|
858
1167
|
const less = new Map();
|
|
859
|
-
for (const item of items)
|
|
860
|
-
|
|
861
|
-
|
|
1168
|
+
for (const item of items) {
|
|
1169
|
+
const stated = statedCount(item);
|
|
1170
|
+
if (isCounted(item) && stated !== undefined)
|
|
1171
|
+
less.set(listItemKey(item), (less.get(listItemKey(item)) ?? 0) + stated);
|
|
1172
|
+
}
|
|
862
1173
|
next = held.flatMap((item) => {
|
|
863
|
-
|
|
1174
|
+
const key = listItemKey(item);
|
|
1175
|
+
if (out.has(key))
|
|
864
1176
|
return [];
|
|
865
|
-
if (!
|
|
1177
|
+
if (!isCounted(item) || !less.has(key))
|
|
866
1178
|
return [item];
|
|
867
|
-
const left =
|
|
868
|
-
return left > 0 ? [
|
|
1179
|
+
const left = countOf(item) - less.get(key);
|
|
1180
|
+
return left > 0 ? [recount(item, left)] : [];
|
|
869
1181
|
});
|
|
870
1182
|
break;
|
|
871
1183
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 Bridges — how a field that is not a ruleset's own touches its mechanics.
|
|
3
|
+
*
|
|
4
|
+
* A genre's field, a custom field or a plugin's field resolves at `prose`
|
|
5
|
+
* whatever the rigour, unless it declares a **bridge** to the active ruleset:
|
|
6
|
+
* a small set of effects the ruleset's handler applies **additively** after
|
|
7
|
+
* the ruleset's own. A bridge may `modify`, `adjustDegree` or add a `rider`;
|
|
8
|
+
* it may never `set` a stat — "never overrides" is a property of the
|
|
9
|
+
* operations, checked when the bridge is authored.
|
|
10
|
+
*
|
|
11
|
+
* One way: a bridge lives with the field that owns it, written by the
|
|
12
|
+
* field's author, and is **registered** there (`registerBridge`) so the host
|
|
13
|
+
* reads every bridge to a session's ruleset (`bridgesFor`). A ruleset that
|
|
14
|
+
* wants to read a foreign field declares a `stat` selector over it instead.
|
|
15
|
+
*
|
|
16
|
+
* (2026-10-17: `listing: before | after` and `seam` were cut — no host
|
|
17
|
+
* ordered effects by seam; every bridge effect adds.)
|
|
18
|
+
*
|
|
19
|
+
* ⚠ Not the *capability bridge* (QuickJS's host-function transport). Prose
|
|
20
|
+
* says *ruleset bridge* where the two could meet.
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
23
|
+
import { type MechanicDecl } from './repertoires.js';
|
|
24
|
+
/** @experimental */
|
|
25
|
+
export interface BridgeDecl {
|
|
26
|
+
/** The attribute slot that owns the bridge. */
|
|
27
|
+
field: string;
|
|
28
|
+
/** The ruleset it bridges to. */
|
|
29
|
+
ruleset: string;
|
|
30
|
+
/** Additive mechanics: `modify`, `adjustDegree`, `rider` — never `set`. */
|
|
31
|
+
effects: readonly MechanicDecl[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 🚧 Why a bridge is refused, each finding opened by its reason's name:
|
|
35
|
+
* `unknown-field` · `unknown-ruleset` · `no-effects` · `bridge-set` ·
|
|
36
|
+
* `bridge-listing` (the cut `listing`/`seam`) · 🚧 `bridge-piece-verb` (a
|
|
37
|
+
* verb that acts when a piece is used — a bridge has no piece) ·
|
|
38
|
+
* `derived-target` · and every
|
|
39
|
+
* mechanic reason (`unknown-selector`, `inert-pairing`, …).
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export declare function bridgeFindings(decl: BridgeDecl): string[];
|
|
43
|
+
/**
|
|
44
|
+
* 🚧 Declare a bridge, refused here (`RulesetError`) on any finding. Pure:
|
|
45
|
+
* `registerBridge` makes it readable to the host.
|
|
46
|
+
* @experimental
|
|
47
|
+
*/
|
|
48
|
+
export declare function defineBridge(decl: BridgeDecl): BridgeDecl;
|
|
49
|
+
/**
|
|
50
|
+
* 🚧 Register a bridge where its field is declared, so the host applies it
|
|
51
|
+
* in every session on its ruleset (`bridgesFor`). Checked as `defineBridge`
|
|
52
|
+
* checks it. One bridge per field and ruleset: an identical re-registration
|
|
53
|
+
* is a no-op, a different one throws with both hashes.
|
|
54
|
+
* @experimental
|
|
55
|
+
*/
|
|
56
|
+
export declare function registerBridge(decl: BridgeDecl): BridgeDecl;
|
|
57
|
+
/** 🚧 Every registered bridge to a ruleset, in registration order — what the handler applies after the ruleset's own effects. @experimental */
|
|
58
|
+
export declare const bridgesFor: (rulesetId: string) => readonly BridgeDecl[];
|
|
59
|
+
/** @internal */
|
|
60
|
+
export declare function _clearBridges(): void;
|
|
61
|
+
//# sourceMappingURL=bridges.d.ts.map
|
package/dist/bridges.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 Bridges — how a field that is not a ruleset's own touches its mechanics.
|
|
3
|
+
*
|
|
4
|
+
* A genre's field, a custom field or a plugin's field resolves at `prose`
|
|
5
|
+
* whatever the rigour, unless it declares a **bridge** to the active ruleset:
|
|
6
|
+
* a small set of effects the ruleset's handler applies **additively** after
|
|
7
|
+
* the ruleset's own. A bridge may `modify`, `adjustDegree` or add a `rider`;
|
|
8
|
+
* it may never `set` a stat — "never overrides" is a property of the
|
|
9
|
+
* operations, checked when the bridge is authored.
|
|
10
|
+
*
|
|
11
|
+
* One way: a bridge lives with the field that owns it, written by the
|
|
12
|
+
* field's author, and is **registered** there (`registerBridge`) so the host
|
|
13
|
+
* reads every bridge to a session's ruleset (`bridgesFor`). A ruleset that
|
|
14
|
+
* wants to read a foreign field declares a `stat` selector over it instead.
|
|
15
|
+
*
|
|
16
|
+
* (2026-10-17: `listing: before | after` and `seam` were cut — no host
|
|
17
|
+
* ordered effects by seam; every bridge effect adds.)
|
|
18
|
+
*
|
|
19
|
+
* ⚠ Not the *capability bridge* (QuickJS's host-function transport). Prose
|
|
20
|
+
* says *ruleset bridge* where the two could meet.
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
23
|
+
import { getAttributeSlot } from './attributes.js';
|
|
24
|
+
import { refuseUnlessIdentical } from './hash.js';
|
|
25
|
+
import { _mechanicFindings, finding, PIECE_USE_VERBS, RulesetError } from './repertoires.js';
|
|
26
|
+
import { getRuleset, rulesetContext } from './rulesets.js';
|
|
27
|
+
/**
|
|
28
|
+
* 🚧 Why a bridge is refused, each finding opened by its reason's name:
|
|
29
|
+
* `unknown-field` · `unknown-ruleset` · `no-effects` · `bridge-set` ·
|
|
30
|
+
* `bridge-listing` (the cut `listing`/`seam`) · 🚧 `bridge-piece-verb` (a
|
|
31
|
+
* verb that acts when a piece is used — a bridge has no piece) ·
|
|
32
|
+
* `derived-target` · and every
|
|
33
|
+
* mechanic reason (`unknown-selector`, `inert-pairing`, …).
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export function bridgeFindings(decl) {
|
|
37
|
+
const at = `bridge from '${String(decl?.field)}'`;
|
|
38
|
+
const out = [];
|
|
39
|
+
if (typeof decl?.field !== 'string' || !getAttributeSlot(decl.field))
|
|
40
|
+
out.push(finding('unknown-field', `${at} names a field nothing declares. A bridge lives on a declared attribute slot; declare it first.`));
|
|
41
|
+
const ruleset = typeof decl?.ruleset === 'string' ? getRuleset(decl.ruleset) : undefined;
|
|
42
|
+
if (!ruleset)
|
|
43
|
+
out.push(finding('unknown-ruleset', `${at} bridges to '${String(decl?.ruleset)}', which no registered ruleset is. Its selectors are what the bridge is checked against — install or declare it first.`));
|
|
44
|
+
// A bridge's predicates may name its own field — by its bare key and its
|
|
45
|
+
// id, and their properties — which the host reads beside the ruleset's
|
|
46
|
+
// values (2026-10-17). Predicates only: the field is never a target.
|
|
47
|
+
const ownPaths = typeof decl?.field === 'string' && decl.field.includes('/') && decl.field.includes('@')
|
|
48
|
+
? new Set([decl.field.slice(decl.field.indexOf('/') + 1, decl.field.lastIndexOf('@')), decl.field])
|
|
49
|
+
: undefined;
|
|
50
|
+
const ctx = ruleset ? { ...rulesetContext(ruleset), predicatePaths: ownPaths } : undefined;
|
|
51
|
+
if (!Array.isArray(decl?.effects) || !decl.effects.length)
|
|
52
|
+
out.push(finding('no-effects', `${at} declares no effects. A bridge with nothing to apply does nothing; drop it.`));
|
|
53
|
+
(Array.isArray(decl?.effects) ? decl.effects : []).forEach((e, i) => {
|
|
54
|
+
const where = `${at} effect ${i}`;
|
|
55
|
+
const o = e;
|
|
56
|
+
if ('listing' in o || 'seam' in o) {
|
|
57
|
+
out.push(finding('bridge-listing', `${where} says where it is listed. Every bridge effect adds after the ruleset's own — drop 'listing' and 'seam'.`));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (e.verb === 'set') {
|
|
61
|
+
out.push(finding('bridge-set', `${where} sets '${String(e.target)}'. Only the ruleset that owns a stat sets it; a bridge modifies.`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (PIECE_USE_VERBS.has(e.verb)) {
|
|
65
|
+
out.push(finding('bridge-piece-verb', `${where} is ${e.verb}, which acts when a piece is used — and a bridge has no piece. A bridge modifies, adjusts a degree or adds a rider.`));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
out.push(..._mechanicFindings(e, i, ctx, at));
|
|
69
|
+
const target = e.target;
|
|
70
|
+
if (ruleset && typeof target === 'string' && ruleset.selectors?.[target]?.kind === 'derived')
|
|
71
|
+
out.push(finding('derived-target', `${where} targets '${target}', a derived selector. Derived values are computed before bridges apply, so it would never change; target one of its inputs.`));
|
|
72
|
+
});
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 🚧 Declare a bridge, refused here (`RulesetError`) on any finding. Pure:
|
|
77
|
+
* `registerBridge` makes it readable to the host.
|
|
78
|
+
* @experimental
|
|
79
|
+
*/
|
|
80
|
+
export function defineBridge(decl) {
|
|
81
|
+
const found = bridgeFindings(decl);
|
|
82
|
+
if (found.length)
|
|
83
|
+
throw new RulesetError(`bridge from '${String(decl?.field)}'`, found);
|
|
84
|
+
return Object.freeze({ ...decl, effects: Object.freeze([...decl.effects]) });
|
|
85
|
+
}
|
|
86
|
+
/** Registered bridges, by ruleset id, then by field. */
|
|
87
|
+
const registry = new Map();
|
|
88
|
+
/**
|
|
89
|
+
* 🚧 Register a bridge where its field is declared, so the host applies it
|
|
90
|
+
* in every session on its ruleset (`bridgesFor`). Checked as `defineBridge`
|
|
91
|
+
* checks it. One bridge per field and ruleset: an identical re-registration
|
|
92
|
+
* is a no-op, a different one throws with both hashes.
|
|
93
|
+
* @experimental
|
|
94
|
+
*/
|
|
95
|
+
export function registerBridge(decl) {
|
|
96
|
+
const bridge = defineBridge(decl);
|
|
97
|
+
let byField = registry.get(bridge.ruleset);
|
|
98
|
+
if (!byField)
|
|
99
|
+
registry.set(bridge.ruleset, (byField = new Map()));
|
|
100
|
+
const existing = byField.get(bridge.field);
|
|
101
|
+
if (existing)
|
|
102
|
+
refuseUnlessIdentical(existing, bridge, `duplicate bridge from ${bridge.field} to ${bridge.ruleset}`);
|
|
103
|
+
byField.set(bridge.field, bridge);
|
|
104
|
+
return bridge;
|
|
105
|
+
}
|
|
106
|
+
/** 🚧 Every registered bridge to a ruleset, in registration order — what the handler applies after the ruleset's own effects. @experimental */
|
|
107
|
+
export const bridgesFor = (rulesetId) => [...(registry.get(rulesetId)?.values() ?? [])];
|
|
108
|
+
/** @internal */
|
|
109
|
+
export function _clearBridges() {
|
|
110
|
+
registry.clear();
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=bridges.js.map
|