@burojs/context 0.2.0 → 0.4.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 +289 -334
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -83
- package/dist/index.d.ts +98 -83
- package/dist/index.js +288 -332
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/dist/index.cjs
CHANGED
|
@@ -1,373 +1,328 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// src/atom.ts
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/atom.ts
|
|
4
3
|
function createAtom(initial) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
};
|
|
4
|
+
let value = initial;
|
|
5
|
+
const subscribers = new Set();
|
|
6
|
+
return {
|
|
7
|
+
get() {
|
|
8
|
+
return value;
|
|
9
|
+
},
|
|
10
|
+
set(next) {
|
|
11
|
+
if (Object.is(value, next)) return;
|
|
12
|
+
value = next;
|
|
13
|
+
for (const sub of subscribers) sub();
|
|
14
|
+
},
|
|
15
|
+
subscribe(fn) {
|
|
16
|
+
subscribers.add(fn);
|
|
17
|
+
return () => {
|
|
18
|
+
subscribers.delete(fn);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/tracked-deps.ts
|
|
28
25
|
function makeTracker(target, prefix, deps) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
deps.add(path);
|
|
38
|
-
const value = Reflect.get(obj, key);
|
|
39
|
-
return makeTracker(value, path, deps);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
26
|
+
if (target === null || target === void 0) return target;
|
|
27
|
+
if (typeof target !== "object") return target;
|
|
28
|
+
return new Proxy(target, { get(obj, key) {
|
|
29
|
+
if (typeof key === "symbol") return Reflect.get(obj, key);
|
|
30
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
31
|
+
deps.add(path);
|
|
32
|
+
return makeTracker(Reflect.get(obj, key), path, deps);
|
|
33
|
+
} });
|
|
42
34
|
}
|
|
43
35
|
function trackReads(ctx, selector) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
const deps = new Set();
|
|
37
|
+
return {
|
|
38
|
+
result: selector(makeTracker(ctx, "", deps)),
|
|
39
|
+
deps
|
|
40
|
+
};
|
|
48
41
|
}
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/store.ts
|
|
51
44
|
function createStore(initial) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
45
|
+
const root = createAtom({ ...initial });
|
|
46
|
+
const subscribers = new Set();
|
|
47
|
+
let lastChangedKey = null;
|
|
48
|
+
root.subscribe(() => {
|
|
49
|
+
for (const sub of subscribers) {
|
|
50
|
+
if (!sub.selector) {
|
|
51
|
+
sub.fn();
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const { deps } = trackReads(root.get(), sub.selector);
|
|
55
|
+
sub.lastDeps = deps;
|
|
56
|
+
if (lastChangedKey && intersects(deps, lastChangedKey)) sub.fn();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
snapshot() {
|
|
61
|
+
return root.get();
|
|
62
|
+
},
|
|
63
|
+
setSlice(key, value) {
|
|
64
|
+
const prev = root.get();
|
|
65
|
+
lastChangedKey = key;
|
|
66
|
+
root.set({
|
|
67
|
+
...prev,
|
|
68
|
+
[key]: value
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
subscribe(fn, selector) {
|
|
72
|
+
const sub = {
|
|
73
|
+
fn,
|
|
74
|
+
selector
|
|
75
|
+
};
|
|
76
|
+
if (selector) {
|
|
77
|
+
const { deps } = trackReads(root.get(), selector);
|
|
78
|
+
sub.lastDeps = deps;
|
|
79
|
+
}
|
|
80
|
+
subscribers.add(sub);
|
|
81
|
+
return () => {
|
|
82
|
+
subscribers.delete(sub);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
89
86
|
}
|
|
90
87
|
function intersects(deps, changedKey) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
88
|
+
if (deps.has(changedKey)) return true;
|
|
89
|
+
for (const dep of deps) if (dep.startsWith(`${changedKey}.`)) return true;
|
|
90
|
+
return false;
|
|
96
91
|
}
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/dag.ts
|
|
99
94
|
function topoSort(nodes) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const node = byName.get(name);
|
|
123
|
-
for (const dep of node.deps) {
|
|
124
|
-
visit(dep, [...path, name]);
|
|
125
|
-
}
|
|
126
|
-
visiting.delete(name);
|
|
127
|
-
visited.add(name);
|
|
128
|
-
result.push(node);
|
|
129
|
-
}
|
|
130
|
-
for (const n of nodes) {
|
|
131
|
-
visit(n.name, []);
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
95
|
+
const byName = new Map();
|
|
96
|
+
for (const n of nodes) byName.set(n.name, n);
|
|
97
|
+
for (const n of nodes) for (const d of n.deps) if (!byName.has(d)) throw new Error(`Unknown dependency '${d}' referenced by '${n.name}'`);
|
|
98
|
+
const visited = new Set();
|
|
99
|
+
const visiting = new Set();
|
|
100
|
+
const result = [];
|
|
101
|
+
function visit(name, path) {
|
|
102
|
+
if (visited.has(name)) return;
|
|
103
|
+
if (visiting.has(name)) {
|
|
104
|
+
const cycleStart = path.indexOf(name);
|
|
105
|
+
const cyclePath = path.slice(cycleStart).concat(name).join(" → ");
|
|
106
|
+
throw new Error(`Cycle detected: ${cyclePath}`);
|
|
107
|
+
}
|
|
108
|
+
visiting.add(name);
|
|
109
|
+
const node = byName.get(name);
|
|
110
|
+
for (const dep of node.deps) visit(dep, [...path, name]);
|
|
111
|
+
visiting.delete(name);
|
|
112
|
+
visited.add(name);
|
|
113
|
+
result.push(node);
|
|
114
|
+
}
|
|
115
|
+
for (const n of nodes) visit(n.name, []);
|
|
116
|
+
return result;
|
|
134
117
|
}
|
|
135
|
-
|
|
136
|
-
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/slices/static.ts
|
|
137
120
|
function defineStaticSlice(name, config) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
121
|
+
return {
|
|
122
|
+
kind: "static",
|
|
123
|
+
name,
|
|
124
|
+
deps: [],
|
|
125
|
+
value: typeof config.value === "function" ? config.value : () => config.value
|
|
126
|
+
};
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/slices/from-auth.ts
|
|
148
130
|
function defineFromAuthSlice(name, config) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
131
|
+
return {
|
|
132
|
+
kind: "fromAuth",
|
|
133
|
+
name,
|
|
134
|
+
deps: [],
|
|
135
|
+
extract: config.extract,
|
|
136
|
+
invalidateOn: config.invalidateOn ?? ["login", "logout"]
|
|
137
|
+
};
|
|
156
138
|
}
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/slices/picker.ts
|
|
159
141
|
function definePickerSlice(name, config) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
142
|
+
return {
|
|
143
|
+
kind: "picker",
|
|
144
|
+
name,
|
|
145
|
+
deps: config.dependsOn ?? [],
|
|
146
|
+
resource: config.resource,
|
|
147
|
+
filter: config.filter,
|
|
148
|
+
resetWhen: config.resetWhen,
|
|
149
|
+
persist: config.persist,
|
|
150
|
+
required: config.required ?? false
|
|
151
|
+
};
|
|
170
152
|
}
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/slices/async.ts
|
|
173
155
|
function defineAsyncSlice(name, config) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
156
|
+
return {
|
|
157
|
+
kind: "async",
|
|
158
|
+
name,
|
|
159
|
+
deps: config.dependsOn ?? [],
|
|
160
|
+
fetch: config.fetch,
|
|
161
|
+
cacheKey: config.cacheKey,
|
|
162
|
+
staleTime: config.staleTime ?? 0
|
|
163
|
+
};
|
|
182
164
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/define-context-slices.ts
|
|
167
|
+
const builder = {
|
|
168
|
+
static: (config) => defineStaticSlice("", config),
|
|
169
|
+
fromAuth: (config) => defineFromAuthSlice("", config),
|
|
170
|
+
picker: (config) => definePickerSlice("", config),
|
|
171
|
+
async: (config) => defineAsyncSlice("", config)
|
|
190
172
|
};
|
|
191
173
|
function defineContextSlices(factory) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
174
|
+
const result = factory(builder);
|
|
175
|
+
for (const [key, slice] of Object.entries(result)) slice.name = key;
|
|
176
|
+
return result;
|
|
197
177
|
}
|
|
198
|
-
|
|
199
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/resolver.ts
|
|
200
180
|
function createResolver(slices) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
setSlice(key, value) {
|
|
290
|
-
store.setSlice(key, value);
|
|
291
|
-
invalidateDependents(key);
|
|
292
|
-
},
|
|
293
|
-
subscribe(fn, selector) {
|
|
294
|
-
return store.subscribe(fn, selector);
|
|
295
|
-
},
|
|
296
|
-
feedAuth(rawAuthUser) {
|
|
297
|
-
for (const slice of sortedSlices) {
|
|
298
|
-
if (slice.kind === "fromAuth") {
|
|
299
|
-
const authSlice = slice;
|
|
300
|
-
store.setSlice(authSlice.name, authSlice.extract(rawAuthUser));
|
|
301
|
-
invalidateDependents(authSlice.name);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
async flushAsync() {
|
|
306
|
-
const queue = Array.from(pendingAsync);
|
|
307
|
-
pendingAsync.clear();
|
|
308
|
-
for (const name of queue) {
|
|
309
|
-
const slice = sortedSlices.find((s) => s.name === name);
|
|
310
|
-
if (slice) {
|
|
311
|
-
await runAsyncFor(slice);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
181
|
+
const sliceList = Object.values(slices);
|
|
182
|
+
let sortedSlices = [];
|
|
183
|
+
let store;
|
|
184
|
+
const pendingAsync = new Set();
|
|
185
|
+
const asyncCache = new Map();
|
|
186
|
+
function initial() {
|
|
187
|
+
const init = {};
|
|
188
|
+
for (const slice of sliceList) if (slice.kind === "static") init[slice.name] = slice.value();
|
|
189
|
+
else if (slice.kind === "picker") init[slice.name] = null;
|
|
190
|
+
else init[slice.name] = void 0;
|
|
191
|
+
return init;
|
|
192
|
+
}
|
|
193
|
+
async function runAsyncFor(slice) {
|
|
194
|
+
if (slice.kind !== "async") return;
|
|
195
|
+
const asyncSlice = slice;
|
|
196
|
+
const ctx = store.snapshot();
|
|
197
|
+
const key = asyncSlice.cacheKey ? asyncSlice.cacheKey(ctx) : "__no_key__";
|
|
198
|
+
const cached = asyncCache.get(asyncSlice.name);
|
|
199
|
+
const now = Date.now();
|
|
200
|
+
if (cached && cached.key === key && asyncSlice.staleTime > 0 && now - cached.fetchedAt < asyncSlice.staleTime) {
|
|
201
|
+
store.setSlice(asyncSlice.name, cached.value);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const value = await asyncSlice.fetch(ctx);
|
|
206
|
+
asyncCache.set(asyncSlice.name, {
|
|
207
|
+
key,
|
|
208
|
+
value,
|
|
209
|
+
fetchedAt: Date.now()
|
|
210
|
+
});
|
|
211
|
+
store.setSlice(asyncSlice.name, value);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
store.setSlice(asyncSlice.name, { __error: err });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function invalidateDependents(changedKey) {
|
|
217
|
+
for (const slice of sortedSlices) if (slice.deps.includes(changedKey)) {
|
|
218
|
+
if (slice.kind === "picker") {
|
|
219
|
+
const picker = slice;
|
|
220
|
+
if (picker.resetWhen?.includes(changedKey)) store.setSlice(picker.name, null);
|
|
221
|
+
} else if (slice.kind === "async") pendingAsync.add(slice.name);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
async boot() {
|
|
226
|
+
sortedSlices = topoSort(sliceList);
|
|
227
|
+
store = createStore(initial());
|
|
228
|
+
for (const slice of sortedSlices) if (slice.kind === "picker") try {
|
|
229
|
+
const t = slice.resource();
|
|
230
|
+
if (t && (t.scope !== void 0 || t.requireScope !== void 0)) {
|
|
231
|
+
if (typeof console !== "undefined") console.warn(`[@burojs/context] picker-slice '${slice.name}': resource has scope/requireScope set; these are ignored by picker-slice (scope-isolation contract).`);
|
|
232
|
+
}
|
|
233
|
+
} catch {}
|
|
234
|
+
for (const slice of sortedSlices) if (slice.kind === "async") {
|
|
235
|
+
const snap = store.snapshot();
|
|
236
|
+
if (slice.deps.every((dep) => {
|
|
237
|
+
const val = snap[dep];
|
|
238
|
+
return val !== null && val !== void 0;
|
|
239
|
+
})) pendingAsync.add(slice.name);
|
|
240
|
+
}
|
|
241
|
+
await this.flushAsync();
|
|
242
|
+
},
|
|
243
|
+
snapshot() {
|
|
244
|
+
return store.snapshot();
|
|
245
|
+
},
|
|
246
|
+
setSlice(key, value) {
|
|
247
|
+
store.setSlice(key, value);
|
|
248
|
+
invalidateDependents(key);
|
|
249
|
+
},
|
|
250
|
+
subscribe(fn, selector) {
|
|
251
|
+
return store.subscribe(fn, selector);
|
|
252
|
+
},
|
|
253
|
+
feedAuth(rawAuthUser) {
|
|
254
|
+
for (const slice of sortedSlices) if (slice.kind === "fromAuth") {
|
|
255
|
+
const authSlice = slice;
|
|
256
|
+
store.setSlice(authSlice.name, authSlice.extract(rawAuthUser));
|
|
257
|
+
invalidateDependents(authSlice.name);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
async flushAsync() {
|
|
261
|
+
const queue = Array.from(pendingAsync);
|
|
262
|
+
pendingAsync.clear();
|
|
263
|
+
for (const name of queue) {
|
|
264
|
+
const slice = sortedSlices.find((s) => s.name === name);
|
|
265
|
+
if (slice) await runAsyncFor(slice);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
316
269
|
}
|
|
317
|
-
|
|
318
|
-
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/scope.ts
|
|
319
272
|
function mergeScope(base, patch) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
273
|
+
if (base === null && patch === null) return null;
|
|
274
|
+
if (base === null) return { ...patch };
|
|
275
|
+
if (patch === null) return { ...base };
|
|
276
|
+
return {
|
|
277
|
+
...base,
|
|
278
|
+
...patch
|
|
279
|
+
};
|
|
324
280
|
}
|
|
325
281
|
function cascadeScope(chain, ctx) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
282
|
+
let acc = null;
|
|
283
|
+
for (const entry of chain) {
|
|
284
|
+
const slice = entry.scope(ctx);
|
|
285
|
+
acc = mergeScope(acc, slice);
|
|
286
|
+
}
|
|
287
|
+
return acc;
|
|
332
288
|
}
|
|
333
289
|
function checkRequireScope(scope, required) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return missing.length === 0 ? { ok: true } : { ok: false, missing };
|
|
290
|
+
const missing = [];
|
|
291
|
+
for (const key of required) if (scope === null || scope[key] === void 0) missing.push(key);
|
|
292
|
+
return missing.length === 0 ? { ok: true } : {
|
|
293
|
+
ok: false,
|
|
294
|
+
missing
|
|
295
|
+
};
|
|
341
296
|
}
|
|
342
|
-
|
|
343
|
-
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/permissions.ts
|
|
344
299
|
function createPendingPermissions() {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
300
|
+
return {
|
|
301
|
+
status: "loading",
|
|
302
|
+
can: () => false,
|
|
303
|
+
reason: () => "Permissions loading…"
|
|
304
|
+
};
|
|
350
305
|
}
|
|
351
306
|
function createErrorPermissions(error) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
307
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
308
|
+
return {
|
|
309
|
+
status: "error",
|
|
310
|
+
can: () => false,
|
|
311
|
+
reason: () => `Permissions error: ${message}`
|
|
312
|
+
};
|
|
358
313
|
}
|
|
359
314
|
function createReadyPermissions(config) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
315
|
+
return {
|
|
316
|
+
status: "ready",
|
|
317
|
+
can: config.can,
|
|
318
|
+
reason: config.reason ?? (() => void 0)
|
|
319
|
+
};
|
|
365
320
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/index.ts
|
|
323
|
+
const PACKAGE_NAME = "@burojs/context";
|
|
324
|
+
const PACKAGE_VERSION = "0.0.0";
|
|
325
|
+
//#endregion
|
|
371
326
|
exports.PACKAGE_NAME = PACKAGE_NAME;
|
|
372
327
|
exports.PACKAGE_VERSION = PACKAGE_VERSION;
|
|
373
328
|
exports.cascadeScope = cascadeScope;
|
|
@@ -386,5 +341,5 @@ exports.defineStaticSlice = defineStaticSlice;
|
|
|
386
341
|
exports.mergeScope = mergeScope;
|
|
387
342
|
exports.topoSort = topoSort;
|
|
388
343
|
exports.trackReads = trackReads;
|
|
389
|
-
|
|
344
|
+
|
|
390
345
|
//# sourceMappingURL=index.cjs.map
|