@vicin/sigil 1.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.
Files changed (51) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +620 -0
  3. package/dist/core/classes.d.ts +48 -0
  4. package/dist/core/classes.d.ts.map +1 -0
  5. package/dist/core/classes.js +18 -0
  6. package/dist/core/classes.js.map +1 -0
  7. package/dist/core/decorator.d.ts +28 -0
  8. package/dist/core/decorator.d.ts.map +1 -0
  9. package/dist/core/decorator.js +48 -0
  10. package/dist/core/decorator.js.map +1 -0
  11. package/dist/core/enhancers.d.ts +58 -0
  12. package/dist/core/enhancers.d.ts.map +1 -0
  13. package/dist/core/enhancers.js +101 -0
  14. package/dist/core/enhancers.js.map +1 -0
  15. package/dist/core/helpers.d.ts +192 -0
  16. package/dist/core/helpers.d.ts.map +1 -0
  17. package/dist/core/helpers.js +349 -0
  18. package/dist/core/helpers.js.map +1 -0
  19. package/dist/core/index.d.ts +9 -0
  20. package/dist/core/index.d.ts.map +1 -0
  21. package/dist/core/index.js +8 -0
  22. package/dist/core/index.js.map +1 -0
  23. package/dist/core/mixin.d.ts +115 -0
  24. package/dist/core/mixin.d.ts.map +1 -0
  25. package/dist/core/mixin.js +209 -0
  26. package/dist/core/mixin.js.map +1 -0
  27. package/dist/core/options.d.ts +74 -0
  28. package/dist/core/options.d.ts.map +1 -0
  29. package/dist/core/options.js +39 -0
  30. package/dist/core/options.js.map +1 -0
  31. package/dist/core/registry.d.ts +104 -0
  32. package/dist/core/registry.d.ts.map +1 -0
  33. package/dist/core/registry.js +174 -0
  34. package/dist/core/registry.js.map +1 -0
  35. package/dist/core/symbols.d.ts +96 -0
  36. package/dist/core/symbols.d.ts.map +1 -0
  37. package/dist/core/symbols.js +96 -0
  38. package/dist/core/symbols.js.map +1 -0
  39. package/dist/core/types.d.ts +169 -0
  40. package/dist/core/types.d.ts.map +1 -0
  41. package/dist/core/types.js +2 -0
  42. package/dist/core/types.js.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +3 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/utils/index.d.ts +2 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +2 -0
  50. package/dist/utils/index.js.map +1 -0
  51. package/package.json +57 -0
@@ -0,0 +1,18 @@
1
+ import { Sigilify } from './mixin';
2
+ /**
3
+ * A minimal root Sigil class used by the library as a base identity.
4
+ *
5
+ * This is produced by `Sigilify` and can serve as a basic sentinel/base
6
+ * class for other sigil classes or for debugging/inspection.
7
+ */
8
+ export const Sigil = Sigilify(class {
9
+ }, 'Sigil');
10
+ /**
11
+ * A sigil variant of the built-in `Error` constructor used by the library
12
+ * to represent Sigil-specific errors.
13
+ *
14
+ * Use `SigilError` when you want an Error type that is identifiable via sigil
15
+ * runtime checks (e.g. `SigilError.isOfType(someError)`).
16
+ */
17
+ export const SigilError = Sigilify(Error, 'SigilError');
18
+ //# sourceMappingURL=classes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classes.js","sourceRoot":"","sources":["../../src/core/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC;CAAQ,EAAE,OAAO,CAAC,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { SigilOptions } from './options';
2
+ /**
3
+ * Class decorator factory that attaches sigil statics to a class constructor.
4
+ *
5
+ * Usage:
6
+ * ```ts
7
+ * @WithSigil('@myorg/mypkg.MyClass')
8
+ * class MyClass { ... }
9
+ * ```
10
+ *
11
+ * The returned decorator:
12
+ * - validates the provided label (via `verifyLabel`)
13
+ * - performs inheritance checks (via `checkInheritance`) in DEV builds
14
+ * - attaches sigil-related statics to the constructor (via `decorateCtor`)
15
+ *
16
+ * Notes:
17
+ * - This decorator is intended to be applied to classes only. When used
18
+ * incorrectly (e.g. on a property), it is a no-op.
19
+ * - Throws an error during class creation if the label validation fails.
20
+ *
21
+ * @typeParam L - Narrow string literal type for the provided label.
22
+ * @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
23
+ * If not passed a random label is generated instead.
24
+ * @param opts - Options object to override any global options if needed.
25
+ * @returns A class decorator compatible with the ECMAScript decorator context.
26
+ */
27
+ export declare function WithSigil<L extends string>(label?: L, opts?: SigilOptions): (value: Function, context: ClassDecoratorContext) => void;
28
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../../src/core/decorator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY,IAQvD,OAAO,QAAQ,EAAE,SAAS,qBAAqB,UAYjE"}
@@ -0,0 +1,48 @@
1
+ import { checkInheritance, decorateCtor, generateRandomLabel, isSigilCtor, verifyLabel, } from './helpers';
2
+ /**
3
+ * Class decorator factory that attaches sigil statics to a class constructor.
4
+ *
5
+ * Usage:
6
+ * ```ts
7
+ * @WithSigil('@myorg/mypkg.MyClass')
8
+ * class MyClass { ... }
9
+ * ```
10
+ *
11
+ * The returned decorator:
12
+ * - validates the provided label (via `verifyLabel`)
13
+ * - performs inheritance checks (via `checkInheritance`) in DEV builds
14
+ * - attaches sigil-related statics to the constructor (via `decorateCtor`)
15
+ *
16
+ * Notes:
17
+ * - This decorator is intended to be applied to classes only. When used
18
+ * incorrectly (e.g. on a property), it is a no-op.
19
+ * - Throws an error during class creation if the label validation fails.
20
+ *
21
+ * @typeParam L - Narrow string literal type for the provided label.
22
+ * @param label - Optional sigil label to assign to the decorated class (e.g. `@scope/pkg.ClassName`).
23
+ * If not passed a random label is generated instead.
24
+ * @param opts - Options object to override any global options if needed.
25
+ * @returns A class decorator compatible with the ECMAScript decorator context.
26
+ */
27
+ export function WithSigil(label, opts) {
28
+ // generate random label if not passed and verify it
29
+ let l;
30
+ if (label) {
31
+ verifyLabel(label, opts);
32
+ l = label;
33
+ }
34
+ else
35
+ l = generateRandomLabel();
36
+ return function (value, context) {
37
+ // Only apply to class declarations
38
+ if (context.kind !== 'class')
39
+ return;
40
+ if (!isSigilCtor(value))
41
+ throw new Error(`[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`);
42
+ // Attach sigil metadata to constructor (registers label, sets symbols, marks decorated)
43
+ decorateCtor(value, l);
44
+ // Development-only inheritance checks and potential autofill
45
+ checkInheritance(value, opts);
46
+ };
47
+ }
48
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/core/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,WAAW,GACZ,MAAM,WAAW,CAAC;AAGnB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,SAAS,CAAmB,KAAS,EAAE,IAAmB;IACxE,oDAAoD;IACpD,IAAI,CAAS,CAAC;IACd,IAAI,KAAK,EAAE,CAAC;QACV,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,GAAG,KAAK,CAAC;IACZ,CAAC;;QAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC;IAEjC,OAAO,UAAU,KAAe,EAAE,OAA8B;QAC9D,mCAAmC;QACnC,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO;QACrC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,mFAAmF,KAAK,CAAC,IAAI,EAAE,CAChG,CAAC;QACJ,wFAAwF;QACxF,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACvB,6DAA6D;QAC7D,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { type SigilOptions } from './options';
2
+ import type { TypedSigil } from './types';
3
+ /**
4
+ * HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
5
+ * Alternative to '@WithSigil' if you prefer HOFs.
6
+ *
7
+ * This does both:
8
+ * - validate (and autofill) a label,
9
+ * - perform runtime decoration (via `decorateCtor`),
10
+ *
11
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
12
+ * decorated; we handle this gracefully in DEV to support HMR flows.
13
+ *
14
+ * @typeParam S - Constructor type (should be an ISigil).
15
+ * @typeParam L - Label literal to attach.
16
+ * @param Class - The constructor (class) to enhance.
17
+ * @param label - Optional label string. If omitted, a random label is generated.
18
+ * @param opts - Options object to override any global options if needed.
19
+ * @returns The same constructor value, with runtime metadata ensured.
20
+ */
21
+ export declare function withSigil<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): S;
22
+ /**
23
+ * Narrow a constructor to a compile-time `TypedSigil` without modifying runtime.
24
+ *
25
+ * This is a *purely type-level* helper (no runtime changes). It optionally
26
+ * verifies in DEV that the runtime `SigilLabel` matches the provided `label`.
27
+ *
28
+ * Use this when the runtime metadata is already present (for example the class
29
+ * is already decorated or was created via `Sigilify`).
30
+ *
31
+ * @typeParam S - Constructor type (should be an ISigil).
32
+ * @typeParam L - Label literal to associate at compile-time.
33
+ * @param Class - The constructor to assert as typed sigil.
34
+ * @param label - Optional label literal to assert at compile-time (and to verify in DEV).
35
+ * @returns The same constructor value, typed as `TypedSigil<S, L, P>`.
36
+ */
37
+ export declare function typed<S extends Function, L extends string = string>(Class: S, label?: L, opts?: Pick<SigilOptions, 'devMarker'>): TypedSigil<S, L>;
38
+ /**
39
+ * Convenience helper that combine 'withSigil' and 'typeSigil'.
40
+ *
41
+ * This does both:
42
+ * - validate (and autofill) a label,
43
+ * - perform runtime decoration (via `decorateCtor`),
44
+ * - return the constructor typed as `TypedSigil`.
45
+ *
46
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
47
+ * decorated; we handle this gracefully in DEV to support HMR flows.
48
+ *
49
+ * @typeParam S - Constructor type (should be an ISigil).
50
+ * @typeParam L - Label literal to attach.
51
+ * @param Class - The constructor (class) to decorate and type.
52
+ * @param label - Optional label string. If omitted, a random label is generated.
53
+ * @param parent - Optional parent sigil constructor (type-only).
54
+ * @param opts - Options object to override any global options if needed.
55
+ * @returns The same constructor value, with runtime metadata ensured and typed as `TypedSigil<S,L,P>`.
56
+ */
57
+ export declare function withSigilTyped<S extends Function, L extends string = string>(Class: S, label?: L, opts?: SigilOptions): TypedSigil<S, L>;
58
+ //# sourceMappingURL=enhancers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enhancers.d.ts","sourceRoot":"","sources":["../../src/core/enhancers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EACrE,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,CAAC,EACT,IAAI,CAAC,EAAE,YAAY,GAClB,CAAC,CAmBH;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EACjE,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,CAAC,EACT,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GACrC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAgBlB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAC1E,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,CAAC,EACT,IAAI,CAAC,EAAE,YAAY,GAClB,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAmBlB"}
@@ -0,0 +1,101 @@
1
+ import { checkInheritance, decorateCtor, generateRandomLabel, isSigilCtor, verifyLabel, } from './helpers';
2
+ import { OPTIONS } from './options';
3
+ /**
4
+ * HOF (class inhancer) that attaches runtime sigil metadata to Sigil class.
5
+ * Alternative to '@WithSigil' if you prefer HOFs.
6
+ *
7
+ * This does both:
8
+ * - validate (and autofill) a label,
9
+ * - perform runtime decoration (via `decorateCtor`),
10
+ *
11
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
12
+ * decorated; we handle this gracefully in DEV to support HMR flows.
13
+ *
14
+ * @typeParam S - Constructor type (should be an ISigil).
15
+ * @typeParam L - Label literal to attach.
16
+ * @param Class - The constructor (class) to enhance.
17
+ * @param label - Optional label string. If omitted, a random label is generated.
18
+ * @param opts - Options object to override any global options if needed.
19
+ * @returns The same constructor value, with runtime metadata ensured.
20
+ */
21
+ export function withSigil(Class, label, opts) {
22
+ if (!isSigilCtor(Class))
23
+ throw new Error(`[Sigil Error] 'withSigil' HOF accept only Sigil classes but used on class ${Class?.name ?? 'unknown'}`);
24
+ // generate random label if not passed and verify it
25
+ let l;
26
+ if (label) {
27
+ verifyLabel(label, opts);
28
+ l = label;
29
+ }
30
+ else
31
+ l = generateRandomLabel();
32
+ // decorate and check inheritance.
33
+ const ctor = Class;
34
+ decorateCtor(ctor, l);
35
+ checkInheritance(ctor, opts);
36
+ return Class;
37
+ }
38
+ /**
39
+ * Narrow a constructor to a compile-time `TypedSigil` without modifying runtime.
40
+ *
41
+ * This is a *purely type-level* helper (no runtime changes). It optionally
42
+ * verifies in DEV that the runtime `SigilLabel` matches the provided `label`.
43
+ *
44
+ * Use this when the runtime metadata is already present (for example the class
45
+ * is already decorated or was created via `Sigilify`).
46
+ *
47
+ * @typeParam S - Constructor type (should be an ISigil).
48
+ * @typeParam L - Label literal to associate at compile-time.
49
+ * @param Class - The constructor to assert as typed sigil.
50
+ * @param label - Optional label literal to assert at compile-time (and to verify in DEV).
51
+ * @returns The same constructor value, typed as `TypedSigil<S, L, P>`.
52
+ */
53
+ export function typed(Class, label, opts) {
54
+ if (!isSigilCtor(Class))
55
+ throw new Error(`[Sigil Error] 'typed' HOF accept only Sigil classes but used on class ${Class?.name ?? 'unknown'}`);
56
+ if ((opts?.devMarker ?? OPTIONS.devMarker) && label) {
57
+ const runtimeLabel = Class.SigilLabel;
58
+ if (runtimeLabel && runtimeLabel !== label) {
59
+ // Runtime label mismatch — surfaced in DEV only
60
+ throw new Error(`[Sigil Error][typed] runtime label "${runtimeLabel}" does not match asserted label "${label}".`);
61
+ }
62
+ }
63
+ return Class;
64
+ }
65
+ /**
66
+ * Convenience helper that combine 'withSigil' and 'typeSigil'.
67
+ *
68
+ * This does both:
69
+ * - validate (and autofill) a label,
70
+ * - perform runtime decoration (via `decorateCtor`),
71
+ * - return the constructor typed as `TypedSigil`.
72
+ *
73
+ * The helper is idempotent: `decorateCtor` will register the label and throw if already
74
+ * decorated; we handle this gracefully in DEV to support HMR flows.
75
+ *
76
+ * @typeParam S - Constructor type (should be an ISigil).
77
+ * @typeParam L - Label literal to attach.
78
+ * @param Class - The constructor (class) to decorate and type.
79
+ * @param label - Optional label string. If omitted, a random label is generated.
80
+ * @param parent - Optional parent sigil constructor (type-only).
81
+ * @param opts - Options object to override any global options if needed.
82
+ * @returns The same constructor value, with runtime metadata ensured and typed as `TypedSigil<S,L,P>`.
83
+ */
84
+ export function withSigilTyped(Class, label, opts) {
85
+ if (!isSigilCtor(Class))
86
+ throw new Error(`[Sigil Error] 'withSigilTyped' HOF accept only Sigil classes but used on class ${Class?.name ?? 'unknown'}`);
87
+ // generate random label if not passed and verify it
88
+ let l;
89
+ if (label) {
90
+ verifyLabel(label, opts);
91
+ l = label;
92
+ }
93
+ else
94
+ l = generateRandomLabel();
95
+ // decorate and check inheritance.
96
+ const ctor = Class;
97
+ decorateCtor(ctor, l);
98
+ checkInheritance(ctor, opts);
99
+ return Class;
100
+ }
101
+ //# sourceMappingURL=enhancers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enhancers.js","sourceRoot":"","sources":["../../src/core/enhancers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AAGvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CACvB,KAAQ,EACR,KAAS,EACT,IAAmB;IAEnB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,8EAA8E,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,CACzG,CAAC;IAEJ,oDAAoD;IACpD,IAAI,CAAS,CAAC;IACd,IAAI,KAAK,EAAE,CAAC;QACV,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,GAAG,KAAK,CAAC;IACZ,CAAC;;QAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC;IAEjC,kCAAkC;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC;IACnB,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE7B,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK,CACnB,KAAQ,EACR,KAAS,EACT,IAAsC;IAEtC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,yEAAyE,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,CACpG,CAAC;IAEJ,IAAI,CAAC,IAAI,EAAE,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,EAAE,CAAC;QACpD,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC;QACtC,IAAI,YAAY,IAAI,YAAY,KAAK,KAAK,EAAE,CAAC;YAC3C,gDAAgD;YAChD,MAAM,IAAI,KAAK,CACb,uCAAuC,YAAY,oCAAoC,KAAK,IAAI,CACjG,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAyB,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAQ,EACR,KAAS,EACT,IAAmB;IAEnB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,kFAAkF,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,CAC7G,CAAC;IAEJ,oDAAoD;IACpD,IAAI,CAAS,CAAC;IACd,IAAI,KAAK,EAAE,CAAC;QACV,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,GAAG,KAAK,CAAC;IACZ,CAAC;;QAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC;IAEjC,kCAAkC;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC;IACnB,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACtB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE7B,OAAO,KAAyB,CAAC;AACnC,CAAC"}
@@ -0,0 +1,192 @@
1
+ import { type SigilOptions } from './options';
2
+ import type { ISigil, ISigilInstance } from './types';
3
+ /** -----------------------------------------
4
+ * High level helpers
5
+ * ----------------------------------------- */
6
+ /**
7
+ * Attach sigil-related statics to a constructor and register its label.
8
+ *
9
+ * Side effects:
10
+ * - Registers `label` in the global registry via `REGISTRY.register(label)`.
11
+ * - Defines non-enumerable statics on the constructor:
12
+ * - `__LABEL__` (string)
13
+ * - `__TYPE__` (Symbol.for(label))
14
+ * - `__TYPE_LINEAGE__` (array of symbols)
15
+ * - `__TYPE_SET__` (Set of symbols)
16
+ * - Marks the constructor as decorated via `markDecorated`.
17
+ *
18
+ * Throws if the constructor is already decorated.
19
+ *
20
+ * @internal
21
+ * @param ctor - The constructor to decorate.
22
+ * @param label - The identity label to register and attach (e.g. '@scope/pkg.ClassName').
23
+ * @param opts - Options object to override any global options if needed.
24
+ * @throws Error when `ctor` is already decorated.
25
+ */
26
+ export declare function decorateCtor(ctor: Function, label: string): void;
27
+ /**
28
+ * Perform development-only inheritance checks to ensure no ancestor classes
29
+ * reuse the same sigil label.
30
+ *
31
+ * Behavior:
32
+ * - No-op if `ctor` is not a sigil constructor.
33
+ * - No-op in non-DEV builds.
34
+ * - No-op if inheritance checks were already performed or `OPTIONS.skipLabelInheritanceCheck` is true.
35
+ *
36
+ * When a duplicate label is detected:
37
+ * - If the class is explicitly decorated (`isDecorated`) or `OPTIONS.autofillLabels` is false,
38
+ * an Error is thrown describing the label collision.
39
+ * - Otherwise (autofill enabled), a random label will be generated and assigned
40
+ * to the offending constructor via `decorateCtor`.
41
+ *
42
+ * @internal
43
+ * @param ctor - The constructor to validate.
44
+ * @param opts - Options object to override any global options if needed.
45
+ * @throws Error when a decorated subclass re-uses an ancestor's sigil label.
46
+ */
47
+ export declare function checkInheritance(ctor: Function, opts?: Pick<SigilOptions, 'skipLabelInheritanceCheck' | 'autofillLabels' | 'devMarker'>): void;
48
+ /**
49
+ * Validate a sigil label at runtime and throw a helpful error if it is malformed.
50
+ *
51
+ * This is intentionally `void` and runs synchronously at class declaration time so
52
+ * invalid labels fail fast during development. Validation behavior follows `OPTIONS.labelValidation`:
53
+ * - If `OPTIONS.labelValidation` is `null` no validation is performed.
54
+ * - If it is a `RegExp`, the label must match the regex.
55
+ * - If it is a function, the function must return `true` for the label to be considered valid.
56
+ *
57
+ * @internal
58
+ * @typeParam L - Label string literal type.
59
+ * @param label - The label to validate.
60
+ * @param opts - Options object to override any global options if needed.
61
+ * @throws {Error} Throws when the label does not pass configured validation.
62
+ */
63
+ export declare function verifyLabel<L extends string>(label: L, opts?: Pick<SigilOptions, 'labelValidation'>): void;
64
+ /**
65
+ * Generate a random alphanumeric label of the requested length.
66
+ *
67
+ * This is used to auto-generate labels when `OPTIONS.autofillLabels` is enabled.
68
+ * It insures that generated label is not registered yet.
69
+ *
70
+ * @internal
71
+ * @param length - Desired length of the generated string (defaults to 16).
72
+ * @returns A random label.
73
+ */
74
+ export declare function generateRandomLabel(length?: number): string;
75
+ /** -----------------------------------------
76
+ * Introspection helpers
77
+ * ----------------------------------------- */
78
+ /**
79
+ * Mark a constructor as a sigil constructor by attaching an internal symbol.
80
+ *
81
+ * This function defines a non-enumerable, non-writable, non-configurable
82
+ * property on the constructor so subsequent checks can detect sigil
83
+ * constructors.
84
+ *
85
+ * @internal
86
+ * @param ctor - The constructor to mark.
87
+ */
88
+ export declare function markSigil(ctor: Function): void;
89
+ /**
90
+ * Mark a constructor as a "sigil base" constructor.
91
+ *
92
+ * A sigil base constructor indicates that the class is the base for
93
+ * other sigil classes. This writes a stable, non-enumerable property
94
+ * to the constructor.
95
+ *
96
+ * @internal
97
+ * @param ctor - The constructor to mark as sigil base.
98
+ */
99
+ export declare function markSigilBase(ctor: Function): void;
100
+ /**
101
+ * Mark a constructor as having been decorated with `WithSigil`.
102
+ *
103
+ * This is used to detect classes that were explicitly decorated rather
104
+ * than auto-filled by the library.
105
+ *
106
+ * @internal
107
+ * @param ctor - The constructor that was decorated.
108
+ */
109
+ export declare function markDecorated(ctor: Function): void;
110
+ /**
111
+ * Mark that inheritance checks for this constructor have already been performed.
112
+ *
113
+ * The library uses this to avoid repeating expensive inheritance validation
114
+ * during development.
115
+ *
116
+ * @internal
117
+ * @param ctor - The constructor that has been checked.
118
+ */
119
+ export declare function markInheritanceChecked(ctor: Function): void;
120
+ /**
121
+ * Runtime predicate that checks whether the provided value is a sigil constructor.
122
+ *
123
+ * This is a lightweight check that verifies the presence of an internal
124
+ * symbol attached to the constructor.
125
+ *
126
+ * @param value - Value to test.
127
+ * @returns `true` if `value` is a sigil constructor, otherwise `false`.
128
+ */
129
+ export declare function isSigilCtor(value: unknown): value is ISigil;
130
+ /**
131
+ * Runtime predicate that checks whether the provided object is an instance
132
+ * of a sigil class.
133
+ *
134
+ * The function is defensive: non-objects return `false`. If an object is
135
+ * passed, the object's constructor is resolved and tested with `isSigilCtor`.
136
+ *
137
+ * @param obj - The value to test.
138
+ * @returns `true` if `obj` is an instance produced by a sigil constructor.
139
+ */
140
+ export declare function isSigilInstance(obj: unknown): obj is ISigilInstance;
141
+ /**
142
+ * Check whether the provided constructor was marked as a sigil base constructor.
143
+ *
144
+ * Uses `Object.hasOwn` to ensure we only check own properties.
145
+ *
146
+ * @param ctor - Constructor to check.
147
+ * @returns `true` if `ctor` is a sigil base constructor.
148
+ */
149
+ export declare function isSigilBaseCtor(ctor: Function): boolean;
150
+ /**
151
+ * Check whether the provided object is an instance of a sigil base constructor.
152
+ *
153
+ * This resolves the object's constructor and delegates to `isSigilBaseCtor`.
154
+ *
155
+ * @param obj - The object to test.
156
+ * @returns `true` if `obj` is an instance of a sigil base constructor.
157
+ */
158
+ export declare function isSigilBaseInstance(obj: unknown): obj is ISigilInstance;
159
+ /**
160
+ * Returns whether the constructor has been explicitly decorated with `WithSigil`.
161
+ *
162
+ * This is an own-property check and does not traverse the prototype chain.
163
+ *
164
+ * @internal
165
+ * @param ctor - Constructor to test.
166
+ * @returns `true` if the constructor is explicitly decorated.
167
+ */
168
+ export declare function isDecorated(ctor: Function): boolean;
169
+ /**
170
+ * Returns whether inheritance checks have already been performed for the constructor.
171
+ *
172
+ * This is used to avoid repeated checks during development (DEV-only checks).
173
+ *
174
+ * @internal
175
+ * @param ctor - Constructor to test.
176
+ * @returns `true` if inheritance checks were marked as completed.
177
+ */
178
+ export declare function isInheritanceChecked(ctor: Function): boolean;
179
+ /** -----------------------------------------
180
+ * Generic helpers
181
+ * ----------------------------------------- */
182
+ /**
183
+ * Retrieve the constructor function for a given instance.
184
+ *
185
+ * Returns `null` for non-objects or when a constructor cannot be resolved.
186
+ *
187
+ * @internal
188
+ * @param obj - The value that may be an instance whose constructor should be returned.
189
+ * @returns The constructor function or `null` if not available.
190
+ */
191
+ export declare function getConstructor(obj: any): any;
192
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/core/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAYvD,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEtD;;+CAE+C;AAE/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,QA6CzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,IAAI,CAAC,EAAE,IAAI,CACT,YAAY,EACZ,2BAA2B,GAAG,gBAAgB,GAAG,WAAW,CAC7D,QA6CF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,iBAAiB,CAAC,GAC3C,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAK,GAAG,MAAM,CAIvD;AAED;;+CAE+C;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,QAOvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,QAO3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,QAO3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,QAOpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAInE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAIvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAE5D;AAED;;+CAE+C;AAE/C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,OAGtC"}