@blac/core 2.0.4 → 2.0.6
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/README.md +98 -126
- package/dist/StateContainerRegistry-Brmferpf.js +588 -0
- package/dist/StateContainerRegistry-Brmferpf.js.map +1 -0
- package/dist/StateContainerRegistry-CVPTMaHn.cjs +629 -0
- package/dist/StateContainerRegistry-CVPTMaHn.cjs.map +1 -0
- package/dist/branded-DndTHjv2.cjs +18 -0
- package/dist/branded-DndTHjv2.cjs.map +1 -0
- package/dist/branded-mwGzzPF1.js +13 -0
- package/dist/branded-mwGzzPF1.js.map +1 -0
- package/dist/config-BInS_9WT.cjs +101 -0
- package/dist/config-BInS_9WT.cjs.map +1 -0
- package/dist/config-BmFnPVM0.js +42 -0
- package/dist/config-BmFnPVM0.js.map +1 -0
- package/dist/constants.d.cts +81 -0
- package/dist/constants.d.ts +81 -0
- package/dist/core/Cubit.d.ts +24 -0
- package/dist/core/StateContainer.d.ts +177 -0
- package/dist/core/StateContainerRegistry.d.ts +189 -0
- package/dist/debug.cjs +11 -26
- package/dist/debug.d.cts +35 -0
- package/dist/debug.d.ts +35 -0
- package/dist/debug.js +2 -18
- package/dist/decorators/blac.d.ts +40 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/index.cjs +162 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -794
- package/dist/index.d.ts +17 -794
- package/dist/index.js +145 -31
- package/dist/index.js.map +1 -1
- package/dist/plugin/BlacPlugin.d.ts +143 -0
- package/dist/plugin/PluginManager.d.ts +81 -0
- package/dist/plugins.cjs +3 -3
- package/dist/plugins.d.cts +25 -0
- package/dist/plugins.d.ts +25 -0
- package/dist/plugins.js +2 -3
- package/dist/registry/acquire.d.ts +2 -0
- package/dist/registry/borrow.d.ts +9 -0
- package/dist/registry/config.d.ts +8 -0
- package/dist/registry/ensure.d.ts +2 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/management.d.ts +4 -0
- package/dist/registry/queries.d.ts +5 -0
- package/dist/registry/release.d.ts +2 -0
- package/dist/resolve-dependencies-B22YjFGk.cjs +773 -0
- package/dist/resolve-dependencies-B22YjFGk.cjs.map +1 -0
- package/dist/resolve-dependencies-Cvq0glJF.js +648 -0
- package/dist/resolve-dependencies-Cvq0glJF.js.map +1 -0
- package/dist/tracked-B_MUXIpe.cjs +216 -0
- package/dist/tracked-B_MUXIpe.cjs.map +1 -0
- package/dist/tracked-I_q9buYg.js +181 -0
- package/dist/tracked-I_q9buYg.js.map +1 -0
- package/dist/tracking.cjs +3 -3
- package/dist/tracking.js +2 -3
- package/dist/types/branded.d.ts +26 -0
- package/dist/types/utilities.d.ts +51 -0
- package/dist/types.cjs +3 -14
- package/dist/types.js +1 -12
- package/dist/utils/idGenerator.d.ts +73 -0
- package/dist/utils/static-props.d.ts +35 -0
- package/dist/watch/index.d.ts +2 -0
- package/dist/watch/watch.d.ts +50 -0
- package/dist/watch-entry.cjs +7 -109
- package/dist/watch-entry.d.cts +26 -0
- package/dist/watch-entry.d.ts +26 -0
- package/dist/watch-entry.js +1 -104
- package/package.json +29 -51
- package/dist/StateContainerRegistry.cjs.map +0 -1
- package/dist/StateContainerRegistry.js.map +0 -1
- package/dist/debug.cjs.map +0 -1
- package/dist/debug.js.map +0 -1
- package/dist/management.cjs.map +0 -1
- package/dist/management.js.map +0 -1
- package/dist/resolve-dependencies.cjs.map +0 -1
- package/dist/resolve-dependencies.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/watch-entry.cjs.map +0 -1
- package/dist/watch-entry.js.map +0 -1
- package/dist/watch.cjs.map +0 -1
- package/dist/watch.js.map +0 -1
package/dist/types.cjs
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Create a branded InstanceId from a string
|
|
5
|
-
* @param id - The string ID to brand
|
|
6
|
-
* @returns Branded InstanceId
|
|
7
|
-
*/
|
|
8
|
-
function instanceId(id) {
|
|
9
|
-
return id;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
exports.instanceId = instanceId;
|
|
14
|
-
//# sourceMappingURL=types.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_branded = require("./branded-DndTHjv2.cjs");
|
|
3
|
+
exports.instanceId = require_branded.instanceId;
|
package/dist/types.js
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Create a branded InstanceId from a string
|
|
4
|
-
* @param id - The string ID to brand
|
|
5
|
-
* @returns Branded InstanceId
|
|
6
|
-
*/
|
|
7
|
-
function instanceId(id) {
|
|
8
|
-
return id;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
1
|
+
import { t as instanceId } from "./branded-mwGzzPF1.js";
|
|
12
2
|
export { instanceId };
|
|
13
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized ID Generation
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent, collision-resistant ID generation for all BlaC subsystems.
|
|
5
|
+
* Uses timestamp + counter + random suffix for uniqueness.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates an ID generator with isolated counter state
|
|
9
|
+
*
|
|
10
|
+
* @param prefix - Prefix for generated IDs
|
|
11
|
+
* @returns Object with next(), nextSimple(), and reset() methods
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const generator = createIdGenerator('sub');
|
|
16
|
+
* const id1 = generator.next(); // "sub:1698765432100_1_a3k9d7f2q"
|
|
17
|
+
* const id2 = generator.next(); // "sub:1698765432101_2_b4n8e9g3r"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function createIdGenerator(prefix: string): {
|
|
21
|
+
next: () => string;
|
|
22
|
+
nextSimple: () => string;
|
|
23
|
+
reset: () => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
27
|
+
*
|
|
28
|
+
* Format: `${prefix}:${timestamp}_${counter}_${random}`
|
|
29
|
+
*
|
|
30
|
+
* @param prefix - Prefix for the ID (e.g., 'sub', 'consumer', 'stage')
|
|
31
|
+
* @returns Branded ID string
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const id = generateId('sub');
|
|
35
|
+
* // Returns: "sub:1698765432100_1_a3k9d7f2q"
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateId(prefix: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Generate simple ID with timestamp and random (no counter tracking)
|
|
40
|
+
*
|
|
41
|
+
* Format: `${prefix}:${timestamp}_${random}`
|
|
42
|
+
*
|
|
43
|
+
* @param prefix - Prefix for the ID
|
|
44
|
+
* @returns Branded ID string
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const id = generateSimpleId('CounterBloc');
|
|
49
|
+
* // Returns: "CounterBloc:1698765432100_a3k9d7f2q"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateSimpleId(prefix: string, affix?: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Reset all counters for testing purposes
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function __resetIdCounters(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Generate a unique isolated instance key
|
|
60
|
+
* Uses base36 encoding for compact, URL-safe identifiers
|
|
61
|
+
*
|
|
62
|
+
* Format: "isolated-{9-char-random-string}"
|
|
63
|
+
* Example: "isolated-k7x2m9p4q"
|
|
64
|
+
*
|
|
65
|
+
* @returns A unique isolated instance key
|
|
66
|
+
*/
|
|
67
|
+
export declare function generateIsolatedKey(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a key is an isolated instance key
|
|
70
|
+
* @param key - The instance key to check
|
|
71
|
+
* @returns true if the key is an isolated instance key
|
|
72
|
+
*/
|
|
73
|
+
export declare function isIsolatedKey(key: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for accessing static properties on StateContainer classes
|
|
3
|
+
*/
|
|
4
|
+
import { StateContainerConstructor } from '../types/utilities';
|
|
5
|
+
/**
|
|
6
|
+
* Get a static property from a class constructor
|
|
7
|
+
* Type-safe helper that avoids (Type as any) casts
|
|
8
|
+
*
|
|
9
|
+
* @param Type - The class constructor
|
|
10
|
+
* @param propName - The property name to access
|
|
11
|
+
* @param defaultValue - Optional default value if property is undefined
|
|
12
|
+
* @returns The property value or default
|
|
13
|
+
*/
|
|
14
|
+
export declare function getStaticProp<V, T extends StateContainerConstructor = StateContainerConstructor>(Type: T, propName: string, defaultValue?: V): V | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a class is marked as isolated.
|
|
17
|
+
* Isolated classes create separate instances per component.
|
|
18
|
+
* @param Type - The class constructor to check
|
|
19
|
+
* @returns true if the class has `static isolated = true`
|
|
20
|
+
*/
|
|
21
|
+
export declare function isIsolatedClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a class is marked as keepAlive.
|
|
24
|
+
* KeepAlive classes are never auto-disposed when ref count reaches 0.
|
|
25
|
+
* @param Type - The class constructor to check
|
|
26
|
+
* @returns true if the class has `static keepAlive = true`
|
|
27
|
+
*/
|
|
28
|
+
export declare function isKeepAliveClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a class should be excluded from DevTools.
|
|
31
|
+
* Used to prevent infinite loops when DevTools tracks itself.
|
|
32
|
+
* @param Type - The class constructor to check
|
|
33
|
+
* @returns true if the class has `static __excludeFromDevTools = true`
|
|
34
|
+
*/
|
|
35
|
+
export declare function isExcludedFromDevTools<T extends StateContainerConstructor>(Type: T): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { StateContainerConstructor } from '../types/utilities';
|
|
2
|
+
declare const STOP: unique symbol;
|
|
3
|
+
declare const BLOC_REF_MARKER: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Reference to a specific bloc instance by class and instance ID.
|
|
6
|
+
*/
|
|
7
|
+
export interface BlocRef<T extends StateContainerConstructor> {
|
|
8
|
+
[BLOC_REF_MARKER]: true;
|
|
9
|
+
blocClass: T;
|
|
10
|
+
instanceId: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a reference to a specific bloc instance.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* watch(instance(UserBloc, 'user-123'), (userBloc) => {
|
|
18
|
+
* console.log(userBloc.state.name);
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function instance<T extends StateContainerConstructor>(BlocClass: T, instanceId: string): BlocRef<T>;
|
|
23
|
+
type BlocInput = StateContainerConstructor | BlocRef<StateContainerConstructor>;
|
|
24
|
+
type ExtractInstance<T> = T extends BlocRef<infer C> ? InstanceType<C> : T extends StateContainerConstructor ? InstanceType<T> : never;
|
|
25
|
+
type ExtractInstances<T extends readonly BlocInput[]> = {
|
|
26
|
+
[K in keyof T]: ExtractInstance<T[K]>;
|
|
27
|
+
};
|
|
28
|
+
type StopSymbol = typeof STOP;
|
|
29
|
+
/**
|
|
30
|
+
* Watch function signature for single bloc.
|
|
31
|
+
*/
|
|
32
|
+
export interface WatchSingleFn {
|
|
33
|
+
<T extends StateContainerConstructor>(bloc: T | BlocRef<T>, callback: (bloc: InstanceType<T>) => void | StopSymbol): () => void;
|
|
34
|
+
STOP: StopSymbol;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Watch function signature for multiple blocs.
|
|
38
|
+
*/
|
|
39
|
+
export interface WatchMultipleFn {
|
|
40
|
+
<T extends readonly BlocInput[]>(blocs: T, callback: (blocs: ExtractInstances<T>) => void | StopSymbol): () => void;
|
|
41
|
+
STOP: StopSymbol;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Combined watch function type.
|
|
45
|
+
*/
|
|
46
|
+
export interface WatchFn extends WatchSingleFn {
|
|
47
|
+
<T extends readonly BlocInput[]>(blocs: T, callback: (blocs: ExtractInstances<T>) => void | StopSymbol): () => void;
|
|
48
|
+
}
|
|
49
|
+
export declare const watch: WatchFn;
|
|
50
|
+
export {};
|
package/dist/watch-entry.cjs
CHANGED
|
@@ -1,109 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const { result, dependencies } = tracked(() => {
|
|
12
|
-
* const user = ensure(UserBloc);
|
|
13
|
-
* return user.fullName; // getter that may access other blocs
|
|
14
|
-
* });
|
|
15
|
-
* // dependencies contains UserBloc + any blocs accessed in fullName getter
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
function tracked(callback, options) {
|
|
19
|
-
const tracker = require_resolve_dependencies.createState();
|
|
20
|
-
require_resolve_dependencies.startTracking(tracker);
|
|
21
|
-
let result;
|
|
22
|
-
try {
|
|
23
|
-
result = callback();
|
|
24
|
-
} finally {
|
|
25
|
-
require_resolve_dependencies.stopTracking(tracker, { state: null });
|
|
26
|
-
}
|
|
27
|
-
const dependencies = new Set(tracker.dependencies);
|
|
28
|
-
if (options?.exclude) dependencies.delete(options.exclude);
|
|
29
|
-
return {
|
|
30
|
-
result,
|
|
31
|
-
dependencies
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Context for running tracked callbacks with bloc proxies.
|
|
36
|
-
* Provides methods to create proxies and check for changes.
|
|
37
|
-
*/
|
|
38
|
-
var TrackedContext = class {
|
|
39
|
-
constructor() {
|
|
40
|
-
this.proxiedBlocs = /* @__PURE__ */ new WeakMap();
|
|
41
|
-
this.primaryBlocs = /* @__PURE__ */ new Set();
|
|
42
|
-
this.tracker = require_resolve_dependencies.createState();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get a tracking proxy for a bloc instance.
|
|
46
|
-
* The proxy will track state and getter accesses.
|
|
47
|
-
*/
|
|
48
|
-
proxy(bloc) {
|
|
49
|
-
const cached = this.proxiedBlocs.get(bloc);
|
|
50
|
-
if (cached) return cached;
|
|
51
|
-
const proxied = require_resolve_dependencies.createTrackingProxy(bloc, this.tracker);
|
|
52
|
-
this.proxiedBlocs.set(bloc, proxied);
|
|
53
|
-
this.primaryBlocs.add(bloc);
|
|
54
|
-
return proxied;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Start tracking for a new callback execution.
|
|
58
|
-
*/
|
|
59
|
-
start() {
|
|
60
|
-
require_resolve_dependencies.startTracking(this.tracker);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Stop tracking and get discovered dependencies.
|
|
64
|
-
* Excludes primary blocs (those explicitly proxied via proxy()).
|
|
65
|
-
*/
|
|
66
|
-
stop() {
|
|
67
|
-
const allDeps = /* @__PURE__ */ new Set();
|
|
68
|
-
for (const bloc of this.primaryBlocs) {
|
|
69
|
-
const deps = require_resolve_dependencies.stopTracking(this.tracker, bloc);
|
|
70
|
-
for (const dep of deps) if (!this.primaryBlocs.has(dep)) allDeps.add(dep);
|
|
71
|
-
}
|
|
72
|
-
return allDeps;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if any tracked state or getters have changed.
|
|
76
|
-
*/
|
|
77
|
-
changed() {
|
|
78
|
-
for (const bloc of this.primaryBlocs) if (require_resolve_dependencies.hasChanges(this.tracker, bloc)) return true;
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get all primary blocs (those explicitly proxied).
|
|
83
|
-
*/
|
|
84
|
-
getPrimaryBlocs() {
|
|
85
|
-
return new Set(this.primaryBlocs);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Reset the context for reuse.
|
|
89
|
-
*/
|
|
90
|
-
reset() {
|
|
91
|
-
this.tracker = require_resolve_dependencies.createState();
|
|
92
|
-
this.proxiedBlocs = /* @__PURE__ */ new WeakMap();
|
|
93
|
-
this.primaryBlocs.clear();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Create a new tracked context for manual control over tracking.
|
|
98
|
-
*/
|
|
99
|
-
function createTrackedContext() {
|
|
100
|
-
return new TrackedContext();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
exports.TrackedContext = TrackedContext;
|
|
105
|
-
exports.createTrackedContext = createTrackedContext;
|
|
106
|
-
exports.instance = require_watch.instance;
|
|
107
|
-
exports.tracked = tracked;
|
|
108
|
-
exports.watch = require_watch.watch;
|
|
109
|
-
//# sourceMappingURL=watch-entry.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_tracked = require("./tracked-B_MUXIpe.cjs");
|
|
3
|
+
exports.TrackedContext = require_tracked.TrackedContext;
|
|
4
|
+
exports.createTrackedContext = require_tracked.createTrackedContext;
|
|
5
|
+
exports.instance = require_tracked.instance;
|
|
6
|
+
exports.tracked = require_tracked.tracked;
|
|
7
|
+
exports.watch = require_tracked.watch;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch Subpath Export
|
|
3
|
+
*
|
|
4
|
+
* Reactive subscription utilities for watching bloc state changes.
|
|
5
|
+
* Import from '@blac/core/watch'
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { watch, instance } from '@blac/core/watch';
|
|
10
|
+
*
|
|
11
|
+
* // Watch a bloc with automatic dependency tracking
|
|
12
|
+
* const unwatch = watch(UserBloc, (userBloc) => {
|
|
13
|
+
* console.log(userBloc.state.name);
|
|
14
|
+
* console.log(userBloc.fullName); // getter also tracked
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Watch a specific instance
|
|
18
|
+
* const unwatch = watch(instance(UserBloc, 'user-123'), (userBloc) => {
|
|
19
|
+
* console.log(userBloc.state.name);
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { watch, instance, type WatchFn, type BlocRef } from './watch';
|
|
26
|
+
export { tracked, createTrackedContext, TrackedContext, type TrackedResult, type TrackedOptions, } from './tracking/tracked';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch Subpath Export
|
|
3
|
+
*
|
|
4
|
+
* Reactive subscription utilities for watching bloc state changes.
|
|
5
|
+
* Import from '@blac/core/watch'
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { watch, instance } from '@blac/core/watch';
|
|
10
|
+
*
|
|
11
|
+
* // Watch a bloc with automatic dependency tracking
|
|
12
|
+
* const unwatch = watch(UserBloc, (userBloc) => {
|
|
13
|
+
* console.log(userBloc.state.name);
|
|
14
|
+
* console.log(userBloc.fullName); // getter also tracked
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Watch a specific instance
|
|
18
|
+
* const unwatch = watch(instance(UserBloc, 'user-123'), (userBloc) => {
|
|
19
|
+
* console.log(userBloc.state.name);
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { watch, instance, type WatchFn, type BlocRef } from './watch';
|
|
26
|
+
export { tracked, createTrackedContext, TrackedContext, type TrackedResult, type TrackedOptions, } from './tracking/tracked';
|
package/dist/watch-entry.js
CHANGED
|
@@ -1,105 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { b as stopTracking, d as createTrackingProxy, f as hasChanges, u as createState, y as startTracking } from "./resolve-dependencies.js";
|
|
3
|
-
|
|
4
|
-
//#region src/tracking/tracked.ts
|
|
5
|
-
/**
|
|
6
|
-
* Run a callback while tracking all bloc dependencies accessed.
|
|
7
|
-
* Returns both the result and the set of discovered dependencies.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const { result, dependencies } = tracked(() => {
|
|
12
|
-
* const user = ensure(UserBloc);
|
|
13
|
-
* return user.fullName; // getter that may access other blocs
|
|
14
|
-
* });
|
|
15
|
-
* // dependencies contains UserBloc + any blocs accessed in fullName getter
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
function tracked(callback, options) {
|
|
19
|
-
const tracker = createState();
|
|
20
|
-
startTracking(tracker);
|
|
21
|
-
let result;
|
|
22
|
-
try {
|
|
23
|
-
result = callback();
|
|
24
|
-
} finally {
|
|
25
|
-
stopTracking(tracker, { state: null });
|
|
26
|
-
}
|
|
27
|
-
const dependencies = new Set(tracker.dependencies);
|
|
28
|
-
if (options?.exclude) dependencies.delete(options.exclude);
|
|
29
|
-
return {
|
|
30
|
-
result,
|
|
31
|
-
dependencies
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Context for running tracked callbacks with bloc proxies.
|
|
36
|
-
* Provides methods to create proxies and check for changes.
|
|
37
|
-
*/
|
|
38
|
-
var TrackedContext = class {
|
|
39
|
-
constructor() {
|
|
40
|
-
this.proxiedBlocs = /* @__PURE__ */ new WeakMap();
|
|
41
|
-
this.primaryBlocs = /* @__PURE__ */ new Set();
|
|
42
|
-
this.tracker = createState();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get a tracking proxy for a bloc instance.
|
|
46
|
-
* The proxy will track state and getter accesses.
|
|
47
|
-
*/
|
|
48
|
-
proxy(bloc) {
|
|
49
|
-
const cached = this.proxiedBlocs.get(bloc);
|
|
50
|
-
if (cached) return cached;
|
|
51
|
-
const proxied = createTrackingProxy(bloc, this.tracker);
|
|
52
|
-
this.proxiedBlocs.set(bloc, proxied);
|
|
53
|
-
this.primaryBlocs.add(bloc);
|
|
54
|
-
return proxied;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Start tracking for a new callback execution.
|
|
58
|
-
*/
|
|
59
|
-
start() {
|
|
60
|
-
startTracking(this.tracker);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Stop tracking and get discovered dependencies.
|
|
64
|
-
* Excludes primary blocs (those explicitly proxied via proxy()).
|
|
65
|
-
*/
|
|
66
|
-
stop() {
|
|
67
|
-
const allDeps = /* @__PURE__ */ new Set();
|
|
68
|
-
for (const bloc of this.primaryBlocs) {
|
|
69
|
-
const deps = stopTracking(this.tracker, bloc);
|
|
70
|
-
for (const dep of deps) if (!this.primaryBlocs.has(dep)) allDeps.add(dep);
|
|
71
|
-
}
|
|
72
|
-
return allDeps;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if any tracked state or getters have changed.
|
|
76
|
-
*/
|
|
77
|
-
changed() {
|
|
78
|
-
for (const bloc of this.primaryBlocs) if (hasChanges(this.tracker, bloc)) return true;
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get all primary blocs (those explicitly proxied).
|
|
83
|
-
*/
|
|
84
|
-
getPrimaryBlocs() {
|
|
85
|
-
return new Set(this.primaryBlocs);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Reset the context for reuse.
|
|
89
|
-
*/
|
|
90
|
-
reset() {
|
|
91
|
-
this.tracker = createState();
|
|
92
|
-
this.proxiedBlocs = /* @__PURE__ */ new WeakMap();
|
|
93
|
-
this.primaryBlocs.clear();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Create a new tracked context for manual control over tracking.
|
|
98
|
-
*/
|
|
99
|
-
function createTrackedContext() {
|
|
100
|
-
return new TrackedContext();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
1
|
+
import { a as watch, i as instance, n as createTrackedContext, r as tracked, t as TrackedContext } from "./tracked-I_q9buYg.js";
|
|
104
2
|
export { TrackedContext, createTrackedContext, instance, tracked, watch };
|
|
105
|
-
//# sourceMappingURL=watch-entry.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blac/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Brendan Mullins <jsnanigans@gmail.com>",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/jsnanigans/blac/issues"
|
|
14
14
|
},
|
|
15
|
+
"type": "module",
|
|
15
16
|
"main": "./dist/index.cjs",
|
|
16
17
|
"module": "./dist/index.js",
|
|
17
18
|
"types": "./dist/index.d.ts",
|
|
@@ -26,16 +27,6 @@
|
|
|
26
27
|
"default": "./dist/index.cjs"
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
|
-
"./types": {
|
|
30
|
-
"import": {
|
|
31
|
-
"types": "./dist/types.d.ts",
|
|
32
|
-
"default": "./dist/types.js"
|
|
33
|
-
},
|
|
34
|
-
"require": {
|
|
35
|
-
"types": "./dist/types.d.cts",
|
|
36
|
-
"default": "./dist/types.cjs"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
30
|
"./tracking": {
|
|
40
31
|
"import": {
|
|
41
32
|
"types": "./dist/tracking.d.ts",
|
|
@@ -46,14 +37,14 @@
|
|
|
46
37
|
"default": "./dist/tracking.cjs"
|
|
47
38
|
}
|
|
48
39
|
},
|
|
49
|
-
"./
|
|
40
|
+
"./debug": {
|
|
50
41
|
"import": {
|
|
51
|
-
"types": "./dist/
|
|
52
|
-
"default": "./dist/
|
|
42
|
+
"types": "./dist/debug.d.ts",
|
|
43
|
+
"default": "./dist/debug.js"
|
|
53
44
|
},
|
|
54
45
|
"require": {
|
|
55
|
-
"types": "./dist/
|
|
56
|
-
"default": "./dist/
|
|
46
|
+
"types": "./dist/debug.d.cts",
|
|
47
|
+
"default": "./dist/debug.cjs"
|
|
57
48
|
}
|
|
58
49
|
},
|
|
59
50
|
"./plugins": {
|
|
@@ -66,47 +57,35 @@
|
|
|
66
57
|
"default": "./dist/plugins.cjs"
|
|
67
58
|
}
|
|
68
59
|
},
|
|
69
|
-
"./
|
|
60
|
+
"./watch": {
|
|
70
61
|
"import": {
|
|
71
|
-
"types": "./dist/
|
|
72
|
-
"default": "./dist/
|
|
62
|
+
"types": "./dist/watch-entry.d.ts",
|
|
63
|
+
"default": "./dist/watch-entry.js"
|
|
73
64
|
},
|
|
74
65
|
"require": {
|
|
75
|
-
"types": "./dist/
|
|
76
|
-
"default": "./dist/
|
|
66
|
+
"types": "./dist/watch-entry.d.cts",
|
|
67
|
+
"default": "./dist/watch-entry.cjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./types": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/types.d.ts",
|
|
73
|
+
"default": "./dist/types.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/types.d.cts",
|
|
77
|
+
"default": "./dist/types.cjs"
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
81
|
"files": [
|
|
81
|
-
"dist
|
|
82
|
-
"dist/index.cjs",
|
|
83
|
-
"dist/index.d.ts",
|
|
84
|
-
"dist/index.d.cts",
|
|
85
|
-
"dist/types.js",
|
|
86
|
-
"dist/types.cjs",
|
|
87
|
-
"dist/types.d.ts",
|
|
88
|
-
"dist/types.d.cts",
|
|
89
|
-
"dist/tracking.js",
|
|
90
|
-
"dist/tracking.cjs",
|
|
91
|
-
"dist/tracking.d.ts",
|
|
92
|
-
"dist/tracking.d.cts",
|
|
93
|
-
"dist/tracking/**/*.d.ts",
|
|
94
|
-
"dist/watch-entry.js",
|
|
95
|
-
"dist/watch-entry.cjs",
|
|
96
|
-
"dist/watch-entry.d.ts",
|
|
97
|
-
"dist/watch-entry.d.cts",
|
|
98
|
-
"dist/plugins.js",
|
|
99
|
-
"dist/plugins.cjs",
|
|
100
|
-
"dist/plugins.d.ts",
|
|
101
|
-
"dist/plugins.d.cts",
|
|
102
|
-
"dist/debug.js",
|
|
103
|
-
"dist/debug.cjs",
|
|
104
|
-
"dist/debug.d.ts",
|
|
105
|
-
"dist/debug.d.cts",
|
|
106
|
-
"dist/*.map",
|
|
82
|
+
"dist",
|
|
107
83
|
"README.md",
|
|
108
84
|
"LICENSE"
|
|
109
85
|
],
|
|
86
|
+
"publishConfig": {
|
|
87
|
+
"access": "public"
|
|
88
|
+
},
|
|
110
89
|
"sideEffects": false,
|
|
111
90
|
"keywords": [
|
|
112
91
|
"typescript",
|
|
@@ -127,14 +106,12 @@
|
|
|
127
106
|
"typescript": "^5.9.2",
|
|
128
107
|
"valibot": "^1.1.0",
|
|
129
108
|
"vitest": "3.2.4",
|
|
109
|
+
"publint": "^0.3.12",
|
|
130
110
|
"zod": "^4.1.12"
|
|
131
111
|
},
|
|
132
112
|
"scripts": {
|
|
133
113
|
"dev": "tsdown --watch",
|
|
134
|
-
"build": "
|
|
135
|
-
"build:js": "tsdown",
|
|
136
|
-
"build:types": "tsc -p tsconfig.build.json",
|
|
137
|
-
"build:dts": "api-extractor run --local && cp dist/index.d.ts dist/index.d.cts && cp -r dist/.types/tracking dist/tracking && cp dist/.types/tracking.d.ts dist/tracking.d.ts && cp dist/.types/tracking.d.ts dist/tracking.d.cts && cp dist/.types/types.d.ts dist/types.d.ts && cp dist/.types/types.d.ts dist/types.d.cts && rm -rf dist/.types",
|
|
114
|
+
"build": "tsdown && tsc -p tsconfig.build.json && for f in dist/*.d.ts; do cp \"$f\" \"${f%.d.ts}.d.cts\"; done",
|
|
138
115
|
"clean": "rm -rf dist",
|
|
139
116
|
"format": "prettier --write \".\"",
|
|
140
117
|
"lint": "eslint src --ext .ts,.tsx",
|
|
@@ -142,6 +119,7 @@
|
|
|
142
119
|
"test": "vitest run",
|
|
143
120
|
"test:watch": "vitest --watch",
|
|
144
121
|
"coverage": "vitest run --coverage",
|
|
122
|
+
"verify": "node ../../scripts/run-workspace-bin.mjs publint",
|
|
145
123
|
"typecheck": "tsc --noEmit",
|
|
146
124
|
"deploy": "pnpm publish --access public"
|
|
147
125
|
}
|