Skip to content

Commit 6476c7a

Browse files
committed
feat: Introduce ContentAPI.inactiveType as the API-specific inactive type
Assigns ContentAPI.inactiveType as schema.inactiveType everywhere Adds InactiveScriptResource hooks Replaces createMaterializeGhostAction.state parameter with .resolver Adds get/tryTransientTypeName.schema parameter Replaces hard-coded "InactiveResource" with resolver.schema.inactiveType in files: ghost.js, Transient.js
1 parent 3207450 commit 6476c7a

23 files changed

+121
-89
lines changed

packages/engine/ValaaEngine.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ export default class ValaaEngine extends Cog {
145145
if (vExisting) return vExisting;
146146
let typeName;
147147
let transient;
148-
const state = options.state || (options.transaction || this.discourse).getState();
148+
const discourse = options.transaction || this.discourse;
149+
const state = options.state || discourse.getState();
149150
try {
150151
if (explicitTransient) {
151-
typeName = getTransientTypeName(explicitTransient);
152+
typeName = getTransientTypeName(explicitTransient, discourse.schema);
152153
transient = explicitTransient;
153154
} else {
154155
const rawId = getRawIdFrom(idData);

packages/engine/ValaaSpace/ValaaSpaceAPI.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ describe("transpileValaaScriptBody with Engine scriptAPI", () => {
457457
(left.toString() < right.toString() ? -1 : left.toString() > right.toString() ? 1 : 0);
458458
expect(symbols.propertiesSymbols.sort(symbolSorter)).toEqual([]);
459459
expect(symbols.entitySymbols.sort(symbolSorter)).toEqual([
460-
Valaa.name, Valaa.Resource.owner, Valaa.Resource.instances, Valaa.Scope.properties,
460+
Valaa.name, Valaa.Resource.owner, Valaa.Scope.properties, Valaa.TransientFields.instances,
461461
]);
462462
expect(symbols.overriddenPropertiesSymbols.sort(symbolSorter)).toEqual([]);
463463
expect(symbols.instanceSymbols.sort(symbolSorter)).toEqual([
464-
Valaa.Resource.ghostOwnlings, Valaa.Resource.owner, Valaa.prototype, Valaa.Scope.properties,
464+
Valaa.Resource.ghostOwnlings, Valaa.Resource.owner, Valaa.Scope.properties, Valaa.prototype,
465465
]);
466466
});
467467
it("Object.defineProperty", () => {

packages/engine/Vrapper/Vrapper.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import type { Passage, Story } from "~/raem/redux/Bard";
77
import { HostRef, UnpackedHostValue } from "~/raem/VALK/hostReference";
88

99
import { addedTo, fieldsSet, isCreatedLike, removedFrom, replacedWithin } from "~/raem/events";
10-
import { VRef, vRef, invariantifyId, getRawIdFrom, tryCoupledFieldFrom, expandIdDataFrom,
11-
obtainVRef } from "~/raem/ValaaReference";
10+
import { VRef, vRef, invariantifyId, getRawIdFrom, tryCoupledFieldFrom, expandIdDataFrom }
11+
from "~/raem/ValaaReference";
1212
import { createPartitionURI, getPartitionRawIdFrom } from "~/raem/ValaaURI";
1313

1414
import dataFieldValue from "~/raem/tools/denormalized/dataFieldValue";
1515

1616
import { Resolver, State, Transient } from "~/raem/state";
1717
import { tryElevateFieldValue } from "~/raem/state/FieldInfo";
18-
import getObjectTransient from "~/raem/state/getObjectTransient";
18+
import getObjectTransient, { getObjectTransientDetailed } from "~/raem/state/getObjectTransient";
1919
import { getObjectRawField } from "~/raem/state/getObjectField";
2020

2121
import { createGhostVRefInInstance, isMaterialized, createMaterializeGhostAction }
@@ -553,19 +553,23 @@ export default class Vrapper extends Cog {
553553
const explicitState = options.state
554554
|| (options.transaction && options.transaction.getState())
555555
|| (options.withOwnField && this.engine.discourse.getState());
556+
const discourse = options.transaction || this.engine.discourse;
556557
if (explicitState) {
557558
const typeName = options.typeName || this.getTypeName(options);
558559
const ret = explicitState.getIn([typeName, this.getRawId()]);
559560
if (ret && (!options.withOwnField || ret.has(options.withOwnField))) return ret;
560561
// Immaterial ghost.
561-
return getObjectTransient(options.state || options.transaction || this.engine.discourse,
562+
return getObjectTransientDetailed(
563+
!options.state ? discourse
564+
: Object.assign(Object.create(discourse), { state: options.state }),
562565
this[HostRef], typeName, undefined,
563566
options.require, options.mostMaterialized, options.withOwnField);
564567
}
565568
if (this._transientStaledIn) {
566569
this.updateTransient(null,
567-
getObjectTransient(this._transientStaledIn, this.getId(),
568-
options.typeName || this.getTypeName(options), undefined,
570+
getObjectTransientDetailed(
571+
Object.assign(Object.create(discourse), { state: this._transientStaledIn }),
572+
this.getId(), options.typeName || this.getTypeName(options), undefined,
569573
options.require, options.mostMaterialized, options.withOwnField));
570574
}
571575
return this._transient;
@@ -581,9 +585,8 @@ export default class Vrapper extends Cog {
581585
582586
materialize (transaction: ?Transaction): ChronicleEventResult {
583587
const discourse = (transaction || this.engine.discourse);
584-
const state = discourse.getState();
585-
this.requireActive({ state });
586-
return discourse.chronicleEvent(createMaterializeGhostAction(state, this.getId()));
588+
this.requireActive({ state: discourse.getState() });
589+
return discourse.chronicleEvent(createMaterializeGhostAction(discourse, this.getId()));
587590
}
588591
589592
updateTransient (state: ?Object, object: ?Object) {
@@ -942,7 +945,7 @@ export default class Vrapper extends Cog {
942945
if (defaultCoupledField) {
943946
return newValue instanceof Vrapper
944947
? newValue.getIdCoupledWith(defaultCoupledField)
945-
: obtainVRef(newValue, defaultCoupledField);
948+
: this.engine.discourse.obtainReference(newValue, defaultCoupledField);
946949
}
947950
}
948951
return newValue;

packages/raem/RAEMContentAPI.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import createRAEMReducers from "~/raem/redux/createRAEMReducers";
1010
export default createContentAPI({
1111
name: "ValOSRAEMContentAPI",
1212
exposes: [Resource, InactiveResource], // TODO(iridian): Add the rest.
13+
inactiveType: InactiveResource,
1314
mutations,
1415
validators,
1516
reducers: [createRAEMReducers],

packages/raem/VALK/Valker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ export default class Valker extends Resolver {
416416
}
417417

418418
getObjectTypeIntro (object: Object | Transient, possiblePackedHead: Object) {
419-
let typeName = tryTransientTypeName(object);
419+
let typeName = tryTransientTypeName(object, this.schema);
420420
if (!typeName && possiblePackedHead._type && !possiblePackedHead._fieldInfo.intro.isResource) {
421421
typeName = possiblePackedHead._type;
422422
}
423423
const ret = typeName && this.getTypeIntro(typeName);
424-
if ((ret === undefined) && isInactiveTypeName(typeName)) {
424+
if ((ret === undefined) && typeName && isInactiveTypeName(typeName)) {
425425
const partitionURI = object.get("id").getPartitionURI();
426426
throw new MissingPartitionConnectionsError(`Missing active partition connections: '${
427427
partitionURI.toString()}'`, [partitionURI]);

packages/raem/VALK/Valker.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe("ghost lookups", () => {
130130
const harness = createRAEMTestHarness({ verbosity: 0 }, createTestObj, createTestObjInst);
131131
let ghostOwnling = harness.run(vRef("testObjInst"),
132132
["§->", "children", 0]);
133-
const materializeEvent = createMaterializeGhostAction(harness.getState(), ghostOwnling);
133+
const materializeEvent = createMaterializeGhostAction(harness.getValker(), ghostOwnling);
134134
harness.chronicleEvent(materializeEvent);
135135
ghostOwnling = harness.run(vRef("testObjInst"),
136136
["§->", "children", 0]);
@@ -149,7 +149,7 @@ describe("ghost lookups", () => {
149149
const harness = createRAEMTestHarness({ verbosity: 0 }, createTestObj, createTestObjInst);
150150
let ghostOwnling = harness.run(vRef("testObjInst"),
151151
["§->", "children", 0]);
152-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), ghostOwnling));
152+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), ghostOwnling));
153153
ghostOwnling = harness.run(vRef("testObjInst"),
154154
["§->", "children", 0]);
155155
const ghostGrandling = harness.run(ghostOwnling, ["§->", "children", 0]);
@@ -174,7 +174,7 @@ describe("ghost lookups", () => {
174174
const harness = createRAEMTestHarness({ verbosity: 0 }, createTestObj, createOwnlingInst);
175175
let ghostGrandling = harness.run(vRef("ownlingInst"),
176176
["§->", "children", 0]);
177-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), ghostGrandling));
177+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), ghostGrandling));
178178
ghostGrandling = harness.run(vRef("ownlingInst"),
179179
["§->", "children", 0]);
180180

@@ -191,7 +191,7 @@ describe("ghost lookups", () => {
191191
const harness = createRAEMTestHarness({ verbosity: 0 }, createTestObj, createOwnlingInst);
192192
let ghostGrandling = harness.run(vRef("ownlingInst"),
193193
["§->", "children", 0]);
194-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), ghostGrandling));
194+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), ghostGrandling));
195195
ghostGrandling = harness.run(vRef("ownlingInst"),
196196
["§->", "children", 0]);
197197
const ghostGreatGrandling = harness.run(ghostGrandling, ["§->", "children", 0]);
@@ -490,9 +490,9 @@ describe("complex structures", () => {
490490
["§->", "children", 0], { verbosity: 0 });
491491
492492
// Falling apart workaround
493-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), gA1_B));
494-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), gA1_B_C));
495-
harness.chronicleEvent(createMaterializeGhostAction(harness.getState(), gA_B1_C));
493+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), gA1_B));
494+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), gA1_B_C));
495+
harness.chronicleEvent(createMaterializeGhostAction(harness.getValker(), gA_B1_C));
496496
497497
// Here everything falls apart
498498
harness.chronicleEvent(created({ id: "gA1_B1", typeName: "TestThing", initialState: {

packages/raem/redux/Bard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ export default class Bard extends Resolver {
281281

282282
goToObjectTypeIntro (operationDescription: string = this.passage.type): Object {
283283
this.objectTypeIntro = this.schema.getType(this.typeName
284-
|| getTransientTypeName(this.objectTransient));
284+
|| getTransientTypeName(this.objectTransient, this.schema));
285285
if (!this.objectTypeIntro) {
286286
throw new Error(`${operationDescription} schema introspection missing for type '${
287-
getTransientTypeName(this.objectTransient)}'`);
287+
getTransientTypeName(this.objectTransient, this.schema)}'`);
288288
}
289289
return this.objectTypeIntro;
290290
}

packages/raem/redux/reducers/construct.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ export function prepareCreateOrDuplicateObjectTransientAndId (bard: CreateBard,
7676
invariantifyString(passage.typeName, "CREATED.typeName required");
7777
bard.updateState(
7878
bard.subReduce(bard.state,
79-
createMaterializeGhostPathAction(
80-
bard.state, passage.id.getGhostPath(), passage.typeName)));
79+
createMaterializeGhostPathAction(bard, passage.id.getGhostPath(), passage.typeName)));
8180
bard.goToTransientOfRawId(passage.id.rawId());
8281
passage.id = bard.objectTransient.get("id");
8382
if (!passage.id) throw new Error("INTERNAL ERROR: no bard.objectTransient.get('id')");

packages/raem/redux/reducers/duplicate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function duplicate (bard: DuplicateBard) {
3939
// in inactive interface and type tables.
4040
bard.goToObjectIdTransient(duplicateOf, "Resource");
4141
const ghostPath = passage.id.getGhostPath();
42-
passage.typeName = getTransientTypeName(bard.objectTransient);
42+
passage.typeName = getTransientTypeName(bard.objectTransient, bard.schema);
4343
if (!ghostPath.isGhost()) {
4444
// original is not a ghost: only check if it is an instance for _duplicationRootPrototypeId
4545
const prototypeId = bard.objectTransient.get("prototype");

packages/raem/redux/reducers/modify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function modifyResource (bard: Bard) {
5151
bard.goToTransientOfPassageObject(); // no-require, non-ghost-lookup
5252
if (!bard.objectTransient) { // ghost or fail
5353
const materializeGhostSubCommand = createMaterializeGhostPathAction(
54-
bard.state, passage.id.getGhostPath(), passage.typeName);
54+
bard, passage.id.getGhostPath(), passage.typeName);
5555
bard.updateState(bard.subReduce(bard.state, materializeGhostSubCommand));
5656
bard.goToTransientOfRawId(passage.id.rawId());
5757
passage.id = bard.objectId;

0 commit comments

Comments
 (0)