@vicin/sigil 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +620 -0
  3. package/dist/core/classes.d.ts +48 -0
  4. package/dist/core/classes.d.ts.map +1 -0
  5. package/dist/core/classes.js +18 -0
  6. package/dist/core/classes.js.map +1 -0
  7. package/dist/core/decorator.d.ts +28 -0
  8. package/dist/core/decorator.d.ts.map +1 -0
  9. package/dist/core/decorator.js +48 -0
  10. package/dist/core/decorator.js.map +1 -0
  11. package/dist/core/enhancers.d.ts +58 -0
  12. package/dist/core/enhancers.d.ts.map +1 -0
  13. package/dist/core/enhancers.js +101 -0
  14. package/dist/core/enhancers.js.map +1 -0
  15. package/dist/core/helpers.d.ts +192 -0
  16. package/dist/core/helpers.d.ts.map +1 -0
  17. package/dist/core/helpers.js +349 -0
  18. package/dist/core/helpers.js.map +1 -0
  19. package/dist/core/index.d.ts +9 -0
  20. package/dist/core/index.d.ts.map +1 -0
  21. package/dist/core/index.js +8 -0
  22. package/dist/core/index.js.map +1 -0
  23. package/dist/core/mixin.d.ts +115 -0
  24. package/dist/core/mixin.d.ts.map +1 -0
  25. package/dist/core/mixin.js +209 -0
  26. package/dist/core/mixin.js.map +1 -0
  27. package/dist/core/options.d.ts +74 -0
  28. package/dist/core/options.d.ts.map +1 -0
  29. package/dist/core/options.js +39 -0
  30. package/dist/core/options.js.map +1 -0
  31. package/dist/core/registry.d.ts +104 -0
  32. package/dist/core/registry.d.ts.map +1 -0
  33. package/dist/core/registry.js +174 -0
  34. package/dist/core/registry.js.map +1 -0
  35. package/dist/core/symbols.d.ts +96 -0
  36. package/dist/core/symbols.d.ts.map +1 -0
  37. package/dist/core/symbols.js +96 -0
  38. package/dist/core/symbols.js.map +1 -0
  39. package/dist/core/types.d.ts +169 -0
  40. package/dist/core/types.d.ts.map +1 -0
  41. package/dist/core/types.js +2 -0
  42. package/dist/core/types.js.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +3 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/utils/index.d.ts +2 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +2 -0
  50. package/dist/utils/index.js.map +1 -0
  51. package/package.json +57 -0
@@ -0,0 +1,349 @@
1
+ import { OPTIONS } from './options';
2
+ import { REGISTRY } from './registry';
3
+ import { __DECORATED__, __INHERITANCE_CHECKED__, __LABEL__, __SIGIL_BASE__, __SIGIL__, __TYPE_LINEAGE__, __TYPE_SET__, __TYPE__, } from './symbols';
4
+ /** -----------------------------------------
5
+ * High level helpers
6
+ * ----------------------------------------- */
7
+ /**
8
+ * Attach sigil-related statics to a constructor and register its label.
9
+ *
10
+ * Side effects:
11
+ * - Registers `label` in the global registry via `REGISTRY.register(label)`.
12
+ * - Defines non-enumerable statics on the constructor:
13
+ * - `__LABEL__` (string)
14
+ * - `__TYPE__` (Symbol.for(label))
15
+ * - `__TYPE_LINEAGE__` (array of symbols)
16
+ * - `__TYPE_SET__` (Set of symbols)
17
+ * - Marks the constructor as decorated via `markDecorated`.
18
+ *
19
+ * Throws if the constructor is already decorated.
20
+ *
21
+ * @internal
22
+ * @param ctor - The constructor to decorate.
23
+ * @param label - The identity label to register and attach (e.g. '@scope/pkg.ClassName').
24
+ * @param opts - Options object to override any global options if needed.
25
+ * @throws Error when `ctor` is already decorated.
26
+ */
27
+ export function decorateCtor(ctor, label) {
28
+ // if already decorated throw error
29
+ if (isDecorated(ctor))
30
+ throw new Error(`Constructor ${ctor} is already decorated. if you are using 'withSigilTyped()' & '@WithSigil()' at the same time remove one of them.`);
31
+ // get symbol for the label and update registry
32
+ const symbol = Symbol.for(label);
33
+ REGISTRY.register(label, ctor);
34
+ // attach basic runtime statics
35
+ Object.defineProperty(ctor, __LABEL__, {
36
+ value: label,
37
+ configurable: false,
38
+ enumerable: false,
39
+ writable: false,
40
+ });
41
+ Object.defineProperty(ctor, __TYPE__, {
42
+ value: symbol,
43
+ configurable: false,
44
+ enumerable: false,
45
+ writable: false,
46
+ });
47
+ // compute type chain from parent (safe if parent hasn't been augmented yet — uses existing value or empty)
48
+ const parent = Object.getPrototypeOf(ctor);
49
+ const parentChain = parent && parent[__TYPE_LINEAGE__] ? parent[__TYPE_LINEAGE__] : [];
50
+ const ctorChain = [...parentChain, symbol];
51
+ Object.defineProperty(ctor, __TYPE_LINEAGE__, {
52
+ value: ctorChain,
53
+ configurable: false,
54
+ enumerable: false,
55
+ writable: false,
56
+ });
57
+ Object.defineProperty(ctor, __TYPE_SET__, {
58
+ value: new Set(ctorChain),
59
+ configurable: false,
60
+ enumerable: false,
61
+ writable: false,
62
+ });
63
+ // mark as decorated
64
+ markDecorated(ctor);
65
+ }
66
+ /**
67
+ * Perform development-only inheritance checks to ensure no ancestor classes
68
+ * reuse the same sigil label.
69
+ *
70
+ * Behavior:
71
+ * - No-op if `ctor` is not a sigil constructor.
72
+ * - No-op in non-DEV builds.
73
+ * - No-op if inheritance checks were already performed or `OPTIONS.skipLabelInheritanceCheck` is true.
74
+ *
75
+ * When a duplicate label is detected:
76
+ * - If the class is explicitly decorated (`isDecorated`) or `OPTIONS.autofillLabels` is false,
77
+ * an Error is thrown describing the label collision.
78
+ * - Otherwise (autofill enabled), a random label will be generated and assigned
79
+ * to the offending constructor via `decorateCtor`.
80
+ *
81
+ * @internal
82
+ * @param ctor - The constructor to validate.
83
+ * @param opts - Options object to override any global options if needed.
84
+ * @throws Error when a decorated subclass re-uses an ancestor's sigil label.
85
+ */
86
+ export function checkInheritance(ctor, opts) {
87
+ if (!(opts?.devMarker ?? OPTIONS.devMarker))
88
+ return;
89
+ if (!isSigilCtor(ctor))
90
+ return;
91
+ if (isInheritanceChecked(ctor) ||
92
+ (opts?.skipLabelInheritanceCheck ?? OPTIONS.skipLabelInheritanceCheck))
93
+ return;
94
+ /** Array of all sigil constructors in the chain (starting with the provided ctor) */
95
+ const ctors = [ctor];
96
+ // go through prototype chain to get all sigil ancestors
97
+ let ancestor = Object.getPrototypeOf(ctor);
98
+ while (isSigilCtor(ancestor)) {
99
+ ctors.push(ancestor);
100
+ ancestor = Object.getPrototypeOf(ancestor);
101
+ }
102
+ /** Map<label, className> to record the owner of each label. */
103
+ const labelOwner = new Map();
104
+ // loop ctors from base to current and make sure no label is reused
105
+ for (let i = ctors.length - 1; i >= 0; i--) {
106
+ const ctor = ctors[i];
107
+ if (!ctor)
108
+ continue;
109
+ let label = ctor.SigilLabel;
110
+ if (labelOwner.has(label)) {
111
+ if (isDecorated(ctor) ||
112
+ !(opts?.autofillLabels ?? OPTIONS.autofillLabels)) {
113
+ const ancestorName = labelOwner.get(label);
114
+ throw new Error(`[Sigil Error] Class "${ctor.name}" re-uses Sigil label "${label}" from ancestor "${ancestorName}". ` +
115
+ `Each Sigil subclass must use a unique label. Did you forget to use "WithSigil(newLabel)" on the subclass?`);
116
+ }
117
+ label = generateRandomLabel();
118
+ decorateCtor(ctor, label);
119
+ }
120
+ labelOwner.set(label, ctor.name);
121
+ }
122
+ markInheritanceChecked(ctor);
123
+ }
124
+ /**
125
+ * Validate a sigil label at runtime and throw a helpful error if it is malformed.
126
+ *
127
+ * This is intentionally `void` and runs synchronously at class declaration time so
128
+ * invalid labels fail fast during development. Validation behavior follows `OPTIONS.labelValidation`:
129
+ * - If `OPTIONS.labelValidation` is `null` no validation is performed.
130
+ * - If it is a `RegExp`, the label must match the regex.
131
+ * - If it is a function, the function must return `true` for the label to be considered valid.
132
+ *
133
+ * @internal
134
+ * @typeParam L - Label string literal type.
135
+ * @param label - The label to validate.
136
+ * @param opts - Options object to override any global options if needed.
137
+ * @throws {Error} Throws when the label does not pass configured validation.
138
+ */
139
+ export function verifyLabel(label, opts) {
140
+ const labelValidation = opts?.labelValidation ?? OPTIONS.labelValidation;
141
+ if (labelValidation) {
142
+ let valid;
143
+ if (labelValidation instanceof RegExp)
144
+ valid = labelValidation.test(label);
145
+ else
146
+ valid = labelValidation(label);
147
+ if (!valid)
148
+ throw new Error(`[Sigil] Invalid identity label "${label}". Make sure that supplied label matches validation regex or function.`);
149
+ }
150
+ }
151
+ /**
152
+ * Generate a random alphanumeric label of the requested length.
153
+ *
154
+ * This is used to auto-generate labels when `OPTIONS.autofillLabels` is enabled.
155
+ * It insures that generated label is not registered yet.
156
+ *
157
+ * @internal
158
+ * @param length - Desired length of the generated string (defaults to 16).
159
+ * @returns A random label.
160
+ */
161
+ export function generateRandomLabel(length = 16) {
162
+ let label = generateRandomString(length);
163
+ while (REGISTRY.has(label))
164
+ label = generateRandomLabel();
165
+ return `@Sigil.auto-${label}`;
166
+ }
167
+ /** -----------------------------------------
168
+ * Introspection helpers
169
+ * ----------------------------------------- */
170
+ /**
171
+ * Mark a constructor as a sigil constructor by attaching an internal symbol.
172
+ *
173
+ * This function defines a non-enumerable, non-writable, non-configurable
174
+ * property on the constructor so subsequent checks can detect sigil
175
+ * constructors.
176
+ *
177
+ * @internal
178
+ * @param ctor - The constructor to mark.
179
+ */
180
+ export function markSigil(ctor) {
181
+ Object.defineProperty(ctor, __SIGIL__, {
182
+ value: true,
183
+ configurable: false,
184
+ enumerable: false,
185
+ writable: false,
186
+ });
187
+ }
188
+ /**
189
+ * Mark a constructor as a "sigil base" constructor.
190
+ *
191
+ * A sigil base constructor indicates that the class is the base for
192
+ * other sigil classes. This writes a stable, non-enumerable property
193
+ * to the constructor.
194
+ *
195
+ * @internal
196
+ * @param ctor - The constructor to mark as sigil base.
197
+ */
198
+ export function markSigilBase(ctor) {
199
+ Object.defineProperty(ctor, __SIGIL_BASE__, {
200
+ value: true,
201
+ configurable: false,
202
+ enumerable: false,
203
+ writable: false,
204
+ });
205
+ }
206
+ /**
207
+ * Mark a constructor as having been decorated with `WithSigil`.
208
+ *
209
+ * This is used to detect classes that were explicitly decorated rather
210
+ * than auto-filled by the library.
211
+ *
212
+ * @internal
213
+ * @param ctor - The constructor that was decorated.
214
+ */
215
+ export function markDecorated(ctor) {
216
+ Object.defineProperty(ctor, __DECORATED__, {
217
+ value: true,
218
+ configurable: false,
219
+ enumerable: false,
220
+ writable: false,
221
+ });
222
+ }
223
+ /**
224
+ * Mark that inheritance checks for this constructor have already been performed.
225
+ *
226
+ * The library uses this to avoid repeating expensive inheritance validation
227
+ * during development.
228
+ *
229
+ * @internal
230
+ * @param ctor - The constructor that has been checked.
231
+ */
232
+ export function markInheritanceChecked(ctor) {
233
+ Object.defineProperty(ctor, __INHERITANCE_CHECKED__, {
234
+ value: true,
235
+ configurable: false,
236
+ enumerable: false,
237
+ writable: false,
238
+ });
239
+ }
240
+ /**
241
+ * Runtime predicate that checks whether the provided value is a sigil constructor.
242
+ *
243
+ * This is a lightweight check that verifies the presence of an internal
244
+ * symbol attached to the constructor.
245
+ *
246
+ * @param value - Value to test.
247
+ * @returns `true` if `value` is a sigil constructor, otherwise `false`.
248
+ */
249
+ export function isSigilCtor(value) {
250
+ return typeof value === 'function' && value[__SIGIL__] === true;
251
+ }
252
+ /**
253
+ * Runtime predicate that checks whether the provided object is an instance
254
+ * of a sigil class.
255
+ *
256
+ * The function is defensive: non-objects return `false`. If an object is
257
+ * passed, the object's constructor is resolved and tested with `isSigilCtor`.
258
+ *
259
+ * @param obj - The value to test.
260
+ * @returns `true` if `obj` is an instance produced by a sigil constructor.
261
+ */
262
+ export function isSigilInstance(obj) {
263
+ if (!obj || typeof obj !== 'object')
264
+ return false;
265
+ const ctor = getConstructor(obj);
266
+ return isSigilCtor(ctor);
267
+ }
268
+ /**
269
+ * Check whether the provided constructor was marked as a sigil base constructor.
270
+ *
271
+ * Uses `Object.hasOwn` to ensure we only check own properties.
272
+ *
273
+ * @param ctor - Constructor to check.
274
+ * @returns `true` if `ctor` is a sigil base constructor.
275
+ */
276
+ export function isSigilBaseCtor(ctor) {
277
+ return Object.hasOwn(ctor, __SIGIL_BASE__);
278
+ }
279
+ /**
280
+ * Check whether the provided object is an instance of a sigil base constructor.
281
+ *
282
+ * This resolves the object's constructor and delegates to `isSigilBaseCtor`.
283
+ *
284
+ * @param obj - The object to test.
285
+ * @returns `true` if `obj` is an instance of a sigil base constructor.
286
+ */
287
+ export function isSigilBaseInstance(obj) {
288
+ if (!obj || typeof obj !== 'object')
289
+ return false;
290
+ const ctor = getConstructor(obj);
291
+ return isSigilBaseCtor(ctor);
292
+ }
293
+ /**
294
+ * Returns whether the constructor has been explicitly decorated with `WithSigil`.
295
+ *
296
+ * This is an own-property check and does not traverse the prototype chain.
297
+ *
298
+ * @internal
299
+ * @param ctor - Constructor to test.
300
+ * @returns `true` if the constructor is explicitly decorated.
301
+ */
302
+ export function isDecorated(ctor) {
303
+ return Object.hasOwn(ctor, __DECORATED__);
304
+ }
305
+ /**
306
+ * Returns whether inheritance checks have already been performed for the constructor.
307
+ *
308
+ * This is used to avoid repeated checks during development (DEV-only checks).
309
+ *
310
+ * @internal
311
+ * @param ctor - Constructor to test.
312
+ * @returns `true` if inheritance checks were marked as completed.
313
+ */
314
+ export function isInheritanceChecked(ctor) {
315
+ return Object.hasOwn(ctor, __INHERITANCE_CHECKED__);
316
+ }
317
+ /** -----------------------------------------
318
+ * Generic helpers
319
+ * ----------------------------------------- */
320
+ /**
321
+ * Retrieve the constructor function for a given instance.
322
+ *
323
+ * Returns `null` for non-objects or when a constructor cannot be resolved.
324
+ *
325
+ * @internal
326
+ * @param obj - The value that may be an instance whose constructor should be returned.
327
+ * @returns The constructor function or `null` if not available.
328
+ */
329
+ export function getConstructor(obj) {
330
+ if (!obj || typeof obj !== 'object')
331
+ return null;
332
+ return obj.constructor ?? Object.getPrototypeOf(obj)?.constructor ?? null;
333
+ }
334
+ /**
335
+ * Generate a random alphanumeric string of the requested length.
336
+ *
337
+ * @internal
338
+ * @param length - Desired length of the generated string (defaults to 16).
339
+ * @returns A random string consisting of upper/lower letters and digits.
340
+ */
341
+ function generateRandomString(length = 16) {
342
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
343
+ let result = '';
344
+ for (let i = 0; i < length; i++) {
345
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
346
+ }
347
+ return result;
348
+ }
349
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/core/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,SAAS,EACT,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,QAAQ,GACT,MAAM,WAAW,CAAC;AAGnB;;+CAE+C;AAE/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc,EAAE,KAAa;IACxD,mCAAmC;IACnC,IAAI,WAAW,CAAC,IAAI,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,eAAe,IAAI,kHAAkH,CACtI,CAAC;IAEJ,+CAA+C;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAc,CAAC,CAAC;IAEzC,+BAA+B;IAC/B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;QACrC,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;QACpC,KAAK,EAAE,MAAM;QACb,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;IAEH,2GAA2G;IAC3G,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,I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IAAI,EAAE,uBAAuB,CAAC,CAAC;AACtD,CAAC;AAED;;+CAE+C;AAE/C;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,GAAQ;IACrC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,GAAG,CAAC,WAAW,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,WAAW,IAAI,IAAI,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,MAAM,GAAG,EAAE;IACvC,MAAM,KAAK,GACT,gEAAgE,CAAC;IACnE,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { Sigil, SigilError } from './classes';
2
+ export { WithSigil } from './decorator';
3
+ export { typed, withSigil, withSigilTyped } from './enhancers';
4
+ export { isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, } from './helpers';
5
+ export { Sigilify } from './mixin';
6
+ export { updateOptions, type SigilOptions, DEFAULT_LABEL_REGEX, } from './options';
7
+ export { REGISTRY } from './registry';
8
+ export type { GetInstance, ISigil, ISigilInstance, ISigilStatic, SigilBrandOf, TypedSigil, } from './types';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,aAAa,EACb,KAAK,YAAY,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EACV,WAAW,EACX,MAAM,EACN,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { Sigil, SigilError } from './classes';
2
+ export { WithSigil } from './decorator';
3
+ export { typed, withSigil, withSigilTyped } from './enhancers';
4
+ export { isDecorated, isInheritanceChecked, isSigilBaseCtor, isSigilBaseInstance, isSigilCtor, isSigilInstance, } from './helpers';
5
+ export { Sigilify } from './mixin';
6
+ export { updateOptions, DEFAULT_LABEL_REGEX, } from './options';
7
+ export { REGISTRY } from './registry';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,aAAa,EAEb,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,115 @@
1
+ import { type SigilOptions } from './options';
2
+ import type { Constructor, ISigil } from './types';
3
+ /**
4
+ * Mixin factory that augments an existing class with Sigil runtime metadata and
5
+ * helpers. The returned class:
6
+ * - registers a stable symbol for the provided `label` (via `WithSigil`)
7
+ * - exposes static helpers such as `SigilLabel`, `SigilType`, `isOfType`, and `isOfTypeStrict`
8
+ * - exposes instance helpers such as `getSigilLabel`, `getSigilType`, etc.
9
+ *
10
+ * Notes:
11
+ * - Uses `Symbol.for(label)` internally so symbols are stable across bundles/realms
12
+ * that share the global symbol registry.
13
+ * - Throws if `Base` is already a sigil constructor.
14
+ *
15
+ * @param Base - The base constructor to extend.
16
+ * @param label - Optional identity label to attach to the resulting class (e.g. '@scope/pkg.ClassName').
17
+ * If not passed a random label is generated instead.
18
+ * @param opts - Options object to override any global options if needed.
19
+ * @returns A new abstract constructor that extends `Base` and includes Sigil statics/instance methods.
20
+ * @throws Error if `Base` is already sigilized.
21
+ */
22
+ export declare function Sigilify(Base: Constructor, label?: string, opts?: SigilOptions): {
23
+ new (...args: any[]): {
24
+ readonly __SIGIL_BRAND__: Record<string, true>;
25
+ /**
26
+ * Returns the human-readable sigil label of this instance's constructor.
27
+ *
28
+ * @returns The label string (e.g. '@scope/pkg.ClassName') or '@Sigil.unknown' in DEV when constructor is missing.
29
+ */
30
+ getSigilLabel(): string;
31
+ /**
32
+ * Returns the runtime sigil type symbol of this instance's constructor.
33
+ *
34
+ * @returns The symbol that identifies this type at runtime.
35
+ */
36
+ getSigilType(): symbol;
37
+ /**
38
+ * Returns a copy of the sigil type symbol lineage for this instance's constructor.
39
+ *
40
+ * @returns readonly array of symbols representing the type lineage.
41
+ */
42
+ getSigilTypeLineage(): readonly symbol[];
43
+ /**
44
+ * Returns a readonly copy of the sigil type symbol set for this instance's constructor.
45
+ *
46
+ * @returns A Readonly Set of symbols representing the type lineage for O(1) membership tests.
47
+ */
48
+ getSigilTypeSet(): Readonly<Set<symbol>>;
49
+ };
50
+ readonly __SIGIL_BRAND__: Record<string, true>;
51
+ /**
52
+ * Class-level human-readable label constant for this sigil constructor.
53
+ */
54
+ get SigilLabel(): string;
55
+ /**
56
+ * Class-level unique runtime symbol used as the type identifier.
57
+ *
58
+ * This symbol is created with `Symbol.for(label)` during decoration so it is
59
+ * stable across realms that share the same global symbol registry.
60
+ */
61
+ get SigilType(): symbol;
62
+ /**
63
+ * Copy of the linearized sigil type symbol chain for the current constructor.
64
+ *
65
+ * Useful for debugging and performing strict lineage comparisons.
66
+ *
67
+ * @returns An array of symbols representing parent → child type symbols.
68
+ */
69
+ get SigilTypeLineage(): readonly symbol[];
70
+ /**
71
+ * Copy of the sigil type symbol set for the current constructor.
72
+ *
73
+ * Useful for quick membership checks (O(1) lookups) and debugging.
74
+ *
75
+ * @returns A Readonly Set of symbols that represent the type lineage.
76
+ */
77
+ get SigilTypeSet(): Readonly<Set<symbol>>;
78
+ /**
79
+ * Runtime predicate indicating whether `obj` is an instance produced by a sigil class.
80
+ *
81
+ * @param obj - The value to test.
82
+ * @returns `true` if `obj` is a sigil instance.
83
+ */
84
+ isSigilified(obj: unknown): obj is ISigil;
85
+ /**
86
+ * Check whether `other` is (or inherits from) the type represented by the calling constructor.
87
+ *
88
+ * Implementation detail:
89
+ * - Uses the other instance's `__TYPE_SET__` for O(1) membership test.
90
+ * - O(1) and reliable as long as `OPTIONS.skipLabelInheritanceCheck` is `false`.
91
+ *
92
+ * This replaces `instanceof` so that checks remain valid across bundles/realms
93
+ * and when subclassing.
94
+ *
95
+ * @typeParam T - The calling constructor type (narrowing the returned instance type).
96
+ * @param this - The constructor performing the check.
97
+ * @param other - The object to test.
98
+ * @returns `true` if `other` is an instance of this type or a subtype.
99
+ */
100
+ isOfType<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
101
+ /**
102
+ * Strict lineage check: compares the type symbol lineage arrays element-by-element.
103
+ *
104
+ * Implementation detail:
105
+ * - Works in O(n) time where n is the depth of the lineage.
106
+ * - Reliable when `OPTIONS.skipLabelInheritanceCheck` is `false`.
107
+ *
108
+ * @typeParam T - The calling constructor type.
109
+ * @param this - The constructor performing the check.
110
+ * @param other - The object to test.
111
+ * @returns `true` if `other` has an identical lineage up to the length of this constructor's lineage.
112
+ */
113
+ isOfTypeStrict<T extends ISigil>(this: T, other: unknown): other is InstanceType<T>;
114
+ };
115
+ //# sourceMappingURL=mixin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../../src/core/mixin.ts"],"names":[],"mappings":"AAWA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,WAAW,EACjB,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,YAAY;kBA4DI,GAAG,EAAE;kCAFQ,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;QAuFtD;;;;WAIG;yBACc,MAAM;QAYvB;;;;WAIG;wBACa,MAAM;QAYtB;;;;WAIG;+BACoB,SAAS,MAAM,EAAE;QAYxC;;;;WAIG;2BACgB,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;;8BA1LC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;IAE7D;;OAEG;sBACsB,MAAM;IAI/B;;;;;OAKG;qBACqB,MAAM;IAI9B;;;;;;OAMG;4BAC4B,SAAS,MAAM,EAAE;IAIhD;;;;;;OAMG;wBACwB,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IA6BhD;;;;;OAKG;sBACsB,OAAO,GAAG,GAAG,IAAI,MAAM;IAIhD;;;;;;;;;;;;;;OAcG;aACa,CAAC,SAAS,MAAM,QACxB,CAAC,SACA,OAAO,GACb,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC;IAS3B;;;;;;;;;;;OAWG;mBACmB,CAAC,SAAS,MAAM,QAC9B,CAAC,SACA,OAAO,GACb,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC;EAyF9B"}