slicejs-web-framework 3.4.3 → 3.5.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 (27) hide show
  1. package/.opencode/opencode.json +14 -14
  2. package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
  3. package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +468 -468
  4. package/Slice/Components/Structural/Controller/Controller.js +1406 -1198
  5. package/Slice/Components/Structural/Debugger/Debugger.js +1503 -1503
  6. package/Slice/Components/Structural/EventManager/EventManager.js +651 -366
  7. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +368 -30
  8. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -0
  9. package/Slice/Components/Structural/Logger/Logger.js +225 -225
  10. package/Slice/Components/Structural/Router/Router.js +775 -775
  11. package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
  12. package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +106 -106
  13. package/Slice/Slice.js +663 -627
  14. package/Slice/tests/build-singleton.test.js +244 -244
  15. package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -738
  16. package/Slice/tests/context-patch-use.test.js +95 -95
  17. package/Slice/tests/event-emitters.test.js +79 -0
  18. package/Slice/tests/event-registry.test.js +141 -0
  19. package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
  20. package/Slice/tests/leak-orphans.test.js +131 -0
  21. package/Slice/tests/public-env-typed-accessors.test.js +66 -66
  22. package/api/index.js +308 -281
  23. package/api/utils/publicEnvResolver.js +123 -123
  24. package/package.json +44 -44
  25. package/sliceConfig.schema.json +10 -1
  26. package/src/sliceConfig.json +5 -1
  27. package/types/index.d.ts +12 -0
@@ -1,123 +1,123 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
-
3
- const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
4
- const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
5
-
6
- function parseEnvFile(envFilePath) {
7
- if (!envFilePath || !existsSync(envFilePath)) {
8
- return {};
9
- }
10
-
11
- let fileContent;
12
- try {
13
- fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
14
- } catch (error) {
15
- console.error(`Error reading env file ${envFilePath}:`, error);
16
- return {};
17
- }
18
- const parsed = {};
19
- const lines = fileContent.split(/\r?\n/);
20
-
21
- for (const rawLine of lines) {
22
- const line = rawLine.trim();
23
-
24
- if (!line || line.startsWith('#')) {
25
- continue;
26
- }
27
-
28
- const equalsIndex = line.indexOf('=');
29
- if (equalsIndex === -1) {
30
- continue;
31
- }
32
-
33
- let key = line.slice(0, equalsIndex).trim();
34
- if (!key) {
35
- continue;
36
- }
37
-
38
- if (key.startsWith('export ')) {
39
- key = key.slice('export '.length).trim();
40
- }
41
-
42
- let value = line.slice(equalsIndex + 1).trim();
43
-
44
- const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
45
-
46
- if (quotedWithOptionalCommentMatch) {
47
- value = quotedWithOptionalCommentMatch[2];
48
- } else {
49
- value = value.replace(/\s+#.*$/, '').trimEnd();
50
- }
51
-
52
- parsed[key] = value;
53
- }
54
-
55
- return parsed;
56
- }
57
-
58
- function warnSuspiciousKey(key, logger, warnedKeys) {
59
- const upperKey = key.toUpperCase();
60
- const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
61
-
62
- if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
63
- logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
64
- warnedKeys.add(key);
65
- }
66
- }
67
-
68
- function buildPublicPayload({ envFromFile, processEnv, logger }) {
69
- const env = {};
70
- const warnedKeys = new Set();
71
-
72
- for (const [key, value] of Object.entries(envFromFile)) {
73
- if (key.startsWith(PUBLIC_PREFIX)) {
74
- env[key] = String(value ?? '');
75
- warnSuspiciousKey(key, logger, warnedKeys);
76
- }
77
- }
78
-
79
- for (const [key, value] of Object.entries(processEnv || {})) {
80
- if (key.startsWith(PUBLIC_PREFIX)) {
81
- env[key] = String(value ?? '');
82
- warnSuspiciousKey(key, logger, warnedKeys);
83
- }
84
- }
85
-
86
- return env;
87
- }
88
-
89
- export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
90
- const envFromFile = parseEnvFile(envFilePath);
91
- const env = buildPublicPayload({
92
- envFromFile,
93
- processEnv,
94
- logger,
95
- });
96
-
97
- return {
98
- mode,
99
- env,
100
- };
101
- }
102
-
103
- export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
104
- if (mode === 'production') {
105
- let cachedPayload;
106
-
107
- return {
108
- getPayload() {
109
- if (!cachedPayload) {
110
- cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
111
- }
112
-
113
- return cachedPayload;
114
- },
115
- };
116
- }
117
-
118
- return {
119
- getPayload() {
120
- return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
121
- },
122
- };
123
- }
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+
3
+ const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
4
+ const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
5
+
6
+ function parseEnvFile(envFilePath) {
7
+ if (!envFilePath || !existsSync(envFilePath)) {
8
+ return {};
9
+ }
10
+
11
+ let fileContent;
12
+ try {
13
+ fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
14
+ } catch (error) {
15
+ console.error(`Error reading env file ${envFilePath}:`, error);
16
+ return {};
17
+ }
18
+ const parsed = {};
19
+ const lines = fileContent.split(/\r?\n/);
20
+
21
+ for (const rawLine of lines) {
22
+ const line = rawLine.trim();
23
+
24
+ if (!line || line.startsWith('#')) {
25
+ continue;
26
+ }
27
+
28
+ const equalsIndex = line.indexOf('=');
29
+ if (equalsIndex === -1) {
30
+ continue;
31
+ }
32
+
33
+ let key = line.slice(0, equalsIndex).trim();
34
+ if (!key) {
35
+ continue;
36
+ }
37
+
38
+ if (key.startsWith('export ')) {
39
+ key = key.slice('export '.length).trim();
40
+ }
41
+
42
+ let value = line.slice(equalsIndex + 1).trim();
43
+
44
+ const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
45
+
46
+ if (quotedWithOptionalCommentMatch) {
47
+ value = quotedWithOptionalCommentMatch[2];
48
+ } else {
49
+ value = value.replace(/\s+#.*$/, '').trimEnd();
50
+ }
51
+
52
+ parsed[key] = value;
53
+ }
54
+
55
+ return parsed;
56
+ }
57
+
58
+ function warnSuspiciousKey(key, logger, warnedKeys) {
59
+ const upperKey = key.toUpperCase();
60
+ const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
61
+
62
+ if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
63
+ logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
64
+ warnedKeys.add(key);
65
+ }
66
+ }
67
+
68
+ function buildPublicPayload({ envFromFile, processEnv, logger }) {
69
+ const env = {};
70
+ const warnedKeys = new Set();
71
+
72
+ for (const [key, value] of Object.entries(envFromFile)) {
73
+ if (key.startsWith(PUBLIC_PREFIX)) {
74
+ env[key] = String(value ?? '');
75
+ warnSuspiciousKey(key, logger, warnedKeys);
76
+ }
77
+ }
78
+
79
+ for (const [key, value] of Object.entries(processEnv || {})) {
80
+ if (key.startsWith(PUBLIC_PREFIX)) {
81
+ env[key] = String(value ?? '');
82
+ warnSuspiciousKey(key, logger, warnedKeys);
83
+ }
84
+ }
85
+
86
+ return env;
87
+ }
88
+
89
+ export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
90
+ const envFromFile = parseEnvFile(envFilePath);
91
+ const env = buildPublicPayload({
92
+ envFromFile,
93
+ processEnv,
94
+ logger,
95
+ });
96
+
97
+ return {
98
+ mode,
99
+ env,
100
+ };
101
+ }
102
+
103
+ export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
104
+ if (mode === 'production') {
105
+ let cachedPayload;
106
+
107
+ return {
108
+ getPayload() {
109
+ if (!cachedPayload) {
110
+ cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
111
+ }
112
+
113
+ return cachedPayload;
114
+ },
115
+ };
116
+ }
117
+
118
+ return {
119
+ getPayload() {
120
+ return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
121
+ },
122
+ };
123
+ }
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "slicejs-web-framework",
3
- "version": "3.4.3",
4
- "description": "",
5
- "engines": {
6
- "node": ">=20"
7
- },
8
- "scripts": {
9
- "dev": "node ./node_modules/slicejs-cli/client.js dev",
10
- "build": "node ./node_modules/slicejs-cli/client.js build",
11
- "start": "node ./node_modules/slicejs-cli/client.js start",
12
- "test": "echo \"Error: no test specified\" && exit 1",
13
- "slice:init": "node ./node_modules/slicejs-cli/client.js init",
14
- "slice:create": "node ./node_modules/slicejs-cli/client.js component create",
15
- "slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
16
- "slice:list": "node ./node_modules/slicejs-cli/client.js component list",
17
- "slice:start": "node ./node_modules/slicejs-cli/client.js start",
18
- "format": "prettier --write \"**/*.js\"",
19
- "run": "node ./node_modules/slicejs-cli/client.js dev",
20
- "slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
21
- },
22
- "keywords": [],
23
- "author": "",
24
- "license": "ISC",
25
- "type": "module",
26
- "exports": {
27
- ".": "./Slice/Slice.js",
28
- "./api/framework/express.js": "./api/framework/express.js"
29
- },
30
- "types": "./types/index.d.ts",
31
- "dependencies": {
32
- "express": "^4.19.2"
33
- },
34
- "devDependencies": {
35
- "prettier": "3.3.3"
36
- },
37
- "prettier": {
38
- "trailingComma": "es5",
39
- "tabWidth": 3,
40
- "semi": true,
41
- "singleQuote": true,
42
- "printWidth": 120
43
- }
44
- }
1
+ {
2
+ "name": "slicejs-web-framework",
3
+ "version": "3.5.0",
4
+ "description": "",
5
+ "engines": {
6
+ "node": ">=20"
7
+ },
8
+ "scripts": {
9
+ "dev": "node ./node_modules/slicejs-cli/client.js dev",
10
+ "build": "node ./node_modules/slicejs-cli/client.js build",
11
+ "start": "node ./node_modules/slicejs-cli/client.js start",
12
+ "test": "echo \"Error: no test specified\" && exit 1",
13
+ "slice:init": "node ./node_modules/slicejs-cli/client.js init",
14
+ "slice:create": "node ./node_modules/slicejs-cli/client.js component create",
15
+ "slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
16
+ "slice:list": "node ./node_modules/slicejs-cli/client.js component list",
17
+ "slice:start": "node ./node_modules/slicejs-cli/client.js start",
18
+ "format": "prettier --write \"**/*.js\"",
19
+ "run": "node ./node_modules/slicejs-cli/client.js dev",
20
+ "slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "type": "module",
26
+ "exports": {
27
+ ".": "./Slice/Slice.js",
28
+ "./api/framework/express.js": "./api/framework/express.js"
29
+ },
30
+ "types": "./types/index.d.ts",
31
+ "dependencies": {
32
+ "express": "^4.19.2"
33
+ },
34
+ "devDependencies": {
35
+ "prettier": "3.3.3"
36
+ },
37
+ "prettier": {
38
+ "trailingComma": "es5",
39
+ "tabWidth": 3,
40
+ "semi": true,
41
+ "singleQuote": true,
42
+ "printWidth": 120
43
+ }
44
+ }
@@ -10,7 +10,16 @@
10
10
  "additionalProperties": true,
11
11
  "properties": {
12
12
  "enabled": { "type": "boolean" },
13
- "click": { "type": "string", "enum": ["right", "left"] }
13
+ "click": { "type": "string", "enum": ["right", "left"] },
14
+ "leakInspector": {
15
+ "type": "object",
16
+ "additionalProperties": true,
17
+ "description": "Dev-only memory-leak panel. Disabled in production regardless of this flag.",
18
+ "properties": {
19
+ "enabled": { "type": "boolean" },
20
+ "shortcut": { "type": "string" }
21
+ }
22
+ }
14
23
  }
15
24
  },
16
25
  "stylesManager": {
@@ -5,7 +5,11 @@
5
5
  },
6
6
  "debugger": {
7
7
  "enabled": false,
8
- "click": "right"
8
+ "click": "right",
9
+ "leakInspector": {
10
+ "enabled": true,
11
+ "shortcut": "alt+shift+k"
12
+ }
9
13
  },
10
14
  "events": {
11
15
  "enabled": true,
package/types/index.d.ts CHANGED
@@ -44,6 +44,10 @@ export interface SliceControllerApi {
44
44
  destroyComponent(components: HTMLElement | string | Array<HTMLElement | string>): number;
45
45
  destroyByContainer(container: HTMLElement): number;
46
46
  destroyByPattern(pattern: string | RegExp): number;
47
+ findOrphans(): Array<{ sliceId: string; name: string; reason: string; retainPath: string[] }>;
48
+ registerLeakExclusion(predicate: (component: HTMLElement) => boolean): void;
49
+ sampleComponentGrowth(): void;
50
+ isGrowthMonotonic(): boolean;
47
51
  }
48
52
 
49
53
  export interface SliceStylesManagerApi {
@@ -88,6 +92,13 @@ export interface SliceEventManagerApi {
88
92
  unsubscribe(eventName: string, subscriptionId: string): boolean;
89
93
  emit(eventName: string, ...data: unknown[]): void;
90
94
  bind(component: HTMLElement): SliceEventBindingApi | null;
95
+ register(namespace: string, catalog: Record<string, { description?: string; payload?: unknown }>): SliceEventManagerApi;
96
+ register(catalog: Record<string, { description?: string; payload?: unknown }>): SliceEventManagerApi;
97
+ loadGraph(graph: { events: Record<string, unknown>; dynamic?: unknown }): SliceEventManagerApi;
98
+ staticEmittersOf(eventName: string): Array<{ file: string; line: number; component: string | null }>;
99
+ staticListenersOf(eventName: string): Array<{ file: string; line: number; component: string | null }>;
100
+ isDeclared(eventName: string): boolean;
101
+ namespaceOf(eventName: string): string | null;
91
102
  cleanupComponent(sliceId: string): number;
92
103
  hasSubscribers(eventName: string): boolean;
93
104
  subscriberCount(eventName: string): number;
@@ -178,6 +189,7 @@ export interface SliceApi {
178
189
  debugger?: SliceDebuggerApi;
179
190
  eventsDebugger?: SlicePanelDebuggerApi;
180
191
  contextDebugger?: SlicePanelDebuggerApi;
192
+ leakInspector?: SlicePanelDebuggerApi;
181
193
  loading?: SliceLoadingApi;
182
194
  paths: SlicePaths;
183
195
  _mode: SliceMode;