@prometheus-ags/entity-graph-core 3.0.4 → 3.0.5
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/CHANGELOG.md +28 -0
- package/dist/index.cjs +94 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -1
- package/dist/index.d.ts +72 -1
- package/dist/index.mjs +90 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @prometheus-ags/entity-graph-core
|
|
2
2
|
|
|
3
|
+
## 3.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Resolve imperative graph access against the active graph instead of the package
|
|
8
|
+
singleton, so `GraphStoreProvider` scopes `useGraphStore.getState()`,
|
|
9
|
+
`.setState()`, `.subscribe()` and `.getInitialState()` (issue #42).
|
|
10
|
+
|
|
11
|
+
3.0.4 replaced the copied StoreApi with delegates that warned but still targeted
|
|
12
|
+
the singleton, which left consumers using the documented imperative API with no
|
|
13
|
+
isolation. The React binding now proxies those methods, resolving per call.
|
|
14
|
+
|
|
15
|
+
New in `entity-graph-core`:
|
|
16
|
+
- `runWithGraphStore(store, fn)` — an `AsyncLocalStorage` request scope, so
|
|
17
|
+
concurrent server renders never share entity state.
|
|
18
|
+
- `prepareGraphStoreScope()` — awaited once during startup on **pure-ESM**
|
|
19
|
+
servers, where there is no synchronous `require` to load `node:async_hooks`.
|
|
20
|
+
Without it request scoping degrades to a module-level store and warns.
|
|
21
|
+
- `setActiveGraphStore(store)` — the module-level active store, set by
|
|
22
|
+
`GraphStoreProvider` on mount and restored on unmount.
|
|
23
|
+
- `resolveActiveGraphStore(fallback)` — request scope → module-level store →
|
|
24
|
+
fallback.
|
|
25
|
+
|
|
26
|
+
`node:async_hooks` is loaded lazily and never statically imported, so browser
|
|
27
|
+
bundles are unaffected. With no provider and no request scope, behaviour is
|
|
28
|
+
unchanged from 3.0.4, and the deprecation warning is gone because the methods
|
|
29
|
+
now do what callers expected.
|
|
30
|
+
|
|
3
31
|
## 3.0.4
|
|
4
32
|
|
|
5
33
|
## 3.0.3
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,13 @@ var vanilla = require('zustand/vanilla');
|
|
|
4
4
|
var middleware = require('zustand/middleware');
|
|
5
5
|
var immer = require('zustand/middleware/immer');
|
|
6
6
|
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
|
|
7
14
|
// src/errors.ts
|
|
8
15
|
var TerminalError = class _TerminalError extends Error {
|
|
9
16
|
kind = "terminal";
|
|
@@ -70,6 +77,88 @@ function getRegisteredEntityTypes() {
|
|
|
70
77
|
return Array.from(transports.keys());
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
// src/active-store.ts
|
|
81
|
+
var moduleActiveStore = null;
|
|
82
|
+
var asyncScope = null;
|
|
83
|
+
var asyncScopeAttempted = false;
|
|
84
|
+
function isNodeLike() {
|
|
85
|
+
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
86
|
+
}
|
|
87
|
+
function resolveAsyncScope() {
|
|
88
|
+
if (asyncScopeAttempted) return asyncScope;
|
|
89
|
+
asyncScopeAttempted = true;
|
|
90
|
+
if (!isNodeLike()) return null;
|
|
91
|
+
try {
|
|
92
|
+
const req = typeof module !== "undefined" && typeof module.require === "function" ? module.require : typeof __require === "function" ? __require : null;
|
|
93
|
+
if (!req) return null;
|
|
94
|
+
const { AsyncLocalStorage } = req("node:async_hooks");
|
|
95
|
+
asyncScope = new AsyncLocalStorage();
|
|
96
|
+
} catch {
|
|
97
|
+
asyncScope = null;
|
|
98
|
+
}
|
|
99
|
+
return asyncScope;
|
|
100
|
+
}
|
|
101
|
+
async function prepareGraphStoreScope() {
|
|
102
|
+
if (asyncScope) return true;
|
|
103
|
+
if (!isNodeLike()) {
|
|
104
|
+
asyncScopeAttempted = true;
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (resolveAsyncScope()) return true;
|
|
108
|
+
try {
|
|
109
|
+
const specifier = "node:async_hooks";
|
|
110
|
+
const mod = await import(
|
|
111
|
+
/* @vite-ignore */
|
|
112
|
+
specifier
|
|
113
|
+
);
|
|
114
|
+
asyncScope = new mod.AsyncLocalStorage();
|
|
115
|
+
asyncScopeAttempted = true;
|
|
116
|
+
return true;
|
|
117
|
+
} catch {
|
|
118
|
+
asyncScopeAttempted = true;
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function setActiveGraphStore(store) {
|
|
123
|
+
const previous = moduleActiveStore;
|
|
124
|
+
moduleActiveStore = store;
|
|
125
|
+
return () => {
|
|
126
|
+
moduleActiveStore = previous;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
var warnedUnscopedFallback = false;
|
|
130
|
+
function warnUnscopedRequestFallback() {
|
|
131
|
+
if (warnedUnscopedFallback || !isNodeLike()) return;
|
|
132
|
+
warnedUnscopedFallback = true;
|
|
133
|
+
console.warn(
|
|
134
|
+
"[entity-graph-core] runWithGraphStore() could not load node:async_hooks, so it fell back to a module-level store. Concurrent requests will NOT be isolated. Await prepareGraphStoreScope() once during server startup."
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function runWithGraphStore(store, fn) {
|
|
138
|
+
const scope = resolveAsyncScope();
|
|
139
|
+
if (!scope) {
|
|
140
|
+
warnUnscopedRequestFallback();
|
|
141
|
+
const restore = setActiveGraphStore(store);
|
|
142
|
+
try {
|
|
143
|
+
return fn();
|
|
144
|
+
} finally {
|
|
145
|
+
restore();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return scope.run(store, fn);
|
|
149
|
+
}
|
|
150
|
+
function resolveActiveGraphStore(fallback) {
|
|
151
|
+
const scoped = resolveAsyncScope()?.getStore();
|
|
152
|
+
if (scoped) return scoped;
|
|
153
|
+
return moduleActiveStore ?? fallback;
|
|
154
|
+
}
|
|
155
|
+
function __resetActiveGraphStore() {
|
|
156
|
+
moduleActiveStore = null;
|
|
157
|
+
asyncScope = null;
|
|
158
|
+
asyncScopeAttempted = false;
|
|
159
|
+
warnedUnscopedFallback = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
73
162
|
// src/view/prisma-compile.ts
|
|
74
163
|
function nestWhereField(parts, leaf) {
|
|
75
164
|
if (parts.length === 0) return {};
|
|
@@ -3956,6 +4045,7 @@ exports.IncrementalView = IncrementalView;
|
|
|
3956
4045
|
exports.RealtimeManager = RealtimeManager;
|
|
3957
4046
|
exports.TerminalError = TerminalError;
|
|
3958
4047
|
exports.TransientError = TransientError;
|
|
4048
|
+
exports.__resetActiveGraphStore = __resetActiveGraphStore;
|
|
3959
4049
|
exports.__resetEntityTransports = __resetEntityTransports;
|
|
3960
4050
|
exports.__resetStoreRegistry = __resetStoreRegistry;
|
|
3961
4051
|
exports.applyAgUiDelta = applyAgUiDelta;
|
|
@@ -4033,6 +4123,7 @@ exports.matchesFilter = matchesFilter;
|
|
|
4033
4123
|
exports.matchesSearch = matchesSearch;
|
|
4034
4124
|
exports.parseCreateTable = parseCreateTable;
|
|
4035
4125
|
exports.persistGraphToStorage = persistGraphToStorage;
|
|
4126
|
+
exports.prepareGraphStoreScope = prepareGraphStoreScope;
|
|
4036
4127
|
exports.publishFlintMutation = publishFlintMutation;
|
|
4037
4128
|
exports.queryOnce = queryOnce;
|
|
4038
4129
|
exports.readRelations = readRelations;
|
|
@@ -4049,10 +4140,13 @@ exports.registryKey = registryKey;
|
|
|
4049
4140
|
exports.renderMarkdownToHtml = renderMarkdownToHtml;
|
|
4050
4141
|
exports.replayActionWithRetry = replayActionWithRetry;
|
|
4051
4142
|
exports.resetRealtimeManager = resetRealtimeManager;
|
|
4143
|
+
exports.resolveActiveGraphStore = resolveActiveGraphStore;
|
|
4052
4144
|
exports.restoreGraphSnapshot = restoreGraphSnapshot;
|
|
4053
4145
|
exports.restoreGraphSnapshotBySeq = restoreGraphSnapshotBySeq;
|
|
4146
|
+
exports.runWithGraphStore = runWithGraphStore;
|
|
4054
4147
|
exports.selectGraph = selectGraph;
|
|
4055
4148
|
exports.serializeKey = serializeKey;
|
|
4149
|
+
exports.setActiveGraphStore = setActiveGraphStore;
|
|
4056
4150
|
exports.setDefaultMergeStrategy = setDefaultMergeStrategy;
|
|
4057
4151
|
exports.setValueAtPath = setValueAtPath;
|
|
4058
4152
|
exports.sqlTypeToJsonSchema = sqlTypeToJsonSchema;
|