topsyde-utils 1.0.48 → 1.0.49

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.
@@ -3,7 +3,17 @@ export type Constructor<T> = (abstract new (...args: any[]) => T) | (new (...arg
3
3
  } & Function);
4
4
  declare abstract class Singleton {
5
5
  private static readonly instances;
6
+ private static readonly shareInstances;
6
7
  protected constructor();
8
+ /**
9
+ * Configure a class to share instances with its base class
10
+ * @param classRef The class to configure
11
+ * @param share Whether to share instances with the base class (default: true)
12
+ */
13
+ static ShareInstanceWithBaseClass<T extends Singleton>(classRef: Constructor<T>, share?: boolean): void;
14
+ /**
15
+ * Get the instance for a class, respecting the sharing configuration
16
+ */
7
17
  static GetInstance<T extends Singleton>(this: Constructor<T>, ...args: any[]): T;
8
18
  static GetInstanceCount(): number;
9
19
  }
package/dist/singleton.js CHANGED
@@ -2,9 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class Singleton {
4
4
  constructor() { }
5
+ /**
6
+ * Configure a class to share instances with its base class
7
+ * @param classRef The class to configure
8
+ * @param share Whether to share instances with the base class (default: true)
9
+ */
10
+ static ShareInstanceWithBaseClass(classRef, share = true) {
11
+ Singleton.shareInstances.set(classRef, share);
12
+ }
13
+ /**
14
+ * Get the instance for a class, respecting the sharing configuration
15
+ */
5
16
  static GetInstance(...args) {
6
17
  const classReference = this;
7
- // If we already have an instance for this exact class, return it
18
+ // Check if this class should share instances
19
+ const shouldShare = Singleton.shareInstances.get(classReference) === true;
20
+ // If we already have an instance for this class, return it
8
21
  if (Singleton.instances.has(classReference)) {
9
22
  return Singleton.instances.get(classReference);
10
23
  }
@@ -19,5 +32,7 @@ class Singleton {
19
32
  }
20
33
  // Store instances by class
21
34
  Singleton.instances = new Map();
35
+ // Flag to determine if a class should share instances with its base class
36
+ Singleton.shareInstances = new Map();
22
37
  exports.default = Singleton;
23
38
  //# sourceMappingURL=singleton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":";;AAEA,MAAe,SAAS;IAIvB,gBAAyB,CAAC;IAEnB,MAAM,CAAC,WAAW,CAA4C,GAAG,IAAW;QAClF,MAAM,cAAc,GAAG,IAAI,CAAC;QAE5B,iEAAiE;QACjE,IAAI,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,OAAO,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAM,CAAC;QACrD,CAAC;QAED,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,IAAK,cAAsB,CAAC,GAAG,IAAI,CAAC,CAAC;QACtD,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO,QAAa,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,gBAAgB;QAC7B,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;IACjC,CAAC;;AAtBD,2BAA2B;AACH,mBAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;AAwBpE,kBAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":";;AAEA,MAAe,SAAS;IAOvB,gBAAyB,CAAC;IAE1B;;;;OAIG;IACI,MAAM,CAAC,0BAA0B,CAAsB,QAAwB,EAAE,QAAiB,IAAI;QAC5G,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,WAAW,CAA4C,GAAG,IAAW;QAClF,MAAM,cAAc,GAAG,IAAI,CAAC;QAE5B,6CAA6C;QAC7C,MAAM,WAAW,GAAG,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;QAE1E,2DAA2D;QAC3D,IAAI,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,OAAO,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAM,CAAC;QACrD,CAAC;QAED,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,IAAK,cAAsB,CAAC,GAAG,IAAI,CAAC,CAAC;QACtD,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAElD,OAAO,QAAa,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,gBAAgB;QAC7B,OAAO,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;IACjC,CAAC;;AAxCD,2BAA2B;AACH,mBAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;AAEnE,0EAA0E;AAClD,wBAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;AAuCvE,kBAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topsyde-utils",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "A bundle of TypeScript utility classes and functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,6 +8,22 @@
8
8
  "dist",
9
9
  "dist/**/*"
10
10
  ],
11
+ "scripts": {
12
+ "clean": "rimraf dist",
13
+ "format": "prettier --cache --write \"**/*.ts\"",
14
+ "format:generated": "prettier --cache --write \"src/index.ts\"",
15
+ "generate-indexes": "bash ./scripts/generate-indexes.sh",
16
+ "build:ts": "tsc",
17
+ "build:types": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
18
+ "build:prepare": "bun run clean && bun run generate-indexes && bun run format:generated",
19
+ "build": "bun run build:prepare && bun run build:ts && bun run build:types",
20
+ "test": "npx jest --no-coverage --testPathIgnorePatterns=src/__tests__/app.test.ts",
21
+ "test:bun": "bun test",
22
+ "release": "./scripts/release.sh",
23
+ "release:dry-run": "./scripts/release.sh --dry-run",
24
+ "release:test": "./scripts/release.sh --test-publish",
25
+ "version:bump": "npm version --no-git-tag-version"
26
+ },
11
27
  "exports": {
12
28
  ".": {
13
29
  "types": "./dist/index.d.ts",
@@ -39,21 +55,6 @@
39
55
  ]
40
56
  }
41
57
  },
42
- "scripts": {
43
- "clean": "rimraf dist",
44
- "format": "prettier --cache --write \"**/*.ts\"",
45
- "format:generated": "prettier --cache --write \"src/index.ts\"",
46
- "generate-indexes": "bash ./scripts/generate-indexes.sh",
47
- "build:ts": "tsc",
48
- "build:types": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
49
- "build:prepare": "bun run clean && bun run generate-indexes && bun run format:generated",
50
- "build": "bun run build:prepare && bun run build:ts && bun run build:types",
51
- "test": "bun test",
52
- "release": "./scripts/release.sh",
53
- "release:dry-run": "./scripts/release.sh --dry-run",
54
- "release:test": "./scripts/release.sh --test-publish",
55
- "version:bump": "npm version --no-git-tag-version"
56
- },
57
58
  "keywords": [
58
59
  "typescript",
59
60
  "utilities",