@almadar/runtime 6.72.0 → 6.74.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, normalizeCallSiteConfigToValues, StateMachineManager, parseDurationString, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor, LIFECYCLE_EVENTS } from './chunk-
|
|
2
|
-
export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-
|
|
1
|
+
import { createTickScheduler, EventBus, createUnifiedLoader, MockPersistenceAdapter, InMemoryPersistence, preprocessSchema, normalizeCallSiteConfigToValues, StateMachineManager, parseDurationString, validateEventPayload, formatPayloadValidationError, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, EffectExecutor, LIFECYCLE_EVENTS } from './chunk-QUW37QRQ.js';
|
|
2
|
+
export { InMemoryPersistence, collectDeclaredConfigDefaults } from './chunk-QUW37QRQ.js';
|
|
3
3
|
import { isValidCronExpression } from './chunk-OU3ITB5S.js';
|
|
4
4
|
import { createContextFromBindings, checkMutationAccess, applyRowAccess, accessDeniedMessage } from './chunk-ZWAOJT6R.js';
|
|
5
5
|
import './chunk-T4VDAB4C.js';
|
|
@@ -4,7 +4,7 @@ import { seedRandom, randomArrayElement, randomInt, shuffleArray, randomPastDate
|
|
|
4
4
|
import { collectTraitRefsFromValue, collectTraitRefsFromEffects } from './chunk-SCRAHWOC.js';
|
|
5
5
|
import { createLogger, setNamespaceLevel } from '@almadar/logger';
|
|
6
6
|
import { evaluateGuard, SExpressionEvaluator } from '@almadar/evaluator';
|
|
7
|
-
import { OrbitalSchemaSchema, isInlineTrait, isEntityCall, isEntityReference, parseEntityRef, parseImportedTraitRef, isPageReference, isPageReferenceString, isPageReferenceObject, parsePageRef, parseOrbitalRef, overrideDeclaredKnobs, asTraitId, asEntityId, asPageId, asOrbitalId, deriveId, isReferenceConfigType, configRefEventKnob, normalizeCallSiteConfigToValues, resolveConfigRefEventName, isCallSiteConfigDeclaration, idPrefix, eventListPropsOf } from '@almadar/core';
|
|
7
|
+
import { OrbitalSchemaSchema, isInlineTrait, isEntityCall, isEntityReference, parseEntityRef, parseImportedTraitRef, isPageReference, isPageReferenceString, isPageReferenceObject, parsePageRef, parseOrbitalRef, overrideDeclaredKnobs, asTraitId, asEntityId, asPageId, asOrbitalId, deriveId, isReferenceConfigType, configRefEventKnob, normalizeCallSiteConfigToValues, resolveConfigRefEventName, isCallSiteConfigDeclaration, asEventId, ledgerRename, idPrefix, eventListPropsOf } from '@almadar/core';
|
|
8
8
|
export { normalizeCallSiteConfigToValues } from '@almadar/core';
|
|
9
9
|
import { sampleRowCount, sampleRow, identityEntitiesOf, roleVocabularyOf } from '@almadar/core/mock';
|
|
10
10
|
|
|
@@ -3852,6 +3852,13 @@ function resolveSentinelFields(fields, entityDef, subs, declaredNames) {
|
|
|
3852
3852
|
}
|
|
3853
3853
|
return changed;
|
|
3854
3854
|
}
|
|
3855
|
+
function resolvePayloadEntitySchema(payloadEntity, setPayloadSchema, entitiesByName) {
|
|
3856
|
+
if (!payloadEntity) return false;
|
|
3857
|
+
const entity = entitiesByName.get(payloadEntity);
|
|
3858
|
+
if (!entity) return false;
|
|
3859
|
+
setPayloadSchema(entityFieldsToPayloadFields(entity));
|
|
3860
|
+
return true;
|
|
3861
|
+
}
|
|
3855
3862
|
function resolveTraitTypeParamSentinels(trait, entityDef, entitiesByName, typesByName, typeArgs) {
|
|
3856
3863
|
const declared = trait.typeParams ?? [];
|
|
3857
3864
|
const subs = /* @__PURE__ */ new Map();
|
|
@@ -3872,6 +3879,16 @@ function resolveTraitTypeParamSentinels(trait, entityDef, entitiesByName, typesB
|
|
|
3872
3879
|
let changed = false;
|
|
3873
3880
|
for (const emit of trait.emits ?? []) {
|
|
3874
3881
|
if (!emit.payloadSchema) continue;
|
|
3882
|
+
if (resolvePayloadEntitySchema(
|
|
3883
|
+
emit.payloadEntity,
|
|
3884
|
+
(schema2) => {
|
|
3885
|
+
emit.payloadSchema = schema2;
|
|
3886
|
+
},
|
|
3887
|
+
entitiesByName
|
|
3888
|
+
)) {
|
|
3889
|
+
changed = true;
|
|
3890
|
+
continue;
|
|
3891
|
+
}
|
|
3875
3892
|
const schema = emit.payloadSchema;
|
|
3876
3893
|
if (flattenBareEntityPayload(schema, entityDef, subs)) {
|
|
3877
3894
|
changed = true;
|
|
@@ -3881,6 +3898,16 @@ function resolveTraitTypeParamSentinels(trait, entityDef, entitiesByName, typesB
|
|
|
3881
3898
|
}
|
|
3882
3899
|
for (const ev of trait.stateMachine?.events ?? []) {
|
|
3883
3900
|
if (!ev.payloadSchema) continue;
|
|
3901
|
+
if (resolvePayloadEntitySchema(
|
|
3902
|
+
ev.payloadEntity,
|
|
3903
|
+
(schema2) => {
|
|
3904
|
+
ev.payloadSchema = schema2;
|
|
3905
|
+
},
|
|
3906
|
+
entitiesByName
|
|
3907
|
+
)) {
|
|
3908
|
+
changed = true;
|
|
3909
|
+
continue;
|
|
3910
|
+
}
|
|
3884
3911
|
const schema = ev.payloadSchema;
|
|
3885
3912
|
if (flattenBareEntityPayload(schema, entityDef, subs)) {
|
|
3886
3913
|
changed = true;
|
|
@@ -4299,10 +4326,18 @@ function traitEmbedNamesOf(trait) {
|
|
|
4299
4326
|
for (const field of Object.values(trait.config ?? {})) walk(field.default);
|
|
4300
4327
|
return [...found].sort();
|
|
4301
4328
|
}
|
|
4302
|
-
function resolveForwardedSiblingConfigFrom(trait, parentChain, orbitalConfig, schemaConfig) {
|
|
4329
|
+
function resolveForwardedSiblingConfigFrom(trait, parentChain, orbitalConfig, schemaConfig, schemaOnlyKeys) {
|
|
4303
4330
|
const declared = trait.config;
|
|
4304
4331
|
if (!declared) return trait;
|
|
4305
|
-
const next = resolveConfigForwards(
|
|
4332
|
+
const next = resolveConfigForwards(
|
|
4333
|
+
declared,
|
|
4334
|
+
parentChain,
|
|
4335
|
+
orbitalConfig,
|
|
4336
|
+
void 0,
|
|
4337
|
+
void 0,
|
|
4338
|
+
schemaConfig,
|
|
4339
|
+
schemaOnlyKeys
|
|
4340
|
+
);
|
|
4306
4341
|
return next ? { ...trait, config: next } : trait;
|
|
4307
4342
|
}
|
|
4308
4343
|
function callSiteRungValue(rungConfig, knob) {
|
|
@@ -4311,8 +4346,9 @@ function callSiteRungValue(rungConfig, knob) {
|
|
|
4311
4346
|
return isCallSiteConfigDeclaration(entry) ? entry.default : entry;
|
|
4312
4347
|
}
|
|
4313
4348
|
function walkConfigForwardChain(forward, parentChain, orbitalConfig, upstreamOrbitalConfig, upstreamSchemaConfig, schemaConfig) {
|
|
4349
|
+
const unresolved = { value: void 0, reachedSchemaConfigOnly: false };
|
|
4314
4350
|
let knob = forward.slice("@config.".length);
|
|
4315
|
-
if (knob.length === 0 || knob.includes(".")) return
|
|
4351
|
+
if (knob.length === 0 || knob.includes(".")) return unresolved;
|
|
4316
4352
|
let value;
|
|
4317
4353
|
let currentForward = forward;
|
|
4318
4354
|
for (const rungConfig of parentChain) {
|
|
@@ -4331,16 +4367,17 @@ function walkConfigForwardChain(forward, parentChain, orbitalConfig, upstreamOrb
|
|
|
4331
4367
|
if (value === void 0 || value === currentForward) value = orbitalConfig?.[knob]?.default;
|
|
4332
4368
|
if (value === void 0 || value === currentForward) value = upstreamOrbitalConfig?.[knob]?.default;
|
|
4333
4369
|
if (value === void 0 || value === currentForward) value = upstreamSchemaConfig?.[knob]?.default;
|
|
4334
|
-
|
|
4335
|
-
if (
|
|
4336
|
-
return
|
|
4370
|
+
const reachesSchemaConfigRung = value === void 0 || value === currentForward;
|
|
4371
|
+
if (reachesSchemaConfigRung) value = schemaConfig?.[knob]?.default;
|
|
4372
|
+
if (value === void 0 || value === currentForward) return unresolved;
|
|
4373
|
+
return { value, reachedSchemaConfigOnly: reachesSchemaConfigRung };
|
|
4337
4374
|
}
|
|
4338
|
-
function resolveConfigForwards(declared, parentChain, orbitalConfig, upstreamOrbitalConfig, upstreamSchemaConfig, schemaConfig) {
|
|
4375
|
+
function resolveConfigForwards(declared, parentChain, orbitalConfig, upstreamOrbitalConfig, upstreamSchemaConfig, schemaConfig, schemaOnlyKeys) {
|
|
4339
4376
|
let next;
|
|
4340
4377
|
for (const [key, field] of Object.entries(declared)) {
|
|
4341
4378
|
const forward = field.default;
|
|
4342
4379
|
if (typeof forward !== "string" || !forward.startsWith("@config.")) continue;
|
|
4343
|
-
const value = walkConfigForwardChain(
|
|
4380
|
+
const { value, reachedSchemaConfigOnly } = walkConfigForwardChain(
|
|
4344
4381
|
forward,
|
|
4345
4382
|
parentChain,
|
|
4346
4383
|
orbitalConfig,
|
|
@@ -4349,6 +4386,7 @@ function resolveConfigForwards(declared, parentChain, orbitalConfig, upstreamOrb
|
|
|
4349
4386
|
schemaConfig
|
|
4350
4387
|
);
|
|
4351
4388
|
if (value === void 0) continue;
|
|
4389
|
+
if (reachedSchemaConfigOnly) schemaOnlyKeys?.add(key);
|
|
4352
4390
|
next ??= { ...declared };
|
|
4353
4391
|
next[key] = { ...field, default: value, forwardedFrom: forward };
|
|
4354
4392
|
}
|
|
@@ -4359,7 +4397,7 @@ function resolveCallSiteConfigForwards(config, parentChain, orbitalConfig, schem
|
|
|
4359
4397
|
for (const [key, entry] of Object.entries(config)) {
|
|
4360
4398
|
const forward = isCallSiteConfigDeclaration(entry) ? entry.default : entry;
|
|
4361
4399
|
if (typeof forward !== "string" || !forward.startsWith("@config.")) continue;
|
|
4362
|
-
const value = walkConfigForwardChain(forward, parentChain, orbitalConfig, void 0, void 0, schemaConfig);
|
|
4400
|
+
const { value } = walkConfigForwardChain(forward, parentChain, orbitalConfig, void 0, void 0, schemaConfig);
|
|
4363
4401
|
if (value === void 0) continue;
|
|
4364
4402
|
next ??= { ...config };
|
|
4365
4403
|
next[key] = isCallSiteConfigDeclaration(entry) ? { ...entry, default: value, forwardedFrom: forward } : value;
|
|
@@ -4445,7 +4483,7 @@ function applyLinkedEntityRename(trait, linkedEntity, entityIds) {
|
|
|
4445
4483
|
const atomLinked = trait.linkedEntity;
|
|
4446
4484
|
const entitySubs = consumerKnownEntityRebindSubs(trait, entityIds);
|
|
4447
4485
|
if (!linkedEntity || !atomLinked || linkedEntity === atomLinked) {
|
|
4448
|
-
return rewriteEntityRefIds(trait, entitySubs, entityIds);
|
|
4486
|
+
return rewriteEntityTypedConfigValues(rewriteEntityRefIds(trait, entitySubs, entityIds), entitySubs, entityIds);
|
|
4449
4487
|
}
|
|
4450
4488
|
for (const [from, to] of staleEntityRebindSubs(trait, linkedEntity)) {
|
|
4451
4489
|
entitySubs.set(from, to);
|
|
@@ -4459,7 +4497,11 @@ function applyLinkedEntityRename(trait, linkedEntity, entityIds) {
|
|
|
4459
4497
|
linkedEntityId: entityIds.get(linkedEntity)
|
|
4460
4498
|
};
|
|
4461
4499
|
if (!sm) {
|
|
4462
|
-
return
|
|
4500
|
+
return rewriteEntityTypedConfigValues(
|
|
4501
|
+
renamePayloadEntityMarkers(rewriteEntityRefIds(rebound, entitySubs, entityIds), rename),
|
|
4502
|
+
entitySubs,
|
|
4503
|
+
entityIds
|
|
4504
|
+
);
|
|
4463
4505
|
}
|
|
4464
4506
|
const nextTransitions = (sm.transitions ?? []).map((t) => {
|
|
4465
4507
|
const nextEffects = t.effects ? renameEntityInEffects(
|
|
@@ -4475,13 +4517,17 @@ function applyLinkedEntityRename(trait, linkedEntity, entityIds) {
|
|
|
4475
4517
|
to: linkedEntity,
|
|
4476
4518
|
transitionCount: nextTransitions.length
|
|
4477
4519
|
});
|
|
4478
|
-
return
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4520
|
+
return rewriteEntityTypedConfigValues(
|
|
4521
|
+
renamePayloadEntityMarkers(
|
|
4522
|
+
rewriteEntityRefIds(
|
|
4523
|
+
{ ...rebound, stateMachine: { ...sm, transitions: nextTransitions } },
|
|
4524
|
+
entitySubs,
|
|
4525
|
+
entityIds
|
|
4526
|
+
),
|
|
4527
|
+
rename
|
|
4483
4528
|
),
|
|
4484
|
-
|
|
4529
|
+
entitySubs,
|
|
4530
|
+
entityIds
|
|
4485
4531
|
);
|
|
4486
4532
|
}
|
|
4487
4533
|
function resolveEntityTokensById(trait, idIndex) {
|
|
@@ -4566,7 +4612,7 @@ function resolveConfigRefsById(trait, idIndex) {
|
|
|
4566
4612
|
});
|
|
4567
4613
|
return { ...trait, config: nextSchema };
|
|
4568
4614
|
}
|
|
4569
|
-
function applyEventRenames(trait, renames) {
|
|
4615
|
+
function applyEventRenames(trait, renames, keptFinalNames) {
|
|
4570
4616
|
if (!renames || Object.keys(renames).length === 0) return trait;
|
|
4571
4617
|
const rename = (k) => k !== void 0 && k in renames ? renames[k] : k;
|
|
4572
4618
|
const sm = trait.stateMachine;
|
|
@@ -4596,7 +4642,9 @@ function applyEventRenames(trait, renames) {
|
|
|
4596
4642
|
);
|
|
4597
4643
|
const nextListens = (trait.listens ?? []).map((l) => {
|
|
4598
4644
|
const sourced = l.source !== void 0 && l.source.kind !== "any";
|
|
4599
|
-
const
|
|
4645
|
+
const sourceTraitName = l.source && l.source.kind !== "any" ? l.source.trait : void 0;
|
|
4646
|
+
const fromThisImport = sourceTraitName !== void 0 && keptFinalNames !== void 0 && keptFinalNames.has(sourceTraitName);
|
|
4647
|
+
const nextEvent = sourced && !fromThisImport ? l.event : rename(l.event) ?? l.event;
|
|
4600
4648
|
const nextTriggers = rename(l.triggers) ?? l.triggers;
|
|
4601
4649
|
return nextEvent === l.event && nextTriggers === l.triggers ? l : { ...l, event: nextEvent, triggers: nextTriggers };
|
|
4602
4650
|
});
|
|
@@ -4759,26 +4807,73 @@ function foldCallSiteConfigOntoTrait(trait, callSiteConfig) {
|
|
|
4759
4807
|
}
|
|
4760
4808
|
return { ...trait, config: nextConfig };
|
|
4761
4809
|
}
|
|
4762
|
-
var
|
|
4810
|
+
var ROW_ALIAS_TOKEN_PREFIXES = ["@entity.", "@item.", "@row."];
|
|
4811
|
+
var ROW_ALIAS_ROOTS = /* @__PURE__ */ new Set(["@entity", "@item", "@row"]);
|
|
4812
|
+
var FIELD_NAME_MEMBER_KEYS = ["key", "name", "field"];
|
|
4763
4813
|
function rewriteEntityFieldTokensInValue(node, subs) {
|
|
4764
4814
|
if (node === null || node === void 0) return node;
|
|
4765
4815
|
if (typeof node === "string") {
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4816
|
+
for (const prefix of ROW_ALIAS_TOKEN_PREFIXES) {
|
|
4817
|
+
if (!node.startsWith(prefix)) continue;
|
|
4818
|
+
const rest = node.slice(prefix.length);
|
|
4819
|
+
const dot = rest.search(/[.[]/);
|
|
4820
|
+
const name = dot === -1 ? rest : rest.slice(0, dot);
|
|
4821
|
+
const suffix = dot === -1 ? "" : rest.slice(dot);
|
|
4822
|
+
const to = subs.get(name);
|
|
4823
|
+
return to === void 0 ? node : `${prefix}${to}${suffix}`;
|
|
4824
|
+
}
|
|
4825
|
+
return node;
|
|
4826
|
+
}
|
|
4827
|
+
if (Array.isArray(node)) {
|
|
4828
|
+
if (node.length >= 3 && node[0] === "object/get" && typeof node[1] === "string" && ROW_ALIAS_ROOTS.has(node[1]) && typeof node[2] === "string") {
|
|
4829
|
+
const to = subs.get(node[2]);
|
|
4830
|
+
if (to !== void 0) {
|
|
4831
|
+
const rewritten = node.map((item) => rewriteEntityFieldTokensInValue(item, subs));
|
|
4832
|
+
rewritten[2] = to;
|
|
4833
|
+
return rewritten;
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4836
|
+
return node.map((item) => rewriteEntityFieldTokensInValue(item, subs));
|
|
4773
4837
|
}
|
|
4774
|
-
if (Array.isArray(node)) return node.map((item) => rewriteEntityFieldTokensInValue(item, subs));
|
|
4775
4838
|
if (typeof node !== "object") return node;
|
|
4776
4839
|
const next = {};
|
|
4777
4840
|
for (const [key, value] of Object.entries(node)) {
|
|
4841
|
+
if (FIELD_NAME_MEMBER_KEYS.includes(key) && typeof value === "string") {
|
|
4842
|
+
const to = subs.get(value);
|
|
4843
|
+
next[key] = to === void 0 ? value : to;
|
|
4844
|
+
continue;
|
|
4845
|
+
}
|
|
4778
4846
|
next[key] = rewriteEntityFieldTokensInValue(value, subs);
|
|
4779
4847
|
}
|
|
4780
4848
|
return next;
|
|
4781
4849
|
}
|
|
4850
|
+
function rewriteBareFieldNameConfigDefault(value, fieldSubs) {
|
|
4851
|
+
if (typeof value === "string") {
|
|
4852
|
+
if (value === "" || value.startsWith("@")) return value;
|
|
4853
|
+
return fieldSubs.get(value) ?? value;
|
|
4854
|
+
}
|
|
4855
|
+
if (Array.isArray(value) && value.every((v) => typeof v === "string")) {
|
|
4856
|
+
return value.map((v) => v === "" || v.startsWith("@") ? v : fieldSubs.get(v) ?? v);
|
|
4857
|
+
}
|
|
4858
|
+
return value;
|
|
4859
|
+
}
|
|
4860
|
+
function rewriteEntityFieldsInConfig(config, fieldSubs) {
|
|
4861
|
+
if (fieldSubs.size === 0 || !config) return config;
|
|
4862
|
+
const rewrite = (v) => rewriteEntityFieldTokensInValue(v, fieldSubs);
|
|
4863
|
+
const nextConfig = {};
|
|
4864
|
+
for (const [key, field] of Object.entries(config)) {
|
|
4865
|
+
if (field.default === void 0) {
|
|
4866
|
+
nextConfig[key] = field;
|
|
4867
|
+
continue;
|
|
4868
|
+
}
|
|
4869
|
+
const afterSigils = rewrite(field.default);
|
|
4870
|
+
nextConfig[key] = {
|
|
4871
|
+
...field,
|
|
4872
|
+
default: rewriteBareFieldNameConfigDefault(afterSigils, fieldSubs)
|
|
4873
|
+
};
|
|
4874
|
+
}
|
|
4875
|
+
return nextConfig;
|
|
4876
|
+
}
|
|
4782
4877
|
function rewriteEntityFieldsInTrait(trait, fieldSubs) {
|
|
4783
4878
|
if (fieldSubs.size === 0) return trait;
|
|
4784
4879
|
const rewrite = (v) => rewriteEntityFieldTokensInValue(v, fieldSubs);
|
|
@@ -4812,11 +4907,7 @@ function rewriteEntityFieldsInTrait(trait, fieldSubs) {
|
|
|
4812
4907
|
next.initialEffects = rewrite(trait.initialEffects);
|
|
4813
4908
|
}
|
|
4814
4909
|
if (trait.config) {
|
|
4815
|
-
|
|
4816
|
-
for (const [key, field] of Object.entries(trait.config)) {
|
|
4817
|
-
nextConfig[key] = field.default === void 0 ? field : { ...field, default: rewrite(field.default) };
|
|
4818
|
-
}
|
|
4819
|
-
next.config = nextConfig;
|
|
4910
|
+
next.config = rewriteEntityFieldsInConfig(trait.config, fieldSubs);
|
|
4820
4911
|
}
|
|
4821
4912
|
return next;
|
|
4822
4913
|
}
|
|
@@ -4993,12 +5084,24 @@ function renamePayloadEntity(fields, rename) {
|
|
|
4993
5084
|
}
|
|
4994
5085
|
function renamePayloadEntityMarkers(trait, rename) {
|
|
4995
5086
|
const sm = trait.stateMachine;
|
|
4996
|
-
const nextEvents = sm?.events ? sm.events.map(
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5087
|
+
const nextEvents = sm?.events ? sm.events.map((ev) => {
|
|
5088
|
+
const renamedEntity = ev.payloadEntity !== void 0 ? rename(ev.payloadEntity) : void 0;
|
|
5089
|
+
if (!ev.payloadSchema && renamedEntity === void 0) return ev;
|
|
5090
|
+
return {
|
|
5091
|
+
...ev,
|
|
5092
|
+
...ev.payloadSchema ? { payloadSchema: renamePayloadEntity(ev.payloadSchema, rename) } : {},
|
|
5093
|
+
...renamedEntity !== void 0 ? { payloadEntity: renamedEntity } : {}
|
|
5094
|
+
};
|
|
5095
|
+
}) : void 0;
|
|
5096
|
+
const nextEmits = trait.emits ? trait.emits.map((em) => {
|
|
5097
|
+
const renamedEntity = em.payloadEntity !== void 0 ? rename(em.payloadEntity) : void 0;
|
|
5098
|
+
if (!em.payloadSchema && renamedEntity === void 0) return em;
|
|
5099
|
+
return {
|
|
5100
|
+
...em,
|
|
5101
|
+
...em.payloadSchema ? { payloadSchema: renamePayloadEntity(em.payloadSchema, rename) } : {},
|
|
5102
|
+
...renamedEntity !== void 0 ? { payloadEntity: renamedEntity } : {}
|
|
5103
|
+
};
|
|
5104
|
+
}) : void 0;
|
|
5002
5105
|
return {
|
|
5003
5106
|
...trait,
|
|
5004
5107
|
...sm && nextEvents ? { stateMachine: { ...sm, events: nextEvents } } : {},
|
|
@@ -5012,7 +5115,7 @@ function walkEntityInPayloadMapping(payloadMapping, rename, props) {
|
|
|
5012
5115
|
}
|
|
5013
5116
|
return next;
|
|
5014
5117
|
}
|
|
5015
|
-
function renameEntitiesInTrait(trait, entitySubs) {
|
|
5118
|
+
function renameEntitiesInTrait(trait, entitySubs, entityIds) {
|
|
5016
5119
|
if (entitySubs.size === 0) return trait;
|
|
5017
5120
|
const rename = (name) => entitySubs.get(name);
|
|
5018
5121
|
const withTokens = (value) => renameEntityNameTokensInValue(value, entitySubs);
|
|
@@ -5042,16 +5145,20 @@ function renameEntitiesInTrait(trait, entitySubs) {
|
|
|
5042
5145
|
rename,
|
|
5043
5146
|
REBIND_ENTITY_PROPS
|
|
5044
5147
|
)) : trait.initialEffects;
|
|
5045
|
-
return
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5148
|
+
return rewriteEntityTypedConfigValues(
|
|
5149
|
+
renamePayloadEntityMarkers(
|
|
5150
|
+
{
|
|
5151
|
+
...trait,
|
|
5152
|
+
linkedEntity: nextLinked,
|
|
5153
|
+
...sm ? { stateMachine: { ...sm, transitions: nextTransitions ?? [] } } : {},
|
|
5154
|
+
...nextTicks !== void 0 ? { ticks: nextTicks } : {},
|
|
5155
|
+
...nextListens !== void 0 ? { listens: nextListens } : {},
|
|
5156
|
+
...nextInitial !== void 0 ? { initialEffects: nextInitial } : {}
|
|
5157
|
+
},
|
|
5158
|
+
rename
|
|
5159
|
+
),
|
|
5160
|
+
entitySubs,
|
|
5161
|
+
entityIds
|
|
5055
5162
|
);
|
|
5056
5163
|
}
|
|
5057
5164
|
function rewriteEntityRefIds(trait, entitySubs, entityIds) {
|
|
@@ -5064,6 +5171,19 @@ function rewriteEntityRefIds(trait, entitySubs, entityIds) {
|
|
|
5064
5171
|
}
|
|
5065
5172
|
return { ...trait, entityRefIds: out };
|
|
5066
5173
|
}
|
|
5174
|
+
function rewriteEntityTypedConfigValues(trait, entitySubs, entityIds) {
|
|
5175
|
+
if (entitySubs.size === 0 || !trait.config) return trait;
|
|
5176
|
+
let changed = false;
|
|
5177
|
+
const nextConfig = { ...trait.config };
|
|
5178
|
+
for (const [key, field] of Object.entries(trait.config)) {
|
|
5179
|
+
if (field.type !== "entity" || typeof field.default !== "string") continue;
|
|
5180
|
+
const to = entitySubs.get(field.default);
|
|
5181
|
+
if (to === void 0) continue;
|
|
5182
|
+
changed = true;
|
|
5183
|
+
nextConfig[key] = { ...field, default: to, refId: entityIds.get(to) };
|
|
5184
|
+
}
|
|
5185
|
+
return changed ? { ...trait, config: nextConfig } : trait;
|
|
5186
|
+
}
|
|
5067
5187
|
function applyAliasEntityRenames(trait, subs, entityIds) {
|
|
5068
5188
|
if (subs.size === 0) return trait;
|
|
5069
5189
|
const rename = (name) => subs.get(name);
|
|
@@ -5126,7 +5246,7 @@ function relationTargetsOfEntity(entity, candidates) {
|
|
|
5126
5246
|
for (const field of entity.fields) collectRelationTargets(field, candidates, out);
|
|
5127
5247
|
return out;
|
|
5128
5248
|
}
|
|
5129
|
-
function rewriteListenSources(trait, subs, idByName, orbitalRename) {
|
|
5249
|
+
function rewriteListenSources(trait, subs, idByName, orbitalRename, alias, listenSourceTargets) {
|
|
5130
5250
|
const listens = trait.listens;
|
|
5131
5251
|
if (!listens || listens.length === 0) return trait;
|
|
5132
5252
|
let changed = false;
|
|
@@ -5143,19 +5263,35 @@ function rewriteListenSources(trait, subs, idByName, orbitalRename) {
|
|
|
5143
5263
|
source: { kind: "trait", trait: target, ...traitId ? { traitId } : {} }
|
|
5144
5264
|
};
|
|
5145
5265
|
}
|
|
5146
|
-
if (source.kind === "orbital"
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5266
|
+
if (source.kind === "orbital") {
|
|
5267
|
+
if (orbitalRename && source.orbital === orbitalRename.from) {
|
|
5268
|
+
const targetTrait = subs.get(source.trait) ?? source.trait;
|
|
5269
|
+
changed = true;
|
|
5270
|
+
const traitId = idByName.get(targetTrait);
|
|
5271
|
+
return {
|
|
5272
|
+
...listen,
|
|
5273
|
+
source: {
|
|
5274
|
+
kind: "orbital",
|
|
5275
|
+
orbital: orbitalRename.to,
|
|
5276
|
+
trait: targetTrait,
|
|
5277
|
+
...traitId ? { traitId } : {}
|
|
5278
|
+
}
|
|
5279
|
+
};
|
|
5280
|
+
}
|
|
5281
|
+
const info = alias && listenSourceTargets ? listenSourceTargets.get(siblingImportKey(alias, source.orbital)) : void 0;
|
|
5282
|
+
if (info) {
|
|
5283
|
+
const target = info.traitSubs.get(source.trait);
|
|
5284
|
+
changed = true;
|
|
5285
|
+
return {
|
|
5286
|
+
...listen,
|
|
5287
|
+
source: {
|
|
5288
|
+
kind: "orbital",
|
|
5289
|
+
orbital: info.localName,
|
|
5290
|
+
trait: target?.finalName ?? source.trait,
|
|
5291
|
+
...target?.finalId ? { traitId: target.finalId } : {}
|
|
5292
|
+
}
|
|
5293
|
+
};
|
|
5294
|
+
}
|
|
5159
5295
|
}
|
|
5160
5296
|
return listen;
|
|
5161
5297
|
});
|
|
@@ -5335,6 +5471,25 @@ function materializedPrimaryEntity(upstreamEntity, upstreamOrbitalId, ref, local
|
|
|
5335
5471
|
);
|
|
5336
5472
|
return { name, id };
|
|
5337
5473
|
}
|
|
5474
|
+
function materializedTraitSubs(upstreamId, traits, ref, localName) {
|
|
5475
|
+
const onlySet = ref.only ? new Set(ref.only) : void 0;
|
|
5476
|
+
const omitSet = new Set(ref.omit ?? []);
|
|
5477
|
+
const out = /* @__PURE__ */ new Map();
|
|
5478
|
+
for (const rt of traits) {
|
|
5479
|
+
const name = rt.trait.name;
|
|
5480
|
+
if (!name) continue;
|
|
5481
|
+
const keep = onlySet ? onlySet.has(name) : !omitSet.has(name);
|
|
5482
|
+
if (!keep) continue;
|
|
5483
|
+
out.set(name, {
|
|
5484
|
+
finalName: `${localName}${name}`,
|
|
5485
|
+
finalId: asTraitId(deriveMaterializedId(rt.trait.id, upstreamId, name, localName, "trait"))
|
|
5486
|
+
});
|
|
5487
|
+
}
|
|
5488
|
+
return out;
|
|
5489
|
+
}
|
|
5490
|
+
function siblingImportKey(alias, upstreamOrbitalName) {
|
|
5491
|
+
return `${alias}\0${upstreamOrbitalName}`;
|
|
5492
|
+
}
|
|
5338
5493
|
function applyExtendFields(entity, extend, fieldSubs, consumerEntityIds, localName) {
|
|
5339
5494
|
if (!extend || extend.length === 0) return { entity, errors: [] };
|
|
5340
5495
|
const errors = [];
|
|
@@ -5440,11 +5595,11 @@ function rewriteConfigPagePaths(node, pathMap) {
|
|
|
5440
5595
|
}
|
|
5441
5596
|
return node;
|
|
5442
5597
|
}
|
|
5443
|
-
function rewriteTraitConfigPagePaths(trait, pathMap) {
|
|
5598
|
+
function rewriteTraitConfigPagePaths(trait, pathMap, schemaOnlyKeys) {
|
|
5444
5599
|
if (pathMap.size === 0 || !trait.config) return trait;
|
|
5445
5600
|
const nextConfig = {};
|
|
5446
5601
|
for (const [key, field] of Object.entries(trait.config)) {
|
|
5447
|
-
nextConfig[key] = field.default === void 0 ? field : { ...field, default: rewriteConfigPagePaths(field.default, pathMap) };
|
|
5602
|
+
nextConfig[key] = field.default === void 0 || schemaOnlyKeys.has(key) ? field : { ...field, default: rewriteConfigPagePaths(field.default, pathMap) };
|
|
5448
5603
|
}
|
|
5449
5604
|
return { ...trait, config: nextConfig };
|
|
5450
5605
|
}
|
|
@@ -6842,6 +6997,7 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6842
6997
|
for (const [name, id] of await this.precomputeReferenceFormPrimaryIds(schema, chain)) {
|
|
6843
6998
|
if (!consumerEntityIds.has(name)) consumerEntityIds.set(name, id);
|
|
6844
6999
|
}
|
|
7000
|
+
const listenSourceTargets = await this.precomputeReferenceFormListenTargets(schema.orbitals, chain);
|
|
6845
7001
|
const consumerRoster = identityEntitiesOf(schema.orbitals);
|
|
6846
7002
|
for (const orbital of schema.orbitals) {
|
|
6847
7003
|
if (!orbital.reference) {
|
|
@@ -6856,14 +7012,31 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6856
7012
|
flattened.push(orbital);
|
|
6857
7013
|
continue;
|
|
6858
7014
|
}
|
|
6859
|
-
const result = await this.resolveOrbitalRefChain(
|
|
7015
|
+
const result = await this.resolveOrbitalRefChain(
|
|
7016
|
+
orbital,
|
|
7017
|
+
void 0,
|
|
7018
|
+
chain,
|
|
7019
|
+
visiting,
|
|
7020
|
+
consumerEntityIds,
|
|
7021
|
+
consumerRoster,
|
|
7022
|
+
listenSourceTargets
|
|
7023
|
+
);
|
|
6860
7024
|
if (!result.success) {
|
|
6861
7025
|
errors.push(...result.errors);
|
|
6862
7026
|
continue;
|
|
6863
7027
|
}
|
|
7028
|
+
if (!opts?.skipTypeParamSentinels && isInlineEntity(result.data.entity)) {
|
|
7029
|
+
resolveOrbitalTypeParamSentinels(
|
|
7030
|
+
result.data.traits.filter(isInlineTrait).map((t) => ({ trait: t })),
|
|
7031
|
+
result.data.entity,
|
|
7032
|
+
(result.data.auxiliaryEntities ?? []).filter(isInlineEntity),
|
|
7033
|
+
result.data.types
|
|
7034
|
+
);
|
|
7035
|
+
}
|
|
6864
7036
|
flattened.push(result.data);
|
|
6865
7037
|
}
|
|
6866
7038
|
if (errors.length > 0) return { success: false, errors };
|
|
7039
|
+
reconcileOrbitalRefEventIdRenames(schema, flattened);
|
|
6867
7040
|
return { success: true, data: flattened, warnings: [] };
|
|
6868
7041
|
}
|
|
6869
7042
|
/**
|
|
@@ -6906,6 +7079,58 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6906
7079
|
}
|
|
6907
7080
|
return out;
|
|
6908
7081
|
}
|
|
7082
|
+
/**
|
|
7083
|
+
* G1 (`docs/Almadar_Compiler_Gaps.md` §82): every reference-form
|
|
7084
|
+
* orbital's OWN materialized trait set, keyed by {@link siblingImportKey}
|
|
7085
|
+
* (upstream alias + upstream orbital name), mapped to that import's local
|
|
7086
|
+
* orbital name + every kept trait's final name/id ({@link
|
|
7087
|
+
* materializedTraitSubs}). Computed order-free — WITHOUT requiring any
|
|
7088
|
+
* other orbital in `schema` to have resolved first — same precompute
|
|
7089
|
+
* shape as {@link precomputeReferenceFormPrimaryIds}, but for LISTEN-
|
|
7090
|
+
* SOURCE rewriting: consulted by {@link rewriteListenSources} so a source
|
|
7091
|
+
* naming ANY reference-form orbital of this schema resolves regardless of
|
|
7092
|
+
* declaration order. Unlike the entity-id precompute, this resolves the
|
|
7093
|
+
* upstream's OWN traits via the ordinary `this.resolve()` pass (the same
|
|
7094
|
+
* call {@link materializeOrbitalRef} makes on its own upstream, with the
|
|
7095
|
+
* same `schemaConfig` save/restore) rather than reading the raw unresolved
|
|
7096
|
+
* schema — the JS identity model has no pre-resolve declaration id for a
|
|
7097
|
+
* COMPOSED trait reference (unlike the compiled path's V4 dual-carry
|
|
7098
|
+
* `TraitReference::Reference.id`), so a shallow read would silently
|
|
7099
|
+
* under-report every composed trait's id.
|
|
7100
|
+
*
|
|
7101
|
+
* Best-effort: a reference this pre-pass cannot resolve (unknown alias,
|
|
7102
|
+
* malformed reference string, upstream orbital not found, itself still
|
|
7103
|
+
* reference-form, load/resolve failure) is silently skipped here — the
|
|
7104
|
+
* REAL `resolveOrbitalRefChain`/`materializeOrbitalRef` call moments
|
|
7105
|
+
* later still surfaces the actual error for it.
|
|
7106
|
+
*/
|
|
7107
|
+
async precomputeReferenceFormListenTargets(orbitals, chain) {
|
|
7108
|
+
const out = /* @__PURE__ */ new Map();
|
|
7109
|
+
for (const orbital of orbitals) {
|
|
7110
|
+
const ref = orbital.reference;
|
|
7111
|
+
if (!ref) continue;
|
|
7112
|
+
const parsed = parseOrbitalRef(ref.ref);
|
|
7113
|
+
if (!parsed) continue;
|
|
7114
|
+
const importsResult = await this.resolveImports(orbital.uses ?? [], void 0, chain);
|
|
7115
|
+
if (!importsResult.success) continue;
|
|
7116
|
+
const imported = importsResult.data.orbitals.get(parsed.alias);
|
|
7117
|
+
if (!imported) continue;
|
|
7118
|
+
const upstream = importedOrbitals(imported).find((o) => o.name === parsed.orbitalName);
|
|
7119
|
+
if (!upstream || upstream.reference) continue;
|
|
7120
|
+
const savedSchemaConfig = this.schemaConfig;
|
|
7121
|
+
this.schemaConfig = imported.schemaConfig;
|
|
7122
|
+
let resolvedUpstream;
|
|
7123
|
+
try {
|
|
7124
|
+
resolvedUpstream = await this.resolve(upstream, imported.sourcePath, chain);
|
|
7125
|
+
} finally {
|
|
7126
|
+
this.schemaConfig = savedSchemaConfig;
|
|
7127
|
+
}
|
|
7128
|
+
if (!resolvedUpstream.success) continue;
|
|
7129
|
+
const traitSubs = materializedTraitSubs(upstream.id, resolvedUpstream.data.traits, ref, orbital.name);
|
|
7130
|
+
out.set(siblingImportKey(parsed.alias, parsed.orbitalName), { localName: orbital.name, traitSubs });
|
|
7131
|
+
}
|
|
7132
|
+
return out;
|
|
7133
|
+
}
|
|
6909
7134
|
/**
|
|
6910
7135
|
* Resolve one reference-form orbital, recursing into the upstream first
|
|
6911
7136
|
* when IT is also reference-form ("already fully inlined because inline
|
|
@@ -6913,7 +7138,7 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6913
7138
|
* step 3 — the JS resolver needs its own cycle guard since it has no
|
|
6914
7139
|
* file-level inline-order pass to lean on).
|
|
6915
7140
|
*/
|
|
6916
|
-
async resolveOrbitalRefChain(orbital, sourcePath, chain, visiting, consumerEntityIds, consumerRoster) {
|
|
7141
|
+
async resolveOrbitalRefChain(orbital, sourcePath, chain, visiting, consumerEntityIds, consumerRoster, listenSourceTargets) {
|
|
6917
7142
|
const ref = orbital.reference;
|
|
6918
7143
|
if (!ref) return { success: true, data: orbital, warnings: [] };
|
|
6919
7144
|
const parsed = parseOrbitalRef(ref.ref);
|
|
@@ -6955,13 +7180,15 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6955
7180
|
}
|
|
6956
7181
|
visiting.add(cycleKey);
|
|
6957
7182
|
if (upstream.reference) {
|
|
7183
|
+
const nestedListenSourceTargets = await this.precomputeReferenceFormListenTargets(candidates, chain);
|
|
6958
7184
|
const nested = await this.resolveOrbitalRefChain(
|
|
6959
7185
|
upstream,
|
|
6960
7186
|
imported.sourcePath,
|
|
6961
7187
|
chain,
|
|
6962
7188
|
visiting,
|
|
6963
7189
|
consumerEntityIds,
|
|
6964
|
-
consumerRoster
|
|
7190
|
+
consumerRoster,
|
|
7191
|
+
nestedListenSourceTargets
|
|
6965
7192
|
);
|
|
6966
7193
|
if (!nested.success) {
|
|
6967
7194
|
visiting.delete(cycleKey);
|
|
@@ -6980,7 +7207,9 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
6980
7207
|
candidates,
|
|
6981
7208
|
consumerEntityIds,
|
|
6982
7209
|
consumerRoster,
|
|
6983
|
-
imported.schemaConfig
|
|
7210
|
+
imported.schemaConfig,
|
|
7211
|
+
parsed.alias,
|
|
7212
|
+
listenSourceTargets
|
|
6984
7213
|
);
|
|
6985
7214
|
if (!materialized.success) return materialized;
|
|
6986
7215
|
const siblingTraits = orbital.traits ?? [];
|
|
@@ -7001,7 +7230,7 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
7001
7230
|
* §4.3). JS twin of the (not-yet-landed) compiler's
|
|
7002
7231
|
* `resolve_orbital_reference`.
|
|
7003
7232
|
*/
|
|
7004
|
-
async materializeOrbitalRef(upstream, ref, localName, localId, sourcePath, chain, aliasOrbitals, consumerEntityIds, consumerRoster, importedSchemaConfig) {
|
|
7233
|
+
async materializeOrbitalRef(upstream, ref, localName, localId, sourcePath, chain, aliasOrbitals, consumerEntityIds, consumerRoster, importedSchemaConfig, alias, listenSourceTargets) {
|
|
7005
7234
|
const savedSchemaConfig = this.schemaConfig;
|
|
7006
7235
|
this.schemaConfig = importedSchemaConfig;
|
|
7007
7236
|
let resolvedUpstream;
|
|
@@ -7051,6 +7280,7 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
7051
7280
|
let auxEntities = upstreamAuxiliaryEntities ?? [];
|
|
7052
7281
|
const subs = /* @__PURE__ */ new Map();
|
|
7053
7282
|
for (const rt of keptTraits) subs.set(rt.trait.name, `${localName}${rt.trait.name}`);
|
|
7283
|
+
const keptFinalNames = new Set(subs.values());
|
|
7054
7284
|
const { name: primaryFinalName, id: primaryId } = materializedPrimaryEntity(
|
|
7055
7285
|
upstreamEntity,
|
|
7056
7286
|
upstream.id,
|
|
@@ -7247,7 +7477,7 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
7247
7477
|
const orbitalRename = upstream.name !== localName ? { from: upstream.name, to: localName } : void 0;
|
|
7248
7478
|
const finalTraits = materializedTraits.map((trait) => {
|
|
7249
7479
|
let next = renameTraitEmbeds(trait, subs);
|
|
7250
|
-
next = renameEntitiesInTrait(next, subs);
|
|
7480
|
+
next = renameEntitiesInTrait(next, subs, entityIds);
|
|
7251
7481
|
if (next.linkedEntity !== void 0) {
|
|
7252
7482
|
const linkedEntityId = entityIds.get(next.linkedEntity);
|
|
7253
7483
|
if (linkedEntityId !== void 0) next = { ...next, linkedEntityId };
|
|
@@ -7256,20 +7486,36 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
7256
7486
|
next = renameSourceEntityDefinition(next, subs, entityIds);
|
|
7257
7487
|
next = rewriteRoleLiteralsInTrait(next, roleFields, ref.roles ?? {});
|
|
7258
7488
|
if (fieldSubs.size > 0) next = rewriteEntityFieldsInTrait(next, fieldSubs);
|
|
7259
|
-
next = rewriteListenSources(next, subs, idByName, orbitalRename);
|
|
7489
|
+
next = rewriteListenSources(next, subs, idByName, orbitalRename, alias, listenSourceTargets);
|
|
7260
7490
|
if (pathMap.size > 0) {
|
|
7261
7491
|
next = rewriteTraitNavigateTargets(next, pathMap);
|
|
7262
7492
|
}
|
|
7493
|
+
const schemaOnlyKeys = /* @__PURE__ */ new Set();
|
|
7263
7494
|
for (const embedderName of embeddersOf.get(trait.name) ?? []) {
|
|
7264
7495
|
const embedderConfig = parentConfigs.get(embedderName);
|
|
7265
|
-
next = resolveForwardedSiblingConfigFrom(
|
|
7496
|
+
next = resolveForwardedSiblingConfigFrom(
|
|
7497
|
+
next,
|
|
7498
|
+
embedderConfig ? [embedderConfig] : [],
|
|
7499
|
+
void 0,
|
|
7500
|
+
void 0,
|
|
7501
|
+
schemaOnlyKeys
|
|
7502
|
+
);
|
|
7503
|
+
}
|
|
7504
|
+
next = resolveForwardedSiblingConfigFrom(
|
|
7505
|
+
next,
|
|
7506
|
+
transitiveEmbedderChain(trait.name),
|
|
7507
|
+
void 0,
|
|
7508
|
+
void 0,
|
|
7509
|
+
schemaOnlyKeys
|
|
7510
|
+
);
|
|
7511
|
+
next = resolveForwardedSiblingConfigFrom(next, [], foldedConfig, importedSchemaConfig, schemaOnlyKeys);
|
|
7512
|
+
if (fieldSubs.size > 0 && next.config) {
|
|
7513
|
+
next = { ...next, config: rewriteEntityFieldsInConfig(next.config, fieldSubs) };
|
|
7266
7514
|
}
|
|
7267
|
-
next = resolveForwardedSiblingConfigFrom(next, transitiveEmbedderChain(trait.name));
|
|
7268
|
-
next = resolveForwardedSiblingConfigFrom(next, [], foldedConfig, importedSchemaConfig);
|
|
7269
7515
|
if (pathMap.size > 0) {
|
|
7270
|
-
next = rewriteTraitConfigPagePaths(next, pathMap);
|
|
7516
|
+
next = rewriteTraitConfigPagePaths(next, pathMap, schemaOnlyKeys);
|
|
7271
7517
|
}
|
|
7272
|
-
next = applyEventRenames(next, ref.events);
|
|
7518
|
+
next = applyEventRenames(next, ref.events, keptFinalNames);
|
|
7273
7519
|
return next;
|
|
7274
7520
|
});
|
|
7275
7521
|
const renamedPrimaryEntity = rewriteRoleLiteralsInEntity(
|
|
@@ -7402,6 +7648,117 @@ var ReferenceResolver = class _ReferenceResolver {
|
|
|
7402
7648
|
this.loader?.clearCache();
|
|
7403
7649
|
}
|
|
7404
7650
|
};
|
|
7651
|
+
function isInlineTraitWithStateMachine(tr) {
|
|
7652
|
+
return isInlineTrait(tr);
|
|
7653
|
+
}
|
|
7654
|
+
function reconcileOrbitalRefEventIdRenames(schema, flattened) {
|
|
7655
|
+
if (!schema.ledger) return;
|
|
7656
|
+
const renamedRefs = schema.orbitals.filter((o) => o.reference?.events && Object.keys(o.reference.events).length > 0).map((o) => ({ localName: o.name, eventSubs: o.reference.events }));
|
|
7657
|
+
if (renamedRefs.length === 0) return;
|
|
7658
|
+
const sites = [];
|
|
7659
|
+
for (const { localName, eventSubs } of renamedRefs) {
|
|
7660
|
+
const newKeys = new Set(Object.values(eventSubs));
|
|
7661
|
+
const orbital = flattened.find((o) => o.name === localName);
|
|
7662
|
+
if (!orbital) continue;
|
|
7663
|
+
for (const tr of orbital.traits) {
|
|
7664
|
+
if (!isInlineTraitWithStateMachine(tr)) continue;
|
|
7665
|
+
for (const ev of tr.stateMachine?.events ?? []) {
|
|
7666
|
+
if (!ev.id || !newKeys.has(ev.key)) continue;
|
|
7667
|
+
const entry = schema.ledger.entries[ev.id];
|
|
7668
|
+
if (!entry || entry.curName === ev.key) continue;
|
|
7669
|
+
sites.push({ orbitalName: orbital.name, traitName: tr.name, oldId: ev.id, newKey: ev.key });
|
|
7670
|
+
}
|
|
7671
|
+
}
|
|
7672
|
+
}
|
|
7673
|
+
if (sites.length === 0) return;
|
|
7674
|
+
const candidateIds = new Set(sites.map((s) => s.oldId));
|
|
7675
|
+
const owners = /* @__PURE__ */ new Map();
|
|
7676
|
+
for (const orbital of flattened) {
|
|
7677
|
+
for (const tr of orbital.traits) {
|
|
7678
|
+
if (!isInlineTraitWithStateMachine(tr)) continue;
|
|
7679
|
+
for (const ev of tr.stateMachine?.events ?? []) {
|
|
7680
|
+
if (ev.id && candidateIds.has(ev.id)) {
|
|
7681
|
+
const ownerKey = `${orbital.name}\0${tr.name}`;
|
|
7682
|
+
const set = owners.get(ev.id) ?? /* @__PURE__ */ new Set();
|
|
7683
|
+
set.add(ownerKey);
|
|
7684
|
+
owners.set(ev.id, set);
|
|
7685
|
+
}
|
|
7686
|
+
}
|
|
7687
|
+
}
|
|
7688
|
+
}
|
|
7689
|
+
const renameInPlace = /* @__PURE__ */ new Map();
|
|
7690
|
+
const deriveSites = [];
|
|
7691
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7692
|
+
for (const site of sites) {
|
|
7693
|
+
const ownerCount = owners.get(site.oldId)?.size ?? 1;
|
|
7694
|
+
if (ownerCount <= 1) {
|
|
7695
|
+
renameInPlace.set(site.oldId, site.newKey);
|
|
7696
|
+
} else if (!seen.has(site.oldId)) {
|
|
7697
|
+
seen.add(site.oldId);
|
|
7698
|
+
deriveSites.push({ site, newId: asEventId(deriveId(site.oldId, site.newKey)) });
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7701
|
+
for (const { site, newId } of deriveSites) {
|
|
7702
|
+
const orbital = flattened.find((o) => o.name === site.orbitalName);
|
|
7703
|
+
if (!orbital) continue;
|
|
7704
|
+
orbital.traits = orbital.traits.map((tr) => {
|
|
7705
|
+
if (!isInlineTraitWithStateMachine(tr) || tr.name !== site.traitName) return tr;
|
|
7706
|
+
let next = tr;
|
|
7707
|
+
if (next.stateMachine?.events) {
|
|
7708
|
+
next = {
|
|
7709
|
+
...next,
|
|
7710
|
+
stateMachine: {
|
|
7711
|
+
...next.stateMachine,
|
|
7712
|
+
events: next.stateMachine.events.map((ev) => ev.id === site.oldId ? { ...ev, id: newId } : ev),
|
|
7713
|
+
transitions: (next.stateMachine.transitions ?? []).map(
|
|
7714
|
+
(t) => t.eventId === site.oldId ? { ...t, eventId: newId } : t
|
|
7715
|
+
)
|
|
7716
|
+
}
|
|
7717
|
+
};
|
|
7718
|
+
}
|
|
7719
|
+
if (next.emits) {
|
|
7720
|
+
next = {
|
|
7721
|
+
...next,
|
|
7722
|
+
emits: next.emits.map(
|
|
7723
|
+
(e) => typeof e !== "string" && e.eventId === site.oldId ? { ...e, eventId: newId } : e
|
|
7724
|
+
)
|
|
7725
|
+
};
|
|
7726
|
+
}
|
|
7727
|
+
if (next.listens) {
|
|
7728
|
+
next = {
|
|
7729
|
+
...next,
|
|
7730
|
+
listens: next.listens.map((l) => {
|
|
7731
|
+
const eventId = l.eventId === site.oldId ? newId : l.eventId;
|
|
7732
|
+
const triggersId = l.triggersId === site.oldId ? newId : l.triggersId;
|
|
7733
|
+
return eventId === l.eventId && triggersId === l.triggersId ? l : { ...l, eventId, triggersId };
|
|
7734
|
+
})
|
|
7735
|
+
};
|
|
7736
|
+
}
|
|
7737
|
+
return next;
|
|
7738
|
+
});
|
|
7739
|
+
}
|
|
7740
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
7741
|
+
let ledger = schema.ledger;
|
|
7742
|
+
for (const [oldId, newKey] of renameInPlace) {
|
|
7743
|
+
ledger = ledgerRename(ledger, oldId, newKey, at);
|
|
7744
|
+
}
|
|
7745
|
+
for (const { site, newId } of deriveSites) {
|
|
7746
|
+
const src = ledger.entries[site.oldId];
|
|
7747
|
+
if (!src) continue;
|
|
7748
|
+
const ownerTrait = flattened.find((o) => o.name === site.orbitalName)?.traits.find((tr) => isInlineTraitWithStateMachine(tr) && tr.name === site.traitName);
|
|
7749
|
+
const newEntry = {
|
|
7750
|
+
id: newId,
|
|
7751
|
+
kind: src.kind,
|
|
7752
|
+
bakedName: src.bakedName,
|
|
7753
|
+
curName: site.newKey,
|
|
7754
|
+
renames: [...src.renames, { from: src.curName, to: site.newKey, at }],
|
|
7755
|
+
owner: src.owner,
|
|
7756
|
+
...ownerTrait?.id !== void 0 ? { parent: ownerTrait.id } : {}
|
|
7757
|
+
};
|
|
7758
|
+
ledger = { ...ledger, entries: { ...ledger.entries, [newId]: newEntry } };
|
|
7759
|
+
}
|
|
7760
|
+
schema.ledger = ledger;
|
|
7761
|
+
}
|
|
7405
7762
|
async function resolveSchema(schema, options) {
|
|
7406
7763
|
const resolver = new ReferenceResolver({ ...options, schemaConfig: schema.config });
|
|
7407
7764
|
const errors = [];
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EffectExecutor } from './chunk-
|
|
2
|
-
export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, LIFECYCLE_EVENTS, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, createInitialTraitState, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeCallSiteConfigToValues, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-
|
|
1
|
+
import { EffectExecutor } from './chunk-QUW37QRQ.js';
|
|
2
|
+
export { EffectExecutor, EventBus, HANDLER_MANIFEST, InMemoryPersistence, LIFECYCLE_EVENTS, MockPersistenceAdapter, StateMachineManager, TickScheduler, buildEmitsFromTraits, collectDeclaredConfigDefaults, collectDeclaredEntityDefaults, createInitialTraitState, createMockPersistence, createTestExecutor, createTickScheduler, createUnifiedLoader, findInitialState, findTransition, formatPayloadValidationError, getIsolatedCollectionName, getNamespacedEvent, isBrowser, isElectron, isNamespacedEvent, isNode, isValidDurationString, normalizeCallSiteConfigToValues, normalizeEventKey, parseDurationString, parseNamespacedEvent, preprocessSchema, processEvent, validateEventPayload, validatePayloadShapes } from './chunk-QUW37QRQ.js';
|
|
3
3
|
export { cronMatches, cronMinuteKey, isValidCronExpression, parseCron, parseCronField } from './chunk-OU3ITB5S.js';
|
|
4
4
|
import { createContextFromBindings, applyRowAccess, checkMutationAccess, accessDeniedMessage } from './chunk-ZWAOJT6R.js';
|
|
5
5
|
export { applyRowAccess, checkMutationAccess, containsBindings, createContextFromBindings, createMinimalContext, deferEntityBindings, extractBindings, interpolateProps, interpolateValue } from './chunk-ZWAOJT6R.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almadar/runtime",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.74.0",
|
|
4
4
|
"description": "Interpreted runtime for Almadar orbital applications (OrbitalServerRuntime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@almadar/core": "^10.
|
|
60
|
+
"@almadar/core": "^10.89.0",
|
|
61
61
|
"@almadar/evaluator": "^2.45.0",
|
|
62
62
|
"@almadar/logger": "^1.12.0",
|
|
63
63
|
"@almadar/server": "^2.40.0",
|
|
64
|
-
"@almadar/std": "^16.
|
|
64
|
+
"@almadar/std": "^16.210.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"express": "^5.0.0"
|