@cldmv/slothlet 2.10.0 → 3.0.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/AGENT-USAGE.md +365 -294
- package/README.md +556 -233
- package/dist/lib/builders/api-assignment.mjs +605 -0
- package/dist/lib/builders/api_builder.mjs +1073 -0
- package/dist/lib/builders/builder.mjs +94 -0
- package/dist/lib/builders/modes-processor.mjs +1816 -0
- package/dist/lib/errors.mjs +227 -0
- package/dist/lib/factories/component-base.mjs +96 -0
- package/dist/lib/factories/context.mjs +38 -0
- package/dist/lib/handlers/api-cache-manager.mjs +216 -0
- package/dist/lib/handlers/api-manager.mjs +2364 -0
- package/dist/lib/handlers/context-async.mjs +184 -0
- package/dist/lib/handlers/context-live.mjs +184 -0
- package/dist/lib/handlers/hook-manager.mjs +789 -0
- package/dist/lib/handlers/lifecycle-token.mjs +44 -0
- package/dist/lib/handlers/lifecycle.mjs +131 -0
- package/dist/lib/handlers/materialize-manager.mjs +64 -0
- package/dist/lib/handlers/metadata.mjs +500 -0
- package/dist/lib/handlers/ownership.mjs +338 -0
- package/dist/lib/handlers/unified-wrapper.mjs +3031 -0
- package/dist/lib/helpers/class-instance-wrapper.mjs +125 -0
- package/dist/lib/helpers/config.mjs +343 -0
- package/dist/lib/helpers/eventemitter-context.mjs +365 -0
- package/dist/lib/helpers/hint-detector.mjs +63 -0
- package/dist/lib/helpers/modes-utils.mjs +53 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +125 -85
- package/dist/lib/helpers/sanitize.mjs +247 -168
- package/dist/lib/helpers/utilities.mjs +46 -81
- package/dist/lib/i18n/languages/de-de.json +377 -0
- package/dist/lib/i18n/languages/en-gb.json +377 -0
- package/dist/lib/i18n/languages/en-us.json +377 -0
- package/dist/lib/i18n/languages/es-mx.json +377 -0
- package/dist/lib/i18n/languages/fr-fr.json +377 -0
- package/dist/lib/i18n/languages/hi-in.json +377 -0
- package/dist/lib/i18n/languages/ja-jp.json +377 -0
- package/dist/lib/i18n/languages/ko-kr.json +377 -0
- package/dist/lib/i18n/languages/pt-br.json +377 -0
- package/dist/lib/i18n/languages/ru-ru.json +377 -0
- package/dist/lib/i18n/languages/zh-cn.json +377 -0
- package/dist/lib/i18n/translations.mjs +140 -0
- package/dist/lib/modes/eager.mjs +75 -0
- package/dist/lib/modes/lazy.mjs +97 -0
- package/dist/lib/processors/flatten.mjs +453 -0
- package/dist/lib/processors/loader.mjs +355 -0
- package/dist/lib/processors/type-generator.mjs +291 -0
- package/dist/lib/processors/typescript.mjs +188 -0
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +80 -522
- package/dist/lib/runtime/runtime-livebindings.mjs +45 -390
- package/dist/lib/runtime/runtime.mjs +39 -159
- package/dist/slothlet.mjs +529 -700
- package/docs/API-RULES.md +497 -617
- package/index.cjs +4 -4
- package/index.mjs +82 -45
- package/package.json +139 -26
- package/types/dist/lib/builders/api-assignment.d.mts +97 -0
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -0
- package/types/dist/lib/builders/api_builder.d.mts +96 -0
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -0
- package/types/dist/lib/builders/builder.d.mts +60 -0
- package/types/dist/lib/builders/builder.d.mts.map +1 -0
- package/types/dist/lib/builders/modes-processor.d.mts +32 -0
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -0
- package/types/dist/lib/errors.d.mts +118 -0
- package/types/dist/lib/errors.d.mts.map +1 -0
- package/types/dist/lib/factories/component-base.d.mts +182 -0
- package/types/dist/lib/factories/component-base.d.mts.map +1 -0
- package/types/dist/lib/factories/context.d.mts +26 -0
- package/types/dist/lib/factories/context.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts +208 -0
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/api-manager.d.mts +392 -0
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-async.d.mts +66 -0
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -0
- package/types/dist/lib/handlers/context-live.d.mts +65 -0
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -0
- package/types/dist/lib/handlers/hook-manager.d.mts +199 -0
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts +49 -0
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -0
- package/types/dist/lib/handlers/lifecycle.d.mts +90 -0
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts +75 -0
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/metadata.d.mts +215 -0
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -0
- package/types/dist/lib/handlers/ownership.d.mts +170 -0
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +250 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +54 -0
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -0
- package/types/dist/lib/helpers/config.d.mts +96 -0
- package/types/dist/lib/helpers/config.d.mts.map +1 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts +31 -0
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -0
- package/types/dist/lib/helpers/hint-detector.d.mts +20 -0
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -0
- package/types/dist/lib/helpers/modes-utils.d.mts +35 -0
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +29 -145
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +95 -94
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +53 -116
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +39 -0
- package/types/dist/lib/i18n/translations.d.mts.map +1 -0
- package/types/dist/lib/modes/eager.d.mts +36 -0
- package/types/dist/lib/modes/eager.d.mts.map +1 -0
- package/types/dist/lib/modes/lazy.d.mts +49 -0
- package/types/dist/lib/modes/lazy.d.mts.map +1 -0
- package/types/dist/lib/processors/flatten.d.mts +114 -0
- package/types/dist/lib/processors/flatten.d.mts.map +1 -0
- package/types/dist/lib/processors/loader.d.mts +47 -0
- package/types/dist/lib/processors/loader.d.mts.map +1 -0
- package/types/dist/lib/processors/type-generator.d.mts +19 -0
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -0
- package/types/dist/lib/processors/typescript.d.mts +55 -0
- package/types/dist/lib/processors/typescript.d.mts.map +1 -0
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +47 -42
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +34 -65
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +39 -9
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +186 -105
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +1 -3
- package/dist/lib/engine/README.md +0 -21
- package/dist/lib/engine/slothlet_child.mjs +0 -59
- package/dist/lib/engine/slothlet_engine.mjs +0 -372
- package/dist/lib/engine/slothlet_esm.mjs +0 -230
- package/dist/lib/engine/slothlet_helpers.mjs +0 -455
- package/dist/lib/engine/slothlet_worker.mjs +0 -149
- package/dist/lib/helpers/als-eventemitter.mjs +0 -256
- package/dist/lib/helpers/api_builder/add_api.mjs +0 -292
- package/dist/lib/helpers/api_builder/analysis.mjs +0 -532
- package/dist/lib/helpers/api_builder/construction.mjs +0 -457
- package/dist/lib/helpers/api_builder/decisions.mjs +0 -737
- package/dist/lib/helpers/api_builder/metadata.mjs +0 -248
- package/dist/lib/helpers/api_builder.mjs +0 -41
- package/dist/lib/helpers/auto-wrap.mjs +0 -62
- package/dist/lib/helpers/hooks.mjs +0 -389
- package/dist/lib/helpers/instance-manager.mjs +0 -111
- package/dist/lib/helpers/metadata-api.mjs +0 -201
- package/dist/lib/helpers/multidefault.mjs +0 -216
- package/dist/lib/modes/slothlet_eager.mjs +0 -126
- package/dist/lib/modes/slothlet_lazy.mjs +0 -513
- package/docs/API-RULES-CONDITIONS.md +0 -508
- package/types/dist/lib/engine/slothlet_child.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_child.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_engine.d.mts +0 -31
- package/types/dist/lib/engine/slothlet_engine.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_esm.d.mts +0 -19
- package/types/dist/lib/engine/slothlet_esm.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_helpers.d.mts +0 -25
- package/types/dist/lib/engine/slothlet_helpers.d.mts.map +0 -1
- package/types/dist/lib/engine/slothlet_worker.d.mts +0 -2
- package/types/dist/lib/engine/slothlet_worker.d.mts.map +0 -1
- package/types/dist/lib/helpers/als-eventemitter.d.mts +0 -56
- package/types/dist/lib/helpers/als-eventemitter.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/add_api.d.mts +0 -76
- package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/analysis.d.mts +0 -189
- package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/construction.d.mts +0 -107
- package/types/dist/lib/helpers/api_builder/construction.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/decisions.d.mts +0 -213
- package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder/metadata.d.mts +0 -99
- package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +0 -1
- package/types/dist/lib/helpers/api_builder.d.mts +0 -6
- package/types/dist/lib/helpers/api_builder.d.mts.map +0 -1
- package/types/dist/lib/helpers/auto-wrap.d.mts +0 -49
- package/types/dist/lib/helpers/auto-wrap.d.mts.map +0 -1
- package/types/dist/lib/helpers/hooks.d.mts +0 -342
- package/types/dist/lib/helpers/hooks.d.mts.map +0 -1
- package/types/dist/lib/helpers/instance-manager.d.mts +0 -41
- package/types/dist/lib/helpers/instance-manager.d.mts.map +0 -1
- package/types/dist/lib/helpers/metadata-api.d.mts +0 -132
- package/types/dist/lib/helpers/metadata-api.d.mts.map +0 -1
- package/types/dist/lib/helpers/multidefault.d.mts +0 -90
- package/types/dist/lib/helpers/multidefault.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_eager.d.mts +0 -65
- package/types/dist/lib/modes/slothlet_eager.d.mts.map +0 -1
- package/types/dist/lib/modes/slothlet_lazy.d.mts +0 -31
- package/types/dist/lib/modes/slothlet_lazy.d.mts.map +0 -1
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 CLDMV/Shinrai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
21
|
+
import { resolveWrapper } from "@cldmv/slothlet/handlers/unified-wrapper";
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export class OwnershipManager extends ComponentBase {
|
|
27
|
+
static slothletProperty = "ownership";
|
|
28
|
+
|
|
29
|
+
constructor(slothlet) {
|
|
30
|
+
super(slothlet);
|
|
31
|
+
this.moduleToPath = new Map();
|
|
32
|
+
this.pathToModule = new Map();
|
|
33
|
+
this._unregisteredModules = new Set();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
register({ moduleID, apiPath, value, source = "core", collisionMode = "error", config = null, filePath = null }) {
|
|
38
|
+
|
|
39
|
+
if (!moduleID || typeof moduleID !== "string") {
|
|
40
|
+
throw new this.SlothletError("OWNERSHIP_INVALID_MODULE_ID", { moduleID }, null, { validationError: true });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (apiPath !== "" && (!apiPath || typeof apiPath !== "string")) {
|
|
44
|
+
throw new this.SlothletError("OWNERSHIP_INVALID_API_PATH", { apiPath }, null, { validationError: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (this._unregisteredModules.has(moduleID)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const currentOwner = this.getCurrentOwner(apiPath);
|
|
56
|
+
if (currentOwner && currentOwner.moduleID !== moduleID) {
|
|
57
|
+
|
|
58
|
+
if (collisionMode === "merge" || collisionMode === "replace" || collisionMode === "merge-replace") {
|
|
59
|
+
|
|
60
|
+
} else if (collisionMode === "skip") {
|
|
61
|
+
|
|
62
|
+
return null;
|
|
63
|
+
} else if (collisionMode === "warn") {
|
|
64
|
+
|
|
65
|
+
if (!config?.silent) {
|
|
66
|
+
new this.SlothletWarning("WARNING_OWNERSHIP_CONFLICT", {
|
|
67
|
+
apiPath,
|
|
68
|
+
existingModuleId: currentOwner.moduleID,
|
|
69
|
+
newModuleId: moduleID
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
} else {
|
|
74
|
+
|
|
75
|
+
throw new this.SlothletError("OWNERSHIP_CONFLICT", {
|
|
76
|
+
apiPath,
|
|
77
|
+
existingModuleId: currentOwner.moduleID,
|
|
78
|
+
newModuleId: moduleID,
|
|
79
|
+
validationError: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (!this.moduleToPath.has(moduleID)) {
|
|
86
|
+
this.moduleToPath.set(moduleID, new Set());
|
|
87
|
+
}
|
|
88
|
+
this.moduleToPath.get(moduleID).add(apiPath);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (!this.pathToModule.has(apiPath)) {
|
|
92
|
+
this.pathToModule.set(apiPath, []);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const stack = this.pathToModule.get(apiPath);
|
|
97
|
+
const existingEntry = stack.find((entry) => entry.moduleID === moduleID);
|
|
98
|
+
if (existingEntry) {
|
|
99
|
+
|
|
100
|
+
existingEntry.source = source;
|
|
101
|
+
existingEntry.timestamp = Date.now();
|
|
102
|
+
existingEntry.value = value;
|
|
103
|
+
if (filePath !== null) {
|
|
104
|
+
existingEntry.filePath = filePath;
|
|
105
|
+
}
|
|
106
|
+
return existingEntry;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const entry = {
|
|
110
|
+
moduleID,
|
|
111
|
+
source,
|
|
112
|
+
timestamp: Date.now(),
|
|
113
|
+
value,
|
|
114
|
+
filePath
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
this.pathToModule.get(apiPath).push(entry);
|
|
118
|
+
|
|
119
|
+
return entry;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
unregister(moduleID) {
|
|
124
|
+
const paths = this.moduleToPath.get(moduleID);
|
|
125
|
+
if (!paths) {
|
|
126
|
+
return { removed: [], rolledBack: [] };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
this._unregisteredModules.add(moduleID);
|
|
132
|
+
|
|
133
|
+
const removed = [];
|
|
134
|
+
const rolledBack = [];
|
|
135
|
+
|
|
136
|
+
for (const apiPath of paths) {
|
|
137
|
+
const result = this.removePath(apiPath, moduleID);
|
|
138
|
+
|
|
139
|
+
if (result.action === "delete") {
|
|
140
|
+
removed.push(apiPath);
|
|
141
|
+
} else if (result.action === "restore") {
|
|
142
|
+
rolledBack.push({
|
|
143
|
+
apiPath,
|
|
144
|
+
restoredTo: result.restoreModuleId
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.moduleToPath.delete(moduleID);
|
|
150
|
+
|
|
151
|
+
return { removed, rolledBack };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
removePath(apiPath, moduleID = null) {
|
|
156
|
+
const stack = this.pathToModule.get(apiPath);
|
|
157
|
+
if (!stack) {
|
|
158
|
+
return { action: "none", removedModuleId: null, restoreModuleId: null };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
const index = moduleID ? stack.findIndex((entry) => entry.moduleID === moduleID) : stack.length - 1;
|
|
163
|
+
if (index === -1) {
|
|
164
|
+
return { action: "none", removedModuleId: null, restoreModuleId: null };
|
|
165
|
+
}
|
|
166
|
+
const [removed] = stack.splice(index, 1);
|
|
167
|
+
const removedModuleId = removed.moduleID;
|
|
168
|
+
if (removedModuleId && this.moduleToPath.has(removedModuleId)) {
|
|
169
|
+
const pathSet = this.moduleToPath.get(removedModuleId);
|
|
170
|
+
pathSet.delete(apiPath);
|
|
171
|
+
if (pathSet.size === 0) {
|
|
172
|
+
this.moduleToPath.delete(removedModuleId);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if (stack.length === 0) {
|
|
178
|
+
this.pathToModule.delete(apiPath);
|
|
179
|
+
return { action: "delete", removedModuleId, restoreModuleId: null };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
const previous = stack[stack.length - 1];
|
|
184
|
+
return {
|
|
185
|
+
action: "restore",
|
|
186
|
+
removedModuleId,
|
|
187
|
+
restoreModuleId: previous.moduleID
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
getCurrentOwner(apiPath) {
|
|
193
|
+
const stack = this.pathToModule.get(apiPath);
|
|
194
|
+
if (!stack || stack.length === 0) return null;
|
|
195
|
+
return stack[stack.length - 1];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
getCurrentValue(apiPath) {
|
|
200
|
+
const owner = this.getCurrentOwner(apiPath);
|
|
201
|
+
if (!owner) return undefined;
|
|
202
|
+
|
|
203
|
+
const value = owner.value;
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
const rawWrapper = resolveWrapper(value);
|
|
209
|
+
if (rawWrapper) {
|
|
210
|
+
return rawWrapper.__impl;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
getModulePaths(moduleID) {
|
|
218
|
+
return Array.from(this.moduleToPath.get(moduleID) || []);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
getPathHistory(apiPath) {
|
|
223
|
+
return this.pathToModule.get(apiPath) || [];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
ownsPath(moduleID, apiPath) {
|
|
228
|
+
const owner = this.getCurrentOwner(apiPath);
|
|
229
|
+
return owner && owner.moduleID === moduleID;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
getDiagnostics() {
|
|
234
|
+
return {
|
|
235
|
+
totalModules: this.moduleToPath.size,
|
|
236
|
+
totalPaths: this.pathToModule.size,
|
|
237
|
+
modules: Array.from(this.moduleToPath.entries()).map(([id, paths]) => ({
|
|
238
|
+
moduleID: id,
|
|
239
|
+
pathCount: paths.size
|
|
240
|
+
})),
|
|
241
|
+
conflictedPaths: Array.from(this.pathToModule.entries())
|
|
242
|
+
.filter(([_, stack]) => stack.length > 1)
|
|
243
|
+
.map(([path, stack]) => ({
|
|
244
|
+
apiPath: path,
|
|
245
|
+
ownerStack: stack.map((e) => e.moduleID)
|
|
246
|
+
}))
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
getPathOwnership(apiPath) {
|
|
252
|
+
const stack = this.pathToModule.get(apiPath);
|
|
253
|
+
if (!stack || stack.length === 0) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return new Set(stack.map((entry) => entry.moduleID));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
registerSubtree(api, moduleID, path, visited = new WeakSet()) {
|
|
261
|
+
if (!api || typeof api !== "object") return;
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
if (visited.has(api)) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
visited.add(api);
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
if (path) {
|
|
271
|
+
this.register({
|
|
272
|
+
moduleID,
|
|
273
|
+
apiPath: path,
|
|
274
|
+
value: api,
|
|
275
|
+
source: "core",
|
|
276
|
+
collisionMode: "merge",
|
|
277
|
+
filePath: null
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
for (const [key, value] of Object.entries(api)) {
|
|
283
|
+
|
|
284
|
+
const skipProps = ["__metadata", "__type", "_materialize", "_impl", "____slothletInternal"];
|
|
285
|
+
if (skipProps.includes(key)) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const childPath = path ? `${path}.${key}` : key;
|
|
290
|
+
if (typeof value === "function" || (value && typeof value === "object")) {
|
|
291
|
+
this.register({
|
|
292
|
+
moduleID,
|
|
293
|
+
apiPath: childPath,
|
|
294
|
+
value,
|
|
295
|
+
source: "core",
|
|
296
|
+
collisionMode: "merge",
|
|
297
|
+
filePath: null
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
302
|
+
this.registerSubtree(value, moduleID, childPath, visited);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
clear() {
|
|
310
|
+
this.moduleToPath.clear();
|
|
311
|
+
this.pathToModule.clear();
|
|
312
|
+
this._unregisteredModules.clear();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
exportState() {
|
|
317
|
+
return {
|
|
318
|
+
moduleToPath: Array.from(this.moduleToPath.entries()).map(([id, paths]) => [id, Array.from(paths)]),
|
|
319
|
+
pathToModule: Array.from(this.pathToModule.entries())
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
importState(state) {
|
|
325
|
+
|
|
326
|
+
this.clear();
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
for (const [id, paths] of state.moduleToPath) {
|
|
330
|
+
this.moduleToPath.set(id, new Set(paths));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
for (const [path, stack] of state.pathToModule) {
|
|
335
|
+
this.pathToModule.set(path, stack);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|