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