@mica-js/sdk 0.3.1 → 0.3.2

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.
@@ -10,5 +10,19 @@ export interface ContentFile {
10
10
  readonly source: string;
11
11
  }
12
12
  export declare function modelExpression(value: unknown): string;
13
+ /**
14
+ * Deep-copies a compiled model while omitting `source` metadata for artifacts.
15
+ *
16
+ * Every operation and region carries a `source: { uri, range }` pointing back at
17
+ * model.ddl, which dominates the embedded IR payload and the deep copy
18
+ * `createDeviceLibrary` performs on cold start. `source` is optional throughout
19
+ * the IR, so shipped models remain valid without it; the tradeoff is that
20
+ * runtime diagnostics can no longer report DDL file and line locations.
21
+ *
22
+ * Numbers (including NaN, ±Infinity and -0) are preserved by construction, and
23
+ * Uint8Array values are copied so `modelExpression` keeps emitting
24
+ * `new Uint8Array([...])`.
25
+ */
26
+ export declare function stripModelSource(value: unknown): unknown;
13
27
  /** Builds each registration separately so no shared chunk or runtime import escapes. */
14
28
  export declare function buildContent(options: ContentBuildOptions): Promise<readonly ContentFile[]>;
@@ -59,6 +59,39 @@ export function modelExpression(value) {
59
59
  .join(',')}}`;
60
60
  throw new TypeError(`Cannot serialize model value: ${typeof value}`);
61
61
  }
62
+ /**
63
+ * Deep-copies a compiled model while omitting `source` metadata for artifacts.
64
+ *
65
+ * Every operation and region carries a `source: { uri, range }` pointing back at
66
+ * model.ddl, which dominates the embedded IR payload and the deep copy
67
+ * `createDeviceLibrary` performs on cold start. `source` is optional throughout
68
+ * the IR, so shipped models remain valid without it; the tradeoff is that
69
+ * runtime diagnostics can no longer report DDL file and line locations.
70
+ *
71
+ * Numbers (including NaN, ±Infinity and -0) are preserved by construction, and
72
+ * Uint8Array values are copied so `modelExpression` keeps emitting
73
+ * `new Uint8Array([...])`.
74
+ */
75
+ export function stripModelSource(value) {
76
+ if (value instanceof Uint8Array)
77
+ return new Uint8Array(value);
78
+ if (Array.isArray(value))
79
+ return value.map(stripModelSource);
80
+ if (value === null || typeof value !== 'object')
81
+ return value;
82
+ const copy = {};
83
+ for (const [key, item] of Object.entries(value)) {
84
+ if (key === 'source')
85
+ continue;
86
+ Object.defineProperty(copy, key, {
87
+ value: stripModelSource(item),
88
+ enumerable: true,
89
+ writable: true,
90
+ configurable: true,
91
+ });
92
+ }
93
+ return copy;
94
+ }
62
95
  /** Builds each registration separately so no shared chunk or runtime import escapes. */
63
96
  export async function buildContent(options) {
64
97
  const files = [];
@@ -86,7 +119,7 @@ export async function buildContent(options) {
86
119
  uri: `mica:devices/${id}/model.ddl`,
87
120
  });
88
121
  const adapter = resolve(base, 'index.ts');
89
- source = `export const model = ${modelExpression(model)};\n`;
122
+ source = `export const model = ${modelExpression(stripModelSource(model))};\n`;
90
123
  source += (await exists(adapter))
91
124
  ? `export { default as create } from ${JSON.stringify(normalizePath(adapter))};\n`
92
125
  : 'export function create() { return { sync() {}, dispose() {} }; }\n';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mica-js/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Device and widget author APIs with CLI-managed content builds",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -58,7 +58,7 @@
58
58
  "@mica-js/core": "0.7.0",
59
59
  "@mica-js/ddl": "0.3.0",
60
60
  "@mica-js/device-model": "0.6.0",
61
- "@mica-js/simulator": "2.3.0",
61
+ "@mica-js/simulator": "2.4.0",
62
62
  "@mica-js/widget": "0.4.0",
63
63
  "ajv": "^8.17.1",
64
64
  "rolldown": "^1.2.14",
@@ -72,6 +72,7 @@
72
72
  "scripts": {
73
73
  "build": "tsc -p tsconfig.build.json",
74
74
  "typecheck": "tsc --noEmit",
75
- "test": "vitest run"
75
+ "test": "vitest run",
76
+ "bench:cold-start": "node scripts/cold-start.mjs"
76
77
  }
77
78
  }