@xylabs/base 5.0.80 → 5.0.82

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/README.md CHANGED
@@ -24,6 +24,7 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
24
24
  ## Classes
25
25
 
26
26
  - [Base](#classes/Base)
27
+ - [UniqueBase](#classes/UniqueBase)
27
28
 
28
29
  ## Type Aliases
29
30
 
@@ -44,6 +45,10 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
44
45
 
45
46
  ***
46
47
 
48
+ ## Extended by
49
+
50
+ - [`UniqueBase`](#UniqueBase)
51
+
47
52
  ## Type Parameters
48
53
 
49
54
  ### TParams
@@ -92,6 +97,338 @@ readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]> = {};
92
97
  readonly static globalInstancesCountHistory: Record<BaseClassName, number[]> = {};
93
98
  ```
94
99
 
100
+ ## Accessors
101
+
102
+ ### historyInterval
103
+
104
+ ### Get Signature
105
+
106
+ ```ts
107
+ get static historyInterval(): number;
108
+ ```
109
+
110
+ #### Returns
111
+
112
+ `number`
113
+
114
+ ### Set Signature
115
+
116
+ ```ts
117
+ set static historyInterval(value): void;
118
+ ```
119
+
120
+ #### Parameters
121
+
122
+ ##### value
123
+
124
+ `number`
125
+
126
+ #### Returns
127
+
128
+ `void`
129
+
130
+ ***
131
+
132
+ ### historyTime
133
+
134
+ ### Get Signature
135
+
136
+ ```ts
137
+ get static historyTime(): number;
138
+ ```
139
+
140
+ #### Returns
141
+
142
+ `number`
143
+
144
+ ### Set Signature
145
+
146
+ ```ts
147
+ set static historyTime(value): void;
148
+ ```
149
+
150
+ #### Parameters
151
+
152
+ ##### value
153
+
154
+ `number`
155
+
156
+ #### Returns
157
+
158
+ `void`
159
+
160
+ ***
161
+
162
+ ### maxGcFrequency
163
+
164
+ ### Get Signature
165
+
166
+ ```ts
167
+ get static maxGcFrequency(): number;
168
+ ```
169
+
170
+ #### Returns
171
+
172
+ `number`
173
+
174
+ ### Set Signature
175
+
176
+ ```ts
177
+ set static maxGcFrequency(value): void;
178
+ ```
179
+
180
+ #### Parameters
181
+
182
+ ##### value
183
+
184
+ `number`
185
+
186
+ #### Returns
187
+
188
+ `void`
189
+
190
+ ***
191
+
192
+ ### maxHistoryDepth
193
+
194
+ ### Get Signature
195
+
196
+ ```ts
197
+ get static maxHistoryDepth(): number;
198
+ ```
199
+
200
+ #### Returns
201
+
202
+ `number`
203
+
204
+ ***
205
+
206
+ ### logger
207
+
208
+ ### Get Signature
209
+
210
+ ```ts
211
+ get logger(): Logger | undefined;
212
+ ```
213
+
214
+ #### Returns
215
+
216
+ `Logger` \| `undefined`
217
+
218
+ ***
219
+
220
+ ### meter
221
+
222
+ ### Get Signature
223
+
224
+ ```ts
225
+ get meter(): Meter | undefined;
226
+ ```
227
+
228
+ #### Returns
229
+
230
+ `Meter` \| `undefined`
231
+
232
+ ***
233
+
234
+ ### params
235
+
236
+ ### Get Signature
237
+
238
+ ```ts
239
+ get params(): BaseParams<TParams>;
240
+ ```
241
+
242
+ #### Returns
243
+
244
+ [`BaseParams`](#../type-aliases/BaseParams)\<`TParams`\>
245
+
246
+ ***
247
+
248
+ ### tracer
249
+
250
+ ### Get Signature
251
+
252
+ ```ts
253
+ get tracer(): Tracer | undefined;
254
+ ```
255
+
256
+ #### Returns
257
+
258
+ `Tracer` \| `undefined`
259
+
260
+ ## Methods
261
+
262
+ ### gc()
263
+
264
+ ### Call Signature
265
+
266
+ ```ts
267
+ static gc(force?): void;
268
+ ```
269
+
270
+ #### Parameters
271
+
272
+ ##### force?
273
+
274
+ `boolean`
275
+
276
+ #### Returns
277
+
278
+ `void`
279
+
280
+ ### Call Signature
281
+
282
+ ```ts
283
+ static gc(className): void;
284
+ ```
285
+
286
+ #### Parameters
287
+
288
+ ##### className
289
+
290
+ [`BaseClassName`](#../type-aliases/BaseClassName)
291
+
292
+ #### Returns
293
+
294
+ `void`
295
+
296
+ ***
297
+
298
+ ### instanceCount()
299
+
300
+ ```ts
301
+ static instanceCount(className): number;
302
+ ```
303
+
304
+ ### Parameters
305
+
306
+ #### className
307
+
308
+ [`BaseClassName`](#../type-aliases/BaseClassName)
309
+
310
+ ### Returns
311
+
312
+ `number`
313
+
314
+ ***
315
+
316
+ ### instanceCounts()
317
+
318
+ ```ts
319
+ static instanceCounts(): Record<BaseClassName, number>;
320
+ ```
321
+
322
+ ### Returns
323
+
324
+ `Record`\<[`BaseClassName`](#../type-aliases/BaseClassName), `number`\>
325
+
326
+ ***
327
+
328
+ ### startHistory()
329
+
330
+ ```ts
331
+ static startHistory(): void;
332
+ ```
333
+
334
+ ### Returns
335
+
336
+ `void`
337
+
338
+ ***
339
+
340
+ ### stopHistory()
341
+
342
+ ```ts
343
+ static stopHistory(): void;
344
+ ```
345
+
346
+ ### Returns
347
+
348
+ `void`
349
+
350
+ ### <a id="UniqueBase"></a>UniqueBase
351
+
352
+ [**@xylabs/base**](#../README)
353
+
354
+ ***
355
+
356
+ ## Extends
357
+
358
+ - [`Base`](#Base)\<`TParams`\>
359
+
360
+ ## Type Parameters
361
+
362
+ ### TParams
363
+
364
+ `TParams` *extends* [`BaseParams`](#../type-aliases/BaseParams) = [`BaseParams`](#../type-aliases/BaseParams)
365
+
366
+ ## Constructors
367
+
368
+ ### Constructor
369
+
370
+ ```ts
371
+ new UniqueBase<TParams>(params): UniqueBase<TParams>;
372
+ ```
373
+
374
+ ### Parameters
375
+
376
+ #### params
377
+
378
+ [`BaseParams`](#../type-aliases/BaseParams)\<`TParams`\>
379
+
380
+ ### Returns
381
+
382
+ `UniqueBase`\<`TParams`\>
383
+
384
+ ### Overrides
385
+
386
+ [`Base`](#Base).[`constructor`](Base.md#constructor)
387
+
388
+ ## Properties
389
+
390
+ ### defaultLogger?
391
+
392
+ ```ts
393
+ static optional defaultLogger: Logger;
394
+ ```
395
+
396
+ ### Inherited from
397
+
398
+ [`Base`](#Base).[`defaultLogger`](Base.md#defaultlogger)
399
+
400
+ ***
401
+
402
+ ### globalInstances
403
+
404
+ ```ts
405
+ readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]> = {};
406
+ ```
407
+
408
+ ### Inherited from
409
+
410
+ [`Base`](#Base).[`globalInstances`](Base.md#globalinstances)
411
+
412
+ ***
413
+
414
+ ### globalInstancesCountHistory
415
+
416
+ ```ts
417
+ readonly static globalInstancesCountHistory: Record<BaseClassName, number[]> = {};
418
+ ```
419
+
420
+ ### Inherited from
421
+
422
+ [`Base`](#Base).[`globalInstancesCountHistory`](Base.md#globalinstancescounthistory)
423
+
424
+ ***
425
+
426
+ ### uniqueDomain
427
+
428
+ ```ts
429
+ readonly static uniqueDomain: "xy" = 'xy';
430
+ ```
431
+
95
432
  ***
96
433
 
97
434
  ### uniqueName
@@ -100,6 +437,14 @@ readonly static globalInstancesCountHistory: Record<BaseClassName, number[]> = {
100
437
  readonly static uniqueName: string;
101
438
  ```
102
439
 
440
+ ***
441
+
442
+ ### uniqueNameXyo
443
+
444
+ ```ts
445
+ readonly static uniqueNameXyo: string;
446
+ ```
447
+
103
448
  ## Accessors
104
449
 
105
450
  ### historyInterval
@@ -130,6 +475,10 @@ set static historyInterval(value): void;
130
475
 
131
476
  `void`
132
477
 
478
+ ### Inherited from
479
+
480
+ [`Base`](#Base).[`historyInterval`](Base.md#historyinterval)
481
+
133
482
  ***
134
483
 
135
484
  ### historyTime
@@ -160,6 +509,10 @@ set static historyTime(value): void;
160
509
 
161
510
  `void`
162
511
 
512
+ ### Inherited from
513
+
514
+ [`Base`](#Base).[`historyTime`](Base.md#historytime)
515
+
163
516
  ***
164
517
 
165
518
  ### maxGcFrequency
@@ -190,6 +543,10 @@ set static maxGcFrequency(value): void;
190
543
 
191
544
  `void`
192
545
 
546
+ ### Inherited from
547
+
548
+ [`Base`](#Base).[`maxGcFrequency`](Base.md#maxgcfrequency)
549
+
193
550
  ***
194
551
 
195
552
  ### maxHistoryDepth
@@ -204,6 +561,10 @@ get static maxHistoryDepth(): number;
204
561
 
205
562
  `number`
206
563
 
564
+ ### Inherited from
565
+
566
+ [`Base`](#Base).[`maxHistoryDepth`](Base.md#maxhistorydepth)
567
+
207
568
  ***
208
569
 
209
570
  ### logger
@@ -211,12 +572,16 @@ get static maxHistoryDepth(): number;
211
572
  ### Get Signature
212
573
 
213
574
  ```ts
214
- get logger(): undefined | Logger;
575
+ get logger(): Logger | undefined;
215
576
  ```
216
577
 
217
578
  #### Returns
218
579
 
219
- `undefined` \| `Logger`
580
+ `Logger` \| `undefined`
581
+
582
+ ### Inherited from
583
+
584
+ [`Base`](#Base).[`logger`](Base.md#logger)
220
585
 
221
586
  ***
222
587
 
@@ -225,12 +590,16 @@ get logger(): undefined | Logger;
225
590
  ### Get Signature
226
591
 
227
592
  ```ts
228
- get meter(): undefined | Meter;
593
+ get meter(): Meter | undefined;
229
594
  ```
230
595
 
231
596
  #### Returns
232
597
 
233
- `undefined` \| `Meter`
598
+ `Meter` \| `undefined`
599
+
600
+ ### Inherited from
601
+
602
+ [`Base`](#Base).[`meter`](Base.md#meter)
234
603
 
235
604
  ***
236
605
 
@@ -246,6 +615,10 @@ get params(): BaseParams<TParams>;
246
615
 
247
616
  [`BaseParams`](#../type-aliases/BaseParams)\<`TParams`\>
248
617
 
618
+ ### Inherited from
619
+
620
+ [`Base`](#Base).[`params`](Base.md#params)
621
+
249
622
  ***
250
623
 
251
624
  ### tracer
@@ -253,12 +626,16 @@ get params(): BaseParams<TParams>;
253
626
  ### Get Signature
254
627
 
255
628
  ```ts
256
- get tracer(): undefined | Tracer;
629
+ get tracer(): Tracer | undefined;
257
630
  ```
258
631
 
259
632
  #### Returns
260
633
 
261
- `undefined` \| `Tracer`
634
+ `Tracer` \| `undefined`
635
+
636
+ ### Inherited from
637
+
638
+ [`Base`](#Base).[`tracer`](Base.md#tracer)
262
639
 
263
640
  ## Methods
264
641
 
@@ -280,6 +657,10 @@ static gc(force?): void;
280
657
 
281
658
  `void`
282
659
 
660
+ #### Inherited from
661
+
662
+ [`Base`](#Base).[`gc`](Base.md#gc)
663
+
283
664
  ### Call Signature
284
665
 
285
666
  ```ts
@@ -290,12 +671,16 @@ static gc(className): void;
290
671
 
291
672
  ##### className
292
673
 
293
- `string`
674
+ [`BaseClassName`](#../type-aliases/BaseClassName)
294
675
 
295
676
  #### Returns
296
677
 
297
678
  `void`
298
679
 
680
+ #### Inherited from
681
+
682
+ [`Base`](#Base).[`gc`](Base.md#gc)
683
+
299
684
  ***
300
685
 
301
686
  ### instanceCount()
@@ -308,12 +693,16 @@ static instanceCount(className): number;
308
693
 
309
694
  #### className
310
695
 
311
- `string`
696
+ [`BaseClassName`](#../type-aliases/BaseClassName)
312
697
 
313
698
  ### Returns
314
699
 
315
700
  `number`
316
701
 
702
+ ### Inherited from
703
+
704
+ [`Base`](#Base).[`instanceCount`](Base.md#instancecount)
705
+
317
706
  ***
318
707
 
319
708
  ### instanceCounts()
@@ -326,6 +715,10 @@ static instanceCounts(): Record<BaseClassName, number>;
326
715
 
327
716
  `Record`\<[`BaseClassName`](#../type-aliases/BaseClassName), `number`\>
328
717
 
718
+ ### Inherited from
719
+
720
+ [`Base`](#Base).[`instanceCounts`](Base.md#instancecounts)
721
+
329
722
  ***
330
723
 
331
724
  ### startHistory()
@@ -338,6 +731,10 @@ static startHistory(): void;
338
731
 
339
732
  `void`
340
733
 
734
+ ### Inherited from
735
+
736
+ [`Base`](#Base).[`startHistory`](Base.md#starthistory)
737
+
341
738
  ***
342
739
 
343
740
  ### stopHistory()
@@ -350,6 +747,10 @@ static stopHistory(): void;
350
747
 
351
748
  `void`
352
749
 
750
+ ### Inherited from
751
+
752
+ [`Base`](#Base).[`stopHistory`](Base.md#stophistory)
753
+
353
754
  ### functions
354
755
 
355
756
  ### <a id="disableGloballyUnique"></a>disableGloballyUnique
@@ -376,20 +777,20 @@ function disableGloballyUnique(): void;
376
777
  function globallyUnique(
377
778
  name,
378
779
  value,
379
- domain): string;
780
+ domain?): string;
380
781
  ```
381
782
 
382
783
  ## Parameters
383
784
 
384
785
  ### name
385
786
 
386
- `string`
787
+ `string` | `symbol`
387
788
 
388
789
  ### value
389
790
 
390
791
  `unknown`
391
792
 
392
- ### domain
793
+ ### domain?
393
794
 
394
795
  `string` = `'global'`
395
796
 
@@ -406,7 +807,15 @@ function globallyUnique(
406
807
  ***
407
808
 
408
809
  ```ts
409
- type BaseClassName = Exclude<string, "base-class-name-reserved-32546239486">;
810
+ type BaseClassName = string & object;
811
+ ```
812
+
813
+ ## Type Declaration
814
+
815
+ ### \_\_baseClassName
816
+
817
+ ```ts
818
+ __baseClassName: true;
410
819
  ```
411
820
 
412
821
  ### <a id="BaseParams"></a>BaseParams
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/base",
3
- "version": "5.0.80",
3
+ "version": "5.0.82",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -22,32 +22,29 @@
22
22
  "exports": {
23
23
  ".": {
24
24
  "types": "./dist/neutral/index.d.ts",
25
- "source": "./src/index.ts",
26
25
  "default": "./dist/neutral/index.mjs"
27
26
  },
28
27
  "./package.json": "./package.json"
29
28
  },
30
29
  "module": "./dist/neutral/index.mjs",
31
- "source": "./src/index.ts",
32
30
  "types": "./dist/neutral/index.d.ts",
33
31
  "files": [
34
32
  "dist",
35
- "src",
36
33
  "!**/*.bench.*",
37
34
  "!**/*.spec.*",
38
35
  "!**/*.test.*"
39
36
  ],
40
37
  "dependencies": {
41
38
  "@opentelemetry/api": "^1.9.0",
42
- "@xylabs/assert": "~5.0.80",
43
- "@xylabs/logger": "~5.0.80",
44
- "@xylabs/object": "~5.0.80"
39
+ "@xylabs/assert": "~5.0.82",
40
+ "@xylabs/logger": "~5.0.82",
41
+ "@xylabs/object": "~5.0.82"
45
42
  },
46
43
  "devDependencies": {
47
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
48
- "@xylabs/tsconfig": "~7.3.2",
49
- "tslib": "~2.8.1",
50
- "typescript": "~5.9.3"
44
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
45
+ "@xylabs/tsconfig": "~7.4.11",
46
+ "typescript": "~5.9.3",
47
+ "vitest": "~4.0.18"
51
48
  },
52
49
  "publishConfig": {
53
50
  "access": "public"
package/src/Base.ts DELETED
@@ -1,158 +0,0 @@
1
- import type {
2
- Meter,
3
- MeterProvider, Tracer, TracerProvider,
4
- } from '@opentelemetry/api'
5
- import { assertEx } from '@xylabs/assert'
6
- import type { Logger } from '@xylabs/logger'
7
- import type { EmptyObject } from '@xylabs/object'
8
-
9
- const DEFAULT_HISTORY_INTERVAL = 1000 * 5
10
- const DEFAULT_HISTORY_TIME = 60 * 60 * 1000
11
- const MAX_GC_FREQUENCY = 1000 * 60
12
- const MIN_GC_FREQUENCY = 1000
13
- const MIN_HISTORY_INTERVAL = 1000
14
-
15
- export type BaseClassName = string & { __baseClassName: true }
16
-
17
- export type BaseParamsFields = {
18
- logger?: Logger
19
- meterProvider?: MeterProvider
20
- traceProvider?: TracerProvider
21
- }
22
-
23
- export type BaseParams<TAdditionalParams extends EmptyObject = EmptyObject> = TAdditionalParams & BaseParamsFields
24
-
25
- export abstract class Base<TParams extends BaseParams = BaseParams> {
26
- static defaultLogger?: Logger
27
- static readonly globalInstances: Record<BaseClassName, WeakRef<Base>[]> = {}
28
- static readonly globalInstancesCountHistory: Record<BaseClassName, number[]> = {}
29
- private static _historyInterval = DEFAULT_HISTORY_INTERVAL
30
- private static _historyTime = DEFAULT_HISTORY_TIME
31
- private static _historyTimeout?: ReturnType<typeof setTimeout>
32
- private static _lastGC = 0
33
- private static _maxGcFrequency = MAX_GC_FREQUENCY
34
- private _params: BaseParams<TParams>
35
-
36
- constructor(params: BaseParams<TParams>) {
37
- this._params = params
38
- params?.logger?.debug(`Base constructed [${Object(this).name}]`)
39
- this.recordInstance()
40
- }
41
-
42
- static get historyInterval() {
43
- return this._historyInterval
44
- }
45
-
46
- static set historyInterval(value: number) {
47
- assertEx(value <= this.historyTime, () => `historyInterval [${value}] must be less than or equal to historyTime [${this.historyTime}]`)
48
- this._historyInterval = Math.max(value, MIN_HISTORY_INTERVAL)
49
- }
50
-
51
- static get historyTime() {
52
- return this._historyTime
53
- }
54
-
55
- static set historyTime(value: number) {
56
- assertEx(value >= this.historyInterval, () => `historyTime [${value}] must be greater than or equal to historyInterval [${this.historyInterval}]`)
57
- this._historyInterval = value
58
- }
59
-
60
- static get maxGcFrequency() {
61
- return this._maxGcFrequency
62
- }
63
-
64
- static set maxGcFrequency(value: number) {
65
- this._maxGcFrequency = Math.max(value, MIN_GC_FREQUENCY)
66
- }
67
-
68
- static get maxHistoryDepth() {
69
- return Math.floor(this.historyTime / this.historyInterval)
70
- }
71
-
72
- get logger() {
73
- return this.params?.logger ?? Base.defaultLogger
74
- }
75
-
76
- get meter(): Meter | undefined {
77
- return this.params?.meterProvider?.getMeter(this.constructor.name)
78
- }
79
-
80
- get params() {
81
- return this._params
82
- }
83
-
84
- get tracer(): Tracer | undefined {
85
- return this.params?.traceProvider?.getTracer(this.constructor.name)
86
- }
87
-
88
- static gc(force?: boolean): void
89
- static gc(className: BaseClassName): void
90
- static gc(classNameOrForce: BaseClassName | boolean = false): void {
91
- if (typeof classNameOrForce === 'string') {
92
- this.gcClass(classNameOrForce)
93
- } else {
94
- if (classNameOrForce || Date.now() - this._lastGC > this._maxGcFrequency) {
95
- this.gcAll()
96
- }
97
- }
98
- }
99
-
100
- static instanceCount(className: BaseClassName): number {
101
- return this.globalInstances[className]?.length ?? 0
102
- }
103
-
104
- static instanceCounts(): Record<BaseClassName, number> {
105
- this.gc()
106
- const result: Record<BaseClassName, number> = {}
107
- for (const [className, instances] of Object.entries(this.globalInstances)) result[className as BaseClassName] = instances.length
108
- return result
109
- }
110
-
111
- static startHistory(): void {
112
- if (this._historyTimeout) {
113
- this.stopHistory()
114
- }
115
-
116
- const timeoutHandler = () => {
117
- if (this._historyTimeout) {
118
- this.addToHistory()
119
- this._historyTimeout = setTimeout(timeoutHandler, this.historyInterval)
120
- }
121
- }
122
-
123
- this._historyTimeout = setTimeout(timeoutHandler, this.historyInterval)
124
- }
125
-
126
- static stopHistory(): void {
127
- if (this._historyTimeout) {
128
- clearTimeout(this._historyTimeout)
129
- this._historyTimeout = undefined
130
- }
131
- }
132
-
133
- private static addToHistory() {
134
- const counts = this.instanceCounts()
135
- for (const className of Object.keys(this.globalInstances) as BaseClassName[]) {
136
- this.globalInstancesCountHistory[className] = this.globalInstancesCountHistory[className]?.slice(-this.maxHistoryDepth) ?? []
137
- this.globalInstancesCountHistory[className].push(counts[className])
138
- }
139
- }
140
-
141
- private static gcAll() {
142
- for (const className of Object.keys(this.globalInstances) as BaseClassName[]) {
143
- this.gcClass(className)
144
- }
145
- }
146
-
147
- private static gcClass(className: BaseClassName) {
148
- // remove all the weak refs that are now empty
149
- this.globalInstances[className] = this.globalInstances[className]?.filter(ref => ref.deref() !== null) ?? []
150
- }
151
-
152
- private recordInstance() {
153
- const baseClassName = this.constructor.name as BaseClassName
154
- const instanceArray = Base.globalInstances[baseClassName] ?? []
155
- instanceArray.push(new WeakRef(this))
156
- Base.globalInstances[baseClassName] = instanceArray
157
- }
158
- }
package/src/UniqueBase.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { BaseParams } from './Base.ts'
2
- import { Base } from './Base.ts'
3
- import { globallyUnique } from './globallyUnique.ts'
4
-
5
- export abstract class UniqueBase<TParams extends BaseParams = BaseParams> extends Base<TParams> {
6
- static readonly uniqueDomain = 'xy'
7
- static readonly uniqueName = globallyUnique(this.name, this, this.uniqueDomain)
8
- // TODO: Remove xyo domain version when old xyo versions are no longer needed
9
- static readonly uniqueNameXyo = globallyUnique(this.name, this, 'xyo')
10
- constructor(params: BaseParams<TParams>) {
11
- super(params)
12
- }
13
- }
@@ -1,33 +0,0 @@
1
- declare global {
2
- var xylabs: {
3
- unique: Record<string, unknown>
4
- uniqueDisabled?: boolean
5
- }
6
- }
7
-
8
- const xyoGlobal = () => {
9
- globalThis.xylabs = globalThis.xylabs ?? {}
10
- return globalThis.xylabs
11
- }
12
-
13
- export const disableGloballyUnique = () => {
14
- xyoGlobal().uniqueDisabled = true
15
- }
16
-
17
- export const globallyUnique = (name: string | symbol, value: unknown, domain = 'global') => {
18
- const uniqueName = domain === 'bundle' ? [domain, name].join(':') : [domain, import.meta.url, name].join(':')
19
- if (!xyoGlobal().uniqueDisabled) {
20
- const xylabs = globalThis.xylabs = globalThis.xylabs ?? {}
21
- const unique = (xylabs.unique = xylabs.unique ?? {})
22
- if (unique[uniqueName] === undefined) {
23
- unique[uniqueName] = value
24
- } else {
25
- if (unique[uniqueName] !== value) {
26
- throw new Error(
27
- `Global unique item ${uniqueName} already defined. Make sure you are not importing two versions of the package that contains this item`,
28
- )
29
- }
30
- }
31
- }
32
- return uniqueName
33
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './Base.ts'
2
- export * from './globallyUnique.ts'
3
- export * from './UniqueBase.ts'