@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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../src/generated/grammar.ts"],"names":[],"mappings":"AAAA;;;gFAGgF;AAGhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,IAAI,gBAAqC,CAAC;AAC1C,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE,CAAC,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAs0InG,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /******************************************************************************
2
+ * This file was generated by langium-cli 4.4.0.
3
+ * DO NOT EDIT MANUALLY!
4
+ ******************************************************************************/
5
+ import type { LangiumSharedCoreServices, LangiumCoreServices, LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices, Module } from 'langium';
6
+ export declare const DDLLanguageMetaData: {
7
+ readonly languageId: "ddl";
8
+ readonly fileExtensions: readonly [".ddl"];
9
+ readonly caseInsensitive: false;
10
+ readonly mode: "development";
11
+ };
12
+ export declare const DDLGeneratedSharedModule: Module<LangiumSharedCoreServices, LangiumGeneratedSharedCoreServices>;
13
+ export declare const DDLGeneratedModule: Module<LangiumCoreServices, LangiumGeneratedCoreServices>;
14
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/generated/module.ts"],"names":[],"mappings":"AAAA;;;gFAGgF;AAEhF,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,kCAAkC,EAAoB,MAAM,EAAE,MAAM,SAAS,CAAC;AAI1K,eAAO,MAAM,mBAAmB;;;;;CAKK,CAAC;AAEtC,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,yBAAyB,EAAE,kCAAkC,CAE1G,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,mBAAmB,EAAE,4BAA4B,CAIxF,CAAC"}
@@ -0,0 +1,21 @@
1
+ /******************************************************************************
2
+ * This file was generated by langium-cli 4.4.0.
3
+ * DO NOT EDIT MANUALLY!
4
+ ******************************************************************************/
5
+ import { DDLAstReflection } from './ast.js';
6
+ import { DDLGrammar } from './grammar.js';
7
+ export const DDLLanguageMetaData = {
8
+ languageId: 'ddl',
9
+ fileExtensions: ['.ddl'],
10
+ caseInsensitive: false,
11
+ mode: 'development'
12
+ };
13
+ export const DDLGeneratedSharedModule = {
14
+ AstReflection: () => new DDLAstReflection()
15
+ };
16
+ export const DDLGeneratedModule = {
17
+ Grammar: () => DDLGrammar(),
18
+ LanguageMetaData: () => DDLLanguageMetaData,
19
+ parser: {}
20
+ };
21
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/generated/module.ts"],"names":[],"mappings":"AAAA;;;gFAGgF;AAGhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,UAAU,EAAE,KAAK;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,eAAe,EAAE,KAAK;IACtB,IAAI,EAAE,aAAa;CACc,CAAC;AAEtC,MAAM,CAAC,MAAM,wBAAwB,GAA0E;IAC3G,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,gBAAgB,EAAE;CAC9C,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA8D;IACzF,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE;IAC3B,gBAAgB,EAAE,GAAG,EAAE,CAAC,mBAAmB;IAC3C,MAAM,EAAE,EAAE;CACb,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type DeviceIR } from '@mica-js/device-model';
2
+ export { createDDLServices } from './services.js';
3
+ export { generateDeviceTypes, generateDeviceTypeScript } from './projection.js';
4
+ export type { DeviceTypeScriptOptions } from './projection.js';
5
+ export type { DeviceIR } from '@mica-js/device-model';
6
+ export interface CompileDDLOptions {
7
+ /** URI retained by every generated declaration, region and operation. */
8
+ readonly uri?: string;
9
+ }
10
+ /** Parses real DDL grammar, lowers its AST, and validates the canonical IR. */
11
+ export declare function compileDDL(source: string, options?: CompileDDLOptions): Promise<DeviceIR>;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAmB,MAAM,uBAAuB,CAAC;AAKnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAChF,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAmBD,+EAA+E;AAC/E,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,QAAQ,CAAC,CAgDnB"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import { BuildError } from '@mica-js/device-model';
2
+ import { DDLCompiler } from './compiler.js';
3
+ import { createDDLServices } from './services.js';
4
+ export { createDDLServices } from './services.js';
5
+ export { generateDeviceTypes, generateDeviceTypeScript } from './projection.js';
6
+ let services;
7
+ const compiled = new Map();
8
+ const maxCachedModels = 32;
9
+ const maxCachedCharacters = 256 * 1024;
10
+ const maxCachedModelCharacters = 64 * 1024;
11
+ let cachedCharacters = 0;
12
+ function remember(key, model) {
13
+ compiled.set(key, model);
14
+ cachedCharacters += key.length;
15
+ while (compiled.size > maxCachedModels || cachedCharacters > maxCachedCharacters) {
16
+ const oldest = compiled.keys().next().value;
17
+ cachedCharacters -= oldest.length;
18
+ compiled.delete(oldest);
19
+ }
20
+ }
21
+ /** Parses real DDL grammar, lowers its AST, and validates the canonical IR. */
22
+ export async function compileDDL(source, options = {}) {
23
+ const uri = options.uri ?? 'memory:///device.ddl';
24
+ const key = source.length + uri.length + 16 <= maxCachedModelCharacters
25
+ ? `${uri.length}:${uri}${source}`
26
+ : undefined;
27
+ const cached = key === undefined ? undefined : compiled.get(key);
28
+ if (cached) {
29
+ compiled.delete(key);
30
+ compiled.set(key, cached);
31
+ return cached;
32
+ }
33
+ const parser = (services ??= createDDLServices()).DDL.parser.LangiumParser;
34
+ const parsed = parser.parse(source);
35
+ const lexical = parsed.lexerErrors[0];
36
+ const syntax = parsed.parserErrors[0];
37
+ if (lexical || syntax) {
38
+ const token = syntax?.token;
39
+ const offset = lexical?.offset ??
40
+ (token && Number.isFinite(token.startOffset) ? token.startOffset : source.length);
41
+ const length = lexical?.length ??
42
+ (token && Number.isFinite(token.endOffset) ? token.endOffset - offset + 1 : 0);
43
+ const position = (index) => {
44
+ const prefix = source.slice(0, index);
45
+ const lines = prefix.split('\n');
46
+ return { line: lines.length, column: lines.at(-1).length + 1 };
47
+ };
48
+ const info = {
49
+ uri,
50
+ range: { start: position(offset), end: position(offset + length) },
51
+ };
52
+ throw new BuildError([
53
+ {
54
+ code: 'IR_SCHEMA',
55
+ phase: 'construct',
56
+ path: [],
57
+ source: info,
58
+ message: lexical?.message ?? syntax.message,
59
+ related: [],
60
+ },
61
+ ]);
62
+ }
63
+ const model = new DDLCompiler(parsed.value, uri).compile();
64
+ // The shared validator returns a deeply immutable snapshot; cache no parser state or errors.
65
+ if (key !== undefined)
66
+ remember(key, model);
67
+ return model;
68
+ }
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkC,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAShF,IAAI,QAA0D,CAAC;AAC/D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;AAC7C,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC;AACvC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB,SAAS,QAAQ,CAAC,GAAW,EAAE,KAAe;IAC5C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,gBAAgB,IAAI,GAAG,CAAC,MAAM,CAAC;IAC/B,OAAO,QAAQ,CAAC,IAAI,GAAG,eAAe,IAAI,gBAAgB,GAAG,m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AK,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3D,6FAA6F;IAC7F,IAAI,GAAG,KAAK,SAAS;QAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type DeviceIR } from '@mica-js/device-model';
2
+ export interface DeviceTypeScriptOptions {
3
+ /** Public SDK device subpath used by the generated type-only imports. */
4
+ readonly deviceModule?: string;
5
+ /** Prefix for generated public interfaces; defaults to the device name. */
6
+ readonly name?: string;
7
+ }
8
+ /** Generates a type-only ESM module describing the JavaScript device boundary. */
9
+ export declare function generateDeviceTypeScript(input: DeviceIR, options?: DeviceTypeScriptOptions): string;
10
+ export declare const generateDeviceTypes: typeof generateDeviceTypeScript;
11
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAE1F,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kFAAkF;AAClF,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,QAAQ,EACf,OAAO,GAAE,uBAA4B,GACpC,MAAM,CA+FR;AAED,eAAO,MAAM,mBAAmB,iCAA2B,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { validateDeviceIR } from '@mica-js/device-model';
2
+ /** Generates a type-only ESM module describing the JavaScript device boundary. */
3
+ export function generateDeviceTypeScript(input, options = {}) {
4
+ const model = validateDeviceIR(input);
5
+ const prefix = options.name ?? model.name;
6
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(prefix))
7
+ throw new TypeError('The projection name must be an ASCII TypeScript identifier.');
8
+ const quote = (value) => JSON.stringify(value);
9
+ const named = new Map(model.declarations
10
+ .filter((decl) => decl.kind === 'record' || decl.kind === 'enum')
11
+ .map((decl) => [decl.name, `${prefix}_${decl.name}`]));
12
+ const type = (value, inputBytes = false) => {
13
+ switch (value.kind) {
14
+ case 'number':
15
+ case 'string':
16
+ return value.kind;
17
+ case 'bool':
18
+ return 'boolean';
19
+ case 'bytes':
20
+ return inputBytes ? 'Uint8Array' : 'ReadonlyBytes';
21
+ case 'optional':
22
+ return `${type(value.inner, inputBytes)} | null`;
23
+ case 'enum':
24
+ return (named.get(value.name) ??
25
+ (value.name === 'Logic'
26
+ ? '"low" | "high" | "unknown"'
27
+ : value.name === 'SampleStatus'
28
+ ? '"valid" | "floating"'
29
+ : '"drop_new" | "drop_oldest" | "error"'));
30
+ case 'record':
31
+ return named.get(value.name);
32
+ default:
33
+ throw new TypeError(`Type '${value.kind}' cannot be projected through the device JavaScript boundary.`);
34
+ }
35
+ };
36
+ const lines = [
37
+ `import type { BorrowedBytes, ChannelMessage, DeviceAdapter, DeviceBatch, DeviceContext, DeviceFactory, InputChannel, InputNotification, Notification, ReadonlyBytes } from ${quote(options.deviceModule ?? '@mica-js/simulator/device')};`,
38
+ '',
39
+ ];
40
+ for (const decl of model.declarations) {
41
+ if (decl.kind === 'enum')
42
+ lines.push(`export type ${named.get(decl.name)} = ${decl.members.map(quote).join(' | ')};`, '');
43
+ if (decl.kind === 'record') {
44
+ lines.push(`export interface ${named.get(decl.name)} {`);
45
+ for (const field of decl.fields)
46
+ lines.push(` readonly ${quote(field.name)}: ${field.type === 'bool' ? 'boolean' : 'number'};`);
47
+ lines.push('}', '');
48
+ }
49
+ }
50
+ lines.push(`export interface ${prefix}Props {`);
51
+ for (const decl of model.declarations)
52
+ if (decl.kind === 'property')
53
+ lines.push(` readonly ${quote(decl.name)}: ${type(decl.type)};`);
54
+ lines.push('}', '', `export interface ${prefix}PropertyInput {`);
55
+ for (const decl of model.declarations)
56
+ if (decl.kind === 'property')
57
+ lines.push(` readonly ${quote(decl.name)}${decl.default ? '?' : ''}: ${type(decl.type, true)};`);
58
+ lines.push('}', '', `export interface ${prefix}Inputs {`);
59
+ for (const decl of model.declarations) {
60
+ if (decl.kind === 'channel' && decl.direction === 'input')
61
+ lines.push(` readonly ${quote(decl.name)}: InputChannel<${type(decl.type, true)}>;`);
62
+ if (decl.kind === 'notification' && decl.direction === 'input')
63
+ lines.push(` readonly ${quote(decl.name)}: InputNotification;`);
64
+ }
65
+ lines.push('}', '', `export interface ${prefix}Memory {`);
66
+ for (const decl of model.declarations)
67
+ if (decl.kind === 'memory' && decl.public)
68
+ lines.push(` readonly ${quote(decl.name)}: BorrowedBytes;`);
69
+ lines.push('}', '', `export interface ${prefix}Outputs {`);
70
+ for (const decl of model.declarations) {
71
+ if (decl.kind === 'channel' && decl.direction === 'output')
72
+ lines.push(` readonly ${quote(decl.name)}: readonly ChannelMessage<${type(decl.type)}>[];`);
73
+ if (decl.kind === 'notification' && decl.direction === 'output')
74
+ lines.push(` readonly ${quote(decl.name)}: Notification | null;`);
75
+ }
76
+ lines.push('}', '', `export type ${prefix}Context = DeviceContext<${prefix}Props, ${prefix}Inputs, ${prefix}Memory>;`, `export type ${prefix}Batch = DeviceBatch<${prefix}Outputs>;`, `export type ${prefix}Adapter = DeviceAdapter<${prefix}Batch>;`, `export type ${prefix}Factory = DeviceFactory<${prefix}Context, ${prefix}Batch>;`, '');
77
+ return lines.join('\n');
78
+ }
79
+ export const generateDeviceTypes = generateDeviceTypeScript;
80
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,uBAAuB,CAAC;AAS1F,kFAAkF;AAClF,MAAM,UAAU,wBAAwB,CACtC,KAAe,EACf,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7 @@
1
+ import { type DefaultSharedCoreModuleContext, type LangiumCoreServices, type LangiumSharedCoreServices } from 'langium';
2
+ /** Core-only services keep the parser usable without Node.js or a language server. */
3
+ export declare function createDDLServices(context?: DefaultSharedCoreModuleContext): {
4
+ shared: LangiumSharedCoreServices;
5
+ DDL: LangiumCoreServices;
6
+ };
7
+ //# sourceMappingURL=services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,8BAA8B,EACnC,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAC;AAGjB,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,8BAAgD,GAAG;IAC5F,MAAM,EAAE,yBAAyB,CAAC;IAClC,GAAG,EAAE,mBAAmB,CAAC;CAC1B,CAKA"}
@@ -0,0 +1,10 @@
1
+ import { createDefaultCoreModule, createDefaultSharedCoreModule, EmptyFileSystem, inject, } from 'langium';
2
+ import { DDLGeneratedModule, DDLGeneratedSharedModule } from './generated/module.js';
3
+ /** Core-only services keep the parser usable without Node.js or a language server. */
4
+ export function createDDLServices(context = EmptyFileSystem) {
5
+ const shared = inject(createDefaultSharedCoreModule(context), DDLGeneratedSharedModule);
6
+ const DDL = inject(createDefaultCoreModule({ shared }), DDLGeneratedModule);
7
+ shared.ServiceRegistry.register(DDL);
8
+ return { shared, DDL };
9
+ }
10
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,eAAe,EACf,MAAM,GAIP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAErF,sFAAsF;AACtF,MAAM,UAAU,iBAAiB,CAAC,UAA0C,eAAe;IAIzF,MAAM,MAAM,GAAG,MAAM,CAAC,6BAA6B,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC;IACxF,MAAM,GAAG,GAAG,MAAM,CAAC,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAC5E,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@mica-js/ddl",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Browser-compatible Langium frontend and TypeScript projection for Mica DDL",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "dependencies": {
21
+ "@mica-js/device-model": "0.5.0",
22
+ "langium": "4.4.0"
23
+ },
24
+ "devDependencies": {
25
+ "langium-cli": "4.4.0",
26
+ "typescript": "^6.0.3"
27
+ },
28
+ "scripts": {
29
+ "generate": "langium generate",
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "typecheck": "tsc --noEmit"
32
+ }
6
33
  }