@mica-js/ddl 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DigitalEcho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @mica-js/ddl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Browser-compatible TypeScript ESM frontend for self-contained Mica DDL devices. The Langium grammar and generated AST/services implement the language syntax. The compiler lowers that AST directly to canonical structured `DeviceIR`, retaining one-based UTF-16 source ranges, then calls `@mica-js/device-model`'s shared validator for type, scope, effect, dependency, and control-flow checks. Invalid input throws `BuildError`; no partial IR is returned.
4
+
5
+ ```typescript
6
+ import { compileDDL, generateDeviceTypeScript } from '@mica-js/ddl';
7
+
8
+ const model = await compileDDL('device Counter { state count: number = 0; }', {
9
+ uri: 'file:///devices/counter.ddl',
10
+ });
11
+ const types = generateDeviceTypeScript(model);
12
+ ```
13
+
14
+ `compileDDL(source, { uri? })` returns `Promise<DeviceIR>` and rejects with `BuildError` for invalid input. `generateDeviceTypeScript(model, { deviceModule?, name? })` produces a type-only ESM module exporting device-specific props, property inputs, channels, notifications, public memory, context, batches, adapter, and factory types. `generateDeviceTypes` is an alias. The generated imports default to `@mica-js/simulator/device`; `deviceModule` may select another SDK facade. Bytes inputs use `Uint8Array`, while snapshots and public memory use the SDK's `ReadonlyBytes` and `BorrowedBytes`.
15
+
16
+ Compilation reuses one Langium parser. A source-and-URI-keyed LRU retains at most 32 validated immutable models and 256 Ki UTF-16 code units of keys; individual keys above 64 Ki code units bypass caching. Repeated successful calls may share the same frozen IR snapshot. Failures are never cached, and distinct URIs retain independent source locations and diagnostics.
17
+
18
+ `createDDLServices()` exposes the generated Langium core services without a Node filesystem or language-server dependency. Grammar changes require `pnpm generate`; generated files in `src/generated` are tracked. Run `pnpm typecheck` and `pnpm build` after regeneration. Build the shared device-model dependency first.
@@ -0,0 +1,57 @@
1
+ import type { AstNode } from 'langium';
2
+ import { type DeviceIR, type SourceInfo } from '@mica-js/device-model';
3
+ import type * as AST from './generated/ast.js';
4
+ /** Lowers Langium's structured AST directly into the canonical operation regions. */
5
+ export declare class DDLCompiler {
6
+ private readonly device;
7
+ private readonly uri;
8
+ private readonly symbols;
9
+ private readonly types;
10
+ private readonly resolving;
11
+ private readonly sources;
12
+ private readonly valueTypes;
13
+ constructor(device: AST.Device, uri: string);
14
+ source(node: AstNode): SourceInfo;
15
+ private fail;
16
+ private checkName;
17
+ private type;
18
+ private parameterType;
19
+ private context;
20
+ private child;
21
+ private emit;
22
+ private value;
23
+ private constant;
24
+ private expect;
25
+ private describe;
26
+ private symbolType;
27
+ private bind;
28
+ private resource;
29
+ private resourceKind;
30
+ private read;
31
+ private number;
32
+ private string;
33
+ private fieldType;
34
+ private expression;
35
+ private infer;
36
+ private binary;
37
+ private select;
38
+ private args;
39
+ private call;
40
+ private factKey;
41
+ private facts;
42
+ private initializer;
43
+ private await;
44
+ private markValue;
45
+ private block;
46
+ private statement;
47
+ private ifStatement;
48
+ private pattern;
49
+ private match;
50
+ private loop;
51
+ private computation;
52
+ private options;
53
+ private staticNumber;
54
+ private sourceType;
55
+ compile(): DeviceIR;
56
+ }
57
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAQL,KAAK,QAAQ,EASb,KAAK,UAAU,EAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAyK/C,qFAAqF;AACrF,qBAAa,WAAW;IAQpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IARtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAC9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6C;gBAGrD,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,GAAG,EAAE,MAAM;IAW9B,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU;IAiBjC,OAAO,CAAC,IAAI;IAMZ,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,IAAI;IA8BZ,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,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