Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test-ci": "ZENSTACK_TEST=1 pnpm -r run test --silent --forceExit",
"lint": "pnpm -r lint",
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/"
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/",
"unpublish-preview": "pnpm --recursive --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\""
},
"keywords": [],
"author": "",
Expand Down
3 changes: 1 addition & 2 deletions packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"watch": "concurrently \"langium generate --watch\" \"tsc --watch\"",
"lint": "eslint src --ext ts",
"build": "pnpm lint && pnpm clean && pnpm generate && tsc && copyfiles -F ./README.md ./LICENSE ./package.json dist && pnpm pack dist --pack-destination '../../../.build'",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm build && pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"watch": "tsc --watch",
"lint": "eslint src --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down
7 changes: 6 additions & 1 deletion packages/plugins/swr/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.

const models = getDataModels(model);

await generateModelMeta(project, models, path.join(outDir, '__model_meta.ts'), false, true);
await generateModelMeta(project, models, {
output: path.join(outDir, '__model_meta.ts'),
compile: false,
preserveTsFiles: true,
generateAttributes: false,
});

generateIndex(project, outDir, models);

Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/tanstack-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"watch": "concurrently \"tsc --watch\" \"tsup-node --config ./tsup.config.ts --watch\" \"tsup-node --config ./tsup-v5.config.ts --watch\"",
"lint": "eslint src --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down
7 changes: 6 additions & 1 deletion packages/plugins/tanstack-query/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
throw new PluginError(options.name, `Unsupported version "${version}": use "v4" or "v5"`);
}

await generateModelMeta(project, models, path.join(outDir, '__model_meta.ts'), false, true);
await generateModelMeta(project, models, {
output: path.join(outDir, '__model_meta.ts'),
compile: false,
preserveTsFiles: true,
generateAttributes: false,
});

generateIndex(project, outDir, models, target, version);

Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/trpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"watch": "tsc --watch",
"lint": "eslint src --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"build": "pnpm lint && pnpm clean && tsc && tsup-node --config ./tsup-browser.config.ts && tsup-node --config ./tsup-cross.config.ts && copyfiles ./package.json ./README.md ../../LICENSE dist && copyfiles -u1 'res/**/*' dist && pnpm pack dist --pack-destination '../../../.build'",
"watch": "concurrently \"tsc --watch\" \"tsup-node --config ./tsup-browser.config.ts --watch\" \"tsup-node --config ./tsup-cross.config.ts --watch\"",
"lint": "eslint src --ext ts",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"main": "index.js",
"types": "index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"lint": "eslint src tests --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --registry http://localhost:4873",
"postinstall": "node bin/post-install.js"
},
"dependencies": {
Expand Down
7 changes: 6 additions & 1 deletion packages/schema/src/plugins/model-meta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const run: PluginFunction = async (model, options, _dmmf, globalOptions) => {
shouldCompile = globalOptions.compile;
}

await generateModelMeta(project, dataModels, outFile, shouldCompile, options.preserveTsFiles === true);
await generateModelMeta(project, dataModels, {
output: outFile,
compile: shouldCompile,
preserveTsFiles: options.preserveTsFiles === true,
generateAttributes: true,
});
};

export default run;
3 changes: 1 addition & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"lint": "eslint src --ext ts",
"build": "pnpm lint && pnpm clean && tsc && copyfiles ./package.json ./LICENSE ./README.md dist && pnpm pack dist --pack-destination '../../../.build'",
"watch": "tsc --watch",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm build && pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down
27 changes: 14 additions & 13 deletions packages/sdk/src/model-meta-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ import {
saveProject,
} from '.';

export async function generate(
project: Project,
models: DataModel[],
output: string,
compile: boolean,
preserveTsFiles: boolean
) {
const sf = project.createSourceFile(output, undefined, { overwrite: true });
export type ModelMetaGeneratorOptions = {
output: string;
compile: boolean;
preserveTsFiles: boolean;
generateAttributes: boolean;
};

export async function generate(project: Project, models: DataModel[], options: ModelMetaGeneratorOptions) {
const sf = project.createSourceFile(options.output, undefined, { overwrite: true });
sf.addStatements('/* eslint-disable */');
sf.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [{ name: 'metadata', initializer: (writer) => generateModelMetadata(models, writer) }],
declarations: [{ name: 'metadata', initializer: (writer) => generateModelMetadata(models, writer, options) }],
});
sf.addStatements('export default metadata;');

if (!compile || preserveTsFiles) {
if (!options.compile || options.preserveTsFiles) {
// save ts files
await saveProject(project);
}
if (compile) {
if (options.compile) {
await emitProject(project);
}
}

function generateModelMetadata(dataModels: DataModel[], writer: CodeBlockWriter) {
function generateModelMetadata(dataModels: DataModel[], writer: CodeBlockWriter, options: ModelMetaGeneratorOptions) {
writer.block(() => {
writer.write('fields:');
writer.block(() => {
Expand All @@ -75,7 +76,7 @@ function generateModelMetadata(dataModels: DataModel[], writer: CodeBlockWriter)
isDataModel: ${isDataModel(f.type.reference?.ref)},
isArray: ${f.type.array},
isOptional: ${f.type.optional},
attributes: ${JSON.stringify(getFieldAttributes(f))},
attributes: ${options.generateAttributes ? JSON.stringify(getFieldAttributes(f)) : '[]'},
backLink: ${backlink ? "'" + backlink.name + "'" : 'undefined'},
isRelationOwner: ${isRelationOwner(f, backlink)},
isForeignKey: ${isForeignKeyField(f)},
Expand Down
3 changes: 1 addition & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"watch": "tsc --watch",
"lint": "eslint src --ext ts",
"test": "ZENSTACK_TEST=1 jest",
"prepublishOnly": "pnpm build",
"publish-dev": "pnpm publish --tag dev"
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"directory": "dist",
Expand Down