@vicin/sigil 4.0.1 → 4.0.2
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/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAK,SAAA;AAC3E;AASO,SAAS,gBAAgB,IAAA,EAA8B;AAC5D,EAAA,OAAO,CAAC,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,YAAY,SAAA,IAAa,IAAA;AAC5D;;;ACSO,IAAM,OAAA,GAAkC;AAAA,EAC7C,eAAA,EAAiB;AACnB,CAAA;AAYO,IAAM,qBAAqB,CAAC,EAAE,kBAAkB,IAAA,EAAK,GAAkB,EAAC,KAAY;AACzF,EAAA,OAAA,CAAQ,eAAA,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qF,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"]}
|
|
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,CAAK,SAAA;AAC3E;AASO,SAAS,gBAAgB,IAAA,EAA8B;AAC5D,EAAA,OAAO,CAAC,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,YAAY,SAAA,IAAa,IAAA;AAC5D;;;ACSO,IAAM,OAAA,GAAkC;AAAA,EAC7C,eAAA,EAAiB;AACnB,CAAA;AAYO,IAAM,qBAAqB,CAAC,EAAE,kBAAkB,IAAA,EAAK,GAAkB,EAAC,KAAY;AACzF,EAAA,OAAA,C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AqF,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';\nimport type { Sigil } from './classes';\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<B extends ConstructorAbstract>(Base: B) {\n // @ts-expect-error Abstract definition will be used in SigilifyAbstract\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<B extends Constructor, L extends string>(\n Base: B,\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 class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, Sigil>;\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<B extends ConstructorAbstract, L extends string>(\n Base: B,\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, Sigil>;\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.d.cts
CHANGED
|
@@ -78,6 +78,8 @@ declare const Sigil: {
|
|
|
78
78
|
get hasOwnSigil(): boolean;
|
|
79
79
|
isInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
80
80
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
81
|
+
} & {
|
|
82
|
+
new (): {};
|
|
81
83
|
};
|
|
82
84
|
type Sigil = InstanceType<typeof Sigil>;
|
|
83
85
|
/**
|
|
@@ -104,7 +106,7 @@ declare const SigilError: {
|
|
|
104
106
|
get hasOwnSigil(): boolean;
|
|
105
107
|
isInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
106
108
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
107
|
-
};
|
|
109
|
+
} & ErrorConstructor;
|
|
108
110
|
type SigilError = InstanceType<typeof SigilError>;
|
|
109
111
|
|
|
110
112
|
/** -----------------------------------------
|
|
@@ -194,7 +196,7 @@ declare function isSigilInstance(inst: unknown): inst is Sigil;
|
|
|
194
196
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
195
197
|
* @throws Error if `Base` is already sigilified.
|
|
196
198
|
*/
|
|
197
|
-
declare function Sigilify<L extends string>(Base:
|
|
199
|
+
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label: L, opts?: SigilOptions): {
|
|
198
200
|
new (...args: any[]): {
|
|
199
201
|
[sigil]: {
|
|
200
202
|
Sigil: true;
|
|
@@ -276,7 +278,7 @@ declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?:
|
|
|
276
278
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
277
279
|
*/
|
|
278
280
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
279
|
-
};
|
|
281
|
+
} & B;
|
|
280
282
|
/**
|
|
281
283
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
282
284
|
*
|
|
@@ -286,7 +288,7 @@ declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?:
|
|
|
286
288
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
287
289
|
* @throws Error if `Base` is already sigilified.
|
|
288
290
|
*/
|
|
289
|
-
declare function SigilifyAbstract<L extends string>(Base:
|
|
291
|
+
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
290
292
|
[sigil]: {
|
|
291
293
|
Sigil: true;
|
|
292
294
|
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
@@ -367,7 +369,7 @@ declare function SigilifyAbstract<L extends string>(Base: ConstructorAbstract, l
|
|
|
367
369
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
368
370
|
*/
|
|
369
371
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
370
|
-
};
|
|
372
|
+
}) & B;
|
|
371
373
|
|
|
372
374
|
declare function hasOwnSigil(ctor: Function): boolean;
|
|
373
375
|
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ declare const Sigil: {
|
|
|
78
78
|
get hasOwnSigil(): boolean;
|
|
79
79
|
isInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
80
80
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
81
|
+
} & {
|
|
82
|
+
new (): {};
|
|
81
83
|
};
|
|
82
84
|
type Sigil = InstanceType<typeof Sigil>;
|
|
83
85
|
/**
|
|
@@ -104,7 +106,7 @@ declare const SigilError: {
|
|
|
104
106
|
get hasOwnSigil(): boolean;
|
|
105
107
|
isInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
106
108
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
107
|
-
};
|
|
109
|
+
} & ErrorConstructor;
|
|
108
110
|
type SigilError = InstanceType<typeof SigilError>;
|
|
109
111
|
|
|
110
112
|
/** -----------------------------------------
|
|
@@ -194,7 +196,7 @@ declare function isSigilInstance(inst: unknown): inst is Sigil;
|
|
|
194
196
|
* @returns A new constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
195
197
|
* @throws Error if `Base` is already sigilified.
|
|
196
198
|
*/
|
|
197
|
-
declare function Sigilify<L extends string>(Base:
|
|
199
|
+
declare function Sigilify<B extends Constructor, L extends string>(Base: B, label: L, opts?: SigilOptions): {
|
|
198
200
|
new (...args: any[]): {
|
|
199
201
|
[sigil]: {
|
|
200
202
|
Sigil: true;
|
|
@@ -276,7 +278,7 @@ declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?:
|
|
|
276
278
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
277
279
|
*/
|
|
278
280
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
279
|
-
};
|
|
281
|
+
} & B;
|
|
280
282
|
/**
|
|
281
283
|
* Mixin factory that augments an existing class with Sigil runtime metadata and helpers. Accept and return 'abstract' class.
|
|
282
284
|
*
|
|
@@ -286,7 +288,7 @@ declare function Sigilify<L extends string>(Base: Constructor, label: L, opts?:
|
|
|
286
288
|
* @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
|
|
287
289
|
* @throws Error if `Base` is already sigilified.
|
|
288
290
|
*/
|
|
289
|
-
declare function SigilifyAbstract<L extends string>(Base:
|
|
291
|
+
declare function SigilifyAbstract<B extends ConstructorAbstract, L extends string>(Base: B, label: L, opts?: SigilOptions): ((abstract new (...args: any[]) => {
|
|
290
292
|
[sigil]: {
|
|
291
293
|
Sigil: true;
|
|
292
294
|
} & { [K_1 in L]: true; } extends infer T ? { [K in keyof T]: T[K]; } : never;
|
|
@@ -367,7 +369,7 @@ declare function SigilifyAbstract<L extends string>(Base: ConstructorAbstract, l
|
|
|
367
369
|
* @returns A type guard asserting `other` is an instance of the constructor.
|
|
368
370
|
*/
|
|
369
371
|
isExactInstance<T>(this: T, other: any): other is GetPrototype<T>;
|
|
370
|
-
};
|
|
372
|
+
}) & B;
|
|
371
373
|
|
|
372
374
|
declare function hasOwnSigil(ctor: Function): boolean;
|
|
373
375
|
|
package/dist/index.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAK,SAAA,IAAa,aAAa,IAAA,CAAK,SAAA;EAC3E;EASO,SAAS,gBAAgB,IAAA,EAA8B;EAC5D,EAAA,OAAO,CAAC,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,YAAY,S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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"]}
|
|
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,CAAK,SAAA,IAAa,aAAa,IAAA,CAAK,SAAA;EAC3E;EASO,SAAS,gBAAgB,IAAA,EAA8B;EAC5D,EAAA,OAAO,CAAC,CAAC,IAAA,IAAQ,OAAO,IAAA,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I,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';\nimport type { Sigil } from './classes';\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<B extends ConstructorAbstract>(Base: B) {\n // @ts-expect-error Abstract definition will be used in SigilifyAbstract\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<B extends Constructor, L extends string>(\n Base: B,\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 class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, Sigil>;\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<B extends ConstructorAbstract, L extends string>(\n Base: B,\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, Sigil>;\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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAK,SAAA;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ACR,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"]}
|
|
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,CAAK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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';\nimport type { Sigil } from './classes';\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<B extends ConstructorAbstract>(Base: B) {\n // @ts-expect-error Abstract definition will be used in SigilifyAbstract\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<B extends Constructor, L extends string>(\n Base: B,\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 class Sigilified extends BaseSigil {\n declare [sigil]: ExtendSigil<L, Sigil>;\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<B extends ConstructorAbstract, L extends string>(\n Base: B,\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, Sigil>;\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"]}
|