@typemf/core 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +63 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -26
- package/dist/index.d.ts +32 -26
- package/dist/index.js +61 -61
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -47,7 +47,6 @@ __export(index_exports, {
|
|
|
47
47
|
EcoreFactoryImpl: () => EcoreFactoryImpl,
|
|
48
48
|
EcorePackageImpl: () => EcorePackageImpl,
|
|
49
49
|
Ids: () => Ids,
|
|
50
|
-
ProxyEObjectImpl: () => ProxyEObjectImpl,
|
|
51
50
|
ResourceFactoryRegistryImpl: () => ResourceFactoryRegistryImpl,
|
|
52
51
|
ResourceImpl: () => ResourceImpl,
|
|
53
52
|
ResourceSetImpl: () => ResourceSetImpl,
|
|
@@ -56,8 +55,10 @@ __export(index_exports, {
|
|
|
56
55
|
associateRoot: () => associateRoot,
|
|
57
56
|
computeFragment: () => computeFragment,
|
|
58
57
|
createInstanceOf: () => createInstanceOf,
|
|
58
|
+
createProxy: () => createProxy,
|
|
59
59
|
detailValue: () => detailValue,
|
|
60
60
|
dissociateRoot: () => dissociateRoot,
|
|
61
|
+
getProxyURI: () => getProxyURI,
|
|
61
62
|
getResourceOf: () => getResourceOf,
|
|
62
63
|
isEAnnotation: () => isEAnnotation,
|
|
63
64
|
isEAttribute: () => isEAttribute,
|
|
@@ -232,6 +233,7 @@ var fallbackIdCounter = 0;
|
|
|
232
233
|
var EObjectImpl = class _EObjectImpl {
|
|
233
234
|
_eContainer;
|
|
234
235
|
_eContainingFeature;
|
|
236
|
+
_eProxy = false;
|
|
235
237
|
frozen = false;
|
|
236
238
|
/**
|
|
237
239
|
* Marks this object (and, recursively, everything it contains) as no longer intended to be
|
|
@@ -463,7 +465,17 @@ var EObjectImpl = class _EObjectImpl {
|
|
|
463
465
|
return result;
|
|
464
466
|
}
|
|
465
467
|
eIsProxy() {
|
|
466
|
-
return
|
|
468
|
+
return this._eProxy;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Internal - flips the proxy flag. Not part of the public EObject interface, same as
|
|
472
|
+
* eBasicSetContainer/eBasicSetValue; only `resource/proxy.ts`'s createProxy() calls this, right
|
|
473
|
+
* after constructing a real instance of the target EClass through its own factory - a proxy is
|
|
474
|
+
* not a separate class, just an ordinary, freshly-constructed instance flagged as a stand-in
|
|
475
|
+
* until something resolves it.
|
|
476
|
+
*/
|
|
477
|
+
eSetProxy(flag) {
|
|
478
|
+
this._eProxy = flag;
|
|
467
479
|
}
|
|
468
480
|
fullId() {
|
|
469
481
|
const className = this.eClass().getName();
|
|
@@ -4779,59 +4791,23 @@ function resolvePositionalPath(path, roots) {
|
|
|
4779
4791
|
return current;
|
|
4780
4792
|
}
|
|
4781
4793
|
|
|
4782
|
-
// src/resource/proxy
|
|
4783
|
-
var
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
}
|
|
4800
|
-
eContents() {
|
|
4801
|
-
return new BasicEList();
|
|
4802
|
-
}
|
|
4803
|
-
eAllContents() {
|
|
4804
|
-
return [];
|
|
4805
|
-
}
|
|
4806
|
-
fullId() {
|
|
4807
|
-
return `Proxy(${this.proxyEClass.getName()}, ${this.proxyURI.toString()})`;
|
|
4808
|
-
}
|
|
4809
|
-
eGet(_feature) {
|
|
4810
|
-
throw new Error(
|
|
4811
|
-
`Cannot read a feature of an unresolved proxy (${this.fullId()}) - resolve it via ResourceSet.resolve() first.`
|
|
4812
|
-
);
|
|
4813
|
-
}
|
|
4814
|
-
eSet(_feature, _value) {
|
|
4815
|
-
throw new Error(
|
|
4816
|
-
`Cannot set a feature of an unresolved proxy (${this.fullId()}) - resolve it via ResourceSet.resolve() first.`
|
|
4817
|
-
);
|
|
4818
|
-
}
|
|
4819
|
-
eBasicSetValue(_feature, _value) {
|
|
4820
|
-
throw new Error(
|
|
4821
|
-
`Cannot set a feature of an unresolved proxy (${this.fullId()}) - resolve it via ResourceSet.resolve() first.`
|
|
4822
|
-
);
|
|
4823
|
-
}
|
|
4824
|
-
eIsSet(_feature) {
|
|
4825
|
-
throw new Error(
|
|
4826
|
-
`Cannot check a feature of an unresolved proxy (${this.fullId()}) - resolve it via ResourceSet.resolve() first.`
|
|
4827
|
-
);
|
|
4828
|
-
}
|
|
4829
|
-
eUnset(_feature) {
|
|
4830
|
-
throw new Error(
|
|
4831
|
-
`Cannot unset a feature of an unresolved proxy (${this.fullId()}) - resolve it via ResourceSet.resolve() first.`
|
|
4832
|
-
);
|
|
4833
|
-
}
|
|
4834
|
-
};
|
|
4794
|
+
// src/resource/proxy.ts
|
|
4795
|
+
var proxyURIs = /* @__PURE__ */ new WeakMap();
|
|
4796
|
+
function createProxy(eClass, uri) {
|
|
4797
|
+
const factory = eClass.getEPackage()?.getEFactoryInstance();
|
|
4798
|
+
let obj;
|
|
4799
|
+
try {
|
|
4800
|
+
obj = factory ? factory.create(eClass) : new DynamicEObjectImpl(eClass);
|
|
4801
|
+
} catch {
|
|
4802
|
+
obj = new DynamicEObjectImpl(eClass);
|
|
4803
|
+
}
|
|
4804
|
+
obj.eSetProxy(true);
|
|
4805
|
+
proxyURIs.set(obj, uri);
|
|
4806
|
+
return obj;
|
|
4807
|
+
}
|
|
4808
|
+
function getProxyURI(obj) {
|
|
4809
|
+
return proxyURIs.get(obj);
|
|
4810
|
+
}
|
|
4835
4811
|
|
|
4836
4812
|
// src/resource/resource-factory-registry-impl.ts
|
|
4837
4813
|
var ResourceFactoryRegistryImpl = class {
|
|
@@ -5078,24 +5054,27 @@ var ResourceSetImpl = class {
|
|
|
5078
5054
|
}
|
|
5079
5055
|
async resolve(proxy) {
|
|
5080
5056
|
if (!proxy.eIsProxy()) return proxy;
|
|
5081
|
-
|
|
5082
|
-
|
|
5057
|
+
const proxyURI = getProxyURI(proxy);
|
|
5058
|
+
if (!proxyURI) {
|
|
5059
|
+
throw new Error(
|
|
5060
|
+
`eIsProxy() is true but no proxy URI is on record for this ${proxy.eClass().getName()} - it was not created via createProxy().`
|
|
5061
|
+
);
|
|
5083
5062
|
}
|
|
5084
|
-
const
|
|
5063
|
+
const proxyLabel = `${proxy.eClass().getName()} (${proxyURI.toString()})`;
|
|
5085
5064
|
const registeredPackage = this.packageRegistry.getPackage(proxyURI.trimFragment().toString());
|
|
5086
5065
|
if (registeredPackage) {
|
|
5087
5066
|
const fragment2 = proxyURI.getFragment();
|
|
5088
5067
|
const resolved = fragment2 ? resolveAgainstPackage(registeredPackage, fragment2) : void 0;
|
|
5089
5068
|
if (!resolved) {
|
|
5090
5069
|
throw new Error(
|
|
5091
|
-
`Could not resolve proxy '${
|
|
5070
|
+
`Could not resolve proxy '${proxyLabel}': fragment '${fragment2 ?? "<none>"}' did not match anything in the registered package '${registeredPackage.getNsURI() ?? "<no nsURI>"}'.`
|
|
5092
5071
|
);
|
|
5093
5072
|
}
|
|
5094
5073
|
return resolved;
|
|
5095
5074
|
}
|
|
5096
5075
|
const targetResource = await this.getResource(proxyURI.trimFragment(), true);
|
|
5097
5076
|
if (!targetResource) {
|
|
5098
|
-
throw new Error(`Could not resolve proxy '${
|
|
5077
|
+
throw new Error(`Could not resolve proxy '${proxyLabel}': its resource could not be loaded.`);
|
|
5099
5078
|
}
|
|
5100
5079
|
const fragment = proxyURI.getFragment();
|
|
5101
5080
|
const roots = targetResource.getContents().toArray();
|
|
@@ -5104,12 +5083,33 @@ var ResourceSetImpl = class {
|
|
|
5104
5083
|
const found = fragment ? resolver(fragment, roots) : void 0;
|
|
5105
5084
|
if (!found) {
|
|
5106
5085
|
throw new Error(
|
|
5107
|
-
`Could not resolve proxy '${
|
|
5086
|
+
`Could not resolve proxy '${proxyLabel}': fragment '${fragment ?? "<none>"}' did not match any object in '${targetResource.getURI().toString()}'.`
|
|
5108
5087
|
);
|
|
5109
5088
|
}
|
|
5110
5089
|
return found;
|
|
5111
5090
|
}
|
|
5091
|
+
async resolveFeature(container, feature) {
|
|
5092
|
+
const current = container.eGet(feature);
|
|
5093
|
+
if (!isUnresolvedProxy(current)) return current;
|
|
5094
|
+
const resolved = await this.resolve(current);
|
|
5095
|
+
if (resolved !== current) {
|
|
5096
|
+
container.eBasicSetValue(feature, resolved);
|
|
5097
|
+
container.eNotify({
|
|
5098
|
+
eventType: "RESOLVE",
|
|
5099
|
+
notifier: container,
|
|
5100
|
+
feature,
|
|
5101
|
+
oldValue: current,
|
|
5102
|
+
newValue: resolved,
|
|
5103
|
+
position: void 0,
|
|
5104
|
+
wasSet: true
|
|
5105
|
+
});
|
|
5106
|
+
}
|
|
5107
|
+
return resolved;
|
|
5108
|
+
}
|
|
5112
5109
|
};
|
|
5110
|
+
function isUnresolvedProxy(value) {
|
|
5111
|
+
return typeof value === "object" && value !== null && typeof value.eIsProxy === "function" && value.eIsProxy();
|
|
5112
|
+
}
|
|
5113
5113
|
function resolveAgainstPackage(pkg, fragment) {
|
|
5114
5114
|
const segments = fragment.replace(/^\/+/, "").split("/").filter((s) => s.length > 0);
|
|
5115
5115
|
if (segments.length === 0) return void 0;
|
|
@@ -9958,7 +9958,6 @@ var EcorePackageImpl = class _EcorePackageImpl extends EPackageImpl {
|
|
|
9958
9958
|
EcoreFactoryImpl,
|
|
9959
9959
|
EcorePackageImpl,
|
|
9960
9960
|
Ids,
|
|
9961
|
-
ProxyEObjectImpl,
|
|
9962
9961
|
ResourceFactoryRegistryImpl,
|
|
9963
9962
|
ResourceImpl,
|
|
9964
9963
|
ResourceSetImpl,
|
|
@@ -9967,8 +9966,10 @@ var EcorePackageImpl = class _EcorePackageImpl extends EPackageImpl {
|
|
|
9967
9966
|
associateRoot,
|
|
9968
9967
|
computeFragment,
|
|
9969
9968
|
createInstanceOf,
|
|
9969
|
+
createProxy,
|
|
9970
9970
|
detailValue,
|
|
9971
9971
|
dissociateRoot,
|
|
9972
|
+
getProxyURI,
|
|
9972
9973
|
getResourceOf,
|
|
9973
9974
|
isEAnnotation,
|
|
9974
9975
|
isEAttribute,
|