@ifc-lite/codegen 1.15.4 ā 1.15.5
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/README.md +17 -14
- package/package.json +16 -6
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -165
- package/INTEGRATION.md +0 -360
- package/generated/ifc4/entities.ts +0 -7400
- package/generated/ifc4/enums.ts +0 -2467
- package/generated/ifc4/index.ts +0 -17
- package/generated/ifc4/schema-registry.ts +0 -63186
- package/generated/ifc4/selects.ts +0 -315
- package/generated/ifc4/serializers.ts +0 -51
- package/generated/ifc4/test-compile.ts +0 -49
- package/generated/ifc4/type-ids.ts +0 -1682
- package/generated/ifc4/types.ts +0 -401
- package/generated/ifc4x3/entities.ts +0 -8300
- package/generated/ifc4x3/enums.ts +0 -3096
- package/generated/ifc4x3/index.ts +0 -17
- package/generated/ifc4x3/schema-registry.ts +0 -71489
- package/generated/ifc4x3/selects.ts +0 -312
- package/generated/ifc4x3/serializers.ts +0 -51
- package/generated/ifc4x3/test-compile.ts +0 -49
- package/generated/ifc4x3/type-ids.ts +0 -1882
- package/generated/ifc4x3/types.ts +0 -407
- package/src/cli.ts +0 -72
- package/src/crc32.ts +0 -77
- package/src/express-parser.ts +0 -457
- package/src/generator.ts +0 -268
- package/src/index.ts +0 -57
- package/src/rust-generator.ts +0 -714
- package/src/serialization-generator.ts +0 -74
- package/src/type-ids-generator.ts +0 -166
- package/src/typescript-generator.ts +0 -631
- package/test/express-parser.test.ts +0 -363
- package/test/integration.test.ts +0 -246
- package/test/serialization-generator.test.ts +0 -65
- package/test/typescript-generator.test.ts +0 -348
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -18
package/src/generator.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* High-level Code Generator
|
|
7
|
-
*
|
|
8
|
-
* Orchestrates code generation from EXPRESS schemas to:
|
|
9
|
-
* - TypeScript interfaces and types
|
|
10
|
-
* - TypeScript type IDs (CRC32)
|
|
11
|
-
* - TypeScript serialization helpers
|
|
12
|
-
* - Rust types and type IDs
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
16
|
-
import { join, isAbsolute } from 'node:path';
|
|
17
|
-
import { parseExpressSchema, type ExpressSchema } from './express-parser.js';
|
|
18
|
-
import { generateTypeScript, type GeneratedCode } from './typescript-generator.js';
|
|
19
|
-
import { generateTypeIds } from './type-ids-generator.js';
|
|
20
|
-
import { generateSerializers } from './serialization-generator.js';
|
|
21
|
-
import { generateRust, type RustGeneratedCode } from './rust-generator.js';
|
|
22
|
-
import { findCollisions } from './crc32.js';
|
|
23
|
-
|
|
24
|
-
export interface FullGeneratedCode extends GeneratedCode {
|
|
25
|
-
typeIds: string;
|
|
26
|
-
serializers: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface GeneratorOptions {
|
|
30
|
-
/** Generate Rust output */
|
|
31
|
-
rust?: boolean;
|
|
32
|
-
/** Rust output directory (relative to outputDir or absolute) */
|
|
33
|
-
rustDir?: string;
|
|
34
|
-
/** Skip type ID collision check */
|
|
35
|
-
skipCollisionCheck?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generate all code from an EXPRESS schema file
|
|
40
|
-
*/
|
|
41
|
-
export function generateFromFile(
|
|
42
|
-
schemaPath: string,
|
|
43
|
-
outputDir: string,
|
|
44
|
-
options: GeneratorOptions = {}
|
|
45
|
-
): FullGeneratedCode {
|
|
46
|
-
// Read schema file
|
|
47
|
-
const content = readFileSync(schemaPath, 'utf-8');
|
|
48
|
-
|
|
49
|
-
// Generate code
|
|
50
|
-
return generateFromSchema(content, outputDir, options);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Generate all code from EXPRESS schema content
|
|
55
|
-
*/
|
|
56
|
-
export function generateFromSchema(
|
|
57
|
-
schemaContent: string,
|
|
58
|
-
outputDir: string,
|
|
59
|
-
options: GeneratorOptions = {}
|
|
60
|
-
): FullGeneratedCode {
|
|
61
|
-
console.log('š Parsing EXPRESS schema...');
|
|
62
|
-
const schema = parseExpressSchema(schemaContent);
|
|
63
|
-
|
|
64
|
-
console.log(`ā Parsed ${schema.name}`);
|
|
65
|
-
console.log(` - ${schema.entities.length} entities`);
|
|
66
|
-
console.log(` - ${schema.types.length} types`);
|
|
67
|
-
console.log(` - ${schema.enums.length} enums`);
|
|
68
|
-
console.log(` - ${schema.selects.length} selects`);
|
|
69
|
-
|
|
70
|
-
// Check for CRC32 collisions
|
|
71
|
-
if (!options.skipCollisionCheck) {
|
|
72
|
-
console.log('\nš Checking for CRC32 collisions...');
|
|
73
|
-
const entityNames = schema.entities.map((e) => e.name);
|
|
74
|
-
const collisions = findCollisions(entityNames);
|
|
75
|
-
if (collisions.size > 0) {
|
|
76
|
-
console.warn('ā ļø CRC32 collisions detected:');
|
|
77
|
-
for (const [hash, names] of collisions) {
|
|
78
|
-
console.warn(` ${hash}: ${names.join(', ')}`);
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
console.log(' ā No collisions');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log('\nšØ Generating TypeScript code...');
|
|
86
|
-
const tsCode = generateTypeScript(schema);
|
|
87
|
-
const typeIds = generateTypeIds(schema);
|
|
88
|
-
const serializers = generateSerializers(schema);
|
|
89
|
-
|
|
90
|
-
console.log('š¾ Writing TypeScript files...');
|
|
91
|
-
|
|
92
|
-
// Create output directory
|
|
93
|
-
mkdirSync(outputDir, { recursive: true });
|
|
94
|
-
|
|
95
|
-
// Write TypeScript files
|
|
96
|
-
writeFileSync(`${outputDir}/entities.ts`, tsCode.entities);
|
|
97
|
-
console.log(` ā ${outputDir}/entities.ts`);
|
|
98
|
-
|
|
99
|
-
writeFileSync(`${outputDir}/types.ts`, tsCode.types);
|
|
100
|
-
console.log(` ā ${outputDir}/types.ts`);
|
|
101
|
-
|
|
102
|
-
writeFileSync(`${outputDir}/enums.ts`, tsCode.enums);
|
|
103
|
-
console.log(` ā ${outputDir}/enums.ts`);
|
|
104
|
-
|
|
105
|
-
writeFileSync(`${outputDir}/selects.ts`, tsCode.selects);
|
|
106
|
-
console.log(` ā ${outputDir}/selects.ts`);
|
|
107
|
-
|
|
108
|
-
writeFileSync(`${outputDir}/schema-registry.ts`, tsCode.schemaRegistry);
|
|
109
|
-
console.log(` ā ${outputDir}/schema-registry.ts`);
|
|
110
|
-
|
|
111
|
-
writeFileSync(`${outputDir}/type-ids.ts`, typeIds);
|
|
112
|
-
console.log(` ā ${outputDir}/type-ids.ts`);
|
|
113
|
-
|
|
114
|
-
writeFileSync(`${outputDir}/serializers.ts`, serializers);
|
|
115
|
-
console.log(` ā ${outputDir}/serializers.ts`);
|
|
116
|
-
|
|
117
|
-
// Write index file
|
|
118
|
-
const indexContent = `/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
119
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
120
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Generated IFC Schema: ${schema.name}
|
|
124
|
-
*
|
|
125
|
-
* DO NOT EDIT - This file is auto-generated by @ifc-lite/codegen
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
export * from './entities.js';
|
|
129
|
-
export * from './types.js';
|
|
130
|
-
export * from './enums.js';
|
|
131
|
-
export * from './selects.js';
|
|
132
|
-
export * from './schema-registry.js';
|
|
133
|
-
export * from './type-ids.js';
|
|
134
|
-
export * from './serializers.js';
|
|
135
|
-
`;
|
|
136
|
-
writeFileSync(`${outputDir}/index.ts`, indexContent);
|
|
137
|
-
console.log(` ā ${outputDir}/index.ts`);
|
|
138
|
-
|
|
139
|
-
// Generate Rust code if requested
|
|
140
|
-
if (options.rust) {
|
|
141
|
-
console.log('\nš¦ Generating Rust code...');
|
|
142
|
-
const rustCode = generateRust(schema);
|
|
143
|
-
// Use absolute path directly, or join relative path with outputDir
|
|
144
|
-
const rustDir = options.rustDir
|
|
145
|
-
? isAbsolute(options.rustDir)
|
|
146
|
-
? options.rustDir
|
|
147
|
-
: join(outputDir, options.rustDir)
|
|
148
|
-
: join(outputDir, 'rust');
|
|
149
|
-
|
|
150
|
-
mkdirSync(rustDir, { recursive: true });
|
|
151
|
-
|
|
152
|
-
writeFileSync(`${rustDir}/type_ids.rs`, rustCode.typeIds);
|
|
153
|
-
console.log(` ā ${rustDir}/type_ids.rs`);
|
|
154
|
-
|
|
155
|
-
writeFileSync(`${rustDir}/schema.rs`, rustCode.schema);
|
|
156
|
-
console.log(` ā ${rustDir}/schema.rs`);
|
|
157
|
-
|
|
158
|
-
// Write mod.rs
|
|
159
|
-
const modContent = `// This Source Code Form is subject to the terms of the Mozilla Public
|
|
160
|
-
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
161
|
-
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
162
|
-
|
|
163
|
-
//! Auto-generated IFC Schema Types
|
|
164
|
-
//!
|
|
165
|
-
//! Generated from EXPRESS schema: ${schema.name}
|
|
166
|
-
//!
|
|
167
|
-
//! DO NOT EDIT - This file is auto-generated by @ifc-lite/codegen
|
|
168
|
-
|
|
169
|
-
mod type_ids;
|
|
170
|
-
mod schema;
|
|
171
|
-
|
|
172
|
-
pub use type_ids::*;
|
|
173
|
-
pub use schema::*;
|
|
174
|
-
`;
|
|
175
|
-
writeFileSync(`${rustDir}/mod.rs`, modContent);
|
|
176
|
-
console.log(` ā ${rustDir}/mod.rs`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Write test-compile file
|
|
180
|
-
const testCompileContent = `/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
181
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
182
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Type-check test file
|
|
186
|
-
* This file is used to verify the generated types compile correctly.
|
|
187
|
-
*
|
|
188
|
-
* DO NOT EDIT - This file is auto-generated
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
import type { IfcWall, IfcProject, IfcExtrudedAreaSolid } from './entities.js';
|
|
192
|
-
import { TYPE_IDS, getTypeId, getTypeName } from './type-ids.js';
|
|
193
|
-
import { SCHEMA_REGISTRY, getEntityMetadata } from './schema-registry.js';
|
|
194
|
-
import { toStepLine, serializeValue, ref, enumVal, type StepEntity } from './serializers.js';
|
|
195
|
-
|
|
196
|
-
// Test type IDs
|
|
197
|
-
const wallId: number = TYPE_IDS.IfcWall;
|
|
198
|
-
const projectId: number = TYPE_IDS.IfcProject;
|
|
199
|
-
|
|
200
|
-
// Test ID lookup
|
|
201
|
-
const wallIdFromName = getTypeId('IfcWall');
|
|
202
|
-
const nameFromId = getTypeName(wallId);
|
|
203
|
-
|
|
204
|
-
// Test schema registry
|
|
205
|
-
const wallMeta = getEntityMetadata('IfcWall');
|
|
206
|
-
const wallAttrs = wallMeta?.allAttributes;
|
|
207
|
-
|
|
208
|
-
// Test serialization
|
|
209
|
-
const testEntity: StepEntity = {
|
|
210
|
-
expressId: 1,
|
|
211
|
-
type: 'IfcProject',
|
|
212
|
-
GlobalId: '0YvctVUKr0kugbFTf53O9L',
|
|
213
|
-
OwnerHistory: ref(2),
|
|
214
|
-
Name: 'Test Project',
|
|
215
|
-
Description: null,
|
|
216
|
-
ObjectType: null,
|
|
217
|
-
LongName: null,
|
|
218
|
-
Phase: null,
|
|
219
|
-
RepresentationContexts: [ref(3)],
|
|
220
|
-
UnitsInContext: ref(4),
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const stepLine = toStepLine(testEntity);
|
|
224
|
-
|
|
225
|
-
console.log('ā All types compile correctly');
|
|
226
|
-
console.log(' Wall ID:', wallId);
|
|
227
|
-
console.log(' Project ID:', projectId);
|
|
228
|
-
console.log(' STEP line:', stepLine);
|
|
229
|
-
`;
|
|
230
|
-
writeFileSync(`${outputDir}/test-compile.ts`, testCompileContent);
|
|
231
|
-
console.log(` ā ${outputDir}/test-compile.ts`);
|
|
232
|
-
|
|
233
|
-
console.log('\n⨠Code generation complete!');
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
...tsCode,
|
|
237
|
-
typeIds,
|
|
238
|
-
serializers,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Generate code for both IFC4 and IFC4X3 schemas
|
|
244
|
-
*/
|
|
245
|
-
export function generateAll(
|
|
246
|
-
schemasDir: string,
|
|
247
|
-
outputBaseDir: string,
|
|
248
|
-
options: GeneratorOptions = {}
|
|
249
|
-
): void {
|
|
250
|
-
const schemas = [
|
|
251
|
-
{ name: 'IFC4', file: 'IFC4_ADD2_TC1.exp', dir: 'ifc4' },
|
|
252
|
-
{ name: 'IFC4X3', file: 'IFC4X3_ADD2.exp', dir: 'ifc4x3' },
|
|
253
|
-
];
|
|
254
|
-
|
|
255
|
-
for (const schema of schemas) {
|
|
256
|
-
const schemaPath = join(schemasDir, schema.file);
|
|
257
|
-
if (existsSync(schemaPath)) {
|
|
258
|
-
console.log(`\n${'='.repeat(60)}`);
|
|
259
|
-
console.log(`Processing ${schema.name}...`);
|
|
260
|
-
console.log(`${'='.repeat(60)}\n`);
|
|
261
|
-
|
|
262
|
-
const outputDir = join(outputBaseDir, schema.dir);
|
|
263
|
-
generateFromFile(schemaPath, outputDir, options);
|
|
264
|
-
} else {
|
|
265
|
-
console.warn(`ā ļø Schema file not found: ${schemaPath}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @ifc-lite/codegen
|
|
7
|
-
*
|
|
8
|
-
* IFC Code Generator - TypeScript and Rust from EXPRESS schemas
|
|
9
|
-
*
|
|
10
|
-
* Features:
|
|
11
|
-
* - TypeScript interfaces from EXPRESS entities
|
|
12
|
-
* - CRC32 type IDs for fast O(1) lookup
|
|
13
|
-
* - Serialization support for IFC writing
|
|
14
|
-
* - Rust type generation
|
|
15
|
-
* - Schema metadata registry
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// Core parser
|
|
19
|
-
export {
|
|
20
|
-
parseExpressSchema,
|
|
21
|
-
getAllAttributes,
|
|
22
|
-
getInheritanceChain,
|
|
23
|
-
type ExpressSchema,
|
|
24
|
-
type EntityDefinition,
|
|
25
|
-
type AttributeDefinition,
|
|
26
|
-
type TypeDefinition,
|
|
27
|
-
type EnumDefinition,
|
|
28
|
-
type SelectDefinition,
|
|
29
|
-
type DerivedAttribute,
|
|
30
|
-
type InverseAttribute,
|
|
31
|
-
} from './express-parser.js';
|
|
32
|
-
|
|
33
|
-
// TypeScript generation
|
|
34
|
-
export {
|
|
35
|
-
generateTypeScript,
|
|
36
|
-
writeGeneratedFiles,
|
|
37
|
-
type GeneratedCode,
|
|
38
|
-
} from './typescript-generator.js';
|
|
39
|
-
|
|
40
|
-
// Type IDs (CRC32)
|
|
41
|
-
export { generateTypeIds } from './type-ids-generator.js';
|
|
42
|
-
export { crc32, generateTypeIds as generateTypeIdMap, findCollisions } from './crc32.js';
|
|
43
|
-
|
|
44
|
-
// Serialization
|
|
45
|
-
export { generateSerializers } from './serialization-generator.js';
|
|
46
|
-
|
|
47
|
-
// Rust generation
|
|
48
|
-
export { generateRust, type RustGeneratedCode } from './rust-generator.js';
|
|
49
|
-
|
|
50
|
-
// High-level generator
|
|
51
|
-
export {
|
|
52
|
-
generateFromFile,
|
|
53
|
-
generateFromSchema,
|
|
54
|
-
generateAll,
|
|
55
|
-
type FullGeneratedCode,
|
|
56
|
-
type GeneratorOptions,
|
|
57
|
-
} from './generator.js';
|