@suey/rxp-meta 0.0.3 → 0.1.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 (41) hide show
  1. package/dist/commonjs/index.js +0 -3
  2. package/dist/commonjs/src/base/InnerZustandStoreManager.js +15 -12
  3. package/dist/commonjs/src/base/index.js +17 -0
  4. package/dist/commonjs/src/base/rxpInnerStore.js +65 -0
  5. package/dist/commonjs/src/constants/index.js +25 -0
  6. package/dist/commonjs/src/extension/At.js +113 -0
  7. package/dist/commonjs/src/extension/ExtensionManager.js +66 -101
  8. package/dist/commonjs/src/extension/ExtensionManager.old.js +156 -0
  9. package/dist/commonjs/src/metadata/MetadataManager.js +102 -100
  10. package/dist/commonjs/src/metadata/MetadataManager.old.js +171 -0
  11. package/dist/commonjs/tsconfig.tsbuildinfo +1 -1
  12. package/dist/esm/index.js +0 -1
  13. package/dist/esm/src/base/InnerZustandStoreManager.js +15 -12
  14. package/dist/esm/src/base/index.js +1 -0
  15. package/dist/esm/src/base/rxpInnerStore.js +61 -0
  16. package/dist/esm/src/constants/index.js +22 -0
  17. package/dist/esm/src/extension/At.js +109 -0
  18. package/dist/esm/src/extension/ExtensionManager.js +64 -100
  19. package/dist/esm/src/extension/ExtensionManager.old.js +152 -0
  20. package/dist/esm/src/metadata/MetadataManager.js +103 -101
  21. package/dist/esm/src/metadata/MetadataManager.old.js +167 -0
  22. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  23. package/dist/lib/index.d.ts +0 -1
  24. package/dist/lib/src/base/InnerZustandStoreManager.d.ts +11 -3
  25. package/dist/lib/src/base/index.d.ts +1 -0
  26. package/dist/lib/src/base/rxpInnerStore.d.ts +40 -0
  27. package/dist/lib/src/constants/index.d.ts +19 -0
  28. package/dist/lib/src/extension/At.d.ts +53 -0
  29. package/dist/lib/src/extension/ExtensionManager.d.ts +52 -9
  30. package/dist/lib/src/extension/ExtensionManager.old.d.ts +52 -0
  31. package/dist/lib/src/extension/declare.d.ts +9 -8
  32. package/dist/lib/src/extension/index.d.ts +2 -1
  33. package/dist/lib/src/metadata/MetadataManager.d.ts +64 -15
  34. package/dist/lib/src/metadata/MetadataManager.old.d.ts +125 -0
  35. package/dist/lib/src/metadata/declare.d.ts +2 -12
  36. package/dist/lib/src/metadata/index.d.ts +0 -1
  37. package/dist/lib/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +3 -6
  39. package/dist/commonjs/src/rApp.js +0 -102
  40. package/dist/esm/src/rApp.js +0 -99
  41. package/dist/lib/src/rApp.d.ts +0 -99
@@ -0,0 +1,109 @@
1
+ import { InnerZustandStoreManager } from '../base/InnerZustandStoreManager';
2
+ import { ExtensionErrors } from '../constants';
3
+ export const ExtensionSymbolTag = Symbol('ExtensionSymbolTag');
4
+ export const ExtensionSymbolTagKey = Symbol('__TAG__');
5
+ export class ExtensionManager extends InnerZustandStoreManager {
6
+ defineExtension(define) {
7
+ if (!Reflect.has(define, 'name'))
8
+ throw new Error(ExtensionErrors.ExtensionNameIsRequired);
9
+ if (!(typeof define.name === 'string'))
10
+ throw new Error(ExtensionErrors.ExtensionNameMustBeString);
11
+ if (!Reflect.has(define, 'version'))
12
+ throw new Error(ExtensionErrors.ExtensionVersionIsRequired);
13
+ if (!(typeof define.version === 'string'))
14
+ throw new Error(ExtensionErrors.ExtensionVersionMustBeString);
15
+ if (!Reflect.has(define, 'onActivated'))
16
+ throw new Error(ExtensionErrors.ExtensionOnActivatedIsRequired);
17
+ if (typeof define.onActivated !== 'function')
18
+ throw new Error(ExtensionErrors.ExtensionOnActivatedMustBeFunction);
19
+ const name = define['name'];
20
+ const version = define['version'];
21
+ const extensionInnerInstance = {
22
+ name: name,
23
+ version: version,
24
+ isRegistered: false,
25
+ isUnregistered: false,
26
+ isActivated: false,
27
+ isDeactivated: false,
28
+ };
29
+ const that = this;
30
+ const onInstalled = function () {
31
+ };
32
+ const extension = {
33
+ get name() {
34
+ return extensionInnerInstance.name;
35
+ },
36
+ get version() {
37
+ return extensionInnerInstance.version;
38
+ },
39
+ get isInstalled() {
40
+ return extensionInnerInstance.isRegistered;
41
+ },
42
+ get isUninstalled() {
43
+ return extensionInnerInstance.isUnregistered;
44
+ },
45
+ get isActivated() {
46
+ return extensionInnerInstance.isActivated;
47
+ },
48
+ get isDeactivated() {
49
+ return extensionInnerInstance.isDeactivated;
50
+ },
51
+ meta: define['meta'] ?? void 0,
52
+ get onInstalled() {
53
+ return onInstalled;
54
+ },
55
+ get onUninstalled() {
56
+ return () => {
57
+ };
58
+ },
59
+ get onActivated() {
60
+ return () => {
61
+ return () => {
62
+ };
63
+ };
64
+ },
65
+ get onDeactivated() {
66
+ return () => {
67
+ };
68
+ }
69
+ };
70
+ Reflect.defineProperty(extension, ExtensionSymbolTagKey, {
71
+ enumerable: false,
72
+ writable: false,
73
+ value: ExtensionSymbolTag,
74
+ configurable: false
75
+ });
76
+ return extension;
77
+ }
78
+ isExtension(extension) {
79
+ if (typeof extension !== 'object' || extension === null)
80
+ return false;
81
+ if (!Reflect.has(extension, ExtensionSymbolTagKey))
82
+ return false;
83
+ const tag = Reflect.get(extension, ExtensionSymbolTagKey);
84
+ return tag === ExtensionSymbolTag;
85
+ }
86
+ registerExtension(extensionName) {
87
+ if (!(typeof extensionName === 'string'))
88
+ throw new Error(ExtensionErrors.ExtensionNameMustBeString);
89
+ if (!this.isExtension(extensionName))
90
+ throw new Error(ExtensionErrors.ExtensionIsNotExist);
91
+ const extension = this.getExtension(extensionName);
92
+ if (!extension)
93
+ throw new Error(ExtensionErrors.ExtensionIsNotExist);
94
+ extension.onInstalled?.();
95
+ }
96
+ unregisterExtension() {
97
+ }
98
+ activatedExtension() {
99
+ }
100
+ deactivatedExtension() {
101
+ }
102
+ getExtension(extensionName) {
103
+ }
104
+ getExtensions() {
105
+ }
106
+ useExtensionsList() {
107
+ }
108
+ }
109
+ 0;
@@ -1,70 +1,51 @@
1
- import { InnerZustandStoreManager } from '../base/InnerZustandStoreManager';
2
1
  import { useState } from 'react';
2
+ import { RxpInnerStore } from '../base/index';
3
3
  const ExtensionSymbolTag = Symbol('ExtensionSymbolTag');
4
- export class ExtensionManager extends InnerZustandStoreManager {
5
- extNameMapStore = new Map();
6
- defineExtension(define) {
7
- if (!Reflect.has(define, 'name'))
8
- throw new Error(`Extension name is required`);
9
- if (!(typeof define.name === 'symbol') &&
10
- !(typeof define.name === 'string'))
11
- throw new Error(`Extension name must be symbol or string`);
12
- if (!Reflect.has(define, 'version'))
13
- throw new Error(`Extension version is required`);
14
- if (Reflect.has(define, 'onActivated') && !Reflect.has(define, 'onDeactivated'))
15
- throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
16
- if (Reflect.has(define, 'onDeactivated') && !Reflect.has(define, 'onActivated'))
17
- throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
18
- const name = define.name;
19
- const version = define.version;
20
- const onActivated = define.onActivated;
21
- const onDeactivated = define.onDeactivated;
22
- const extension = {
23
- ...define,
24
- onActivated: async (...args) => {
25
- if (!this.extNameMapStore.has(name)) {
26
- console.error(`当前扩展还未注册加载, 但却错误得试图激活`);
27
- return;
28
- }
29
- const lifecycle = this.extNameMapStore.get(name);
30
- if (!lifecycle)
31
- return;
32
- if (lifecycle.isActivated) {
33
- console.error(`当前扩展已被激活, 但却错误得试图再次激活`);
34
- return;
35
- }
36
- await onActivated?.call(extension, ...args);
37
- lifecycle.isActivated = true;
38
- },
39
- onDeactivated: async (...args) => {
40
- if (!this.extNameMapStore.has(name)) {
41
- console.error(`当前扩展还未注册加载, 但却错误得试图去活`);
42
- return;
43
- }
44
- const lifecycle = this.extNameMapStore.get(name);
45
- if (!lifecycle)
46
- return;
47
- if (!lifecycle.isActivated) {
48
- console.error(`当前扩展未被激活, 但却错误得试图去活`);
49
- return;
50
- }
51
- await onDeactivated?.call(extension, ...args);
52
- lifecycle.isActivated = false;
53
- }
54
- };
55
- Reflect.defineProperty(extension, '__TAG__', {
56
- enumerable: false,
57
- writable: false,
58
- value: ExtensionSymbolTag,
59
- configurable: false
60
- });
61
- return extension;
4
+ export class Extension {
5
+ __TAG__ = ExtensionSymbolTag;
6
+ isActivated = false;
7
+ name;
8
+ version;
9
+ meta;
10
+ onActivated;
11
+ onDeactivated;
12
+ constructor(options) {
13
+ const { name, version, meta, onActivated, onDeactivated } = options;
14
+ this.name = name;
15
+ this.version = version;
16
+ this.meta = meta;
17
+ this.onActivated = onActivated;
18
+ this.onDeactivated = onDeactivated;
62
19
  }
63
- isExtension(extension) {
20
+ getIsActivated() {
21
+ return this.isActivated;
22
+ }
23
+ async activated() {
24
+ await this.onActivated();
25
+ this.isActivated = true;
26
+ }
27
+ async deactivated() {
28
+ await this.onDeactivated?.();
29
+ this.isActivated = false;
30
+ }
31
+ static isExtension(extension) {
64
32
  if (typeof extension !== 'object')
65
33
  return false;
66
34
  const hasTAG = Reflect.has(extension, '__TAG__');
67
- return hasTAG;
35
+ if (!hasTAG)
36
+ return false;
37
+ const tag = Reflect.get(extension, '__TAG__');
38
+ return tag === ExtensionSymbolTag;
39
+ }
40
+ }
41
+ export class ExtensionManager {
42
+ rxpInnerStore = new RxpInnerStore();
43
+ extNameMapStore = new Map();
44
+ defineExtension(define) {
45
+ return new Extension(define);
46
+ }
47
+ isExtension(extension) {
48
+ return Extension.isExtension(extension);
68
49
  }
69
50
  hasExtension(extensionName) {
70
51
  const has = this.extNameMapStore.has(extensionName);
@@ -76,7 +57,7 @@ export class ExtensionManager extends InnerZustandStoreManager {
76
57
  getExtension(extensionName) {
77
58
  if (!this.hasExtension(extensionName))
78
59
  return null;
79
- return this.extNameMapStore.get(extensionName)?.extension ?? null;
60
+ return this.extNameMapStore.get(extensionName) ?? null;
80
61
  }
81
62
  registerExtension(extension) {
82
63
  if (!this.isExtension(extension))
@@ -86,47 +67,31 @@ export class ExtensionManager extends InnerZustandStoreManager {
86
67
  console.error(`试图重新注册一个已存在得扩展:应该先移除再注册`);
87
68
  return;
88
69
  }
89
- const extensionLifecycle = {
90
- extension: extension,
91
- isActivated: false,
92
- };
93
- this.extNameMapStore.set(name, extensionLifecycle);
70
+ this.extNameMapStore.set(name, extension);
71
+ this.rxpInnerStore.update();
94
72
  }
95
- async activatedExtension(name, context) {
96
- const lifecycle = this.extNameMapStore.get(name);
97
- if (!lifecycle)
73
+ async activatedExtension(name) {
74
+ const extension = this.extNameMapStore.get(name);
75
+ if (!extension)
98
76
  throw new Error(`试图激活一个不存在得扩展`);
99
- if (lifecycle.isActivated)
100
- return;
101
- if (lifecycle.extension.onActivated)
102
- await lifecycle.extension.onActivated(context);
103
- lifecycle.isActivated = true;
77
+ return extension.activated();
104
78
  }
105
- async deactivatedExtension(name, context) {
106
- const lifecycle = this.extNameMapStore.get(name);
107
- if (!lifecycle)
79
+ async deactivatedExtension(name) {
80
+ const extension = this.extNameMapStore.get(name);
81
+ if (!extension)
108
82
  throw new Error(`试图去活一个不存在得扩展`);
109
- if (!lifecycle.isActivated)
110
- return;
111
- if (lifecycle.extension.onDeactivated)
112
- await lifecycle.extension.onDeactivated(context);
113
- lifecycle.isActivated = false;
83
+ return extension.deactivated();
114
84
  }
115
- async delExtension(name, context) {
116
- const lifecycle = this.extNameMapStore.get(name);
117
- if (!lifecycle)
85
+ async delExtension(name) {
86
+ const extension = this.extNameMapStore.get(name);
87
+ if (!extension)
118
88
  throw new Error(`试图删除一个不存在得扩展`);
119
- if (lifecycle.isActivated) {
120
- if (lifecycle.extension.onDeactivated) {
121
- await lifecycle.extension.onDeactivated(context);
122
- }
123
- }
124
- if (!lifecycle.isActivated) {
125
- this.extNameMapStore.delete(name);
126
- }
89
+ extension.deactivated();
90
+ this.extNameMapStore.delete(name);
91
+ this.rxpInnerStore.update();
127
92
  }
128
93
  useExtensionsList() {
129
- const value = this.useStoreValue();
94
+ const value = this.rxpInnerStore.useValueToRenderReactComponent();
130
95
  const [statusState] = useState(() => ({
131
96
  value: void 0
132
97
  }));
@@ -135,12 +100,11 @@ export class ExtensionManager extends InnerZustandStoreManager {
135
100
  });
136
101
  if (statusState.value !== value) {
137
102
  statusState.value = value;
138
- const extensions = [];
139
- for (const ext of this.extNameMapStore.values()) {
140
- extensions.push(ext.extension);
141
- }
142
- normalState.extensions = extensions;
103
+ normalState.extensions = [...this.extNameMapStore.values()];
143
104
  }
144
105
  return [normalState.extensions];
145
106
  }
107
+ getExtensions() {
108
+ return [...this.extNameMapStore.values()];
109
+ }
146
110
  }
@@ -0,0 +1,152 @@
1
+ import { InnerZustandStoreManager } from '../base/InnerZustandStoreManager';
2
+ import { useState } from 'react';
3
+ const ExtensionSymbolTag = Symbol('ExtensionSymbolTag');
4
+ export class ExtensionManager extends InnerZustandStoreManager {
5
+ extNameMapStore = new Map();
6
+ defineExtension(define) {
7
+ if (!Reflect.has(define, 'name'))
8
+ throw new Error(`Extension name is required`);
9
+ if (!(typeof define.name === 'string'))
10
+ throw new Error(`Extension name must be string`);
11
+ if (!Reflect.has(define, 'version'))
12
+ throw new Error(`Extension version is required`);
13
+ if (Reflect.has(define, 'onActivated') && !Reflect.has(define, 'onDeactivated'))
14
+ throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
15
+ if (Reflect.has(define, 'onDeactivated') && !Reflect.has(define, 'onActivated'))
16
+ throw new Error(`Extension lifecycle: onActivated and onDeactivated must be set at same time`);
17
+ const name = define.name;
18
+ const version = define.version;
19
+ const onActivated = define.onActivated;
20
+ const onDeactivated = define.onDeactivated;
21
+ const extension = {
22
+ ...define,
23
+ onActivated: async (...args) => {
24
+ if (!this.extNameMapStore.has(name)) {
25
+ console.error(`当前扩展还未注册加载, 但却错误得试图激活`);
26
+ return;
27
+ }
28
+ const lifecycle = this.extNameMapStore.get(name);
29
+ if (!lifecycle)
30
+ return;
31
+ if (lifecycle.isActivated) {
32
+ console.error(`当前扩展已被激活, 但却错误得试图再次激活`);
33
+ return;
34
+ }
35
+ await onActivated?.call(extension, ...args);
36
+ lifecycle.isActivated = true;
37
+ },
38
+ onDeactivated: async (...args) => {
39
+ if (!this.extNameMapStore.has(name)) {
40
+ console.error(`当前扩展还未注册加载, 但却错误得试图去活`);
41
+ return;
42
+ }
43
+ const lifecycle = this.extNameMapStore.get(name);
44
+ if (!lifecycle)
45
+ return;
46
+ if (!lifecycle.isActivated) {
47
+ console.error(`当前扩展未被激活, 但却错误得试图去活`);
48
+ return;
49
+ }
50
+ await onDeactivated?.call(extension, ...args);
51
+ lifecycle.isActivated = false;
52
+ }
53
+ };
54
+ Reflect.defineProperty(extension, '__TAG__', {
55
+ enumerable: false,
56
+ writable: false,
57
+ value: ExtensionSymbolTag,
58
+ configurable: false
59
+ });
60
+ return extension;
61
+ }
62
+ isExtension(extension) {
63
+ if (typeof extension !== 'object')
64
+ return false;
65
+ const hasTAG = Reflect.has(extension, '__TAG__');
66
+ return hasTAG;
67
+ }
68
+ hasExtension(extensionName) {
69
+ const has = this.extNameMapStore.has(extensionName);
70
+ const lifecycle = this.extNameMapStore.get(extensionName);
71
+ if (has && !lifecycle)
72
+ throw new Error(`数据状态异常`);
73
+ return has;
74
+ }
75
+ getExtension(extensionName) {
76
+ if (!this.hasExtension(extensionName))
77
+ return null;
78
+ return this.extNameMapStore.get(extensionName)?.extension ?? null;
79
+ }
80
+ registerExtension(extension) {
81
+ if (!this.isExtension(extension))
82
+ throw new Error(`参数非法, 不是一个有效的扩展`);
83
+ const name = extension.name;
84
+ if (this.hasExtension(name)) {
85
+ console.error(`试图重新注册一个已存在得扩展:应该先移除再注册`);
86
+ return;
87
+ }
88
+ const extensionLifecycle = {
89
+ extension: extension,
90
+ isActivated: false,
91
+ };
92
+ this.extNameMapStore.set(name, extensionLifecycle);
93
+ }
94
+ async activatedExtension(name, context) {
95
+ const lifecycle = this.extNameMapStore.get(name);
96
+ if (!lifecycle)
97
+ throw new Error(`试图激活一个不存在得扩展`);
98
+ if (lifecycle.isActivated)
99
+ return;
100
+ if (lifecycle.extension.onActivated)
101
+ await lifecycle.extension.onActivated(context);
102
+ lifecycle.isActivated = true;
103
+ }
104
+ async deactivatedExtension(name, context) {
105
+ const lifecycle = this.extNameMapStore.get(name);
106
+ if (!lifecycle)
107
+ throw new Error(`试图去活一个不存在得扩展`);
108
+ if (!lifecycle.isActivated)
109
+ return;
110
+ if (lifecycle.extension.onDeactivated)
111
+ await lifecycle.extension.onDeactivated(context);
112
+ lifecycle.isActivated = false;
113
+ }
114
+ async delExtension(name, context) {
115
+ const lifecycle = this.extNameMapStore.get(name);
116
+ if (!lifecycle)
117
+ throw new Error(`试图删除一个不存在得扩展`);
118
+ if (lifecycle.isActivated) {
119
+ if (lifecycle.extension.onDeactivated) {
120
+ await lifecycle.extension.onDeactivated(context);
121
+ }
122
+ }
123
+ if (!lifecycle.isActivated) {
124
+ this.extNameMapStore.delete(name);
125
+ }
126
+ }
127
+ useExtensionsList() {
128
+ const value = this.useStoreValueToRerenderComponent();
129
+ const [statusState] = useState(() => ({
130
+ value: void 0
131
+ }));
132
+ const [normalState] = useState({
133
+ extensions: [],
134
+ });
135
+ if (statusState.value !== value) {
136
+ statusState.value = value;
137
+ const extensions = [];
138
+ for (const ext of this.extNameMapStore.values()) {
139
+ extensions.push(ext.extension);
140
+ }
141
+ normalState.extensions = extensions;
142
+ }
143
+ return [normalState.extensions];
144
+ }
145
+ getExtensions() {
146
+ const extensions = [];
147
+ for (const ext of this.extNameMapStore.values()) {
148
+ extensions.push(ext.extension);
149
+ }
150
+ return extensions;
151
+ }
152
+ }