@vicin/sigil 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +157 -37
  2. package/dist/index.d.mts +777 -0
  3. package/dist/index.d.ts +777 -3
  4. package/dist/index.global.js +707 -0
  5. package/dist/index.global.js.map +1 -0
  6. package/dist/index.js +701 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +684 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/package.json +7 -4
  11. package/dist/core/classes.d.ts +0 -48
  12. package/dist/core/classes.d.ts.map +0 -1
  13. package/dist/core/classes.js +0 -18
  14. package/dist/core/classes.js.map +0 -1
  15. package/dist/core/decorator.d.ts +0 -28
  16. package/dist/core/decorator.d.ts.map +0 -1
  17. package/dist/core/decorator.js +0 -48
  18. package/dist/core/decorator.js.map +0 -1
  19. package/dist/core/enhancers.d.ts +0 -58
  20. package/dist/core/enhancers.d.ts.map +0 -1
  21. package/dist/core/enhancers.js +0 -101
  22. package/dist/core/enhancers.js.map +0 -1
  23. package/dist/core/helpers.d.ts +0 -192
  24. package/dist/core/helpers.d.ts.map +0 -1
  25. package/dist/core/helpers.js +0 -349
  26. package/dist/core/helpers.js.map +0 -1
  27. package/dist/core/index.d.ts +0 -9
  28. package/dist/core/index.d.ts.map +0 -1
  29. package/dist/core/index.js +0 -8
  30. package/dist/core/index.js.map +0 -1
  31. package/dist/core/mixin.d.ts +0 -115
  32. package/dist/core/mixin.d.ts.map +0 -1
  33. package/dist/core/mixin.js +0 -209
  34. package/dist/core/mixin.js.map +0 -1
  35. package/dist/core/options.d.ts +0 -74
  36. package/dist/core/options.d.ts.map +0 -1
  37. package/dist/core/options.js +0 -39
  38. package/dist/core/options.js.map +0 -1
  39. package/dist/core/registry.d.ts +0 -104
  40. package/dist/core/registry.d.ts.map +0 -1
  41. package/dist/core/registry.js +0 -174
  42. package/dist/core/registry.js.map +0 -1
  43. package/dist/core/symbols.d.ts +0 -96
  44. package/dist/core/symbols.d.ts.map +0 -1
  45. package/dist/core/symbols.js +0 -96
  46. package/dist/core/symbols.js.map +0 -1
  47. package/dist/core/types.d.ts +0 -169
  48. package/dist/core/types.d.ts.map +0 -1
  49. package/dist/core/types.js +0 -2
  50. package/dist/core/types.js.map +0 -1
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/utils/index.d.ts +0 -2
  53. package/dist/utils/index.d.ts.map +0 -1
  54. package/dist/utils/index.js +0 -2
  55. package/dist/utils/index.js.map +0 -1
@@ -1,192 +0,0 @@
1
- import { type SigilOptions } from './options';
2
- import type { ISigil, ISigilInstance } from './types';
3
- /** -----------------------------------------
4
- * High level helpers
5
- * ----------------------------------------- */
6
- /**
7
- * Attach sigil-related statics to a constructor and register its label.
8
- *
9
- * Side effects:
10
- * - Registers `label` in the global registry via `REGISTRY.register(label)`.
11
- * - Defines non-enumerable statics on the constructor:
12
- * - `__LABEL__` (string)
13
- * - `__TYPE__` (Symbol.for(label))
14
- * - `__TYPE_LINEAGE__` (array of symbols)
15
- * - `__TYPE_SET__` (Set of symbols)
16
- * - Marks the constructor as decorated via `markDecorated`.
17
- *
18
- * Throws if the constructor is already decorated.
19
- *
20
- * @internal
21
- * @param ctor - The constructor to decorate.
22
- * @param label - The identity label to register and attach (e.g. '@scope/pkg.ClassName').
23
- * @param opts - Options object to override any global options if needed.
24
- * @throws Error when `ctor` is already decorated.
25
- */
26
- export declare function decorateCtor(ctor: Function, label: string): void;
27
- /**
28
- * Perform development-only inheritance checks to ensure no ancestor classes
29
- * reuse the same sigil label.
30
- *
31
- * Behavior:
32
- * - No-op if `ctor` is not a sigil constructor.
33
- * - No-op in non-DEV builds.
34
- * - No-op if inheritance checks were already performed or `OPTIONS.skipLabelInheritanceCheck` is true.
35
- *
36
- * When a duplicate label is detected:
37
- * - If the class is explicitly decorated (`isDecorated`) or `OPTIONS.autofillLabels` is false,
38
- * an Error is thrown describing the label collision.
39
- * - Otherwise (autofill enabled), a random label will be generated and assigned
40
- * to the offending constructor via `decorateCtor`.
41
- *
42
- * @internal
43
- * @param ctor - The constructor to validate.
44
- * @param opts - Options object to override any global options if needed.
45
- * @throws Error when a decorated subclass re-uses an ancestor's sigil label.
46
- */
47
- export declare function checkInheritance(ctor: Function, opts?: Pick<SigilOptions, 'skipLabelInheritanceCheck' | 'autofillLabels' | 'devMarker'>): void;
48
- /**
49
- * Validate a sigil label at runtime and throw a helpful error if it is malformed.
50
- *
51
- * This is intentionally `void` and runs synchronously at class declaration time so
52
- * invalid labels fail fast during development. Validation behavior follows `OPTIONS.labelValidation`:
53
- * - If `OPTIONS.labelValidation` is `null` no validation is performed.
54
- * - If it is a `RegExp`, the label must match the regex.
55
- * - If it is a function, the function must return `true` for the label to be considered valid.
56
- *
57
- * @internal
58
- * @typeParam L - Label string literal type.
59
- * @param label - The label to validate.
60
- * @param opts - Options object to override any global options if needed.
61
- * @throws {Error} Throws when the label does not pass configured validation.
62
- */
63
- export declare function verifyLabel<L extends string>(label: L, opts?: Pick<SigilOptions, 'labelValidation'>): void;
64
- /**
65
- * Generate a random alphanumeric label of the requested length.
66
- *
67
- * This is used to auto-generate labels when `OPTIONS.autofillLabels` is enabled.
68
- * It insures that generated label is not registered yet.
69
- *
70
- * @internal
71
- * @param length - Desired length of the generated string (defaults to 16).
72
- * @returns A random label.
73
- */
74
- export declare function generateRandomLabel(length?: number): string;
75
- /** -----------------------------------------
76
- * Introspection helpers
77
- * ----------------------------------------- */
78
- /**
79
- * Mark a constructor as a sigil constructor by attaching an internal symbol.
80
- *
81
- * This function defines a non-enumerable, non-writable, non-configurable
82
- * property on the constructor so subsequent checks can detect sigil
83
- * constructors.
84
- *
85
- * @internal
86
- * @param ctor - The constructor to mark.
87
- */
88
- export declare function markSigil(ctor: Function): void;
89
- /**
90
- * Mark a constructor as a "sigil base" constructor.
91
- *
92
- * A sigil base constructor indicates that the class is the base for
93
- * other sigil classes. This writes a stable, non-enumerable property
94
- * to the constructor.
95
- *
96
- * @internal
97
- * @param ctor - The constructor to mark as sigil base.
98
- */
99
- export declare function markSigilBase(ctor: Function): void;
100
- /**
101
- * Mark a constructor as having been decorated with `WithSigil`.
102
- *
103
- * This is used to detect classes that were explicitly decorated rather
104
- * than auto-filled by the library.
105
- *
106
- * @internal
107
- * @param ctor - The constructor that was decorated.
108
- */
109
- export declare function markDecorated(ctor: Function): void;
110
- /**
111
- * Mark that inheritance checks for this constructor have already been performed.
112
- *
113
- * The library uses this to avoid repeating expensive inheritance validation
114
- * during development.
115
- *
116
- * @internal
117
- * @param ctor - The constructor that has been checked.
118
- */
119
- export declare function markInheritanceChecked(ctor: Function): void;
120
- /**
121
- * Runtime predicate that checks whether the provided value is a sigil constructor.
122
- *
123
- * This is a lightweight check that verifies the presence of an internal
124
- * symbol attached to the constructor.
125
- *
126
- * @param value - Value to test.
127
- * @returns `true` if `value` is a sigil constructor, otherwise `false`.
128
- */
129
- export declare function isSigilCtor(value: unknown): value is ISigil;
130
- /**
131
- * Runtime predicate that checks whether the provided object is an instance
132
- * of a sigil class.
133
- *
134
- * The function is defensive: non-objects return `false`. If an object is
135
- * passed, the object's constructor is resolved and tested with `isSigilCtor`.
136
- *
137
- * @param obj - The value to test.
138
- * @returns `true` if `obj` is an instance produced by a sigil constructor.
139
- */
140
- export declare function isSigilInstance(obj: unknown): obj is ISigilInstance;
141
- /**
142
- * Check whether the provided constructor was marked as a sigil base constructor.
143
- *
144
- * Uses `Object.hasOwn` to ensure we only check own properties.
145
- *
146
- * @param ctor - Constructor to check.
147
- * @returns `true` if `ctor` is a sigil base constructor.
148
- */
149
- export declare function isSigilBaseCtor(ctor: Function): boolean;
150
- /**
151
- * Check whether the provided object is an instance of a sigil base constructor.
152
- *
153
- * This resolves the object's constructor and delegates to `isSigilBaseCtor`.
154
- *
155
- * @param obj - The object to test.
156
- * @returns `true` if `obj` is an instance of a sigil base constructor.
157
- */
158
- export declare function isSigilBaseInstance(obj: unknown): obj is ISigilInstance;
159
- /**
160
- * Returns whether the constructor has been explicitly decorated with `WithSigil`.
161
- *
162
- * This is an own-property check and does not traverse the prototype chain.
163
- *
164
- * @internal
165
- * @param ctor - Constructor to test.
166
- * @returns `true` if the constructor is explicitly decorated.
167
- */
168
- export declare function isDecorated(ctor: Function): boolean;
169
- /**
170
- * Returns whether inheritance checks have already been performed for the constructor.
171
- *
172
- * This is used to avoid repeated checks during development (DEV-only checks).
173
- *
174
- * @internal
175
- * @param ctor - Constructor to test.
176
- * @returns `true` if inheritance checks were marked as completed.
177
- */
178
- export declare function isInheritanceChecked(ctor: Function): boolean;
179
- /** -----------------------------------------
180
- * Generic helpers
181
- * ----------------------------------------- */
182
- /**
183
- * Retrieve the constructor function for a given instance.
184
- *
185
- * Returns `null` for non-objects or when a constructor cannot be resolved.
186
- *
187
- * @internal
188
- * @param obj - The value that may be an instance whose constructor should be returned.
189
- * @returns The constructor function or `null` if not available.
190
- */
191
- export declare function getConstructor(obj: any): any;
192
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/core/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAYvD,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEtD;;+CAE+C;AAE/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,QA6CzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,EACd,IAAI,CAAC,EAAE,IAAI,CACT,YAAY,EACZ,2BAA2B,GAAG,gBAAgB,GAAG,WAAW,CAC7D,QA6CF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,iBAAiB,CAAC,GAC3C,IAAI,CAaN;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAK,GAAG,MAAM,CAIvD;AAED;;+CAE+C;AAE/C;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,QAOvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,QAO3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,QAO3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,QAOpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAInE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAIvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAE5D;AAED;;+CAE+C;AAE/C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,OAGtC"}
@@ -1,349 +0,0 @@
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
@@ -1 +0,0 @@
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,IA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igil, 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
@@ -1 +0,0 @@
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"}
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}