slicejs-web-framework 4.0.2 → 4.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 (73) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +97 -97
  3. package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
  4. package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +470 -470
  5. package/Slice/Components/Structural/Controller/Controller.js +1406 -1406
  6. package/Slice/Components/Structural/Controller/allowedValuesValidation.js +52 -52
  7. package/Slice/Components/Structural/Debugger/Debugger.html +72 -72
  8. package/Slice/Components/Structural/Debugger/Debugger.js +1505 -1505
  9. package/Slice/Components/Structural/EventManager/EventManager.js +651 -651
  10. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +985 -985
  11. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -296
  12. package/Slice/Components/Structural/Logger/Log.js +10 -10
  13. package/Slice/Components/Structural/Logger/LogViewer/LogViewer.js +662 -662
  14. package/Slice/Components/Structural/Logger/Logger.js +225 -225
  15. package/Slice/Components/Structural/Router/Router.js +820 -810
  16. package/Slice/Components/Structural/Router/applyRouteMetadata.js +39 -0
  17. package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
  18. package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +175 -175
  19. package/Slice/Slice.js +711 -710
  20. package/api/framework/devDepsOptimizer.js +335 -335
  21. package/api/framework/express.js +3 -3
  22. package/api/framework/precompressedStatic.js +102 -93
  23. package/api/framework/publicEnvResolver.js +123 -123
  24. package/api/framework/securityMiddleware.js +197 -197
  25. package/api/framework/seo.js +387 -0
  26. package/api/framework/server.js +777 -410
  27. package/api/index.js +14 -4
  28. package/package.json +6 -2
  29. package/sliceConfig.schema.json +122 -122
  30. package/src/App/index.html +69 -69
  31. package/src/App/index.js +20 -20
  32. package/src/App/style.css +11 -11
  33. package/src/Components/AppComponents/AboutSection/AboutSection.css +9 -9
  34. package/src/Components/AppComponents/AboutSection/AboutSection.html +8 -8
  35. package/src/Components/AppComponents/AboutSection/AboutSection.js +12 -12
  36. package/src/Components/AppComponents/AppShell/AppShell.css +10 -10
  37. package/src/Components/AppComponents/AppShell/AppShell.html +4 -4
  38. package/src/Components/AppComponents/AppShell/AppShell.js +36 -36
  39. package/src/Components/AppComponents/HomeSection/HomeSection.css +20 -20
  40. package/src/Components/AppComponents/HomeSection/HomeSection.html +10 -10
  41. package/src/Components/AppComponents/HomeSection/HomeSection.js +19 -19
  42. package/src/Components/components.js +8 -8
  43. package/src/public/Styles/sliceStyles.css +34 -34
  44. package/src/public/Themes/Dark.css +42 -42
  45. package/src/public/Themes/Light.css +31 -31
  46. package/src/public/Themes/Slice.css +47 -47
  47. package/src/public/manifest.json +15 -15
  48. package/src/public/robots.txt +4 -4
  49. package/src/public/sitemap.xml +8 -8
  50. package/src/routes.js +9 -9
  51. package/src/sliceConfig.json +72 -72
  52. package/types/index.d.ts +219 -219
  53. package/.opencode/opencode.json +0 -15
  54. package/Slice/tests/build-bundled-component-without-category.test.js +0 -103
  55. package/Slice/tests/build-js-only-visual-components.test.js +0 -144
  56. package/Slice/tests/build-singleton.test.js +0 -244
  57. package/Slice/tests/bundle-v2-runtime-contract.test.js +0 -747
  58. package/Slice/tests/context-patch-use.test.js +0 -95
  59. package/Slice/tests/destroy-cascade.test.js +0 -215
  60. package/Slice/tests/event-emitters.test.js +0 -79
  61. package/Slice/tests/event-registry.test.js +0 -141
  62. package/Slice/tests/fixtures/real-runtime-loader.mjs +0 -21
  63. package/Slice/tests/leak-orphans.test.js +0 -131
  64. package/Slice/tests/props-allowed-values-validation.test.js +0 -119
  65. package/Slice/tests/public-env-runtime-accessors.test.js +0 -44
  66. package/Slice/tests/public-env-typed-accessors.test.js +0 -66
  67. package/Slice/tests/router-loading-finally.test.js +0 -68
  68. package/api/tests/dev-deps-optimizer.test.js +0 -137
  69. package/api/tests/dev-server-external.test.js +0 -56
  70. package/api/tests/precompressed-static.test.js +0 -119
  71. package/api/tests/public-env-resolver.test.js +0 -193
  72. package/tests/router-build-failure.test.js +0 -125
  73. package/tests/router-emit-ordering.test.js +0 -63
@@ -1,193 +0,0 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { mkdtemp, rm, writeFile } from 'node:fs/promises';
4
- import path from 'node:path';
5
- import { tmpdir } from 'node:os';
6
-
7
- const resolverModulePath = new URL('../framework/publicEnvResolver.js', import.meta.url);
8
-
9
- async function withTempEnvFile(contents, callback) {
10
- const dir = await mkdtemp(path.join(tmpdir(), 'slice-public-env-'));
11
- const envFilePath = path.join(dir, '.env');
12
-
13
- try {
14
- await writeFile(envFilePath, contents, 'utf8');
15
- await callback(envFilePath);
16
- } finally {
17
- await rm(dir, { recursive: true, force: true });
18
- }
19
- }
20
-
21
- test('resolvePublicEnv filters only SLICE_PUBLIC_ keys', async () => {
22
- const { resolvePublicEnv } = await import(resolverModulePath.href);
23
-
24
- await withTempEnvFile(
25
- ['SLICE_PUBLIC_FROM_FILE=file-visible', 'PRIVATE_KEY=hidden-file-value', 'SLICE_API_URL=hidden-file-api-url'].join('\n'),
26
- async (envFilePath) => {
27
- const payload = resolvePublicEnv({
28
- mode: 'development',
29
- envFilePath,
30
- processEnv: {
31
- SLICE_PUBLIC_FROM_PROCESS: 'process-visible',
32
- SECRET_TOKEN: 'hidden-process-token',
33
- NODE_ENV: 'development',
34
- },
35
- });
36
-
37
- assert.equal(payload.mode, 'development');
38
- assert.deepEqual(payload.env, {
39
- SLICE_PUBLIC_FROM_FILE: 'file-visible',
40
- SLICE_PUBLIC_FROM_PROCESS: 'process-visible',
41
- });
42
- }
43
- );
44
- });
45
-
46
- test('resolvePublicEnv uses process.env values over .env values', async () => {
47
- const { resolvePublicEnv } = await import(resolverModulePath.href);
48
-
49
- await withTempEnvFile('SLICE_PUBLIC_API_URL=https://from-file.example', async (envFilePath) => {
50
- const payload = resolvePublicEnv({
51
- mode: 'development',
52
- envFilePath,
53
- processEnv: {
54
- SLICE_PUBLIC_API_URL: 'https://from-process.example',
55
- },
56
- });
57
-
58
- assert.equal(payload.mode, 'development');
59
- assert.equal(payload.env.SLICE_PUBLIC_API_URL, 'https://from-process.example');
60
- });
61
- });
62
-
63
- test('resolvePublicEnv warns about suspicious public key names without exposing values', async () => {
64
- const { resolvePublicEnv } = await import(resolverModulePath.href);
65
- const warnings = [];
66
- const logger = {
67
- warn: (...args) => warnings.push(args.map(String).join(' ')),
68
- };
69
-
70
- await withTempEnvFile('SLICE_PUBLIC_API_KEY=super-secret-value', async (envFilePath) => {
71
- const payload = resolvePublicEnv({
72
- mode: 'development',
73
- envFilePath,
74
- processEnv: {},
75
- logger,
76
- });
77
-
78
- assert.equal(payload.mode, 'development');
79
- assert.equal(payload.env.SLICE_PUBLIC_API_KEY, 'super-secret-value');
80
- assert.equal(warnings.length, 1);
81
- assert.match(warnings[0], /SLICE_PUBLIC_API_KEY/);
82
- assert.doesNotMatch(warnings[0], /super-secret-value/);
83
- });
84
- });
85
-
86
- test('resolvePublicEnv warns once when suspicious key appears in .env and processEnv', async () => {
87
- const { resolvePublicEnv } = await import(resolverModulePath.href);
88
- const warnings = [];
89
- const logger = {
90
- warn: (...args) => warnings.push(args.map(String).join(' ')),
91
- };
92
-
93
- await withTempEnvFile('SLICE_PUBLIC_API_KEY=from-file-secret', async (envFilePath) => {
94
- const payload = resolvePublicEnv({
95
- mode: 'development',
96
- envFilePath,
97
- processEnv: {
98
- SLICE_PUBLIC_API_KEY: 'from-process-secret',
99
- },
100
- logger,
101
- });
102
-
103
- assert.equal(payload.env.SLICE_PUBLIC_API_KEY, 'from-process-secret');
104
- assert.equal(warnings.length, 1);
105
- assert.match(warnings[0], /SLICE_PUBLIC_API_KEY/);
106
- assert.doesNotMatch(warnings[0], /from-file-secret|from-process-secret/);
107
- });
108
- });
109
-
110
- test('resolvePublicEnv parses first key when .env starts with BOM', async () => {
111
- const { resolvePublicEnv } = await import(resolverModulePath.href);
112
-
113
- await withTempEnvFile('\uFEFFSLICE_PUBLIC_TITLE=Slice App', async (envFilePath) => {
114
- const payload = resolvePublicEnv({
115
- mode: 'development',
116
- envFilePath,
117
- processEnv: {},
118
- });
119
-
120
- assert.equal(payload.env.SLICE_PUBLIC_TITLE, 'Slice App');
121
- });
122
- });
123
-
124
- test('resolvePublicEnv strips inline comments for unquoted values', async () => {
125
- const { resolvePublicEnv } = await import(resolverModulePath.href);
126
-
127
- await withTempEnvFile('SLICE_PUBLIC_ORIGIN=https://slice.dev # dev origin', async (envFilePath) => {
128
- const payload = resolvePublicEnv({
129
- mode: 'development',
130
- envFilePath,
131
- processEnv: {},
132
- });
133
-
134
- assert.equal(payload.env.SLICE_PUBLIC_ORIGIN, 'https://slice.dev');
135
- });
136
- });
137
-
138
- test('resolvePublicEnv strips trailing comments after quoted values', async () => {
139
- const { resolvePublicEnv } = await import(resolverModulePath.href);
140
-
141
- await withTempEnvFile('SLICE_PUBLIC_X="value" # comment', async (envFilePath) => {
142
- const payload = resolvePublicEnv({
143
- mode: 'development',
144
- envFilePath,
145
- processEnv: {},
146
- });
147
-
148
- assert.equal(payload.env.SLICE_PUBLIC_X, 'value');
149
- });
150
- });
151
-
152
- test('createPublicEnvProvider caches in production and recomputes in development', async () => {
153
- const { createPublicEnvProvider } = await import(resolverModulePath.href);
154
-
155
- await withTempEnvFile('SLICE_PUBLIC_COUNTER=from-file', async (envFilePath) => {
156
- let processValue = 'first-value';
157
- const processEnv = {
158
- get SLICE_PUBLIC_COUNTER() {
159
- return processValue;
160
- },
161
- };
162
-
163
- const productionProvider = createPublicEnvProvider({
164
- mode: 'production',
165
- envFilePath,
166
- processEnv,
167
- });
168
- assert.equal(typeof productionProvider.getPayload, 'function');
169
-
170
- const firstProduction = productionProvider.getPayload();
171
- processValue = 'second-value';
172
- const secondProduction = productionProvider.getPayload();
173
-
174
- assert.equal(firstProduction.mode, 'production');
175
- assert.equal(firstProduction.env.SLICE_PUBLIC_COUNTER, 'first-value');
176
- assert.equal(secondProduction.env.SLICE_PUBLIC_COUNTER, 'first-value');
177
-
178
- const developmentProvider = createPublicEnvProvider({
179
- mode: 'development',
180
- envFilePath,
181
- processEnv,
182
- });
183
- assert.equal(typeof developmentProvider.getPayload, 'function');
184
-
185
- const firstDevelopment = developmentProvider.getPayload();
186
- processValue = 'third-value';
187
- const secondDevelopment = developmentProvider.getPayload();
188
-
189
- assert.equal(firstDevelopment.mode, 'development');
190
- assert.equal(firstDevelopment.env.SLICE_PUBLIC_COUNTER, 'second-value');
191
- assert.equal(secondDevelopment.env.SLICE_PUBLIC_COUNTER, 'third-value');
192
- });
193
- });
@@ -1,125 +0,0 @@
1
- // Regression test: handleRoute() must not append a failed build to the DOM.
2
- //
3
- // slice.build() returns null on any unrecoverable path (component not
4
- // registered, a resource fetch failed or was aborted mid-flight, init() threw).
5
- // Passing that null straight to appendChild() raised
6
- // TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
7
- // which surfaced far from the real cause and made the failure look like a DOM
8
- // bug. handleRoute() now reports the build failure and leaves the current view
9
- // in place.
10
- //
11
- // Router has no imports and no module-level DOM access, so its prototype can be
12
- // exercised directly against stubs (same approach as router-emit-ordering).
13
- //
14
- // Run: node --test tests/router-build-failure.test.js
15
-
16
- import { test, describe, before, beforeEach } from 'node:test';
17
- import assert from 'node:assert/strict';
18
-
19
- describe('Router.handleRoute — failed component build', () => {
20
- let Router;
21
- let appended;
22
- let loggedErrors;
23
- let appElement;
24
-
25
- before(async () => {
26
- globalThis.window = globalThis.window || { location: { pathname: '/' } };
27
- globalThis.slice = globalThis.slice || {};
28
- ({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
29
- });
30
-
31
- beforeEach(() => {
32
- appended = [];
33
- loggedErrors = [];
34
- appElement = {
35
- innerHTML: 'previous view',
36
- appendChild(node) {
37
- // Mirror the real DOM contract: appending a non-Node is a TypeError.
38
- if (!node || typeof node !== 'object') {
39
- throw new TypeError(
40
- "Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."
41
- );
42
- }
43
- appended.push(node);
44
- },
45
- };
46
-
47
- globalThis.document = { querySelector: (sel) => (sel === '#app' ? appElement : null) };
48
- globalThis.slice = {
49
- logger: { logError: (...args) => loggedErrors.push(args) },
50
- controller: { getComponent: () => null },
51
- router: {},
52
- loading: null,
53
- build: async () => null, // the failure under test
54
- };
55
- });
56
-
57
- const makeRouter = () => {
58
- const r = Object.create(Router.prototype);
59
- r.renderRoutesInComponent = async () => {};
60
- r.invalidateCache = () => {};
61
- return r;
62
- };
63
-
64
- test('does not throw when slice.build() returns null', async () => {
65
- const r = makeRouter();
66
- await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
67
- assert.equal(appended.length, 0, 'nothing should be appended');
68
- });
69
-
70
- test('logs the build failure naming the route and component', async () => {
71
- const r = makeRouter();
72
- await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
73
-
74
- assert.equal(loggedErrors.length, 1, 'exactly one error should be reported');
75
- const [scope, message] = loggedErrors[0];
76
- assert.equal(scope, 'Router');
77
- assert.match(message, /\/broken/);
78
- assert.match(message, /Broken/);
79
- });
80
-
81
- test('leaves the current view untouched instead of blanking it', async () => {
82
- const r = makeRouter();
83
- await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
84
- assert.equal(appElement.innerHTML, 'previous view');
85
- });
86
-
87
- test('does not mark the failed route as active', async () => {
88
- const r = makeRouter();
89
- await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
90
- assert.equal(slice.router.activeRoute, undefined);
91
- });
92
-
93
- test('still stops the loading indicator', async () => {
94
- const stops = [];
95
- slice.loading = { start() {}, stop() { stops.push(1); } };
96
-
97
- const r = makeRouter();
98
- await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
99
- assert.equal(stops.length, 1, 'loading.stop() must run even on the failure path');
100
- });
101
-
102
- test('a successful build still renders and activates the route', async () => {
103
- const component = { tagName: 'DIV' };
104
- slice.build = async () => component;
105
-
106
- const r = makeRouter();
107
- const route = { path: '/ok', component: 'Ok' };
108
- await r.handleRoute(route, {});
109
-
110
- assert.deepEqual(appended, [component]);
111
- assert.equal(appElement.innerHTML, '');
112
- assert.equal(slice.router.activeRoute, route);
113
- assert.equal(loggedErrors.length, 0);
114
- });
115
-
116
- test('reports instead of throwing when #app is missing', async () => {
117
- globalThis.document = { querySelector: () => null };
118
-
119
- const r = makeRouter();
120
- await r.handleRoute({ path: '/ok', component: 'Ok' }, {});
121
-
122
- assert.equal(loggedErrors.length, 1);
123
- assert.match(loggedErrors[0][1], /#app/);
124
- });
125
- });
@@ -1,63 +0,0 @@
1
- // Regression test for GOTCHAS §3: router:change must not be observable before
2
- // slice.router.activeRoute is updated.
3
- //
4
- // Router is a plain class with no module-level DOM/global access and no imports,
5
- // so onRouteChange() can be exercised directly on a stubbed instance. The fix
6
- // makes onRouteChange() resolve only AFTER the debounced handleRoute() runs
7
- // (which is where activeRoute is set), so a caller that awaits it — like
8
- // _performNavigation — emits router:change with activeRoute already current.
9
- //
10
- // Run: node --test tests/router-emit-ordering.test.js
11
-
12
- import { test, describe, before } from 'node:test';
13
- import assert from 'node:assert/strict';
14
-
15
- describe('Router.onRouteChange (§3 emit-after-activeRoute)', () => {
16
- let Router;
17
-
18
- before(async () => {
19
- globalThis.window = globalThis.window || { location: { pathname: '/' } };
20
- globalThis.slice = globalThis.slice || { logger: { error() {} }, router: {} };
21
- ({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
22
- });
23
-
24
- const makeRouter = (handleRoute) => {
25
- const r = Object.create(Router.prototype);
26
- r.renderRoutesComponentsInPage = async () => false; // not the MultiRoute container path
27
- r.matchRoute = () => ({ route: { component: 'X' }, params: {} });
28
- r.handleRoute = handleRoute;
29
- return r;
30
- };
31
-
32
- test('awaiting onRouteChange() waits until handleRoute() has finished', async () => {
33
- const order = [];
34
- const r = makeRouter(async () => {
35
- await new Promise((res) => setTimeout(res, 5)); // simulate async render
36
- order.push('handleRoute-done'); // activeRoute is assigned here in the real code
37
- });
38
-
39
- await r.onRouteChange();
40
- order.push('after-await');
41
-
42
- // With the fix, handleRoute completes BEFORE the await returns. (Before the
43
- // fix the awaited promise resolved the instant the timer was scheduled, so
44
- // 'after-await' would land first — i.e. emit-before-activeRoute.)
45
- assert.deepEqual(order, ['handleRoute-done', 'after-await']);
46
- });
47
-
48
- test('a superseded (debounced) call still resolves — no hang', async () => {
49
- let handled = 0;
50
- const r = makeRouter(async () => { handled++; });
51
-
52
- const p1 = r.onRouteChange(); // schedules timer T1
53
- const p2 = r.onRouteChange(); // clears T1, resolves p1, schedules T2
54
-
55
- await Promise.race([
56
- Promise.all([p1, p2]),
57
- new Promise((_, rej) => setTimeout(() => rej(new Error('onRouteChange hung')), 1000)),
58
- ]);
59
-
60
- // Only the surviving timer runs its work.
61
- assert.equal(handled, 1);
62
- });
63
- });