Skip to content

Commit 237bb59

Browse files
authored
fix: ts compilation issue with generated model meta (#2259)
1 parent 40a48c9 commit 237bb59

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/runtime/src/cross/model-meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type RuntimeAttribute = {
1212
/**
1313
* Attribute arguments
1414
*/
15-
args: Array<{ name?: string; value: unknown }>;
15+
args: Array<{ name?: string; value?: unknown }>;
1616
};
1717

1818
/**

packages/sdk/src/model-meta-generator.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,20 @@ export function generate(
8080
) {
8181
const sf = project.createSourceFile(options.output, undefined, { overwrite: true });
8282

83+
// generate: import type { ModelMeta } from '@zenstackhq/runtime';
84+
sf.addImportDeclaration({
85+
isTypeOnly: true,
86+
namedImports: ['ModelMeta'],
87+
moduleSpecifier: '@zenstackhq/runtime',
88+
});
89+
8390
const writer = new FastWriter();
8491
const extraFunctions: OptionalKind<FunctionDeclarationStructure>[] = [];
8592
generateModelMetadata(models, typeDefs, writer, options, extraFunctions);
8693

8794
sf.addVariableStatement({
8895
declarationKind: VariableDeclarationKind.Const,
89-
declarations: [{ name: 'metadata', initializer: writer.result }],
96+
declarations: [{ name: 'metadata', type: 'ModelMeta', initializer: writer.result }],
9097
});
9198

9299
if (extraFunctions.length > 0) {
@@ -364,7 +371,7 @@ function writeFields(
364371
function getAttributes(target: DataModelField | DataModel | TypeDefField): RuntimeAttribute[] {
365372
return target.attributes
366373
.map((attr) => {
367-
const args: Array<{ name?: string; value: unknown }> = [];
374+
const args: Array<{ name?: string; value?: unknown }> = [];
368375
for (const arg of attr.args) {
369376
const argName = arg.$resolvedParam?.name ?? arg.name;
370377
const argValue = exprToValue(arg.value);

0 commit comments

Comments
 (0)