@shopware-ag/dive 1.18.5-beta.2 → 1.18.5

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 (36) hide show
  1. package/README.md +1 -1
  2. package/build/dive.cjs +3856 -1
  3. package/build/dive.cjs.map +1 -1
  4. package/build/dive.js +24728 -6
  5. package/build/dive.js.map +1 -1
  6. package/build/src/ar/arquicklook/ARQuickLook.d.ts +2 -3
  7. package/build/src/com/Communication.d.ts +1 -4
  8. package/build/src/module/Module.d.ts +8 -0
  9. package/package.json +2 -2
  10. package/src/ar/arquicklook/ARQuickLook.ts +75 -48
  11. package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +45 -80
  12. package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -12
  13. package/src/com/Communication.ts +17 -84
  14. package/src/com/__test__/Communication.test.ts +43 -16
  15. package/src/module/Module.ts +45 -0
  16. package/src/module/__test__/Module.test.ts +54 -0
  17. package/build/AR-B-g0updz.js +0 -1450
  18. package/build/AR-B-g0updz.js.map +0 -1
  19. package/build/AR-BWQebw6-.cjs +0 -153
  20. package/build/AR-BWQebw6-.cjs.map +0 -1
  21. package/build/IO-BgiJzKrU.js +0 -1257
  22. package/build/IO-BgiJzKrU.js.map +0 -1
  23. package/build/IO-CuYml7Y5.cjs +0 -2
  24. package/build/IO-CuYml7Y5.cjs.map +0 -1
  25. package/build/MediaCreator-4zmvmUWH.js +0 -22
  26. package/build/MediaCreator-4zmvmUWH.js.map +0 -1
  27. package/build/MediaCreator-BNxZVYyZ.cjs +0 -2
  28. package/build/MediaCreator-BNxZVYyZ.cjs.map +0 -1
  29. package/build/TextureUtils-CxpuVgwF.js +0 -38
  30. package/build/TextureUtils-CxpuVgwF.js.map +0 -1
  31. package/build/TextureUtils-DNG-yR77.cjs +0 -19
  32. package/build/TextureUtils-DNG-yR77.cjs.map +0 -1
  33. package/build/dive-Mi8g8Khn.js +0 -24852
  34. package/build/dive-Mi8g8Khn.js.map +0 -1
  35. package/build/dive-_-yiZbhn.cjs +0 -3857
  36. package/build/dive-_-yiZbhn.cjs.map +0 -1
@@ -0,0 +1,45 @@
1
+ export class DIVEModule<T> {
2
+ constructor(
3
+ private _path: string,
4
+ private _ctor: string,
5
+ ) {}
6
+
7
+ private _promise: Promise<T> | null = null;
8
+ private _instance: T | null = null;
9
+
10
+ public async get(): Promise<T> {
11
+ // if we already have an instance, return it
12
+ if (this._instance) {
13
+ return Promise.resolve(this._instance);
14
+ }
15
+
16
+ // if we already have a loading process ongoing, return the already created promise
17
+ if (this._promise) {
18
+ return this._promise;
19
+ }
20
+
21
+ // if we don't have a promise yet, it means that we are not already loading the module
22
+ this._promise = (async () => {
23
+ const module = await import(this._path);
24
+
25
+ const ModuleConstructor = module[this._ctor];
26
+
27
+ if (!ModuleConstructor) {
28
+ throw new Error(
29
+ `DIVE: Module class ${this._ctor} not found in ${this._path}`,
30
+ );
31
+ }
32
+
33
+ if (typeof ModuleConstructor !== 'function') {
34
+ throw new Error(
35
+ `DIVE: Module at ${this._path} does not export a valid constructor (${this._ctor} wanted)`,
36
+ );
37
+ }
38
+
39
+ this._instance = new ModuleConstructor() as T;
40
+ return this._instance;
41
+ })();
42
+
43
+ return this._promise;
44
+ }
45
+ }
@@ -0,0 +1,54 @@
1
+ import { DIVEModule } from '../Module';
2
+
3
+ jest.mock('/mock/path', () => mockModule, { virtual: true });
4
+
5
+ const mockModule: Record<string, any> = {};
6
+
7
+ describe('dive/module/DIVEModule', () => {
8
+ beforeEach(() => {
9
+ // Reset the mock module before each test
10
+ Object.keys(mockModule).forEach((key) => delete mockModule[key]);
11
+ });
12
+
13
+ it('should return the same instance on multiple calls to get()', async () => {
14
+ mockModule.TestClass = class TestClass {};
15
+ const diveModule = new DIVEModule('/mock/path', 'TestClass');
16
+
17
+ const instance1 = await diveModule.get();
18
+ const instance2 = await diveModule.get();
19
+
20
+ expect(instance1).toBe(instance2);
21
+ });
22
+
23
+ it('should throw an error if the constructor is not found', async () => {
24
+ const diveModule = new DIVEModule('/mock/path', 'NonExistentClass');
25
+
26
+ await expect(diveModule.get()).rejects.toThrow(
27
+ 'DIVE: Module class NonExistentClass not found in /mock/path',
28
+ );
29
+ });
30
+
31
+ it('should throw an error if the constructor is not a function', async () => {
32
+ mockModule.InvalidClass = {};
33
+ const diveModule = new DIVEModule('/mock/path', 'InvalidClass');
34
+
35
+ await expect(diveModule.get()).rejects.toThrow(
36
+ 'DIVE: Module at /mock/path does not export a valid constructor (InvalidClass wanted)',
37
+ );
38
+ });
39
+
40
+ it('should only load the module once even with concurrent calls to get()', async () => {
41
+ mockModule.TestClass = class TestClass {};
42
+ const diveModule = new DIVEModule('/mock/path', 'TestClass');
43
+
44
+ const [
45
+ instance1,
46
+ instance2,
47
+ ] = await Promise.all([
48
+ diveModule.get(),
49
+ diveModule.get(),
50
+ ]);
51
+
52
+ expect(instance1).toBe(instance2);
53
+ });
54
+ });