@vnejs/shared 0.0.12 → 0.0.14

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/package.json CHANGED
@@ -1,22 +1,24 @@
1
1
  {
2
2
  "name": "@vnejs/shared",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "src",
10
+ "tsconfig.json"
9
11
  ],
10
12
  "scripts": {
11
13
  "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "rm -rf dist && tsc -p tsconfig.json",
13
- "publish:major": "npm run build && npm version major && npm publish --access public",
14
- "publish:minor": "npm run build && npm version minor && npm publish --access public",
15
- "publish:patch": "npm run build && npm version patch && npm publish --access public"
14
+ "build": "npx @vnejs/monorepo package",
15
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
16
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
17
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
16
18
  },
17
19
  "author": "",
18
20
  "license": "ISC",
19
21
  "devDependencies": {
20
- "typescript": "^6.0.3"
22
+ "@vnejs/configs.ts-common": "~0.0.1"
21
23
  }
22
24
  }
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ export type {
2
+ VneModule,
3
+ VneModuleClass,
4
+ VneNamespace,
5
+ VnePluginConstants,
6
+ VnePluginConstantsMap,
7
+ VnePluginConstantsMapRegistry,
8
+ VnePluginConstantsRegistry,
9
+ VnePluginEvents,
10
+ VnePluginEventsMap,
11
+ VnePluginEventsMapRegistry,
12
+ VnePluginEventsRegistry,
13
+ VnePluginParams,
14
+ VnePluginParamsMap,
15
+ VnePluginParamsMapRegistry,
16
+ VnePluginParamsRegistry,
17
+ VnePluginSettings,
18
+ VnePluginSettingsMap,
19
+ VnePluginSettingsMapRegistry,
20
+ VnePluginSettingsRegistry,
21
+ VnePluginShape,
22
+ VneRegistry,
23
+ } from "./types.js";
24
+
25
+ import type { VneModuleClass, VneNamespace, VnePluginShape, VneRegistry } from "./types.js";
26
+
27
+ export const VNE_MODULES: VneModuleClass[] = [];
28
+
29
+ export const VNE: VneRegistry = { CONST: {}, EVENTS: {}, SETTINGS: {}, PARAMS: {} } as VneRegistry;
30
+
31
+ export const regModule = (Module: VneModuleClass) => {
32
+ if (Module) VNE_MODULES.push(Module);
33
+ return Module;
34
+ };
35
+
36
+ export const regPlugin = (
37
+ namespace: VneNamespace = "",
38
+ { constants = {}, events = {}, settings = {}, params = {} }: VnePluginShape = {},
39
+ modules: VneModuleClass[] = [],
40
+ ) => {
41
+ if (!namespace) return;
42
+
43
+ VNE.EVENTS[namespace] = events;
44
+ VNE.PARAMS[namespace] = params;
45
+ VNE.CONST[namespace] = constants;
46
+ VNE.SETTINGS[namespace] = settings;
47
+
48
+ modules.forEach(regModule);
49
+ };
package/src/types.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Extend in consumer packages via module augmentation:
3
+ *
4
+ * @example
5
+ * declare module "@vnejs/shared" {
6
+ * interface VnePluginEventsMap {
7
+ * SCENARIO: typeof SUBSCRIBE_EVENTS;
8
+ * }
9
+ * interface VnePluginConstantsMap {
10
+ * SCENARIO: typeof constants;
11
+ * }
12
+ * interface VnePluginEvents {
13
+ * CUSTOM: string;
14
+ * }
15
+ * }
16
+ *
17
+ * // Namespace and event keys may be unset until regPlugin runs:
18
+ * VNE.EVENTS.STORAGE?.CLEAR
19
+ */
20
+ export interface VnePluginConstantsMap {}
21
+ export interface VnePluginEventsMap {}
22
+ export interface VnePluginSettingsMap {}
23
+ export interface VnePluginParamsMap {}
24
+
25
+ /** Namespace and its fields may be missing until plugins register (use `?.` when needed). */
26
+ type OptionalPluginMapValues<T> = {
27
+ [K in keyof T]?: T[K] extends object ? Partial<T[K]> & T[K] : T[K];
28
+ };
29
+
30
+ export type VnePluginConstantsMapRegistry = OptionalPluginMapValues<VnePluginConstantsMap> &
31
+ Partial<Record<string, VnePluginConstantsRegistry | undefined>>;
32
+ export type VnePluginEventsMapRegistry = OptionalPluginMapValues<VnePluginEventsMap> &
33
+ Partial<Record<string, VnePluginEventsRegistry | undefined>>;
34
+ export type VnePluginSettingsMapRegistry = OptionalPluginMapValues<VnePluginSettingsMap> &
35
+ Partial<Record<string, VnePluginSettingsRegistry | undefined>>;
36
+ export type VnePluginParamsMapRegistry = OptionalPluginMapValues<VnePluginParamsMap> &
37
+ Partial<Record<string, VnePluginParamsRegistry | undefined>>;
38
+
39
+ /** Fallback shape for one plugin namespace not listed in *Map interfaces. */
40
+ export interface VnePluginConstants {}
41
+ export interface VnePluginEvents {}
42
+ export interface VnePluginSettings {}
43
+ export interface VnePluginParams {}
44
+
45
+ export type VnePluginConstantsRegistry = VnePluginConstants & Partial<Record<string, never>>;
46
+ export type VnePluginEventsRegistry = VnePluginEvents & Partial<Record<string, string>>;
47
+ export type VnePluginSettingsRegistry = VnePluginSettings & Partial<Record<string, string>>;
48
+ export type VnePluginParamsRegistry = VnePluginParams & Partial<Record<string, never>>;
49
+
50
+ export type VneNamespace =
51
+ | keyof VnePluginConstantsMap
52
+ | keyof VnePluginEventsMap
53
+ | keyof VnePluginSettingsMap
54
+ | keyof VnePluginParamsMap
55
+ | (string & {});
56
+
57
+ export type VneRegistry = {
58
+ CONST: VnePluginConstantsMapRegistry;
59
+ EVENTS: VnePluginEventsMapRegistry;
60
+ SETTINGS: VnePluginSettingsMapRegistry;
61
+ PARAMS: VnePluginParamsMapRegistry;
62
+ };
63
+
64
+ export interface VnePluginShape {
65
+ constants?: VnePluginConstantsRegistry;
66
+ events?: VnePluginEventsRegistry;
67
+ settings?: VnePluginSettingsRegistry;
68
+ params?: VnePluginParamsRegistry;
69
+ }
70
+
71
+ export interface VneModule {
72
+ name: string;
73
+ isReady: boolean;
74
+ }
75
+
76
+ export type VneModuleClass = new () => VneModule;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": [
8
+ "src/**/*.ts"
9
+ ],
10
+ "exclude": [
11
+ "dist",
12
+ "node_modules"
13
+ ]
14
+ }