@vicin/sigil 2.0.0 → 2.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 CHANGED
@@ -2,11 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.0.2] - 2026-02-21
6
+
7
+ ### Changed
8
+
9
+ - Patched types
10
+
11
+ ## [2.0.1] - 2026-02-21
12
+
13
+ ### Removed
14
+
15
+ - `updateOptions.devMarker`
16
+
17
+ ### Changed
18
+
19
+ - Now dev checks are internal only
20
+
5
21
  ## [2.0.0] - 2026-02-20
6
22
 
7
23
  ### Breaking changes
8
24
 
9
- All `SigilRegistry`options, methods and classes are removed.
25
+ - All `SigilRegistry`options, methods and classes are removed.
10
26
 
11
27
  ## [1.3.0] - 2026-02-18
12
28
 
package/README.md CHANGED
@@ -407,7 +407,7 @@ class X extends Sigil {
407
407
  - `withSigilTyped(Class, label?, opts?)`: like `withSigil` but narrows the TypeScript type to include brands.
408
408
  - `isSigilCtor(value)`: `true` if `value` is a `Sigil` constructor.
409
409
  - `isSigilInstance(value)`: `true` if `value` is an instance of a `Sigil` constructor.
410
- - `updateOptions(opts)`: change global runtime options before `Sigil` decoration (e.g., `autofillLabels`, `devMarker`, etc.).
410
+ - `updateOptions(opts)`: change global runtime options before `Sigil` decoration (e.g., `autofillLabels`).
411
411
  - `DEFAULT_LABEL_REGEX`: regex that ensures structure of `@scope/package.ClassName` to all labels, it's advised to use it as your `SigilOptions.labelValidation`
412
412
 
413
413
  ### Instance & static helpers provided by Sigilified constructors
@@ -443,7 +443,6 @@ updateOptions({
443
443
  autofillLabels: false, // Automatically label unlabeled subclasses
444
444
  skipLabelInheritanceCheck: false, // Bypass dev inheritance checks -- ALMOST NEVER WANT TO SET THIS TO TRUE, Use 'autofillLabels: true' instead.
445
445
  labelValidation: null, // Function or regex, Enforce label format
446
- devMarker: process.env.NODE_ENV !== 'production', // Toggle dev safeguards
447
446
  });
448
447
  ```
449
448
 
package/dist/index.d.mts CHANGED
@@ -58,7 +58,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
58
58
  * @param other - The object to test.
59
59
  * @returns A type guard asserting `other` is an instance of the constructor.
60
60
  */
61
- isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
61
+ isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetInstance<T>;
62
62
  /**
63
63
  * Strict lineage comparison: verifies that the calling constructor's type
64
64
  * lineage (by label) matches the `other`'s lineage element-by-element.
@@ -71,7 +71,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
71
71
  * @param other - The object to test.
72
72
  * @returns A type guard asserting `other` is an instance whose lineage matches exactly.
73
73
  */
74
- isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
74
+ isOfTypeStrict<T extends ISigilStatic>(this: T, other: unknown): other is GetInstance<T>;
75
75
  }
76
76
  /**
77
77
  * Instance-side interface describing properties present on sigil instances.
@@ -99,6 +99,33 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
99
99
  getSigilLabelLineage(): readonly string[];
100
100
  /** Returns copy of sigil type label set of the class constructor. */
101
101
  getSigilLabelSet(): Readonly<Set<string>>;
102
+ /**
103
+ * Check whether `other` is (or inherits from) the type represented by the
104
+ * calling constructor. Uses the other instance's `SigilLabelSet` to check
105
+ * membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
106
+ *
107
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
108
+ * and when subclassing.
109
+ *
110
+ * @typeParam T - The specific sigil constructor (`this`).
111
+ * @param this - The constructor performing the type check.
112
+ * @param other - The object to test.
113
+ * @returns A type guard asserting `other` is an instance of the constructor.
114
+ */
115
+ isOfType<T extends ISigilInstance>(this: T, other: unknown): other is GetInstance<T>;
116
+ /**
117
+ * Strict lineage comparison: verifies that the calling constructor's type
118
+ * lineage (by label) matches the `other`'s lineage element-by-element.
119
+ *
120
+ * Works in O(n) where `n` is the lineage length and is useful when order
121
+ * and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
122
+ *
123
+ * @typeParam T - The specific sigil constructor (`this`).
124
+ * @param this - The constructor performing the strict check.
125
+ * @param other - The object to test.
126
+ * @returns A type guard asserting `other` is an instance whose lineage matches exactly.
127
+ */
128
+ isOfTypeStrict<T extends ISigilInstance>(this: T, other: unknown): other is GetInstance<T>;
102
129
  }
103
130
  /**
104
131
  * Combined constructor + static interface for a sigil class.
@@ -218,7 +245,7 @@ declare const Sigil: {
218
245
  } & {
219
246
  new (): {};
220
247
  };
221
- type Sigil = InstanceType<typeof Sigil>;
248
+ type Sigil = GetInstance<typeof Sigil>;
222
249
  /**
223
250
  * A sigil variant of the built-in `Error` constructor used by the library
224
251
  * to represent Sigil-specific errors.
@@ -249,7 +276,7 @@ declare const SigilError: {
249
276
  isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
250
277
  isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
251
278
  } & ErrorConstructor;
252
- type SigilError = InstanceType<typeof SigilError>;
279
+ type SigilError = GetInstance<typeof SigilError>;
253
280
 
254
281
  /**
255
282
  * Configuration options for the Sigil library.
@@ -290,12 +317,6 @@ interface SigilOptions {
290
317
  * will be assigned an autogenerated random label (so that explicit labels stay unique).
291
318
  */
292
319
  autofillLabels?: boolean;
293
- /**
294
- * Marker used internally to control dev only checks to optimize performace while preserving
295
- * consistency for things like inheritance checks.
296
- * defaults to 'process.env.NODE_ENV !== "production'.
297
- */
298
- devMarker?: boolean;
299
320
  }
300
321
  /**
301
322
  * Update runtime options for the Sigil library.
@@ -400,7 +421,7 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
400
421
  * @param inst - The instanca to test.
401
422
  * @returns `true` if `obj` is an instance produced by a sigil constructor.
402
423
  */
403
- declare function isSigilInstance(inst: unknown): inst is InstanceType<ISigil>;
424
+ declare function isSigilInstance(inst: unknown): inst is GetInstance<ISigil>;
404
425
  /**
405
426
  * Check whether the provided constructor was marked as a sigil base constructor.
406
427
  *
@@ -418,7 +439,7 @@ declare function isSigilBaseCtor(ctor: Function): ctor is ISigil;
418
439
  * @param inst - The instance to test.
419
440
  * @returns `true` if `inst` is an instance of a sigil base constructor.
420
441
  */
421
- declare function isSigilBaseInstance(inst: unknown): inst is InstanceType<ISigil>;
442
+ declare function isSigilBaseInstance(inst: unknown): inst is GetInstance<ISigil>;
422
443
  /**
423
444
  * Returns whether the constructor has been explicitly decorated with `WithSigil`.
424
445
  *
package/dist/index.d.ts CHANGED
@@ -58,7 +58,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
58
58
  * @param other - The object to test.
59
59
  * @returns A type guard asserting `other` is an instance of the constructor.
60
60
  */
61
- isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
61
+ isOfType<T extends ISigilStatic>(this: T, other: unknown): other is GetInstance<T>;
62
62
  /**
63
63
  * Strict lineage comparison: verifies that the calling constructor's type
64
64
  * lineage (by label) matches the `other`'s lineage element-by-element.
@@ -71,7 +71,7 @@ interface ISigilStatic<L extends string = string, P extends Function = never> {
71
71
  * @param other - The object to test.
72
72
  * @returns A type guard asserting `other` is an instance whose lineage matches exactly.
73
73
  */
74
- isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
74
+ isOfTypeStrict<T extends ISigilStatic>(this: T, other: unknown): other is GetInstance<T>;
75
75
  }
76
76
  /**
77
77
  * Instance-side interface describing properties present on sigil instances.
@@ -99,6 +99,33 @@ interface ISigilInstance<L extends string = string, P extends Function = never>
99
99
  getSigilLabelLineage(): readonly string[];
100
100
  /** Returns copy of sigil type label set of the class constructor. */
101
101
  getSigilLabelSet(): Readonly<Set<string>>;
102
+ /**
103
+ * Check whether `other` is (or inherits from) the type represented by the
104
+ * calling constructor. Uses the other instance's `SigilLabelSet` to check
105
+ * membership. Works in O(1) and is reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
106
+ *
107
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
108
+ * and when subclassing.
109
+ *
110
+ * @typeParam T - The specific sigil constructor (`this`).
111
+ * @param this - The constructor performing the type check.
112
+ * @param other - The object to test.
113
+ * @returns A type guard asserting `other` is an instance of the constructor.
114
+ */
115
+ isOfType<T extends ISigilInstance>(this: T, other: unknown): other is GetInstance<T>;
116
+ /**
117
+ * Strict lineage comparison: verifies that the calling constructor's type
118
+ * lineage (by label) matches the `other`'s lineage element-by-element.
119
+ *
120
+ * Works in O(n) where `n` is the lineage length and is useful when order
121
+ * and exact ancestry must be confirmed. reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
122
+ *
123
+ * @typeParam T - The specific sigil constructor (`this`).
124
+ * @param this - The constructor performing the strict check.
125
+ * @param other - The object to test.
126
+ * @returns A type guard asserting `other` is an instance whose lineage matches exactly.
127
+ */
128
+ isOfTypeStrict<T extends ISigilInstance>(this: T, other: unknown): other is GetInstance<T>;
102
129
  }
103
130
  /**
104
131
  * Combined constructor + static interface for a sigil class.
@@ -218,7 +245,7 @@ declare const Sigil: {
218
245
  } & {
219
246
  new (): {};
220
247
  };
221
- type Sigil = InstanceType<typeof Sigil>;
248
+ type Sigil = GetInstance<typeof Sigil>;
222
249
  /**
223
250
  * A sigil variant of the built-in `Error` constructor used by the library
224
251
  * to represent Sigil-specific errors.
@@ -249,7 +276,7 @@ declare const SigilError: {
249
276
  isOfType<T>(this: T, other: unknown): other is GetInstance<T>;
250
277
  isOfTypeStrict<T>(this: T, other: unknown): other is GetInstance<T>;
251
278
  } & ErrorConstructor;
252
- type SigilError = InstanceType<typeof SigilError>;
279
+ type SigilError = GetInstance<typeof SigilError>;
253
280
 
254
281
  /**
255
282
  * Configuration options for the Sigil library.
@@ -290,12 +317,6 @@ interface SigilOptions {
290
317
  * will be assigned an autogenerated random label (so that explicit labels stay unique).
291
318
  */
292
319
  autofillLabels?: boolean;
293
- /**
294
- * Marker used internally to control dev only checks to optimize performace while preserving
295
- * consistency for things like inheritance checks.
296
- * defaults to 'process.env.NODE_ENV !== "production'.
297
- */
298
- devMarker?: boolean;
299
320
  }
300
321
  /**
301
322
  * Update runtime options for the Sigil library.
@@ -400,7 +421,7 @@ declare function isSigilCtor(ctor: unknown): ctor is ISigil;
400
421
  * @param inst - The instanca to test.
401
422
  * @returns `true` if `obj` is an instance produced by a sigil constructor.
402
423
  */
403
- declare function isSigilInstance(inst: unknown): inst is InstanceType<ISigil>;
424
+ declare function isSigilInstance(inst: unknown): inst is GetInstance<ISigil>;
404
425
  /**
405
426
  * Check whether the provided constructor was marked as a sigil base constructor.
406
427
  *
@@ -418,7 +439,7 @@ declare function isSigilBaseCtor(ctor: Function): ctor is ISigil;
418
439
  * @param inst - The instance to test.
419
440
  * @returns `true` if `inst` is an instance of a sigil base constructor.
420
441
  */
421
- declare function isSigilBaseInstance(inst: unknown): inst is InstanceType<ISigil>;
442
+ declare function isSigilBaseInstance(inst: unknown): inst is GetInstance<ISigil>;
422
443
  /**
423
444
  * Returns whether the constructor has been explicitly decorated with `WithSigil`.
424
445
  *
@@ -9,8 +9,7 @@
9
9
  var OPTIONS = {
10
10
  labelValidation: null,
11
11
  skipLabelInheritanceCheck: false,
12
- autofillLabels: false,
13
- devMarker: false
12
+ autofillLabels: false
14
13
  };
15
14
  var updateOptions = (opts) => {
16
15
  for (const [k, v] of Object.entries(opts)) OPTIONS[k] = v;
@@ -18,8 +17,7 @@
18
17
  var DEFAULT_OPTIONS = {
19
18
  labelValidation: null,
20
19
  skipLabelInheritanceCheck: false,
21
- autofillLabels: false,
22
- devMarker: process.env.NODE_ENV !== "production"
20
+ autofillLabels: false
23
21
  };
24
22
  updateOptions(DEFAULT_OPTIONS);
25
23
  var DEFAULT_LABEL_REGEX = /^@[\w-]+(?:\/[\w-]+)*\.[A-Z][A-Za-z0-9]*$/;
@@ -1740,6 +1738,9 @@
1740
1738
  };
1741
1739
  }
1742
1740
 
1741
+ // src/core/constants.ts
1742
+ var __DEV__ = typeof process !== "undefined" && process.env.NODE_ENV === "development";
1743
+
1743
1744
  // src/core/helpers.ts
1744
1745
  function decorateCtor(ctor, label, isMixin = false) {
1745
1746
  if (isDecorated(ctor))
@@ -1770,11 +1771,9 @@
1770
1771
  markDecorated(ctor);
1771
1772
  }
1772
1773
  function checkInheritance(ctor, opts) {
1773
- var _a, _b, _c;
1774
- const devMarker = (_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker;
1775
- const skipLabelInheritanceCheck = (_b = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _b : OPTIONS.skipLabelInheritanceCheck;
1776
- const autofillLabels = (_c = opts == null ? void 0 : opts.autofillLabels) != null ? _c : OPTIONS.autofillLabels;
1777
- if (!devMarker) return;
1774
+ var _a, _b;
1775
+ const skipLabelInheritanceCheck = (_a = opts == null ? void 0 : opts.skipLabelInheritanceCheck) != null ? _a : OPTIONS.skipLabelInheritanceCheck;
1776
+ const autofillLabels = (_b = opts == null ? void 0 : opts.autofillLabels) != null ? _b : OPTIONS.autofillLabels;
1778
1777
  if (!isSigilCtor(ctor)) return;
1779
1778
  if (isInheritanceChecked(ctor) || skipLabelInheritanceCheck) return;
1780
1779
  const ctors = [ctor];
@@ -1918,17 +1917,16 @@
1918
1917
  return set;
1919
1918
  }
1920
1919
  constructor(...args) {
1921
- var _a;
1922
1920
  super(...args);
1923
1921
  if (Object.getPrototypeOf(this) !== new.target.prototype)
1924
1922
  Object.setPrototypeOf(this, new.target.prototype);
1925
1923
  const ctor = getConstructor(this);
1926
1924
  if (!ctor) {
1927
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
1925
+ if (__DEV__)
1928
1926
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
1929
1927
  return;
1930
1928
  }
1931
- checkInheritance(ctor);
1929
+ if (__DEV__) checkInheritance(ctor);
1932
1930
  }
1933
1931
  /**
1934
1932
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -2012,10 +2010,9 @@
2012
2010
  * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
2013
2011
  */
2014
2012
  getSigilLabel() {
2015
- var _a;
2016
2013
  const ctor = getConstructor(this);
2017
2014
  if (!ctor) {
2018
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2015
+ if (__DEV__)
2019
2016
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2020
2017
  return "@Sigil.unknown";
2021
2018
  }
@@ -2027,10 +2024,9 @@
2027
2024
  * @returns readonly array of labels representing the type lineage.
2028
2025
  */
2029
2026
  getSigilLabelLineage() {
2030
- var _a;
2031
2027
  const ctor = getConstructor(this);
2032
2028
  if (!ctor) {
2033
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2029
+ if (__DEV__)
2034
2030
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2035
2031
  return ["@Sigil.unknown"];
2036
2032
  }
@@ -2042,10 +2038,9 @@
2042
2038
  * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
2043
2039
  */
2044
2040
  getSigilLabelSet() {
2045
- var _a;
2046
2041
  const ctor = getConstructor(this);
2047
2042
  if (!ctor) {
2048
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2043
+ if (__DEV__)
2049
2044
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2050
2045
  return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
2051
2046
  }
@@ -2095,17 +2090,16 @@
2095
2090
  return set;
2096
2091
  }
2097
2092
  constructor(...args) {
2098
- var _a;
2099
2093
  super(...args);
2100
2094
  if (Object.getPrototypeOf(this) !== new.target.prototype)
2101
2095
  Object.setPrototypeOf(this, new.target.prototype);
2102
2096
  const ctor = getConstructor(this);
2103
2097
  if (!ctor) {
2104
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2098
+ if (__DEV__)
2105
2099
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2106
2100
  return;
2107
2101
  }
2108
- checkInheritance(ctor);
2102
+ if (__DEV__) checkInheritance(ctor);
2109
2103
  }
2110
2104
  /**
2111
2105
  * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
@@ -2197,10 +2191,9 @@
2197
2191
  * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
2198
2192
  */
2199
2193
  getSigilLabel() {
2200
- var _a;
2201
2194
  const ctor = getConstructor(this);
2202
2195
  if (!ctor) {
2203
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2196
+ if (__DEV__)
2204
2197
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2205
2198
  return "@Sigil.unknown";
2206
2199
  }
@@ -2212,10 +2205,9 @@
2212
2205
  * @returns readonly array of labels representing the type lineage.
2213
2206
  */
2214
2207
  getSigilLabelLineage() {
2215
- var _a;
2216
2208
  const ctor = getConstructor(this);
2217
2209
  if (!ctor) {
2218
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2210
+ if (__DEV__)
2219
2211
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2220
2212
  return ["@Sigil.unknown"];
2221
2213
  }
@@ -2227,10 +2219,9 @@
2227
2219
  * @returns A Readonly Set of labels representing the type lineage for O(1) membership tests.
2228
2220
  */
2229
2221
  getSigilLabelSet() {
2230
- var _a;
2231
2222
  const ctor = getConstructor(this);
2232
2223
  if (!ctor) {
2233
- if ((_a = opts == null ? void 0 : opts.devMarker) != null ? _a : OPTIONS.devMarker)
2224
+ if (__DEV__)
2234
2225
  throw new Error(`[Sigil Error] 'Sigilify(${label})' instance without constructor`);
2235
2226
  return /* @__PURE__ */ new Set(["@Sigil.unknown"]);
2236
2227
  }
@@ -2262,7 +2253,7 @@
2262
2253
  `[Sigil Error] 'WithSigil' decorator accept only Sigil classes but used on class ${value.name}`
2263
2254
  );
2264
2255
  decorateCtor(value, l);
2265
- checkInheritance(value, opts);
2256
+ if (__DEV__) checkInheritance(value, opts);
2266
2257
  };
2267
2258
  }
2268
2259
 
@@ -2280,7 +2271,7 @@
2280
2271
  } else l = generateRandomLabel();
2281
2272
  const ctor = Class;
2282
2273
  decorateCtor(ctor, l);
2283
- checkInheritance(ctor, opts);
2274
+ if (__DEV__) checkInheritance(ctor, opts);
2284
2275
  return Class;
2285
2276
  }
2286
2277
  function withSigilTyped(Class, label, opts) {
@@ -2296,7 +2287,7 @@
2296
2287
  } else l = generateRandomLabel();
2297
2288
  const ctor = Class;
2298
2289
  decorateCtor(ctor, l);
2299
- checkInheritance(ctor, opts);
2290
+ if (__DEV__) checkInheritance(ctor, opts);
2300
2291
  return Class;
2301
2292
  }
2302
2293
  /*! Bundled license information: