@sveltesentio/core 0.2.1 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/golusoris/sveltesentio/compare/core-v0.2.1...core-v0.3.0) (2026-06-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * **core:** typed $sentio virtual-module config schema ([75e9f32](https://github.com/golusoris/sveltesentio/commit/75e9f32d378fe0d5457549cb793524317395a134))
9
+
3
10
  ## [0.2.1](https://github.com/golusoris/sveltesentio/compare/core-v0.2.0...core-v0.2.1) (2026-06-19)
4
11
 
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltesentio/core",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Vite plugin, env schema, error types, id/clock utils — sveltesentio core",
5
5
  "type": "module",
6
6
  "private": false,
@@ -41,6 +41,9 @@
41
41
  "./eslint": {
42
42
  "import": "./src/eslint.ts",
43
43
  "types": "./src/eslint.ts"
44
+ },
45
+ "./sentio": {
46
+ "types": "./sentio.d.ts"
44
47
  }
45
48
  },
46
49
  "peerDependencies": {
@@ -79,6 +82,7 @@
79
82
  },
80
83
  "files": [
81
84
  "src",
85
+ "sentio.d.ts",
82
86
  "CHANGELOG.md"
83
87
  ],
84
88
  "scripts": {
package/sentio.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Ambient declaration for the `$sentio` virtual module emitted by
3
+ * `sentioPlugin` (see `@sveltesentio/core/vite`). Make it visible to your app
4
+ * by adding `"@sveltesentio/core/sentio"` to `compilerOptions.types`, or with
5
+ * `/// <reference types="@sveltesentio/core/sentio" />`.
6
+ *
7
+ * The exported shape matches `SentioConfig` from `defineSentioConfig`.
8
+ */
9
+ declare module '$sentio' {
10
+ import type { SentioConfig, InterfaceType } from '@sveltesentio/core';
11
+
12
+ /** Build-time app version. */
13
+ export const version: string;
14
+ /** Default interface-type preset used before client-side classification. */
15
+ export const interfaceType: InterfaceType;
16
+ /** Static build-time feature flags (flag name → enabled). */
17
+ export const features: Readonly<Record<string, boolean>>;
18
+ /** Active theme preset name. */
19
+ export const theme: string;
20
+
21
+ const config: Readonly<SentioConfig>;
22
+ export default config;
23
+ }
package/src/index.ts CHANGED
@@ -47,4 +47,12 @@ export type {
47
47
  } from './vite.js';
48
48
  export { checkBundleBudget, sentioPlugin } from './vite.js';
49
49
 
50
+ export type { InterfaceType, SentioConfig } from './sentio-config.js';
51
+ export {
52
+ SentioConfigError,
53
+ defineSentioConfig,
54
+ interfaceTypeSchema,
55
+ sentioConfigSchema,
56
+ } from './sentio-config.js';
57
+
50
58
  export { noDirectTime, sentioEslint } from './eslint.js';
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+
3
+ /** Interface-type preset (§2.6): desktop pointer, 10-foot TV, handheld touch. */
4
+ export const interfaceTypeSchema = z.enum(['desktop', 'tenfoot', 'handheld']);
5
+ export type InterfaceType = z.infer<typeof interfaceTypeSchema>;
6
+
7
+ /**
8
+ * Schema for the typed `$sentio` virtual module — build-time configuration
9
+ * surfaced to client + server code via `import { ... } from '$sentio'`. Feed
10
+ * the validated result of {@link defineSentioConfig} to the Vite plugin as
11
+ * `sentioPlugin({ virtualModule })`.
12
+ */
13
+ export const sentioConfigSchema = z.object({
14
+ /** Build-time app version surfaced to client code. */
15
+ version: z.string().min(1).default('0.0.0'),
16
+ /** Default interface-type preset used before client-side classification. */
17
+ interfaceType: interfaceTypeSchema.default('desktop'),
18
+ /** Static feature flags resolved at build time (flag name → enabled). */
19
+ features: z.record(z.string(), z.boolean()).default({}),
20
+ /** Active theme preset name. */
21
+ theme: z.string().min(1).default('default'),
22
+ });
23
+
24
+ export type SentioConfig = z.infer<typeof sentioConfigSchema>;
25
+
26
+ /** Thrown by {@link defineSentioConfig} when the input fails validation. */
27
+ export class SentioConfigError extends Error {
28
+ constructor(message: string) {
29
+ super(message);
30
+ this.name = 'SentioConfigError';
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Validate + normalise a `$sentio` config. Fills defaults for omitted fields
36
+ * and throws {@link SentioConfigError} with a readable summary on invalid
37
+ * input, so misconfiguration fails the build instead of reaching the client.
38
+ */
39
+ export function defineSentioConfig(input: unknown = {}): SentioConfig {
40
+ const result = sentioConfigSchema.safeParse(input);
41
+ if (!result.success) {
42
+ const detail = result.error.issues
43
+ .map((issue) => ` - ${issue.path.join('.') || '(root)'}: ${issue.message}`)
44
+ .join('\n');
45
+ throw new SentioConfigError(`[sentio] Invalid $sentio config:\n${detail}`);
46
+ }
47
+ return result.data;
48
+ }