@vicin/sigil 4.0.0 → 4.0.1
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 +6 -0
- package/README.md +8 -11
- package/dist/index.cjs +39 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +39 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +39 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Reliable `instanceof`-style checks that survive bundling, HMR, monorepos and rea
|
|
|
15
15
|
- **Exact class match (`isExactInstance`)** — not just "inherits from"
|
|
16
16
|
- **One-line nominal branding** (`declare [sigil]: ExtendSigil<…>`)
|
|
17
17
|
- **Human-readable class IDs in logs & debugging** (`SigilLabel`/`SigilLineage`)
|
|
18
|
-
- **Tiny (~
|
|
18
|
+
- **Tiny (~1 kB brotli)**
|
|
19
19
|
- **Fast (near native `instanceof` speed)**
|
|
20
20
|
- **100% test coverage**
|
|
21
21
|
|
|
@@ -45,9 +45,6 @@ Earlier versions of `Sigil` tried to solve these limitations, however it was not
|
|
|
45
45
|
- [Errors & throws](#errors--throws)
|
|
46
46
|
- [API reference](#api-reference)
|
|
47
47
|
- [Options & configuration](#options--configuration)
|
|
48
|
-
- [Minimal mode](#minimal-mode)
|
|
49
|
-
- [Strict mode](#strict-mode)
|
|
50
|
-
- [Hot module reload](#hot-module-reload)
|
|
51
48
|
- [Edge cases](#edge-cases)
|
|
52
49
|
- [Benchmarks](#benchmarks)
|
|
53
50
|
- [Bundle Size](#bundle-size)
|
|
@@ -534,7 +531,7 @@ pnpm run bench --filter @vicin/sigil
|
|
|
534
531
|
|
|
535
532
|
## Bundle Size
|
|
536
533
|
|
|
537
|
-
**Less than 1
|
|
534
|
+
**Less than 1 kB (997 B)** (minified + Brotli, including all dependencies)
|
|
538
535
|
|
|
539
536
|
This makes Sigil one of the smallest full-featured solutions for nominal typing + reliable runtime identity.
|
|
540
537
|
|
|
@@ -555,12 +552,12 @@ pnpm run size --filter @vicin/sigil
|
|
|
555
552
|
|
|
556
553
|
We maintain **100%** test coverage across the entire codebase to ensure that runtime metadata remains consistent and predictable.
|
|
557
554
|
|
|
558
|
-
| Metric | Score
|
|
559
|
-
| ------ |
|
|
560
|
-
| Stmts |
|
|
561
|
-
| Branch | 100%
|
|
562
|
-
| Funcs | 100%
|
|
563
|
-
| Lines | 100%
|
|
555
|
+
| Metric | Score |
|
|
556
|
+
| ------ | ------ |
|
|
557
|
+
| Stmts | 96.96% |
|
|
558
|
+
| Branch | 100% |
|
|
559
|
+
| Funcs | 100% |
|
|
560
|
+
| Lines | 100% |
|
|
564
561
|
|
|
565
562
|
**Running Tests**
|
|
566
563
|
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL__");
|
|
|
5
5
|
var __SIGIL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_LINEAGE__");
|
|
6
6
|
var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
|
|
7
7
|
var __DEPTH__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__DEPTH__");
|
|
8
|
+
var __SIGIL_REGISTRY__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_REGISTRY__");
|
|
8
9
|
|
|
9
10
|
// src/is.ts
|
|
10
11
|
function isSigilCtor(ctor) {
|
|
@@ -23,22 +24,50 @@ var updateSigilOptions = ({ labelValidation = null } = {}) => {
|
|
|
23
24
|
};
|
|
24
25
|
var RECOMMENDED_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
25
26
|
|
|
27
|
+
// src/registry.ts
|
|
28
|
+
function getSigilRegistry() {
|
|
29
|
+
if (globalThis[__SIGIL_REGISTRY__]) return globalThis[__SIGIL_REGISTRY__];
|
|
30
|
+
const resolved = /* @__PURE__ */ new WeakSet();
|
|
31
|
+
const hasOwnSigil2 = /* @__PURE__ */ new WeakSet();
|
|
32
|
+
const registry = {
|
|
33
|
+
registerResolved(ctor) {
|
|
34
|
+
resolved.add(ctor);
|
|
35
|
+
},
|
|
36
|
+
checkResolved(ctor) {
|
|
37
|
+
return resolved.has(ctor);
|
|
38
|
+
},
|
|
39
|
+
registerHasOwn(ctor) {
|
|
40
|
+
hasOwnSigil2.add(ctor);
|
|
41
|
+
},
|
|
42
|
+
checkHasOwn(ctor) {
|
|
43
|
+
return hasOwnSigil2.has(ctor);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
Object.freeze(registry);
|
|
47
|
+
Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {
|
|
48
|
+
value: registry,
|
|
49
|
+
writable: false,
|
|
50
|
+
configurable: false,
|
|
51
|
+
enumerable: false
|
|
52
|
+
});
|
|
53
|
+
return registry;
|
|
54
|
+
}
|
|
55
|
+
|
|
26
56
|
// src/sigilify.ts
|
|
27
|
-
var
|
|
28
|
-
var hasOwnSigilRegistry = /* @__PURE__ */ new WeakSet();
|
|
57
|
+
var sigilRegistry = getSigilRegistry();
|
|
29
58
|
function sigilify(ctor, label, opts) {
|
|
30
|
-
if (
|
|
59
|
+
if (sigilRegistry.checkResolved(ctor))
|
|
31
60
|
throw new Error(
|
|
32
61
|
`[Sigil Error] Class '${ctor.name}' with label '${ctor.SigilLabel}' is already sigilified`
|
|
33
62
|
);
|
|
34
63
|
verifyLabel(label, opts);
|
|
35
64
|
handleAncestors(ctor);
|
|
36
65
|
updateSigil(ctor, label);
|
|
37
|
-
|
|
38
|
-
|
|
66
|
+
sigilRegistry.registerResolved(ctor);
|
|
67
|
+
sigilRegistry.registerHasOwn(ctor);
|
|
39
68
|
}
|
|
40
69
|
function hasOwnSigil(ctor) {
|
|
41
|
-
return
|
|
70
|
+
return sigilRegistry.checkHasOwn(ctor);
|
|
42
71
|
}
|
|
43
72
|
function verifyLabel(label, opts) {
|
|
44
73
|
var _a;
|
|
@@ -56,12 +85,12 @@ function verifyLabel(label, opts) {
|
|
|
56
85
|
function handleAncestors(ctor) {
|
|
57
86
|
let a = Object.getPrototypeOf(ctor);
|
|
58
87
|
while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
|
|
59
|
-
|
|
88
|
+
sigilRegistry.registerResolved(a);
|
|
60
89
|
a = Object.getPrototypeOf(a);
|
|
61
90
|
}
|
|
62
91
|
}
|
|
63
92
|
function updateSigil(ctor, label) {
|
|
64
|
-
var _a, _b
|
|
93
|
+
var _a, _b;
|
|
65
94
|
const sym = Symbol.for(label);
|
|
66
95
|
Object.defineProperty(ctor.prototype, __SIGIL__, {
|
|
67
96
|
value: sym,
|
|
@@ -76,13 +105,13 @@ function updateSigil(ctor, label) {
|
|
|
76
105
|
writable: false
|
|
77
106
|
});
|
|
78
107
|
Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {
|
|
79
|
-
value: [...(
|
|
108
|
+
value: [...(_a = Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__]) != null ? _a : [], sym],
|
|
80
109
|
configurable: false,
|
|
81
110
|
enumerable: false,
|
|
82
111
|
writable: false
|
|
83
112
|
});
|
|
84
113
|
Object.defineProperty(ctor.prototype, __DEPTH__, {
|
|
85
|
-
value: ((
|
|
114
|
+
value: ((_b = ctor.prototype[__DEPTH__]) != null ? _b : -1) + 1,
|
|
86
115
|
configurable: false,
|
|
87
116
|
enumerable: false,
|
|
88
117
|
writable: false
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["Sigil"],"mappings":";;;AAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,iBAAA,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ol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\n\n/** -----------------------------------------\n * Maps\n * ----------------------------------------- */\n\n/** Weak set to ensure that every ctor is handled only once */\nconst resolved = new WeakSet<Function>();\n\n/** Weak set to store ctors that called sigilify function */\nconst hasOwnSigilRegistry = new WeakSet<Function>();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (resolved.has(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n resolved.add(ctor);\n hasOwnSigilRegistry.add(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return hasOwnSigilRegistry.has(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n resolved.add(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor)?.prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/registry.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["hasOwnSigil","Sigil"],"mappings":";;;AAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,iBAAA,mBAAoB,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;AASrE,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,iCAAiC,CAAA;;;AC1BvE,SAAS,YAAY,IAAA,EAAqC;AAC/D,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,IAAc,IAAA,CAAK,SAAA,IAAa,aAAa,IAAA,CA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A;AAAA,QACR,CAAA,mFAAA,EAAsF,OAAO,IAAI,CAAA,CAAA;AAAA,OACnG;AAEF,IAAA,QAAA,CAAS,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EAC9B,CAAA;AACF;AAYO,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;AAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;AACpB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;AAAA,KACjG;AAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;AAC3B,EAAA,OAAO,KAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n\n/**\n * Symbol of global Sigil registry\n *\n * @constant {symbol}\n */\nexport const __SIGIL_REGISTRY__ = Symbol.for('@vicin/sigil.__SIGIL_REGISTRY__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { __SIGIL_REGISTRY__ } from './symbols';\n\ninterface SigilRegistry {\n registerResolved: (ctor: Function) => void;\n checkResolved: (ctor: Function) => boolean;\n registerHasOwn: (ctor: Function) => void;\n checkHasOwn: (ctor: Function) => boolean;\n}\n\nexport function getSigilRegistry(): SigilRegistry {\n if ((globalThis as any)[__SIGIL_REGISTRY__]) return (globalThis as any)[__SIGIL_REGISTRY__];\n\n /** Weak set to ensure that every ctor is handled only once */\n const resolved = new WeakSet<Function>();\n\n /** Weak set to store ctors that called sigilify function */\n const hasOwnSigil = new WeakSet<Function>();\n\n /** Registry */\n const registry: SigilRegistry = {\n registerResolved(ctor) {\n resolved.add(ctor);\n },\n checkResolved(ctor) {\n return resolved.has(ctor);\n },\n registerHasOwn(ctor) {\n hasOwnSigil.add(ctor);\n },\n checkHasOwn(ctor) {\n return hasOwnSigil.has(ctor);\n },\n };\n\n // Freeze registy to prevent any mutations\n Object.freeze(registry);\n // Append registry into globalThis and make it non-writable\n Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {\n value: registry,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n // return registry\n return registry;\n}\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport { getSigilRegistry } from './registry';\n\n/** -----------------------------------------\n * Get registry\n * ----------------------------------------- */\n\nconst sigilRegistry = getSigilRegistry();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (sigilRegistry.checkResolved(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n sigilRegistry.registerResolved(ctor);\n sigilRegistry.registerHasOwn(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return sigilRegistry.checkHasOwn(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n sigilRegistry.registerResolved(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
package/dist/index.global.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
var __SIGIL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_LINEAGE__");
|
|
7
7
|
var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
|
|
8
8
|
var __DEPTH__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__DEPTH__");
|
|
9
|
+
var __SIGIL_REGISTRY__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_REGISTRY__");
|
|
9
10
|
|
|
10
11
|
// src/is.ts
|
|
11
12
|
function isSigilCtor(ctor) {
|
|
@@ -24,22 +25,50 @@
|
|
|
24
25
|
};
|
|
25
26
|
var RECOMMENDED_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
26
27
|
|
|
28
|
+
// src/registry.ts
|
|
29
|
+
function getSigilRegistry() {
|
|
30
|
+
if (globalThis[__SIGIL_REGISTRY__]) return globalThis[__SIGIL_REGISTRY__];
|
|
31
|
+
const resolved = /* @__PURE__ */ new WeakSet();
|
|
32
|
+
const hasOwnSigil2 = /* @__PURE__ */ new WeakSet();
|
|
33
|
+
const registry = {
|
|
34
|
+
registerResolved(ctor) {
|
|
35
|
+
resolved.add(ctor);
|
|
36
|
+
},
|
|
37
|
+
checkResolved(ctor) {
|
|
38
|
+
return resolved.has(ctor);
|
|
39
|
+
},
|
|
40
|
+
registerHasOwn(ctor) {
|
|
41
|
+
hasOwnSigil2.add(ctor);
|
|
42
|
+
},
|
|
43
|
+
checkHasOwn(ctor) {
|
|
44
|
+
return hasOwnSigil2.has(ctor);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
Object.freeze(registry);
|
|
48
|
+
Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {
|
|
49
|
+
value: registry,
|
|
50
|
+
writable: false,
|
|
51
|
+
configurable: false,
|
|
52
|
+
enumerable: false
|
|
53
|
+
});
|
|
54
|
+
return registry;
|
|
55
|
+
}
|
|
56
|
+
|
|
27
57
|
// src/sigilify.ts
|
|
28
|
-
var
|
|
29
|
-
var hasOwnSigilRegistry = /* @__PURE__ */ new WeakSet();
|
|
58
|
+
var sigilRegistry = getSigilRegistry();
|
|
30
59
|
function sigilify(ctor, label, opts) {
|
|
31
|
-
if (
|
|
60
|
+
if (sigilRegistry.checkResolved(ctor))
|
|
32
61
|
throw new Error(
|
|
33
62
|
`[Sigil Error] Class '${ctor.name}' with label '${ctor.SigilLabel}' is already sigilified`
|
|
34
63
|
);
|
|
35
64
|
verifyLabel(label, opts);
|
|
36
65
|
handleAncestors(ctor);
|
|
37
66
|
updateSigil(ctor, label);
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
sigilRegistry.registerResolved(ctor);
|
|
68
|
+
sigilRegistry.registerHasOwn(ctor);
|
|
40
69
|
}
|
|
41
70
|
function hasOwnSigil(ctor) {
|
|
42
|
-
return
|
|
71
|
+
return sigilRegistry.checkHasOwn(ctor);
|
|
43
72
|
}
|
|
44
73
|
function verifyLabel(label, opts) {
|
|
45
74
|
var _a;
|
|
@@ -57,12 +86,12 @@
|
|
|
57
86
|
function handleAncestors(ctor) {
|
|
58
87
|
let a = Object.getPrototypeOf(ctor);
|
|
59
88
|
while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
|
|
60
|
-
|
|
89
|
+
sigilRegistry.registerResolved(a);
|
|
61
90
|
a = Object.getPrototypeOf(a);
|
|
62
91
|
}
|
|
63
92
|
}
|
|
64
93
|
function updateSigil(ctor, label) {
|
|
65
|
-
var _a, _b
|
|
94
|
+
var _a, _b;
|
|
66
95
|
const sym = Symbol.for(label);
|
|
67
96
|
Object.defineProperty(ctor.prototype, __SIGIL__, {
|
|
68
97
|
value: sym,
|
|
@@ -77,13 +106,13 @@
|
|
|
77
106
|
writable: false
|
|
78
107
|
});
|
|
79
108
|
Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {
|
|
80
|
-
value: [...(
|
|
109
|
+
value: [...(_a = Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__]) != null ? _a : [], sym],
|
|
81
110
|
configurable: false,
|
|
82
111
|
enumerable: false,
|
|
83
112
|
writable: false
|
|
84
113
|
});
|
|
85
114
|
Object.defineProperty(ctor.prototype, __DEPTH__, {
|
|
86
|
-
value: ((
|
|
115
|
+
value: ((_b = ctor.prototype[__DEPTH__]) != null ? _b : -1) + 1,
|
|
87
116
|
configurable: false,
|
|
88
117
|
enumerable: false,
|
|
89
118
|
writable: false
|
package/dist/index.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["Sigil"],"mappings":";;;;EAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB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"index.global.js","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\n\n/** -----------------------------------------\n * Maps\n * ----------------------------------------- */\n\n/** Weak set to ensure that every ctor is handled only once */\nconst resolved = new WeakSet<Function>();\n\n/** Weak set to store ctors that called sigilify function */\nconst hasOwnSigilRegistry = new WeakSet<Function>();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (resolved.has(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n resolved.add(ctor);\n hasOwnSigilRegistry.add(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return hasOwnSigilRegistry.has(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n resolved.add(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor)?.prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/registry.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["hasOwnSigil","Sigil"],"mappings":";;;;EAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,iBAAA,mBAAoB,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;EASrE,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;EAOrD,IAAM,kBAAA,mBAAqB,MAAA,CAAO,GAAA,CAAI,iCAAiC,CAAA;;;EC1BvE,SAAS,YAAY,IAAA,EAAqC;EAC/D,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,IAAc,IAAA,CAA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;EACrB,MAAA,MAAM,IAAI,KAAA;EAAA,QACR,CAAA,mFAAA,EAAsF,OAAO,IAAI,CAAA,CAAA;EAAA,OACnG;EAEF,IAAA,QAAA,CAAS,MAAA,EAAQ,OAAO,IAAI,CAAA;EAAA,EAC9B,CAAA;EACF;EAYO,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;EAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;EACpB,IAAA,MAAM,IAAI,KAAA;EAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;EAAA,KACjG;EAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;EAC3B,EAAA,OAAO,KAAA;EACT","file":"index.global.js","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n\n/**\n * Symbol of global Sigil registry\n *\n * @constant {symbol}\n */\nexport const __SIGIL_REGISTRY__ = Symbol.for('@vicin/sigil.__SIGIL_REGISTRY__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { __SIGIL_REGISTRY__ } from './symbols';\n\ninterface SigilRegistry {\n registerResolved: (ctor: Function) => void;\n checkResolved: (ctor: Function) => boolean;\n registerHasOwn: (ctor: Function) => void;\n checkHasOwn: (ctor: Function) => boolean;\n}\n\nexport function getSigilRegistry(): SigilRegistry {\n if ((globalThis as any)[__SIGIL_REGISTRY__]) return (globalThis as any)[__SIGIL_REGISTRY__];\n\n /** Weak set to ensure that every ctor is handled only once */\n const resolved = new WeakSet<Function>();\n\n /** Weak set to store ctors that called sigilify function */\n const hasOwnSigil = new WeakSet<Function>();\n\n /** Registry */\n const registry: SigilRegistry = {\n registerResolved(ctor) {\n resolved.add(ctor);\n },\n checkResolved(ctor) {\n return resolved.has(ctor);\n },\n registerHasOwn(ctor) {\n hasOwnSigil.add(ctor);\n },\n checkHasOwn(ctor) {\n return hasOwnSigil.has(ctor);\n },\n };\n\n // Freeze registy to prevent any mutations\n Object.freeze(registry);\n // Append registry into globalThis and make it non-writable\n Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {\n value: registry,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n // return registry\n return registry;\n}\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport { getSigilRegistry } from './registry';\n\n/** -----------------------------------------\n * Get registry\n * ----------------------------------------- */\n\nconst sigilRegistry = getSigilRegistry();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (sigilRegistry.checkResolved(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n sigilRegistry.registerResolved(ctor);\n sigilRegistry.registerHasOwn(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return sigilRegistry.checkHasOwn(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n sigilRegistry.registerResolved(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __SIGIL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL__");
|
|
|
3
3
|
var __SIGIL_LINEAGE__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_LINEAGE__");
|
|
4
4
|
var __LABEL__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__LABEL__");
|
|
5
5
|
var __DEPTH__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__DEPTH__");
|
|
6
|
+
var __SIGIL_REGISTRY__ = /* @__PURE__ */ Symbol.for("@vicin/sigil.__SIGIL_REGISTRY__");
|
|
6
7
|
|
|
7
8
|
// src/is.ts
|
|
8
9
|
function isSigilCtor(ctor) {
|
|
@@ -21,22 +22,50 @@ var updateSigilOptions = ({ labelValidation = null } = {}) => {
|
|
|
21
22
|
};
|
|
22
23
|
var RECOMMENDED_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
|
|
23
24
|
|
|
25
|
+
// src/registry.ts
|
|
26
|
+
function getSigilRegistry() {
|
|
27
|
+
if (globalThis[__SIGIL_REGISTRY__]) return globalThis[__SIGIL_REGISTRY__];
|
|
28
|
+
const resolved = /* @__PURE__ */ new WeakSet();
|
|
29
|
+
const hasOwnSigil2 = /* @__PURE__ */ new WeakSet();
|
|
30
|
+
const registry = {
|
|
31
|
+
registerResolved(ctor) {
|
|
32
|
+
resolved.add(ctor);
|
|
33
|
+
},
|
|
34
|
+
checkResolved(ctor) {
|
|
35
|
+
return resolved.has(ctor);
|
|
36
|
+
},
|
|
37
|
+
registerHasOwn(ctor) {
|
|
38
|
+
hasOwnSigil2.add(ctor);
|
|
39
|
+
},
|
|
40
|
+
checkHasOwn(ctor) {
|
|
41
|
+
return hasOwnSigil2.has(ctor);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
Object.freeze(registry);
|
|
45
|
+
Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {
|
|
46
|
+
value: registry,
|
|
47
|
+
writable: false,
|
|
48
|
+
configurable: false,
|
|
49
|
+
enumerable: false
|
|
50
|
+
});
|
|
51
|
+
return registry;
|
|
52
|
+
}
|
|
53
|
+
|
|
24
54
|
// src/sigilify.ts
|
|
25
|
-
var
|
|
26
|
-
var hasOwnSigilRegistry = /* @__PURE__ */ new WeakSet();
|
|
55
|
+
var sigilRegistry = getSigilRegistry();
|
|
27
56
|
function sigilify(ctor, label, opts) {
|
|
28
|
-
if (
|
|
57
|
+
if (sigilRegistry.checkResolved(ctor))
|
|
29
58
|
throw new Error(
|
|
30
59
|
`[Sigil Error] Class '${ctor.name}' with label '${ctor.SigilLabel}' is already sigilified`
|
|
31
60
|
);
|
|
32
61
|
verifyLabel(label, opts);
|
|
33
62
|
handleAncestors(ctor);
|
|
34
63
|
updateSigil(ctor, label);
|
|
35
|
-
|
|
36
|
-
|
|
64
|
+
sigilRegistry.registerResolved(ctor);
|
|
65
|
+
sigilRegistry.registerHasOwn(ctor);
|
|
37
66
|
}
|
|
38
67
|
function hasOwnSigil(ctor) {
|
|
39
|
-
return
|
|
68
|
+
return sigilRegistry.checkHasOwn(ctor);
|
|
40
69
|
}
|
|
41
70
|
function verifyLabel(label, opts) {
|
|
42
71
|
var _a;
|
|
@@ -54,12 +83,12 @@ function verifyLabel(label, opts) {
|
|
|
54
83
|
function handleAncestors(ctor) {
|
|
55
84
|
let a = Object.getPrototypeOf(ctor);
|
|
56
85
|
while (a && typeof a === "function" && a.prototype[__SIGIL__]) {
|
|
57
|
-
|
|
86
|
+
sigilRegistry.registerResolved(a);
|
|
58
87
|
a = Object.getPrototypeOf(a);
|
|
59
88
|
}
|
|
60
89
|
}
|
|
61
90
|
function updateSigil(ctor, label) {
|
|
62
|
-
var _a, _b
|
|
91
|
+
var _a, _b;
|
|
63
92
|
const sym = Symbol.for(label);
|
|
64
93
|
Object.defineProperty(ctor.prototype, __SIGIL__, {
|
|
65
94
|
value: sym,
|
|
@@ -74,13 +103,13 @@ function updateSigil(ctor, label) {
|
|
|
74
103
|
writable: false
|
|
75
104
|
});
|
|
76
105
|
Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {
|
|
77
|
-
value: [...(
|
|
106
|
+
value: [...(_a = Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__]) != null ? _a : [], sym],
|
|
78
107
|
configurable: false,
|
|
79
108
|
enumerable: false,
|
|
80
109
|
writable: false
|
|
81
110
|
});
|
|
82
111
|
Object.defineProperty(ctor.prototype, __DEPTH__, {
|
|
83
|
-
value: ((
|
|
112
|
+
value: ((_b = ctor.prototype[__DEPTH__]) != null ? _b : -1) + 1,
|
|
84
113
|
configurable: false,
|
|
85
114
|
enumerable: false,
|
|
86
115
|
writable: false
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/symbols.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R,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;AAAA,KACjG;AAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;AAC3B,EAAA,OAAO,KAAA;AACT","file":"index.js","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\n\n/** -----------------------------------------\n * Maps\n * ----------------------------------------- */\n\n/** Weak set to ensure that every ctor is handled only once */\nconst resolved = new WeakSet<Function>();\n\n/** Weak set to store ctors that called sigilify function */\nconst hasOwnSigilRegistry = new WeakSet<Function>();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (resolved.has(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n resolved.add(ctor);\n hasOwnSigilRegistry.add(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return hasOwnSigilRegistry.has(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n resolved.add(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor)?.prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/symbols.ts","../src/is.ts","../src/options.ts","../src/registry.ts","../src/sigilify.ts","../src/mixin.ts","../src/classes.ts","../src/attach.ts"],"names":["hasOwnSigil","Sigil"],"mappings":";AAKO,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,iBAAA,mBAAoB,MAAA,CAAO,GAAA,CAAI,gCAAgC,CAAA;AASrE,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,SAAA,mBAAY,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAOrD,IAAM,kBAAA,mB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YAAY;;;ACR/C,SAAS,WAAA,CAAY,OAAe,IAAA,EAAqB;AAC9D,EAAA,OAAO,SAAU,QAAkB,GAAA,EAAU;AAC3C,IAAA,IAAI,CAAC,YAAY,MAAM,CAAA;AACrB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,mFAAA,EAAsF,OAAO,IAAI,CAAA,CAAA;AAAA,OACnG;AAEF,IAAA,QAAA,CAAS,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EAC9B,CAAA;AACF;AAYO,SAAS,WAAA,CAAgC,KAAA,EAAU,KAAA,EAAe,IAAA,EAAwB;AAC/F,EAAA,IAAI,CAAC,YAAY,KAAK,CAAA;AACpB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,kFAAA,EAAqF,MAAM,IAAI,CAAA,CAAA;AAAA,KACjG;AAEF,EAAA,QAAA,CAAS,KAAA,EAAO,OAAO,IAAI,CAAA;AAC3B,EAAA,OAAO,KAAA;AACT","file":"index.js","sourcesContent":["/**\n * Symbol to uniquely identify sigil classes.\n *\n * @constant {symbol}\n */\nexport const __SIGIL__ = Symbol.for('@vicin/sigil.__SIGIL__');\n\n/**\n * Symbol to store sigil lineage of a class\n *\n * @constant {symbol}\n */\nexport const __SIGIL_LINEAGE__ = Symbol.for('@vicin/sigil.__SIGIL_LINEAGE__');\n\n/**\n * Symbol used to store the identity label for a sigil constructor.\n *\n * Stored on the constructor as a non-enumerable property.\n *\n * @constant {symbol}\n */\nexport const __LABEL__ = Symbol.for('@vicin/sigil.__LABEL__');\n\n/**\n * Symbol used to store the depth inside Sigil chain. used in exact checks\n *\n * @constant {symbol}\n */\nexport const __DEPTH__ = Symbol.for('@vicin/sigil.__DEPTH__');\n\n/**\n * Symbol of global Sigil registry\n *\n * @constant {symbol}\n */\nexport const __SIGIL_REGISTRY__ = Symbol.for('@vicin/sigil.__SIGIL_REGISTRY__');\n","import type { Sigil } from './classes';\nimport { __SIGIL__ } from './symbols';\n\n/**\n * Runtime predicate that checks whether the provided value is a sigil constructor.\n *\n * @param ctor - Constructor to test.\n * @returns `true` if `value` is a sigil constructor, otherwise `false`.\n */\nexport function isSigilCtor(ctor: unknown): ctor is typeof Sigil {\n return typeof ctor === 'function' && ctor.prototype && __SIGIL__ in ctor.prototype;\n}\n\n/**\n * Runtime predicate that checks whether the provided object is an instance\n * of a sigil class.\n *\n * @param inst - The instanca to test.\n * @returns `true` if `obj` is an instance produced by a sigil constructor.\n */\nexport function isSigilInstance(inst: unknown): inst is Sigil {\n return !!inst && typeof inst === 'object' && __SIGIL__ in inst;\n}\n","/** -----------------------------------------\n * Types\n * ----------------------------------------- */\n\n/**\n * Configuration options for the Sigil library.\n *\n * These options control runtime validation, inheritance checks, label autofill behavior.\n */\nexport interface SigilOptions {\n /**\n * Validation rule applied to sigil labels before registration.\n *\n * - A function receives the label and must return `true` if valid.\n * - A `RegExp` must match the label.\n * - `null` disables validation entirely.\n *\n * Defaults to `null`.\n */\n labelValidation?: ((label: string) => boolean) | RegExp | null;\n}\n\n/** -----------------------------------------\n * Internal options object\n * ----------------------------------------- */\n\n/**\n * Defined SigilOptions used in the library.\n *\n * @internal\n */\nexport const OPTIONS: Required<SigilOptions> = {\n labelValidation: null,\n};\n\n/** -----------------------------------------\n * Update options\n * ----------------------------------------- */\n\n/**\n * Update runtime options for the Sigil library.\n * Call this early during application startup if you want non-default behavior.\n *\n * @param opts - Partial options to merge into the global `OPTIONS` object.\n */\nexport const updateSigilOptions = ({ labelValidation = null }: SigilOptions = {}): void => {\n OPTIONS.labelValidation = labelValidation;\n};\n\n/** -----------------------------------------\n * Label validation\n * ----------------------------------------- */\n\n/**\n * Label validation regex. Labels must follow the pattern\n * `@scope/package.ClassName` where `ClassName` begins with an uppercase\n * letter. This avoids collisions across packages and helps debugging.\n *\n * It's advised to use this regex in 'SigilOptions.labelValidation'.\n */\nexport const RECOMMENDED_LABEL_REGEX = /^@[\\w-]+(?:\\/[\\w-]+)*\\.[A-Z][A-Za-z0-9]*$/;\n","import { __SIGIL_REGISTRY__ } from './symbols';\n\ninterface SigilRegistry {\n registerResolved: (ctor: Function) => void;\n checkResolved: (ctor: Function) => boolean;\n registerHasOwn: (ctor: Function) => void;\n checkHasOwn: (ctor: Function) => boolean;\n}\n\nexport function getSigilRegistry(): SigilRegistry {\n if ((globalThis as any)[__SIGIL_REGISTRY__]) return (globalThis as any)[__SIGIL_REGISTRY__];\n\n /** Weak set to ensure that every ctor is handled only once */\n const resolved = new WeakSet<Function>();\n\n /** Weak set to store ctors that called sigilify function */\n const hasOwnSigil = new WeakSet<Function>();\n\n /** Registry */\n const registry: SigilRegistry = {\n registerResolved(ctor) {\n resolved.add(ctor);\n },\n checkResolved(ctor) {\n return resolved.has(ctor);\n },\n registerHasOwn(ctor) {\n hasOwnSigil.add(ctor);\n },\n checkHasOwn(ctor) {\n return hasOwnSigil.has(ctor);\n },\n };\n\n // Freeze registy to prevent any mutations\n Object.freeze(registry);\n // Append registry into globalThis and make it non-writable\n Object.defineProperty(globalThis, __SIGIL_REGISTRY__, {\n value: registry,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n // return registry\n return registry;\n}\n","import { OPTIONS, type SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport { getSigilRegistry } from './registry';\n\n/** -----------------------------------------\n * Get registry\n * ----------------------------------------- */\n\nconst sigilRegistry = getSigilRegistry();\n\n/** -----------------------------------------\n * Main helpers\n * ----------------------------------------- */\n\n/** Main function to handle 'Sigil' and attach its metadata to the class when label is passed */\nexport function sigilify(ctor: Function, label: string, opts?: SigilOptions): void {\n // throw if already seen\n if (sigilRegistry.checkResolved(ctor))\n throw new Error(\n `[Sigil Error] Class '${ctor.name}' with label '${(ctor as any).SigilLabel}' is already sigilified`\n );\n // verify label\n verifyLabel(label, opts);\n // handle ancestors (add them to seen)\n handleAncestors(ctor);\n // sigilify ctor\n updateSigil(ctor, label);\n // mark as seen and register in hasOwnSigil set\n sigilRegistry.registerResolved(ctor);\n sigilRegistry.registerHasOwn(ctor);\n}\n\nexport function hasOwnSigil(ctor: Function) {\n return sigilRegistry.checkHasOwn(ctor);\n}\n\n/** -----------------------------------------\n * Generic helpers\n * ----------------------------------------- */\n\n/** Helper function to validate passed label */\nexport function verifyLabel<L extends string>(label: L, opts?: SigilOptions): void {\n // If validation regex or function is defined validate\n const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;\n if (labelValidation) {\n let valid: boolean;\n if (labelValidation instanceof RegExp) valid = labelValidation.test(label);\n else valid = labelValidation(label);\n\n if (!valid)\n throw new Error(\n `[Sigil Error] Invalid Sigil label '${label}'. Make sure that supplied label matches validation regex or function`\n );\n }\n}\n\nfunction handleAncestors(ctor: Function) {\n let a = Object.getPrototypeOf(ctor);\n while (a && typeof a === 'function' && a.prototype[__SIGIL__]) {\n sigilRegistry.registerResolved(a);\n a = Object.getPrototypeOf(a);\n }\n}\n\nfunction updateSigil(ctor: Function, label: string) {\n // -------------------------\n // Get symbol from label\n // -------------------------\n\n const sym = Symbol.for(label);\n\n // -------------------------\n // Populate 'Sigil' symbols\n // -------------------------\n\n Object.defineProperty(ctor.prototype, __SIGIL__, {\n value: sym,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __LABEL__, {\n value: label,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __SIGIL_LINEAGE__, {\n value: [...(Object.getPrototypeOf(ctor).prototype[__SIGIL_LINEAGE__] ?? []), sym],\n configurable: false,\n enumerable: false,\n writable: false,\n });\n Object.defineProperty(ctor.prototype, __DEPTH__, {\n value: (ctor.prototype[__DEPTH__] ?? -1) + 1,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n\n // -------------------------\n // Add { symbol: ture } pair\n // -------------------------\n\n Object.defineProperty(ctor.prototype, sym, {\n value: true,\n configurable: false,\n enumerable: false,\n writable: false,\n });\n}\n","import { isSigilCtor } from './is';\nimport { sigilify, hasOwnSigil } from './sigilify';\nimport type { SigilOptions } from './options';\nimport { __LABEL__, __SIGIL__, __SIGIL_LINEAGE__, __DEPTH__ } from './symbols';\nimport type { Constructor, ConstructorAbstract, GetPrototype, sigil, ExtendSigil } from './types';\n\n/**\n * Helper function to extend Base class with Sigil Class that should be present at the start of each Sigil chain\n * @param Base - The base constructor to extend.\n * @returns Base Sigil class at the start of each Sigil chain\n */\nexport function BaseSigilify(Base: ConstructorAbstract) {\n class Sigil extends Base {\n /**\n * Class-level identity label constant for this sigil constructor.\n */\n static get SigilLabel(): string {\n return (this as any).prototype[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n static get SigilLabelLineage(): readonly string[] {\n return (this as any).prototype[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n static get hasOwnSigil(): boolean {\n return hasOwnSigil(this);\n }\n\n /**\n * Compile-time nominal brand that encodes the class sigil labels object.\n */\n declare readonly [sigil]: {\n Sigil: true;\n };\n\n constructor(...args: any[]) {\n super(...args);\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n static isExactInstance<T>(this: T, other: any): other is GetPrototype<T> {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any).prototype[__DEPTH__] !== other[__DEPTH__]) return false;\n return other[(this as any).prototype[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is (or inherits from) the instance represented by the\n * calling constructor.\n *\n * This replaces `instanceof` so that checks remain valid across bundles/realms\n * and when subclassing.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Check whether `other` is exactly the same instance represented by the\n * calling constructor.\n *\n * @typeParam T - The specific sigil constructor (`this`).\n * @param this - The constructor performing the type check.\n * @param other - The object to test.\n * @returns A type guard asserting `other` is an instance of the constructor.\n */\n isExactInstance<T>(this: T, other: any): other is T {\n if (other == null || typeof other !== 'object') return false;\n if ((this as any)[__DEPTH__] !== (other as any)[__DEPTH__]) return false;\n return other[(this as any)[__SIGIL__]] === true;\n }\n\n /**\n * Returns the identity sigil label of this instance's constructor.\n *\n * @returns The label string if passed (e.g. '@scope/pkg.ClassName'), random label if not passed (e.g. '@Sigil-auto:ClassName:1:pnf11bgl').\n */\n get SigilLabel(): string {\n return (this as any)[__LABEL__];\n }\n\n /**\n * Copy of the sigil label lineage for this instance's constructor.\n *\n * Useful for debugging and logging.\n *\n * @returns An array of sigil labels representing parent → child labels.\n */\n get SigilLabelLineage(): readonly string[] {\n return (this as any)[__SIGIL_LINEAGE__].map((v: symbol) => v.description);\n }\n\n /** Check if sigil label has been attached to this class */\n get hasOwnSigil(): boolean {\n return (this.constructor as unknown as Sigil).hasOwnSigil;\n }\n }\n\n sigilify(Sigil, 'Sigil');\n return Sigil;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function Sigilify<L extends string>(Base: Constructor, label: L, opts?: SigilOptions) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n\n/**\n * Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.\n *\n * @param Base - The base constructor to extend.\n * @param label - Identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').\n * @param opts - Options object to override any global options if needed.\n * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.\n * @throws Error if `Base` is already sigilified.\n */\nexport function SigilifyAbstract<L extends string>(\n Base: ConstructorAbstract,\n label: L,\n opts?: SigilOptions\n) {\n if (isSigilCtor(Base))\n throw new Error(\n `[Sigil Error] Class '${Base.name}' with label '${Base.SigilLabel}' is already sigilified`\n );\n\n const BaseSigil = BaseSigilify(Base);\n abstract class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, InstanceType<typeof BaseSigil>>;\n }\n\n sigilify(Sigilified, label, opts);\n return Sigilified;\n}\n","import { Sigilify, BaseSigilify } from './mixin';\nimport type { sigil } from './types';\n\n/**\n * A minimal root Sigil class used by the library as a base identity.\n *\n * This is produced by `Sigilify` and can serve as a basic sentinel/base\n * class for other sigil classes or for debugging/inspection.\n */\nexport const Sigil = BaseSigilify(class {});\nexport type Sigil = InstanceType<typeof Sigil>;\n\n/**\n * A sigil variant of the built-in `Error` constructor used by the library\n * to represent Sigil-specific errors.\n *\n * Use `SigilError` when you want an Error type that is identifiable via sigil\n * runtime checks (e.g. `SigilError.isInstance(someError)`).\n */\nexport const SigilError = Sigilify(Error, 'SigilError');\nexport type SigilError = InstanceType<typeof SigilError>;\n","import { isSigilCtor } from './is';\nimport { sigilify } from './sigilify';\nimport type { SigilOptions } from './options';\n\n/**\n * Class decorator factory that attaches sigil statics to a class constructor.\n *\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns A class decorator compatible with the ECMAScript decorator context.\n */\nexport function AttachSigil(label: string, opts?: SigilOptions) {\n return function (target: Function, ctx: any) {\n if (!isSigilCtor(target))\n throw new Error(\n `[Sigil Error] 'AttachSigil' decorator accept only Sigil classes but used on class '${target.name}'`\n );\n\n sigilify(target, label, opts);\n };\n}\n\n/**\n * Function that attaches runtime sigil metadata to Sigil class.\n * Alternative to '@AttachSigil' if you prefer normal functions.\n *\n * @typeParam S - Constructor type (should be an instance of sigil class).\n * @param Class - The constructor (class) to enhance.\n * @param label - Sigil label string to assign to the decorated class (e.g. `@scope/pkg.ClassName`).\n * @param opts - Options object to override any global options if needed.\n * @returns The same constructor value, with runtime metadata ensured.\n */\nexport function attachSigil<S extends Function>(Class: S, label: string, opts?: SigilOptions): S {\n if (!isSigilCtor(Class))\n throw new Error(\n `[Sigil Error] 'attachSigil' function accept only Sigil classes but used on class '${Class.name}'`\n );\n\n sigilify(Class, label, opts);\n return Class;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vicin/sigil",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Sigil, bulletproof class identity for large TypeScript projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ziad ziadtaha62@gmail.com",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"build": "tsup",
|
|
61
61
|
"dev": "tsx --watch src/index.ts",
|
|
62
62
|
"typecheck": "tsc --noEmit",
|
|
63
|
-
"test:unit": "vitest --coverage",
|
|
64
|
-
"test:types": "tsd",
|
|
65
|
-
"test": "vitest --coverage && tsd",
|
|
63
|
+
"test:unit": "vitest --coverage --run",
|
|
64
|
+
"test:types": "tsd --files tests/types/**/*.test-d.ts",
|
|
65
|
+
"test": "vitest --coverage --run && tsd --files tests/types/**/*.test-d.ts",
|
|
66
66
|
"size": "size-limit",
|
|
67
67
|
"bench": "vitest bench --run",
|
|
68
68
|
"bench:creation": "vitest bench --run bench/creation.bench.ts",
|