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: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
],
"overrides": {
"cookie@<0.7.0": ">=0.7.0",
"lodash-es@>=4.0.0 <=4.17.22": ">=4.17.23",
"lodash@>=4.0.0 <=4.17.22": ">=4.17.23",
"lodash@>=4.0.0 <=4.17.23": ">=4.18.0",
"@better-auth/core": "1.4.19"
}
},
Expand Down
14 changes: 10 additions & 4 deletions packages/auth-adapters/better-auth/src/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function addDefaultNow(df: DataField) {
} as any;
const nowExpr: InvocationExpr = {
$type: 'InvocationExpr',
function: { $refText: 'now' },
function: { $refText: 'now', ref: undefined },
args: [],
$container: nowArg,
};
Expand Down Expand Up @@ -221,6 +221,7 @@ function initializeZmodel(config: AdapterConfig) {
$type: 'InvocationExpr',
function: {
$refText: 'env',
ref: undefined,
},
args: [],
$container: urlField,
Expand Down Expand Up @@ -391,6 +392,7 @@ function addOrUpdateModel(
$type: 'DataFieldType',
reference: {
$refText: upperCaseFirst(referencedCustomModelName),
ref: undefined,
},
array: (field.type as string).endsWith('[]'),
optional: !field.required,
Expand All @@ -408,6 +410,7 @@ function addOrUpdateModel(
$type: 'DataFieldAttribute',
decl: {
$refText: '@relation',
ref: undefined,
},
args: [],
$container: relationField,
Expand All @@ -430,6 +433,7 @@ function addOrUpdateModel(
$container: fieldsExpr,
target: {
$refText: fieldName,
ref: undefined,
},
};
fieldsExpr.items.push(fkRefExpr);
Expand All @@ -452,6 +456,7 @@ function addOrUpdateModel(
$container: referencesExpr,
target: {
$refText: field.references.field,
ref: undefined,
},
};
referencesExpr.items.push(pkRefExpr);
Expand All @@ -465,7 +470,7 @@ function addOrUpdateModel(
} as any;
const onDeleteValueExpr: ReferenceExpr = {
$type: 'ReferenceExpr',
target: { $refText: action },
target: { $refText: action, ref: undefined },
args: [],
$container: onDeleteArg,
};
Expand Down Expand Up @@ -495,6 +500,7 @@ function addOrUpdateModel(
$type: 'DataFieldType',
reference: {
$refText: relatedModel,
ref: undefined,
},
array: true,
optional: false,
Expand All @@ -512,7 +518,7 @@ function addOrUpdateModel(
function addModelAttribute(dataModel: DataModel, name: string, args: Omit<AttributeArg, '$container'>[] = []) {
const attr: DataModelAttribute = {
$type: 'DataModelAttribute',
decl: { $refText: name },
decl: { $refText: name, ref: undefined },
$container: dataModel,
args: [],
};
Expand All @@ -527,7 +533,7 @@ function addModelAttribute(dataModel: DataModel, name: string, args: Omit<Attrib
function addFieldAttribute(dataField: DataField, name: string, args: Omit<AttributeArg, '$container'>[] = []) {
const attr: DataFieldAttribute = {
$type: 'DataFieldAttribute',
decl: { $refText: name },
decl: { $refText: name, ref: undefined },
$container: dataField,
args: [],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function checkPluginResolution(schemaFile: string, model: Model) {
const provider = getPluginProvider(plugin);
if (!provider.startsWith('@core/')) {
const pluginSourcePath =
plugin.$cstNode?.parent?.element.$document?.uri?.fsPath ?? schemaFile;
plugin.$cstNode?.container?.astNode.$document?.uri?.fsPath ?? schemaFile;
await loadPluginModule(provider, path.dirname(pluginSourcePath));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async function runPull(options: PullOptions) {
});
// Add/update models and their fields
newModel.declarations
.filter((d) => [DataModel, Enum].includes(d.$type))
.filter((d) => d.$type === DataModel.$type || d.$type === Enum.$type)
.forEach((_declaration) => {
const newDataModel = _declaration as DataModel | Enum;
const declarations = services.shared.workspace.IndexManager.allElements(newDataModel.$type, docsSet).toArray();
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export async function run(options: Options) {
(
model.declarations.filter(
(v) =>
v.$cstNode?.parent?.element.$type === 'Model' &&
!!v.$cstNode.parent.element.$document?.uri?.fsPath,
v.$cstNode?.container?.astNode.$type === 'Model' &&
!!v.$cstNode.container.astNode.$document?.uri?.fsPath,
) as AbstractDeclaration[]
).map((v) => v.$cstNode!.parent!.element.$document!.uri!.fsPath),
).map((v) => v.$cstNode!.container!.astNode.$document!.uri!.fsPath),
);

const watchedPaths = getRootModelWatchPaths(model);
Expand Down Expand Up @@ -189,7 +189,7 @@ async function runPlugins(schemaFile: string, model: Model, outputPath: string,
// resolve relative plugin paths against the schema file where the plugin is declared,
// not the entry schema file
const pluginSourcePath =
plugin.$cstNode?.parent?.element.$document?.uri?.fsPath ?? schemaFile;
plugin.$cstNode?.container?.astNode.$document?.uri?.fsPath ?? schemaFile;
cliPlugin = await loadPluginModule(provider, path.dirname(pluginSourcePath));
}

Expand Down
1 change: 1 addition & 0 deletions packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"vscode-languageserver": "^9.0.1"
},
"devDependencies": {
"@types/node": "catalog:",
"@types/pluralize": "^0.0.33",
"@types/tmp": "catalog:",
"@zenstackhq/eslint-config": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function validationAfterImportMerge(model: Model) {
export async function formatDocument(content: string) {
const services = createZModelServices().ZModelLanguage;
const langiumDocuments = services.shared.workspace.LangiumDocuments;
const document = langiumDocuments.createDocument(URI.parse('memory://schema.zmodel'), content);
const document = langiumDocuments.createDocument(URI.parse('memory:///schema.zmodel'), content);
const formatter = services.lsp.Formatter as ZModelFormatter;
const identifier = { uri: document.uri.toString() };
const options = formatter.getFormatOptions() ?? {
Expand Down
14 changes: 7 additions & 7 deletions packages/language/src/factory/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class DataFieldAttributeFactory extends AstFactory<DataFieldAttribute> {
args: AttributeArgFactory[] = [];
decl?: Reference<Attribute>;
constructor() {
super({ type: DataFieldAttribute, node: { args: [] } });
super({ type: DataFieldAttribute.$type, node: { args: [] } });
}
setDecl(decl: Attribute) {
if (!decl) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class DataModelAttributeFactory extends AstFactory<DataModelAttribute> {
args: AttributeArgFactory[] = [];
decl?: Reference<Attribute>;
constructor() {
super({ type: DataModelAttribute, node: { args: [] } });
super({ type: DataModelAttribute.$type, node: { args: [] } });
}
setDecl(decl: Attribute) {
if (!decl) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class AttributeArgFactory extends AstFactory<AttributeArg> {
value?: AstFactory<Expression>;

constructor() {
super({ type: AttributeArg });
super({ type: AttributeArg.$type });
}

setName(name: RegularID) {
Expand All @@ -108,7 +108,7 @@ export class InternalAttributeFactory extends AstFactory<InternalAttribute> {
args: AttributeArgFactory[] = [];

constructor() {
super({ type: InternalAttribute, node: { args: [] } });
super({ type: InternalAttribute.$type, node: { args: [] } });
}

setDecl(decl: Attribute) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export class AttributeParamFactory extends AstFactory<AttributeParam> {

constructor() {
super({
type: AttributeParam,
type: AttributeParam.$type,
node: {
comments: [],
attributes: [],
Expand Down Expand Up @@ -199,7 +199,7 @@ export class AttributeParamTypeFactory extends AstFactory<AttributeParamType> {
reference?: Reference<TypeDeclaration>;
type?: AttributeParamType['type'];
constructor() {
super({ type: AttributeParamType });
super({ type: AttributeParamType.$type });
}
setArray(array: boolean) {
this.array = array;
Expand Down Expand Up @@ -244,7 +244,7 @@ export class AttributeFactory extends AstFactory<Attribute> {
params: AttributeParamFactory[] = [];

constructor() {
super({ type: Attribute, node: { comments: [], attributes: [], params: [] } });
super({ type: Attribute.$type, node: { comments: [], attributes: [], params: [] } });
}

setName(name: string) {
Expand Down
16 changes: 8 additions & 8 deletions packages/language/src/factory/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class DataModelFactory extends AstFactory<DataModel> {

constructor() {
super({
type: DataModel,
type: DataModel.$type,
node: {
attributes: [],
comments: [],
Expand Down Expand Up @@ -151,7 +151,7 @@ export class DataFieldFactory extends AstFactory<DataField> {
type?: DataFieldTypeFactory;

constructor() {
super({ type: DataField, node: { attributes: [], comments: [] } });
super({ type: DataField.$type, node: { attributes: [], comments: [] } });
}

addAttribute(
Expand Down Expand Up @@ -204,7 +204,7 @@ export class DataFieldTypeFactory extends AstFactory<DataFieldType> {
unsupported?: UnsupportedFieldTypeFactory;

constructor() {
super({ type: DataFieldType });
super({ type: DataFieldType.$type });
}

setArray(array: boolean) {
Expand Down Expand Up @@ -254,7 +254,7 @@ export class DataFieldTypeFactory extends AstFactory<DataFieldType> {
export class UnsupportedFieldTypeFactory extends AstFactory<UnsupportedFieldType> {
value?: AstFactory<LiteralExpr>;
constructor() {
super({ type: UnsupportedFieldType });
super({ type: UnsupportedFieldType.$type });
}
setValue(builder: (value: ExpressionBuilder<LiteralExpr>) => AstFactory<LiteralExpr>) {
this.value = builder(ExpressionBuilder());
Expand All @@ -269,7 +269,7 @@ export class ModelFactory extends AstFactory<Model> {
declarations: AstFactory<AbstractDeclaration>[] = [];
imports: ModelImportFactory[] = [];
constructor() {
super({ type: Model, node: { declarations: [], imports: [] } });
super({ type: Model.$type, node: { declarations: [], imports: [] } });
}
addImport(builder: (b: ModelImportFactory) => ModelImportFactory) {
this.imports.push(builder(new ModelImportFactory()).setContainer(this.node));
Expand All @@ -291,7 +291,7 @@ export class ModelImportFactory extends AstFactory<ModelImport> {
path?: string | undefined;

constructor() {
super({ type: ModelImport });
super({ type: ModelImport.$type });
}

setPath(path: string) {
Expand All @@ -310,7 +310,7 @@ export class EnumFactory extends AstFactory<Enum> {
attributes: DataModelAttributeFactory[] = [];

constructor() {
super({ type: Enum, node: { comments: [], fields: [], attributes: [] } });
super({ type: Enum.$type, node: { comments: [], fields: [], attributes: [] } });
}

addField(builder: (b: EnumFieldFactory) => EnumFieldFactory) {
Expand Down Expand Up @@ -344,7 +344,7 @@ export class EnumFieldFactory extends AstFactory<EnumField> {
attributes: DataFieldAttributeFactory[] = [];

constructor() {
super({ type: EnumField, node: { comments: [], attributes: [] } });
super({ type: EnumField.$type, node: { comments: [], attributes: [] } });
}

setName(name: RegularIDWithTypeNames) {
Expand Down
20 changes: 10 additions & 10 deletions packages/language/src/factory/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class UnaryExprFactory extends AstFactory<UnaryExpr> {
operand?: AstFactory<Expression>;

constructor() {
super({ type: UnaryExpr, node: { operator: '!' } });
super({ type: UnaryExpr.$type, node: { operator: '!' } });
}

setOperand(builder: (a: ExpressionBuilder) => AstFactory<Expression>) {
Expand All @@ -96,7 +96,7 @@ export class ReferenceExprFactory extends AstFactory<ReferenceExpr> {
args: ReferenceArgFactory[] = [];

constructor() {
super({ type: ReferenceExpr, node: { args: [] } });
super({ type: ReferenceExpr.$type, node: { args: [] } });
}

setTarget(target: ReferenceTarget) {
Expand Down Expand Up @@ -128,7 +128,7 @@ export class ReferenceArgFactory extends AstFactory<ReferenceArg> {
value?: AstFactory<Expression>;

constructor() {
super({ type: ReferenceArg });
super({ type: ReferenceArg.$type });
}

setName(name: string) {
Expand All @@ -153,7 +153,7 @@ export class MemberAccessExprFactory extends AstFactory<MemberAccessExpr> {
operand?: AstFactory<Expression>;

constructor() {
super({ type: MemberAccessExpr });
super({ type: MemberAccessExpr.$type });
}

setMember(target: Reference<MemberAccessTarget>) {
Expand All @@ -177,7 +177,7 @@ export class ObjectExprFactory extends AstFactory<ObjectExpr> {
fields: FieldInitializerFactory[] = [];

constructor() {
super({ type: ObjectExpr, node: { fields: [] } });
super({ type: ObjectExpr.$type, node: { fields: [] } });
}

addField(builder: (b: FieldInitializerFactory) => FieldInitializerFactory) {
Expand All @@ -194,7 +194,7 @@ export class FieldInitializerFactory extends AstFactory<FieldInitializer> {
value?: AstFactory<Expression>;

constructor() {
super({ type: FieldInitializer });
super({ type: FieldInitializer.$type });
}

setName(name: RegularID) {
Expand All @@ -219,7 +219,7 @@ export class InvocationExprFactory extends AstFactory<InvocationExpr> {
function?: Reference<FunctionDecl>;

constructor() {
super({ type: InvocationExpr, node: { args: [] } });
super({ type: InvocationExpr.$type, node: { args: [] } });
}

addArg(builder: (arg: ArgumentFactory) => ArgumentFactory) {
Expand All @@ -246,7 +246,7 @@ export class ArgumentFactory extends AstFactory<Argument> {
value?: AstFactory<Expression>;

constructor() {
super({ type: Argument });
super({ type: Argument.$type });
}

setValue(builder: (a: ExpressionBuilder) => AstFactory<Expression>) {
Expand All @@ -262,7 +262,7 @@ export class ArrayExprFactory extends AstFactory<ArrayExpr> {
items: AstFactory<Expression>[] = [];

constructor() {
super({ type: ArrayExpr, node: { items: [] } });
super({ type: ArrayExpr.$type, node: { items: [] } });
}

addItem(builder: (a: ExpressionBuilder) => AstFactory<Expression>) {
Expand All @@ -281,7 +281,7 @@ export class BinaryExprFactory extends AstFactory<BinaryExpr> {
// TODO: add support for CollectionPredicateBinding

constructor() {
super({ type: BinaryExpr });
super({ type: BinaryExpr.$type });
}

setOperator(operator: BinaryExpr['operator']) {
Expand Down
Loading
Loading