@zenstackhq/language 3.9.8 → 3.10.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.
@@ -1,4 +1,4 @@
1
- import { Bt as isModel, Ct as isDataModel, Dt as isEnumField, Gt as isPlugin, It as isInvocationExpr, Lt as isLiteralExpr, Ot as isExpression, Rt as isMemberAccessExpr, Tt as isDataSource, Ut as isNumberLiteral, Wt as isObjectExpr, Xt as isReferenceExpr, at as isAttribute, en as isStringLiteral, it as isArrayExpr, lt as isBinaryExpr, mt as isConfigArrayExpr, rn as isTypeDef, yt as isDataField } from "./ast-DJOHdY8l.mjs";
1
+ import { Et as isDataSource, Gt as isObjectExpr, Kt as isPlugin, Lt as isInvocationExpr, Ot as isEnumField, Rt as isLiteralExpr, Vt as isModel, Wt as isNumberLiteral, Zt as isReferenceExpr, at as isAttribute, in as isTypeDef, it as isArrayExpr, kt as isExpression, lt as isBinaryExpr, mt as isConfigArrayExpr, tn as isStringLiteral, wt as isDataModel, yt as isDataField, zt as isMemberAccessExpr } from "./ast-taPWpbmU.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { AstUtils, URI } from "langium";
4
4
  import fs from "node:fs";
@@ -144,6 +144,37 @@ function isRelationshipField(field) {
144
144
  return isDataModel(field.type.reference?.ref);
145
145
  }
146
146
  /**
147
+ * Returns the name of the relation the given field belongs to, as declared in its `@relation`
148
+ * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.
149
+ *
150
+ * The name argument is matched by its literal name (or absence of a name for the positional
151
+ * argument) rather than by `$resolvedParam`, because this function is also used during schema
152
+ * validation, where `$resolvedParam` may not have been resolved yet for attributes that have
153
+ * not been validated.
154
+ */
155
+ function getRelationName(field) {
156
+ const relation = getAttribute(field, "@relation");
157
+ if (!relation) return;
158
+ for (const arg of relation.args) if (!arg.name || arg.name === "name") {
159
+ if (isStringLiteral(arg.value)) return arg.value.value;
160
+ }
161
+ }
162
+ /**
163
+ * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an
164
+ * array and whose opposite relation field on the referenced model (belonging to the same relation)
165
+ * is also an array referencing back to the containing model.
166
+ */
167
+ function isManyToManyField(field) {
168
+ if (!isRelationshipField(field) || !field.type.array) return false;
169
+ const oppositeModel = field.type.reference.ref;
170
+ const containingModel = field.$container;
171
+ const relationName = getRelationName(field);
172
+ return getAllFields(oppositeModel).some((f) => {
173
+ if (f === field || !f.type.array || f.type.reference?.ref?.name !== containingModel.name) return false;
174
+ return getRelationName(f) === relationName;
175
+ });
176
+ }
177
+ /**
147
178
  * Returns if the given field is a computed field.
148
179
  */
149
180
  function isComputedField(field) {
@@ -174,6 +205,12 @@ function isLiteAttribute(node) {
174
205
  return isAttribute(node) && hasAttribute(node, "@@@lite");
175
206
  }
176
207
  /**
208
+ * Returns if the given node is primitive type def.
209
+ */
210
+ function isPrimitiveTypeDef(node) {
211
+ return isTypeDef(node) && !!node.base;
212
+ }
213
+ /**
177
214
  * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
178
215
  * if no datasource is found or its provider is not a literal.
179
216
  */
@@ -476,6 +513,9 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
476
513
  fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
477
514
  return fields;
478
515
  }
516
+ function getPrimitiveTypeDefThisField(td) {
517
+ return td.fields.find((f) => f.name === "this");
518
+ }
479
519
  /**
480
520
  * Gets all attributes of a data model or type def, including inherited attributes
481
521
  * from base models and mixins.
@@ -559,6 +599,6 @@ function findRootNode(node) {
559
599
  return node;
560
600
  }
561
601
  //#endregion
562
- export { IssueCodes as $, isAuthInvocation as A, isLiteAttribute as B, getNumberLiteral as C, getStringLiteral as D, getRecursiveBases as E, isComputedField as F, mapBuiltinTypeToExpressionType as G, isNativeTypeMappingAttribute as H, isDataFieldReference as I, resolveTransitiveImports as J, resolveImport as K, isDelegateModel as L, isBeforeInvocation as M, isCheckInvocation as N, getUniqueFields as O, isCollectionPredicate as P, ExpressionContext as Q, isEnumFieldReference as R, getModelUniqueFields as S, getPluginDocuments as T, isPrismaAttribute as U, isMemberContainer as V, isRelationshipField as W, typeAssignable as X, resolved as Y, DB_PROVIDERS_SUPPORTING_LIST_TYPE as Z, getFieldReference as _, getAllDeclarationsIncludingImports as a, getLiteralArray as b, getAllLoadedDataModelsAndTypeDefs as c, getAttributeArgLiteral as d, PLUGIN_MODULE_NAME as et, getAuthDecl as f, getDocument as g, getDataSourceProvider as h, getAllDataModelsIncludingImports as i, isAuthOrAuthMemberAccess as j, hasAttribute as k, getAttribute as l, getDataModelAndTypeDefs as m, findUpAst as n, STD_LIB_MODULE_NAME as nt, getAllFields as o, getContainingDataModel as p, resolveImportUri as q, getAllAttributes as r, SUPPORTED_PROVIDERS as rt, getAllLoadedAndReachableDataModelsAndTypeDefs as s, findRootNode as t, SCALAR_TYPES as tt, getAttributeArg as u, getFunctionExpressionContext as v, getObjectLiteral as w, getModelIdFields as x, getLiteral as y, isFromStdlib as z };
602
+ export { resolved as $, getUniqueFields as A, isEnumFieldReference as B, getNumberLiteral as C, getRecursiveBases as D, getPrimitiveTypeDefThisField as E, isCheckInvocation as F, isNativeTypeMappingAttribute as G, isLiteAttribute as H, isCollectionPredicate as I, isRelationshipField as J, isPrimitiveTypeDef as K, isComputedField as L, isAuthInvocation as M, isAuthOrAuthMemberAccess as N, getRelationName as O, isBeforeInvocation as P, resolveTransitiveImports as Q, isDataFieldReference as R, getModelUniqueFields as S, getPluginDocuments as T, isManyToManyField as U, isFromStdlib as V, isMemberContainer as W, resolveImport as X, mapBuiltinTypeToExpressionType as Y, resolveImportUri as Z, getFieldReference as _, getAllDeclarationsIncludingImports as a, SCALAR_TYPES as at, getLiteralArray as b, getAllLoadedDataModelsAndTypeDefs as c, getAttributeArgLiteral as d, typeAssignable as et, getAuthDecl as f, getDocument as g, getDataSourceProvider as h, getAllDataModelsIncludingImports as i, PLUGIN_MODULE_NAME as it, hasAttribute as j, getStringLiteral as k, getAttribute as l, getDataModelAndTypeDefs as m, findUpAst as n, ExpressionContext as nt, getAllFields as o, STD_LIB_MODULE_NAME as ot, getContainingDataModel as p, isPrismaAttribute as q, getAllAttributes as r, IssueCodes as rt, getAllLoadedAndReachableDataModelsAndTypeDefs as s, SUPPORTED_PROVIDERS as st, findRootNode as t, DB_PROVIDERS_SUPPORTING_LIST_TYPE as tt, getAttributeArg as u, getFunctionExpressionContext as v, getObjectLiteral as w, getModelIdFields as x, getLiteral as y, isDelegateModel as z };
563
603
 
564
- //# sourceMappingURL=utils-jgngKwh1.mjs.map
604
+ //# sourceMappingURL=utils-BWba17ro.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-BWba17ro.mjs","names":[],"sources":["../src/constants.ts","../src/utils.ts"],"sourcesContent":["/**\n * Supported db providers\n */\nexport const SUPPORTED_PROVIDERS = ['sqlite', 'postgresql', 'mysql'];\n\n/**\n * All scalar types\n */\nexport const SCALAR_TYPES = ['String', 'Int', 'Float', 'Decimal', 'BigInt', 'Boolean', 'Bytes', 'DateTime'];\n\n/**\n * Name of standard library module\n */\nexport const STD_LIB_MODULE_NAME = 'stdlib.zmodel';\n\n/**\n * Name of module contributed by plugins\n */\nexport const PLUGIN_MODULE_NAME = 'plugin.zmodel';\n\n/**\n * Validation issues\n */\nexport enum IssueCodes {\n MissingOppositeRelation = 'miss-opposite-relation',\n}\n\n/**\n * Expression context\n */\nexport enum ExpressionContext {\n DefaultValue = 'DefaultValue',\n AccessPolicy = 'AccessPolicy',\n ValidationRule = 'ValidationRule',\n Index = 'Index',\n}\n\n/**\n * Database providers that support list field types.\n */\nexport const DB_PROVIDERS_SUPPORTING_LIST_TYPE = ['postgresql'];\n","import { AstUtils, URI, type AstNode, type LangiumDocument, type LangiumDocuments, type Reference } from 'langium';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { PLUGIN_MODULE_NAME, STD_LIB_MODULE_NAME, type ExpressionContext } from './constants';\nimport {\n InternalAttribute,\n isArrayExpr,\n isAttribute,\n isBinaryExpr,\n isConfigArrayExpr,\n isDataField,\n isDataModel,\n isDataSource,\n isEnumField,\n isExpression,\n isInvocationExpr,\n isLiteralExpr,\n isMemberAccessExpr,\n isModel,\n isNumberLiteral,\n isObjectExpr,\n isPlugin,\n isReferenceExpr,\n isStringLiteral,\n isTypeDef,\n type Attribute,\n type AttributeParam,\n type BinaryExpr,\n type BuiltinType,\n type ConfigExpr,\n type DataField,\n type DataFieldAttribute,\n type DataModel,\n type DataModelAttribute,\n type Enum,\n type EnumField,\n type Expression,\n type ExpressionType,\n type FunctionDecl,\n type Model,\n type ModelImport,\n type ReferenceExpr,\n type TypeDef,\n} from './generated/ast';\n\nexport type AttributeTarget =\n | DataModel\n | TypeDef\n | DataField\n | Enum\n | EnumField\n | FunctionDecl\n | Attribute\n | AttributeParam;\n\nexport function hasAttribute(decl: AttributeTarget, name: string) {\n return !!getAttribute(decl, name);\n}\n\nexport function getAttribute(decl: AttributeTarget, name: string) {\n return (decl.attributes as (DataModelAttribute | DataFieldAttribute)[]).find((attr) => attr.decl.$refText === name);\n}\n\nexport function isFromStdlib(node: AstNode) {\n const model = AstUtils.getContainerOfType(node, isModel);\n return !!model && !!model.$document && model.$document.uri.path.endsWith(STD_LIB_MODULE_NAME);\n}\n\nexport function isAuthInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'auth' && isFromStdlib(node.function.ref);\n}\n\n/**\n * Try getting string value from a potential string literal expression\n */\nexport function getStringLiteral(node: AstNode | undefined): string | undefined {\n return isStringLiteral(node) ? node.value : undefined;\n}\n\n/**\n * Try getting number value from a potential number literal expression\n */\nexport function getNumberLiteral(node: AstNode | undefined): number | undefined {\n return isNumberLiteral(node) ? Number(node.value) : undefined;\n}\n\nconst isoDateTimeRegex = /^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?)?)?$/i;\n\n/**\n * Determines if the given sourceType is assignable to a destination of destType\n */\nexport function typeAssignable(destType: ExpressionType, sourceType: ExpressionType, sourceExpr?: Expression): boolean {\n // implicit conversion from ISO datetime string to datetime\n if (destType === 'DateTime' && sourceType === 'String' && sourceExpr && isStringLiteral(sourceExpr)) {\n const literal = getStringLiteral(sourceExpr);\n if (literal && isoDateTimeRegex.test(literal)) {\n // implicitly convert to DateTime\n sourceType = 'DateTime';\n }\n }\n\n switch (destType) {\n case 'Any':\n return true;\n case 'Float':\n return sourceType === 'Any' || sourceType === 'Int' || sourceType === 'Float';\n default:\n return sourceType === 'Any' || sourceType === destType;\n }\n}\n\n/**\n * Maps a ZModel builtin type to expression type\n */\nexport function mapBuiltinTypeToExpressionType(type: BuiltinType | ExpressionType): ExpressionType {\n switch (type) {\n case 'Any':\n case 'Boolean':\n case 'String':\n case 'DateTime':\n case 'Int':\n case 'Float':\n case 'Null':\n case 'Object':\n case 'Unsupported':\n case 'Void':\n case 'Undefined':\n return type;\n case 'BigInt':\n return 'Int';\n case 'Decimal':\n return 'Float';\n case 'Json':\n case 'Bytes':\n return 'Any';\n }\n}\n\n/**\n * Determines if the given expression is an invocation of `auth` or a member access on the result of an `auth` invocation (e.g. `auth().role`).\n */\nexport function isAuthOrAuthMemberAccess(expr: Expression): boolean {\n return isAuthInvocation(expr) || (isMemberAccessExpr(expr) && isAuthOrAuthMemberAccess(expr.operand));\n}\n\n/**\n * Determines if the given expression is a reference to an enum field.\n */\nexport function isEnumFieldReference(node: AstNode): node is ReferenceExpr {\n return isReferenceExpr(node) && isEnumField(node.target.ref);\n}\n\n/**\n * Determines if the given expression is a reference to a data field.\n */\nexport function isDataFieldReference(node: AstNode): node is ReferenceExpr {\n return isReferenceExpr(node) && isDataField(node.target.ref);\n}\n\n/**\n * Returns if the given field is a relation field.\n */\nexport function isRelationshipField(field: DataField) {\n return isDataModel(field.type.reference?.ref);\n}\n\n/**\n * Returns the name of the relation the given field belongs to, as declared in its `@relation`\n * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.\n *\n * The name argument is matched by its literal name (or absence of a name for the positional\n * argument) rather than by `$resolvedParam`, because this function is also used during schema\n * validation, where `$resolvedParam` may not have been resolved yet for attributes that have\n * not been validated.\n */\nexport function getRelationName(field: DataField): string | undefined {\n const relation = getAttribute(field, '@relation');\n if (!relation) {\n return undefined;\n }\n for (const arg of relation.args) {\n if (!arg.name || arg.name === 'name') {\n if (isStringLiteral(arg.value)) {\n return arg.value.value;\n }\n }\n }\n return undefined;\n}\n\n/**\n * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an\n * array and whose opposite relation field on the referenced model (belonging to the same relation)\n * is also an array referencing back to the containing model.\n */\nexport function isManyToManyField(field: DataField) {\n if (!isRelationshipField(field) || !field.type.array) {\n return false;\n }\n\n const oppositeModel = field.type.reference!.ref as DataModel;\n const containingModel = field.$container as DataModel;\n const relationName = getRelationName(field);\n\n return getAllFields(oppositeModel).some((f) => {\n if (f === field || !f.type.array || f.type.reference?.ref?.name !== containingModel.name) {\n return false;\n }\n // the opposite field must belong to the same relation: either both declare the same\n // explicit relation name, or both are unnamed\n return getRelationName(f) === relationName;\n });\n}\n\n/**\n * Returns if the given field is a computed field.\n */\nexport function isComputedField(field: DataField) {\n return hasAttribute(field, '@computed');\n}\n\n/**\n * Determines if the given data model is a delegate model (i.e. marked with `@@delegate` attribute).\n */\nexport function isDelegateModel(node: AstNode) {\n return isDataModel(node) && hasAttribute(node, '@@delegate');\n}\n\n/**\n * Returns if the given node is a Prisma attribute.\n */\nexport function isPrismaAttribute(node: AstNode): node is Attribute {\n return isAttribute(node) && hasAttribute(node, '@@@prisma');\n}\n\n/**\n * Returns if the given node is a native type mapping attribute.\n */\nexport function isNativeTypeMappingAttribute(node: AstNode): node is Attribute {\n return isPrismaAttribute(node) && node.name.startsWith('@db.');\n}\n\n/**\n * Returns if the given node is a lite attribute.\n */\nexport function isLiteAttribute(node: AstNode): node is Attribute {\n return isAttribute(node) && hasAttribute(node, '@@@lite');\n}\n\n/**\n * Returns if the given node is primitive type def.\n */\nexport function isPrimitiveTypeDef(node: AstNode): node is TypeDef {\n return isTypeDef(node) && !!node.base;\n}\n\n/**\n * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined\n * if no datasource is found or its provider is not a literal.\n */\nexport function getDataSourceProvider(model: Model) {\n const dataSource = model.declarations.find(isDataSource);\n if (!dataSource) {\n return undefined;\n }\n const providerField = dataSource.fields.find((f) => f.name === 'provider');\n if (!providerField) {\n return undefined;\n }\n return getLiteral<string>(providerField.value);\n}\n\n/**\n * Resolves the given reference and returns the target AST node. Throws an error if the reference is not resolved.\n */\nexport function resolved<T extends AstNode>(ref: Reference<T>): T {\n if (!ref.ref) {\n throw new Error(`Reference not resolved: ${ref.$refText}`);\n }\n return ref.ref;\n}\n\n/**\n * Gets all base models and mixins of a data model or type def, recursively.\n */\nexport function getRecursiveBases(\n decl: DataModel | TypeDef,\n includeDelegate = true,\n documents?: LangiumDocuments,\n seen = new Set<DataModel | TypeDef>(),\n): (TypeDef | DataModel)[] {\n const result: (TypeDef | DataModel)[] = [];\n if (seen.has(decl)) {\n return result;\n }\n seen.add(decl);\n const bases = [...decl.mixins, ...(isDataModel(decl) && decl.baseModel ? [decl.baseModel] : [])];\n bases.forEach((base) => {\n let baseDecl: TypeDef | DataModel | undefined;\n\n if (base.ref && (isTypeDef(base.ref) || isDataModel(base.ref))) {\n // base is already resolved\n baseDecl = base.ref;\n } else {\n // otherwise, search by name, in all imported documents if provided\n const declarations = documents\n ? getAllDeclarationsIncludingImports(documents, decl.$container)\n : decl.$container.declarations;\n\n baseDecl = declarations.find(\n (d): d is TypeDef | DataModel => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText,\n );\n }\n\n if (baseDecl) {\n if (!includeDelegate && isDelegateModel(baseDecl)) {\n return;\n }\n result.push(baseDecl);\n result.push(...getRecursiveBases(baseDecl, includeDelegate, documents, seen));\n }\n });\n return result;\n}\n\n/**\n * Gets `@@id` fields declared at the data model level (including search in base models)\n */\nexport function getModelIdFields(model: DataModel) {\n const modelsToCheck = [model, ...getRecursiveBases(model)];\n\n for (const modelToCheck of modelsToCheck) {\n const allAttributes = getAllAttributes(modelToCheck);\n const idAttr = allAttributes.find((attr) => attr.decl.$refText === '@@id');\n if (!idAttr) {\n continue;\n }\n const fieldsArg = idAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n continue;\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n }\n\n return [];\n}\n\n/**\n * Gets `@@unique` fields declared at the data model level (including search in base models)\n */\nexport function getModelUniqueFields(model: DataModel) {\n const modelsToCheck = [model, ...getRecursiveBases(model)];\n\n for (const modelToCheck of modelsToCheck) {\n const allAttributes = getAllAttributes(modelToCheck);\n const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === '@@unique');\n if (!uniqueAttr) {\n continue;\n }\n const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n continue;\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n }\n\n return [];\n}\n\n/**\n * Gets lists of unique fields declared at the data model level\n *\n * TODO: merge this with {@link getModelUniqueFields}\n */\nexport function getUniqueFields(model: DataModel) {\n const uniqueAttrs = model.attributes.filter(\n (attr) => attr.decl.ref?.name === '@@unique' || attr.decl.ref?.name === '@@id',\n );\n return uniqueAttrs.map((uniqueAttr) => {\n const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n return [];\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n });\n}\n\n/**\n * Finds the first ancestor of the given AST node that satisfies the given predicate function. Returns `undefined` if no such ancestor is found.\n */\nexport function findUpAst(node: AstNode, predicate: (node: AstNode) => boolean): AstNode | undefined {\n let curr: AstNode | undefined = node;\n while (curr) {\n if (predicate(curr)) {\n return curr;\n }\n curr = curr.$container;\n }\n return undefined;\n}\n\n/**\n * Tries to get the literal value from the given expression. Returns `undefined` if the expression is not a literal or if the literal value cannot be determined.\n */\nexport function getLiteral<T extends string | number | boolean | any = any>(\n expr: Expression | ConfigExpr | undefined,\n): T | undefined {\n switch (expr?.$type) {\n case 'ObjectExpr':\n return getObjectLiteral<T>(expr);\n case 'StringLiteral':\n case 'BooleanLiteral':\n return expr.value as T;\n case 'NumberLiteral':\n return parseFloat(expr.value) as T;\n default:\n return undefined;\n }\n}\n\n/**\n * Tries to get an object literal from the given expression. Returns `undefined` if the expression is not an object literal or if any of the field values cannot be determined.\n */\nexport function getObjectLiteral<T>(expr: Expression | ConfigExpr | undefined): T | undefined {\n if (!expr || !isObjectExpr(expr)) {\n return undefined;\n }\n const result: Record<string, unknown> = {};\n for (const field of expr.fields) {\n let fieldValue: unknown;\n if (isLiteralExpr(field.value)) {\n fieldValue = getLiteral(field.value);\n } else if (isArrayExpr(field.value)) {\n fieldValue = getLiteralArray(field.value);\n } else if (isObjectExpr(field.value)) {\n fieldValue = getObjectLiteral(field.value);\n }\n if (fieldValue === undefined) {\n return undefined;\n } else {\n result[field.name] = fieldValue;\n }\n }\n return result as T;\n}\n\nexport function getLiteralArray<T extends string | number | boolean | any = any>(\n expr: Expression | ConfigExpr | undefined,\n): T[] | undefined {\n const arr = getArray(expr);\n if (!arr) {\n return undefined;\n }\n return arr.map((item) => isExpression(item) && getLiteral<T>(item)).filter((v): v is T => v !== undefined);\n}\n\nfunction getArray(expr: Expression | ConfigExpr | undefined) {\n return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : undefined;\n}\n\n/**\n * Gets the value of the argument with the given name from the given attribute. Returns `undefined` if no such argument is found or if the argument value cannot be determined.\n */\nexport function getAttributeArg(\n attr: DataModelAttribute | DataFieldAttribute | InternalAttribute,\n name: string,\n): Expression | undefined {\n return attr.args.find((arg) => arg.$resolvedParam?.name === name)?.value;\n}\n\n/**\n * Gets the literal value of the argument with the given name from the given attribute. Returns `undefined` if no such argument is found or if the argument value cannot be determined or is not a literal.\n */\nexport function getAttributeArgLiteral<T extends string | number | boolean>(\n attr: DataModelAttribute | DataFieldAttribute | InternalAttribute,\n name: string,\n): T | undefined {\n for (const arg of attr.args) {\n if (arg.$resolvedParam?.name === name) {\n return getLiteral<T>(arg.value);\n }\n }\n return undefined;\n}\n\n/**\n * Gets the allowed expression contexts for the given function declaration by looking for `@@expressionContext` attribute.\n * Returns an empty array if no such attribute is found or if the attribute value cannot be determined.\n */\nexport function getFunctionExpressionContext(funcDecl: FunctionDecl) {\n const funcAllowedContext: ExpressionContext[] = [];\n const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === '@@@expressionContext');\n if (funcAttr) {\n const contextArg = funcAttr.args[0]?.value;\n if (isArrayExpr(contextArg)) {\n contextArg.items.forEach((item) => {\n if (isEnumFieldReference(item)) {\n funcAllowedContext.push(item.target.$refText as ExpressionContext);\n }\n });\n }\n }\n return funcAllowedContext;\n}\n\n/**\n * Gets the data field referenced by the given expression, if any. Returns `undefined` if the expression is not a reference to a data field.\n */\nexport function getFieldReference(expr: Expression): DataField | undefined {\n if (isReferenceExpr(expr) && isDataField(expr.target.ref)) {\n return expr.target.ref;\n } else if (isMemberAccessExpr(expr) && isDataField(expr.member.ref)) {\n return expr.member.ref;\n } else {\n return undefined;\n }\n}\n\n// TODO: move to policy plugin\nexport function isCheckInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'check';\n}\n\n/**\n * Resolves the transitive imports of the given model and returns the list of imported models. The given model itself is not included in the result.\n */\nexport function resolveTransitiveImports(documents: LangiumDocuments, model: Model) {\n return resolveTransitiveImportsInternal(documents, model);\n}\n\nfunction resolveTransitiveImportsInternal(\n documents: LangiumDocuments,\n model: Model,\n initialModel = model,\n visited: Set<string> = new Set(),\n models: Set<Model> = new Set(),\n) {\n const doc = AstUtils.getDocument(model);\n const initialDoc = AstUtils.getDocument(initialModel);\n\n if (initialDoc.uri.fsPath.toLowerCase() !== doc.uri.fsPath.toLowerCase()) {\n models.add(model);\n }\n\n const normalizedPath = doc.uri.fsPath.toLowerCase();\n if (!visited.has(normalizedPath)) {\n visited.add(normalizedPath);\n for (const imp of model.imports) {\n const importedModel = resolveImport(documents, imp);\n if (importedModel) {\n resolveTransitiveImportsInternal(documents, importedModel, initialModel, visited, models);\n }\n }\n }\n return Array.from(models);\n}\n\n/**\n * Resolves the given import and returns the imported model. Returns `undefined`\n * if the import cannot be resolved.\n */\nexport function resolveImport(documents: LangiumDocuments, imp: ModelImport) {\n const resolvedUri = resolveImportUri(imp);\n try {\n if (resolvedUri) {\n let resolvedDocument = documents.getDocument(resolvedUri);\n if (!resolvedDocument) {\n const content = fs.readFileSync(resolvedUri.fsPath, 'utf-8');\n resolvedDocument = documents.createDocument(resolvedUri, content);\n }\n const node = resolvedDocument.parseResult.value;\n if (isModel(node)) {\n return node;\n }\n }\n } catch {\n // NOOP\n }\n return undefined;\n}\n\n/**\n * Resolves the given import and returns the URI of the imported model.\n * Returns `undefined` if the import cannot be resolved.\n */\nexport function resolveImportUri(imp: ModelImport) {\n if (!imp.path) {\n return undefined;\n }\n const doc = AstUtils.getDocument(imp);\n const dir = path.dirname(doc.uri.fsPath);\n const importPath = imp.path.endsWith('.zmodel') ? imp.path : `${imp.path}.zmodel`;\n return URI.file(path.resolve(dir, importPath));\n}\n\n/**\n * Gets data models and type defs in the ZModel schema.\n */\nexport function getDataModelAndTypeDefs(model: Model, includeIgnored = false) {\n const r = model.declarations.filter((d): d is DataModel | TypeDef => isDataModel(d) || isTypeDef(d));\n if (includeIgnored) {\n return r;\n } else {\n return r.filter((model) => !hasAttribute(model, '@@ignore'));\n }\n}\n\n/**\n * Gets all declarations of the given model and its transitive imports.\n */\nexport function getAllDeclarationsIncludingImports(documents: LangiumDocuments, model: Model) {\n const imports = resolveTransitiveImports(documents, model);\n return model.declarations.concat(...imports.map((imp) => imp.declarations));\n}\n\n/**\n * Gets the model used for auth context, by looking for a model with `@@auth` attribute or a model named `User`.\n * Returns `undefined` if no such model is found.\n */\nexport function getAuthDecl(decls: (DataModel | TypeDef)[]) {\n let authModel = decls.find((d) => hasAttribute(d, '@@auth'));\n if (!authModel) {\n authModel = decls.find((d) => d.name === 'User');\n }\n return authModel;\n}\n\n// TODO: move to policy plugin\nexport function isBeforeInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'before';\n}\n\n/**\n * Determines if the given AST node is a collection predicate.\n */\nexport function isCollectionPredicate(node: AstNode): node is BinaryExpr {\n return isBinaryExpr(node) && ['?', '!', '^'].includes(node.operator);\n}\n\n/**\n * Gets all data models and type defs from the given documents registry.\n */\nexport function getAllLoadedDataModelsAndTypeDefs(langiumDocuments: LangiumDocuments) {\n return langiumDocuments.all\n .map((doc) => doc.parseResult.value as Model)\n .flatMap((model) => model.declarations.filter((d): d is DataModel | TypeDef => isDataModel(d) || isTypeDef(d)))\n .toArray();\n}\n\n/**\n * Gets all data models from the given documents registry and the transitive imports of the given model.\n */\nexport function getAllDataModelsIncludingImports(documents: LangiumDocuments, model: Model) {\n return getAllDeclarationsIncludingImports(documents, model).filter(isDataModel);\n}\n\n/**\n * Gets all data models and type defs from the given documents registry and the transitive imports\n * of the given model. If `fromModel` is not provided, returns all loaded data models and type defs.\n */\nexport function getAllLoadedAndReachableDataModelsAndTypeDefs(\n langiumDocuments: LangiumDocuments,\n fromModel?: DataModel,\n) {\n // get all data models from loaded documents\n const allDataModels = getAllLoadedDataModelsAndTypeDefs(langiumDocuments);\n\n if (fromModel) {\n // merge data models transitively reached from the current model\n const model = AstUtils.getContainerOfType(fromModel, isModel);\n if (model) {\n const transitiveDataModels = getAllDataModelsIncludingImports(langiumDocuments, model);\n transitiveDataModels.forEach((dm) => {\n if (!allDataModels.includes(dm)) {\n allDataModels.push(dm);\n }\n });\n }\n }\n\n return allDataModels;\n}\n\n/**\n * Gets the containing data model of the given AST node, if any.\n * Returns `undefined` if the node is not contained in a data model.\n */\nexport function getContainingDataModel(node: AstNode): DataModel | undefined {\n let curr: AstNode | undefined = node.$container;\n while (curr) {\n if (isDataModel(curr)) {\n return curr;\n }\n curr = curr.$container;\n }\n return undefined;\n}\n\n/**\n * Determines if the given AST node can contain members.\n */\nexport function isMemberContainer(node: unknown): node is DataModel | TypeDef {\n return isDataModel(node) || isTypeDef(node);\n}\n\n/**\n * Gets all fields of a data model or type def, including inherited fields from base models and mixins.\n */\nexport function getAllFields(\n decl: DataModel | TypeDef,\n includeIgnored = false,\n seen: Set<DataModel | TypeDef> = new Set(),\n): DataField[] {\n if (seen.has(decl)) {\n return [];\n }\n seen.add(decl);\n\n const fields: DataField[] = [];\n for (const mixin of decl.mixins) {\n if (mixin.ref) {\n fields.push(...getAllFields(mixin.ref, includeIgnored, seen));\n }\n }\n\n if (isDataModel(decl) && decl.baseModel) {\n if (decl.baseModel.ref) {\n fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));\n }\n }\n\n fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, '@ignore')));\n return fields;\n}\n\nexport function getPrimitiveTypeDefThisField(td: TypeDef) {\n return td.fields.find((f) => f.name === 'this');\n}\n\n/**\n * Gets all attributes of a data model or type def, including inherited attributes\n * from base models and mixins.\n */\nexport function getAllAttributes(\n decl: DataModel | TypeDef,\n seen: Set<DataModel | TypeDef> = new Set(),\n): DataModelAttribute[] {\n if (seen.has(decl)) {\n return [];\n }\n seen.add(decl);\n\n const attributes: DataModelAttribute[] = [];\n for (const mixin of decl.mixins) {\n if (mixin.ref) {\n attributes.push(...getAllAttributes(mixin.ref, seen));\n }\n }\n\n if (isDataModel(decl) && decl.baseModel) {\n if (decl.baseModel.ref) {\n const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));\n attributes.push(...attrs);\n }\n }\n\n attributes.push(...decl.attributes);\n return attributes;\n}\n\nfunction isNonInheritableAttribute(attr: DataModelAttribute) {\n const attrName = attr.decl.ref?.name ?? attr.decl.$refText;\n return ['@@map', '@@unique', '@@index'].includes(attrName);\n}\n\n/**\n * Retrieve the document in which the given AST node is contained. A reference to the document is\n * usually held by the root node of the AST.\n *\n * @throws an error if the node is not contained in a document.\n */\nexport function getDocument<T extends AstNode = AstNode>(node: AstNode): LangiumDocument<T> {\n const rootNode = findRootNode(node);\n const result = rootNode.$document;\n if (!result) {\n throw new Error('AST node has no document.');\n }\n return result as LangiumDocument<T>;\n}\n\n/**\n * Gets the list of plugin documents from the given model.\n */\nexport function getPluginDocuments(model: Model, schemaPath: string): string[] {\n // traverse plugins and collect \"plugin.zmodel\" documents\n const result: string[] = [];\n for (const decl of model.declarations.filter(isPlugin)) {\n const providerField = decl.fields.find((f) => f.name === 'provider');\n if (!providerField) {\n continue;\n }\n\n const provider = getLiteral<string>(providerField.value);\n if (!provider || typeof provider !== 'string') {\n continue;\n }\n\n let pluginModelFile: string | undefined;\n\n // first try to treat provider as a path\n let providerPath = path.resolve(path.dirname(schemaPath), provider);\n if (fs.existsSync(providerPath)) {\n if (fs.statSync(providerPath).isDirectory()) {\n providerPath = path.join(providerPath, 'index.js');\n }\n\n // try plugin.zmodel next to the provider file\n pluginModelFile = path.resolve(path.dirname(providerPath), PLUGIN_MODULE_NAME);\n if (!fs.existsSync(pluginModelFile)) {\n // try to find upwards\n pluginModelFile = findUp([PLUGIN_MODULE_NAME], path.dirname(providerPath));\n }\n }\n\n if (!pluginModelFile) {\n if (typeof import.meta.resolve === 'function') {\n try {\n // try loading as a ESM module\n const resolvedUrl = import.meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);\n pluginModelFile = fileURLToPath(resolvedUrl);\n } catch {\n // noop\n }\n }\n }\n\n if (!pluginModelFile) {\n // try loading as a CJS module\n try {\n const require = createRequire(pathToFileURL(schemaPath));\n pluginModelFile = require.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);\n } catch {\n // noop\n }\n }\n\n if (pluginModelFile && fs.existsSync(pluginModelFile)) {\n result.push(pluginModelFile);\n }\n }\n return result;\n}\n\ntype FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;\n\nfunction findUp<Multiple extends boolean = false>(\n names: string[],\n cwd: string = process.cwd(),\n multiple: Multiple = false as Multiple,\n result: string[] = [],\n): FindUpResult<Multiple> {\n if (!names.some((name) => !!name)) {\n return undefined;\n }\n const target = names.find((name) => fs.existsSync(path.join(cwd, name)));\n if (multiple === false && target) {\n return path.join(cwd, target) as FindUpResult<Multiple>;\n }\n if (target) {\n result.push(path.join(cwd, target));\n }\n const up = path.resolve(cwd, '..');\n if (up === cwd) {\n return (multiple && result.length > 0 ? result : undefined) as FindUpResult<Multiple>;\n }\n return findUp(names, up, multiple, result);\n}\n\n/**\n * Returns the root node of the given AST node by following the `$container` references.\n */\nexport function findRootNode(node: AstNode): AstNode {\n while (node.$container) {\n node = node.$container;\n }\n return node;\n}\n"],"mappings":";;;;;;;;;;AAGA,MAAa,sBAAsB;CAAC;CAAU;CAAc;CAAQ;;;;AAKpE,MAAa,eAAe;CAAC;CAAU;CAAO;CAAS;CAAW;CAAU;CAAW;CAAS;CAAW;;;;AAK3G,MAAa,sBAAsB;;;;AAKnC,MAAa,qBAAqB;;;;AAKlC,IAAY,aAAL,yBAAA,YAAA;AACH,YAAA,6BAAA;;KACH;;;;AAKD,IAAY,oBAAL,yBAAA,mBAAA;AACH,mBAAA,kBAAA;AACA,mBAAA,kBAAA;AACA,mBAAA,oBAAA;AACA,mBAAA,WAAA;;KACH;;;;AAKD,MAAa,oCAAoC,CAAC,aAAa;;;ACiB/D,SAAgB,aAAa,MAAuB,MAAc;AAC9D,QAAO,CAAC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AK,KAAK,KAAK,OAAO;AAEjC,KAAI,OACA,QAAO,KAAK,KAAK,KAAK,KAAK,OAAO,CAAC;CAEvC,MAAM,KAAK,KAAK,QAAQ,KAAK,KAAK;AAClC,KAAI,OAAO,IACP,QAAQ,YAAY,OAAO,SAAS,IAAI,SAAS,KAAA;AAErD,QAAO,OAAO,OAAO,IAAI,UAAU,OAAO;;;;;AAM9C,SAAgB,aAAa,MAAwB;AACjD,QAAO,KAAK,WACR,QAAO,KAAK;AAEhB,QAAO"}
@@ -1,4 +1,4 @@
1
- const require_ast = require("./ast-DSXl7TDv.cjs");
1
+ const require_ast = require("./ast-CbYfvKuN.cjs");
2
2
  let langium = require("langium");
3
3
  let node_fs = require("node:fs");
4
4
  node_fs = require_ast.__toESM(node_fs, 1);
@@ -146,6 +146,37 @@ function isRelationshipField(field) {
146
146
  return require_ast.isDataModel(field.type.reference?.ref);
147
147
  }
148
148
  /**
149
+ * Returns the name of the relation the given field belongs to, as declared in its `@relation`
150
+ * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.
151
+ *
152
+ * The name argument is matched by its literal name (or absence of a name for the positional
153
+ * argument) rather than by `$resolvedParam`, because this function is also used during schema
154
+ * validation, where `$resolvedParam` may not have been resolved yet for attributes that have
155
+ * not been validated.
156
+ */
157
+ function getRelationName(field) {
158
+ const relation = getAttribute(field, "@relation");
159
+ if (!relation) return;
160
+ for (const arg of relation.args) if (!arg.name || arg.name === "name") {
161
+ if (require_ast.isStringLiteral(arg.value)) return arg.value.value;
162
+ }
163
+ }
164
+ /**
165
+ * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an
166
+ * array and whose opposite relation field on the referenced model (belonging to the same relation)
167
+ * is also an array referencing back to the containing model.
168
+ */
169
+ function isManyToManyField(field) {
170
+ if (!isRelationshipField(field) || !field.type.array) return false;
171
+ const oppositeModel = field.type.reference.ref;
172
+ const containingModel = field.$container;
173
+ const relationName = getRelationName(field);
174
+ return getAllFields(oppositeModel).some((f) => {
175
+ if (f === field || !f.type.array || f.type.reference?.ref?.name !== containingModel.name) return false;
176
+ return getRelationName(f) === relationName;
177
+ });
178
+ }
179
+ /**
149
180
  * Returns if the given field is a computed field.
150
181
  */
151
182
  function isComputedField(field) {
@@ -176,6 +207,12 @@ function isLiteAttribute(node) {
176
207
  return require_ast.isAttribute(node) && hasAttribute(node, "@@@lite");
177
208
  }
178
209
  /**
210
+ * Returns if the given node is primitive type def.
211
+ */
212
+ function isPrimitiveTypeDef(node) {
213
+ return require_ast.isTypeDef(node) && !!node.base;
214
+ }
215
+ /**
179
216
  * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
180
217
  * if no datasource is found or its provider is not a literal.
181
218
  */
@@ -478,6 +515,9 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
478
515
  fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
479
516
  return fields;
480
517
  }
518
+ function getPrimitiveTypeDefThisField(td) {
519
+ return td.fields.find((f) => f.name === "this");
520
+ }
481
521
  /**
482
522
  * Gets all attributes of a data model or type def, including inherited attributes
483
523
  * from base models and mixins.
@@ -753,12 +793,24 @@ Object.defineProperty(exports, "getPluginDocuments", {
753
793
  return getPluginDocuments;
754
794
  }
755
795
  });
796
+ Object.defineProperty(exports, "getPrimitiveTypeDefThisField", {
797
+ enumerable: true,
798
+ get: function() {
799
+ return getPrimitiveTypeDefThisField;
800
+ }
801
+ });
756
802
  Object.defineProperty(exports, "getRecursiveBases", {
757
803
  enumerable: true,
758
804
  get: function() {
759
805
  return getRecursiveBases;
760
806
  }
761
807
  });
808
+ Object.defineProperty(exports, "getRelationName", {
809
+ enumerable: true,
810
+ get: function() {
811
+ return getRelationName;
812
+ }
813
+ });
762
814
  Object.defineProperty(exports, "getStringLiteral", {
763
815
  enumerable: true,
764
816
  get: function() {
@@ -843,6 +895,12 @@ Object.defineProperty(exports, "isLiteAttribute", {
843
895
  return isLiteAttribute;
844
896
  }
845
897
  });
898
+ Object.defineProperty(exports, "isManyToManyField", {
899
+ enumerable: true,
900
+ get: function() {
901
+ return isManyToManyField;
902
+ }
903
+ });
846
904
  Object.defineProperty(exports, "isMemberContainer", {
847
905
  enumerable: true,
848
906
  get: function() {
@@ -855,6 +913,12 @@ Object.defineProperty(exports, "isNativeTypeMappingAttribute", {
855
913
  return isNativeTypeMappingAttribute;
856
914
  }
857
915
  });
916
+ Object.defineProperty(exports, "isPrimitiveTypeDef", {
917
+ enumerable: true,
918
+ get: function() {
919
+ return isPrimitiveTypeDef;
920
+ }
921
+ });
858
922
  Object.defineProperty(exports, "isPrismaAttribute", {
859
923
  enumerable: true,
860
924
  get: function() {
@@ -904,4 +968,4 @@ Object.defineProperty(exports, "typeAssignable", {
904
968
  }
905
969
  });
906
970
 
907
- //# sourceMappingURL=utils-C3bnOGl-.cjs.map
971
+ //# sourceMappingURL=utils-DZ0ZKE35.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-DZ0ZKE35.cjs","names":["AstUtils","isModel","isInvocationExpr","isStringLiteral","isNumberLiteral","isMemberAccessExpr","isReferenceExpr","isEnumField","isDataField","isDataModel","isAttribute","isTypeDef","isDataSource","isArrayExpr","isObjectExpr","isLiteralExpr","isExpression","isConfigArrayExpr","fs","path","URI","isBinaryExpr","isPlugin"],"sources":["../src/constants.ts","../src/utils.ts"],"sourcesContent":["/**\n * Supported db providers\n */\nexport const SUPPORTED_PROVIDERS = ['sqlite', 'postgresql', 'mysql'];\n\n/**\n * All scalar types\n */\nexport const SCALAR_TYPES = ['String', 'Int', 'Float', 'Decimal', 'BigInt', 'Boolean', 'Bytes', 'DateTime'];\n\n/**\n * Name of standard library module\n */\nexport const STD_LIB_MODULE_NAME = 'stdlib.zmodel';\n\n/**\n * Name of module contributed by plugins\n */\nexport const PLUGIN_MODULE_NAME = 'plugin.zmodel';\n\n/**\n * Validation issues\n */\nexport enum IssueCodes {\n MissingOppositeRelation = 'miss-opposite-relation',\n}\n\n/**\n * Expression context\n */\nexport enum ExpressionContext {\n DefaultValue = 'DefaultValue',\n AccessPolicy = 'AccessPolicy',\n ValidationRule = 'ValidationRule',\n Index = 'Index',\n}\n\n/**\n * Database providers that support list field types.\n */\nexport const DB_PROVIDERS_SUPPORTING_LIST_TYPE = ['postgresql'];\n","import { AstUtils, URI, type AstNode, type LangiumDocument, type LangiumDocuments, type Reference } from 'langium';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { PLUGIN_MODULE_NAME, STD_LIB_MODULE_NAME, type ExpressionContext } from './constants';\nimport {\n InternalAttribute,\n isArrayExpr,\n isAttribute,\n isBinaryExpr,\n isConfigArrayExpr,\n isDataField,\n isDataModel,\n isDataSource,\n isEnumField,\n isExpression,\n isInvocationExpr,\n isLiteralExpr,\n isMemberAccessExpr,\n isModel,\n isNumberLiteral,\n isObjectExpr,\n isPlugin,\n isReferenceExpr,\n isStringLiteral,\n isTypeDef,\n type Attribute,\n type AttributeParam,\n type BinaryExpr,\n type BuiltinType,\n type ConfigExpr,\n type DataField,\n type DataFieldAttribute,\n type DataModel,\n type DataModelAttribute,\n type Enum,\n type EnumField,\n type Expression,\n type ExpressionType,\n type FunctionDecl,\n type Model,\n type ModelImport,\n type ReferenceExpr,\n type TypeDef,\n} from './generated/ast';\n\nexport type AttributeTarget =\n | DataModel\n | TypeDef\n | DataField\n | Enum\n | EnumField\n | FunctionDecl\n | Attribute\n | AttributeParam;\n\nexport function hasAttribute(decl: AttributeTarget, name: string) {\n return !!getAttribute(decl, name);\n}\n\nexport function getAttribute(decl: AttributeTarget, name: string) {\n return (decl.attributes as (DataModelAttribute | DataFieldAttribute)[]).find((attr) => attr.decl.$refText === name);\n}\n\nexport function isFromStdlib(node: AstNode) {\n const model = AstUtils.getContainerOfType(node, isModel);\n return !!model && !!model.$document && model.$document.uri.path.endsWith(STD_LIB_MODULE_NAME);\n}\n\nexport function isAuthInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'auth' && isFromStdlib(node.function.ref);\n}\n\n/**\n * Try getting string value from a potential string literal expression\n */\nexport function getStringLiteral(node: AstNode | undefined): string | undefined {\n return isStringLiteral(node) ? node.value : undefined;\n}\n\n/**\n * Try getting number value from a potential number literal expression\n */\nexport function getNumberLiteral(node: AstNode | undefined): number | undefined {\n return isNumberLiteral(node) ? Number(node.value) : undefined;\n}\n\nconst isoDateTimeRegex = /^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?)?)?)?$/i;\n\n/**\n * Determines if the given sourceType is assignable to a destination of destType\n */\nexport function typeAssignable(destType: ExpressionType, sourceType: ExpressionType, sourceExpr?: Expression): boolean {\n // implicit conversion from ISO datetime string to datetime\n if (destType === 'DateTime' && sourceType === 'String' && sourceExpr && isStringLiteral(sourceExpr)) {\n const literal = getStringLiteral(sourceExpr);\n if (literal && isoDateTimeRegex.test(literal)) {\n // implicitly convert to DateTime\n sourceType = 'DateTime';\n }\n }\n\n switch (destType) {\n case 'Any':\n return true;\n case 'Float':\n return sourceType === 'Any' || sourceType === 'Int' || sourceType === 'Float';\n default:\n return sourceType === 'Any' || sourceType === destType;\n }\n}\n\n/**\n * Maps a ZModel builtin type to expression type\n */\nexport function mapBuiltinTypeToExpressionType(type: BuiltinType | ExpressionType): ExpressionType {\n switch (type) {\n case 'Any':\n case 'Boolean':\n case 'String':\n case 'DateTime':\n case 'Int':\n case 'Float':\n case 'Null':\n case 'Object':\n case 'Unsupported':\n case 'Void':\n case 'Undefined':\n return type;\n case 'BigInt':\n return 'Int';\n case 'Decimal':\n return 'Float';\n case 'Json':\n case 'Bytes':\n return 'Any';\n }\n}\n\n/**\n * Determines if the given expression is an invocation of `auth` or a member access on the result of an `auth` invocation (e.g. `auth().role`).\n */\nexport function isAuthOrAuthMemberAccess(expr: Expression): boolean {\n return isAuthInvocation(expr) || (isMemberAccessExpr(expr) && isAuthOrAuthMemberAccess(expr.operand));\n}\n\n/**\n * Determines if the given expression is a reference to an enum field.\n */\nexport function isEnumFieldReference(node: AstNode): node is ReferenceExpr {\n return isReferenceExpr(node) && isEnumField(node.target.ref);\n}\n\n/**\n * Determines if the given expression is a reference to a data field.\n */\nexport function isDataFieldReference(node: AstNode): node is ReferenceExpr {\n return isReferenceExpr(node) && isDataField(node.target.ref);\n}\n\n/**\n * Returns if the given field is a relation field.\n */\nexport function isRelationshipField(field: DataField) {\n return isDataModel(field.type.reference?.ref);\n}\n\n/**\n * Returns the name of the relation the given field belongs to, as declared in its `@relation`\n * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.\n *\n * The name argument is matched by its literal name (or absence of a name for the positional\n * argument) rather than by `$resolvedParam`, because this function is also used during schema\n * validation, where `$resolvedParam` may not have been resolved yet for attributes that have\n * not been validated.\n */\nexport function getRelationName(field: DataField): string | undefined {\n const relation = getAttribute(field, '@relation');\n if (!relation) {\n return undefined;\n }\n for (const arg of relation.args) {\n if (!arg.name || arg.name === 'name') {\n if (isStringLiteral(arg.value)) {\n return arg.value.value;\n }\n }\n }\n return undefined;\n}\n\n/**\n * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an\n * array and whose opposite relation field on the referenced model (belonging to the same relation)\n * is also an array referencing back to the containing model.\n */\nexport function isManyToManyField(field: DataField) {\n if (!isRelationshipField(field) || !field.type.array) {\n return false;\n }\n\n const oppositeModel = field.type.reference!.ref as DataModel;\n const containingModel = field.$container as DataModel;\n const relationName = getRelationName(field);\n\n return getAllFields(oppositeModel).some((f) => {\n if (f === field || !f.type.array || f.type.reference?.ref?.name !== containingModel.name) {\n return false;\n }\n // the opposite field must belong to the same relation: either both declare the same\n // explicit relation name, or both are unnamed\n return getRelationName(f) === relationName;\n });\n}\n\n/**\n * Returns if the given field is a computed field.\n */\nexport function isComputedField(field: DataField) {\n return hasAttribute(field, '@computed');\n}\n\n/**\n * Determines if the given data model is a delegate model (i.e. marked with `@@delegate` attribute).\n */\nexport function isDelegateModel(node: AstNode) {\n return isDataModel(node) && hasAttribute(node, '@@delegate');\n}\n\n/**\n * Returns if the given node is a Prisma attribute.\n */\nexport function isPrismaAttribute(node: AstNode): node is Attribute {\n return isAttribute(node) && hasAttribute(node, '@@@prisma');\n}\n\n/**\n * Returns if the given node is a native type mapping attribute.\n */\nexport function isNativeTypeMappingAttribute(node: AstNode): node is Attribute {\n return isPrismaAttribute(node) && node.name.startsWith('@db.');\n}\n\n/**\n * Returns if the given node is a lite attribute.\n */\nexport function isLiteAttribute(node: AstNode): node is Attribute {\n return isAttribute(node) && hasAttribute(node, '@@@lite');\n}\n\n/**\n * Returns if the given node is primitive type def.\n */\nexport function isPrimitiveTypeDef(node: AstNode): node is TypeDef {\n return isTypeDef(node) && !!node.base;\n}\n\n/**\n * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined\n * if no datasource is found or its provider is not a literal.\n */\nexport function getDataSourceProvider(model: Model) {\n const dataSource = model.declarations.find(isDataSource);\n if (!dataSource) {\n return undefined;\n }\n const providerField = dataSource.fields.find((f) => f.name === 'provider');\n if (!providerField) {\n return undefined;\n }\n return getLiteral<string>(providerField.value);\n}\n\n/**\n * Resolves the given reference and returns the target AST node. Throws an error if the reference is not resolved.\n */\nexport function resolved<T extends AstNode>(ref: Reference<T>): T {\n if (!ref.ref) {\n throw new Error(`Reference not resolved: ${ref.$refText}`);\n }\n return ref.ref;\n}\n\n/**\n * Gets all base models and mixins of a data model or type def, recursively.\n */\nexport function getRecursiveBases(\n decl: DataModel | TypeDef,\n includeDelegate = true,\n documents?: LangiumDocuments,\n seen = new Set<DataModel | TypeDef>(),\n): (TypeDef | DataModel)[] {\n const result: (TypeDef | DataModel)[] = [];\n if (seen.has(decl)) {\n return result;\n }\n seen.add(decl);\n const bases = [...decl.mixins, ...(isDataModel(decl) && decl.baseModel ? [decl.baseModel] : [])];\n bases.forEach((base) => {\n let baseDecl: TypeDef | DataModel | undefined;\n\n if (base.ref && (isTypeDef(base.ref) || isDataModel(base.ref))) {\n // base is already resolved\n baseDecl = base.ref;\n } else {\n // otherwise, search by name, in all imported documents if provided\n const declarations = documents\n ? getAllDeclarationsIncludingImports(documents, decl.$container)\n : decl.$container.declarations;\n\n baseDecl = declarations.find(\n (d): d is TypeDef | DataModel => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText,\n );\n }\n\n if (baseDecl) {\n if (!includeDelegate && isDelegateModel(baseDecl)) {\n return;\n }\n result.push(baseDecl);\n result.push(...getRecursiveBases(baseDecl, includeDelegate, documents, seen));\n }\n });\n return result;\n}\n\n/**\n * Gets `@@id` fields declared at the data model level (including search in base models)\n */\nexport function getModelIdFields(model: DataModel) {\n const modelsToCheck = [model, ...getRecursiveBases(model)];\n\n for (const modelToCheck of modelsToCheck) {\n const allAttributes = getAllAttributes(modelToCheck);\n const idAttr = allAttributes.find((attr) => attr.decl.$refText === '@@id');\n if (!idAttr) {\n continue;\n }\n const fieldsArg = idAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n continue;\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n }\n\n return [];\n}\n\n/**\n * Gets `@@unique` fields declared at the data model level (including search in base models)\n */\nexport function getModelUniqueFields(model: DataModel) {\n const modelsToCheck = [model, ...getRecursiveBases(model)];\n\n for (const modelToCheck of modelsToCheck) {\n const allAttributes = getAllAttributes(modelToCheck);\n const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === '@@unique');\n if (!uniqueAttr) {\n continue;\n }\n const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n continue;\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n }\n\n return [];\n}\n\n/**\n * Gets lists of unique fields declared at the data model level\n *\n * TODO: merge this with {@link getModelUniqueFields}\n */\nexport function getUniqueFields(model: DataModel) {\n const uniqueAttrs = model.attributes.filter(\n (attr) => attr.decl.ref?.name === '@@unique' || attr.decl.ref?.name === '@@id',\n );\n return uniqueAttrs.map((uniqueAttr) => {\n const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields');\n if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {\n return [];\n }\n\n return fieldsArg.value.items\n .filter((item): item is ReferenceExpr => isReferenceExpr(item))\n .map((item) => resolved(item.target) as DataField);\n });\n}\n\n/**\n * Finds the first ancestor of the given AST node that satisfies the given predicate function. Returns `undefined` if no such ancestor is found.\n */\nexport function findUpAst(node: AstNode, predicate: (node: AstNode) => boolean): AstNode | undefined {\n let curr: AstNode | undefined = node;\n while (curr) {\n if (predicate(curr)) {\n return curr;\n }\n curr = curr.$container;\n }\n return undefined;\n}\n\n/**\n * Tries to get the literal value from the given expression. Returns `undefined` if the expression is not a literal or if the literal value cannot be determined.\n */\nexport function getLiteral<T extends string | number | boolean | any = any>(\n expr: Expression | ConfigExpr | undefined,\n): T | undefined {\n switch (expr?.$type) {\n case 'ObjectExpr':\n return getObjectLiteral<T>(expr);\n case 'StringLiteral':\n case 'BooleanLiteral':\n return expr.value as T;\n case 'NumberLiteral':\n return parseFloat(expr.value) as T;\n default:\n return undefined;\n }\n}\n\n/**\n * Tries to get an object literal from the given expression. Returns `undefined` if the expression is not an object literal or if any of the field values cannot be determined.\n */\nexport function getObjectLiteral<T>(expr: Expression | ConfigExpr | undefined): T | undefined {\n if (!expr || !isObjectExpr(expr)) {\n return undefined;\n }\n const result: Record<string, unknown> = {};\n for (const field of expr.fields) {\n let fieldValue: unknown;\n if (isLiteralExpr(field.value)) {\n fieldValue = getLiteral(field.value);\n } else if (isArrayExpr(field.value)) {\n fieldValue = getLiteralArray(field.value);\n } else if (isObjectExpr(field.value)) {\n fieldValue = getObjectLiteral(field.value);\n }\n if (fieldValue === undefined) {\n return undefined;\n } else {\n result[field.name] = fieldValue;\n }\n }\n return result as T;\n}\n\nexport function getLiteralArray<T extends string | number | boolean | any = any>(\n expr: Expression | ConfigExpr | undefined,\n): T[] | undefined {\n const arr = getArray(expr);\n if (!arr) {\n return undefined;\n }\n return arr.map((item) => isExpression(item) && getLiteral<T>(item)).filter((v): v is T => v !== undefined);\n}\n\nfunction getArray(expr: Expression | ConfigExpr | undefined) {\n return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : undefined;\n}\n\n/**\n * Gets the value of the argument with the given name from the given attribute. Returns `undefined` if no such argument is found or if the argument value cannot be determined.\n */\nexport function getAttributeArg(\n attr: DataModelAttribute | DataFieldAttribute | InternalAttribute,\n name: string,\n): Expression | undefined {\n return attr.args.find((arg) => arg.$resolvedParam?.name === name)?.value;\n}\n\n/**\n * Gets the literal value of the argument with the given name from the given attribute. Returns `undefined` if no such argument is found or if the argument value cannot be determined or is not a literal.\n */\nexport function getAttributeArgLiteral<T extends string | number | boolean>(\n attr: DataModelAttribute | DataFieldAttribute | InternalAttribute,\n name: string,\n): T | undefined {\n for (const arg of attr.args) {\n if (arg.$resolvedParam?.name === name) {\n return getLiteral<T>(arg.value);\n }\n }\n return undefined;\n}\n\n/**\n * Gets the allowed expression contexts for the given function declaration by looking for `@@expressionContext` attribute.\n * Returns an empty array if no such attribute is found or if the attribute value cannot be determined.\n */\nexport function getFunctionExpressionContext(funcDecl: FunctionDecl) {\n const funcAllowedContext: ExpressionContext[] = [];\n const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === '@@@expressionContext');\n if (funcAttr) {\n const contextArg = funcAttr.args[0]?.value;\n if (isArrayExpr(contextArg)) {\n contextArg.items.forEach((item) => {\n if (isEnumFieldReference(item)) {\n funcAllowedContext.push(item.target.$refText as ExpressionContext);\n }\n });\n }\n }\n return funcAllowedContext;\n}\n\n/**\n * Gets the data field referenced by the given expression, if any. Returns `undefined` if the expression is not a reference to a data field.\n */\nexport function getFieldReference(expr: Expression): DataField | undefined {\n if (isReferenceExpr(expr) && isDataField(expr.target.ref)) {\n return expr.target.ref;\n } else if (isMemberAccessExpr(expr) && isDataField(expr.member.ref)) {\n return expr.member.ref;\n } else {\n return undefined;\n }\n}\n\n// TODO: move to policy plugin\nexport function isCheckInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'check';\n}\n\n/**\n * Resolves the transitive imports of the given model and returns the list of imported models. The given model itself is not included in the result.\n */\nexport function resolveTransitiveImports(documents: LangiumDocuments, model: Model) {\n return resolveTransitiveImportsInternal(documents, model);\n}\n\nfunction resolveTransitiveImportsInternal(\n documents: LangiumDocuments,\n model: Model,\n initialModel = model,\n visited: Set<string> = new Set(),\n models: Set<Model> = new Set(),\n) {\n const doc = AstUtils.getDocument(model);\n const initialDoc = AstUtils.getDocument(initialModel);\n\n if (initialDoc.uri.fsPath.toLowerCase() !== doc.uri.fsPath.toLowerCase()) {\n models.add(model);\n }\n\n const normalizedPath = doc.uri.fsPath.toLowerCase();\n if (!visited.has(normalizedPath)) {\n visited.add(normalizedPath);\n for (const imp of model.imports) {\n const importedModel = resolveImport(documents, imp);\n if (importedModel) {\n resolveTransitiveImportsInternal(documents, importedModel, initialModel, visited, models);\n }\n }\n }\n return Array.from(models);\n}\n\n/**\n * Resolves the given import and returns the imported model. Returns `undefined`\n * if the import cannot be resolved.\n */\nexport function resolveImport(documents: LangiumDocuments, imp: ModelImport) {\n const resolvedUri = resolveImportUri(imp);\n try {\n if (resolvedUri) {\n let resolvedDocument = documents.getDocument(resolvedUri);\n if (!resolvedDocument) {\n const content = fs.readFileSync(resolvedUri.fsPath, 'utf-8');\n resolvedDocument = documents.createDocument(resolvedUri, content);\n }\n const node = resolvedDocument.parseResult.value;\n if (isModel(node)) {\n return node;\n }\n }\n } catch {\n // NOOP\n }\n return undefined;\n}\n\n/**\n * Resolves the given import and returns the URI of the imported model.\n * Returns `undefined` if the import cannot be resolved.\n */\nexport function resolveImportUri(imp: ModelImport) {\n if (!imp.path) {\n return undefined;\n }\n const doc = AstUtils.getDocument(imp);\n const dir = path.dirname(doc.uri.fsPath);\n const importPath = imp.path.endsWith('.zmodel') ? imp.path : `${imp.path}.zmodel`;\n return URI.file(path.resolve(dir, importPath));\n}\n\n/**\n * Gets data models and type defs in the ZModel schema.\n */\nexport function getDataModelAndTypeDefs(model: Model, includeIgnored = false) {\n const r = model.declarations.filter((d): d is DataModel | TypeDef => isDataModel(d) || isTypeDef(d));\n if (includeIgnored) {\n return r;\n } else {\n return r.filter((model) => !hasAttribute(model, '@@ignore'));\n }\n}\n\n/**\n * Gets all declarations of the given model and its transitive imports.\n */\nexport function getAllDeclarationsIncludingImports(documents: LangiumDocuments, model: Model) {\n const imports = resolveTransitiveImports(documents, model);\n return model.declarations.concat(...imports.map((imp) => imp.declarations));\n}\n\n/**\n * Gets the model used for auth context, by looking for a model with `@@auth` attribute or a model named `User`.\n * Returns `undefined` if no such model is found.\n */\nexport function getAuthDecl(decls: (DataModel | TypeDef)[]) {\n let authModel = decls.find((d) => hasAttribute(d, '@@auth'));\n if (!authModel) {\n authModel = decls.find((d) => d.name === 'User');\n }\n return authModel;\n}\n\n// TODO: move to policy plugin\nexport function isBeforeInvocation(node: AstNode) {\n return isInvocationExpr(node) && node.function.ref?.name === 'before';\n}\n\n/**\n * Determines if the given AST node is a collection predicate.\n */\nexport function isCollectionPredicate(node: AstNode): node is BinaryExpr {\n return isBinaryExpr(node) && ['?', '!', '^'].includes(node.operator);\n}\n\n/**\n * Gets all data models and type defs from the given documents registry.\n */\nexport function getAllLoadedDataModelsAndTypeDefs(langiumDocuments: LangiumDocuments) {\n return langiumDocuments.all\n .map((doc) => doc.parseResult.value as Model)\n .flatMap((model) => model.declarations.filter((d): d is DataModel | TypeDef => isDataModel(d) || isTypeDef(d)))\n .toArray();\n}\n\n/**\n * Gets all data models from the given documents registry and the transitive imports of the given model.\n */\nexport function getAllDataModelsIncludingImports(documents: LangiumDocuments, model: Model) {\n return getAllDeclarationsIncludingImports(documents, model).filter(isDataModel);\n}\n\n/**\n * Gets all data models and type defs from the given documents registry and the transitive imports\n * of the given model. If `fromModel` is not provided, returns all loaded data models and type defs.\n */\nexport function getAllLoadedAndReachableDataModelsAndTypeDefs(\n langiumDocuments: LangiumDocuments,\n fromModel?: DataModel,\n) {\n // get all data models from loaded documents\n const allDataModels = getAllLoadedDataModelsAndTypeDefs(langiumDocuments);\n\n if (fromModel) {\n // merge data models transitively reached from the current model\n const model = AstUtils.getContainerOfType(fromModel, isModel);\n if (model) {\n const transitiveDataModels = getAllDataModelsIncludingImports(langiumDocuments, model);\n transitiveDataModels.forEach((dm) => {\n if (!allDataModels.includes(dm)) {\n allDataModels.push(dm);\n }\n });\n }\n }\n\n return allDataModels;\n}\n\n/**\n * Gets the containing data model of the given AST node, if any.\n * Returns `undefined` if the node is not contained in a data model.\n */\nexport function getContainingDataModel(node: AstNode): DataModel | undefined {\n let curr: AstNode | undefined = node.$container;\n while (curr) {\n if (isDataModel(curr)) {\n return curr;\n }\n curr = curr.$container;\n }\n return undefined;\n}\n\n/**\n * Determines if the given AST node can contain members.\n */\nexport function isMemberContainer(node: unknown): node is DataModel | TypeDef {\n return isDataModel(node) || isTypeDef(node);\n}\n\n/**\n * Gets all fields of a data model or type def, including inherited fields from base models and mixins.\n */\nexport function getAllFields(\n decl: DataModel | TypeDef,\n includeIgnored = false,\n seen: Set<DataModel | TypeDef> = new Set(),\n): DataField[] {\n if (seen.has(decl)) {\n return [];\n }\n seen.add(decl);\n\n const fields: DataField[] = [];\n for (const mixin of decl.mixins) {\n if (mixin.ref) {\n fields.push(...getAllFields(mixin.ref, includeIgnored, seen));\n }\n }\n\n if (isDataModel(decl) && decl.baseModel) {\n if (decl.baseModel.ref) {\n fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));\n }\n }\n\n fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, '@ignore')));\n return fields;\n}\n\nexport function getPrimitiveTypeDefThisField(td: TypeDef) {\n return td.fields.find((f) => f.name === 'this');\n}\n\n/**\n * Gets all attributes of a data model or type def, including inherited attributes\n * from base models and mixins.\n */\nexport function getAllAttributes(\n decl: DataModel | TypeDef,\n seen: Set<DataModel | TypeDef> = new Set(),\n): DataModelAttribute[] {\n if (seen.has(decl)) {\n return [];\n }\n seen.add(decl);\n\n const attributes: DataModelAttribute[] = [];\n for (const mixin of decl.mixins) {\n if (mixin.ref) {\n attributes.push(...getAllAttributes(mixin.ref, seen));\n }\n }\n\n if (isDataModel(decl) && decl.baseModel) {\n if (decl.baseModel.ref) {\n const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));\n attributes.push(...attrs);\n }\n }\n\n attributes.push(...decl.attributes);\n return attributes;\n}\n\nfunction isNonInheritableAttribute(attr: DataModelAttribute) {\n const attrName = attr.decl.ref?.name ?? attr.decl.$refText;\n return ['@@map', '@@unique', '@@index'].includes(attrName);\n}\n\n/**\n * Retrieve the document in which the given AST node is contained. A reference to the document is\n * usually held by the root node of the AST.\n *\n * @throws an error if the node is not contained in a document.\n */\nexport function getDocument<T extends AstNode = AstNode>(node: AstNode): LangiumDocument<T> {\n const rootNode = findRootNode(node);\n const result = rootNode.$document;\n if (!result) {\n throw new Error('AST node has no document.');\n }\n return result as LangiumDocument<T>;\n}\n\n/**\n * Gets the list of plugin documents from the given model.\n */\nexport function getPluginDocuments(model: Model, schemaPath: string): string[] {\n // traverse plugins and collect \"plugin.zmodel\" documents\n const result: string[] = [];\n for (const decl of model.declarations.filter(isPlugin)) {\n const providerField = decl.fields.find((f) => f.name === 'provider');\n if (!providerField) {\n continue;\n }\n\n const provider = getLiteral<string>(providerField.value);\n if (!provider || typeof provider !== 'string') {\n continue;\n }\n\n let pluginModelFile: string | undefined;\n\n // first try to treat provider as a path\n let providerPath = path.resolve(path.dirname(schemaPath), provider);\n if (fs.existsSync(providerPath)) {\n if (fs.statSync(providerPath).isDirectory()) {\n providerPath = path.join(providerPath, 'index.js');\n }\n\n // try plugin.zmodel next to the provider file\n pluginModelFile = path.resolve(path.dirname(providerPath), PLUGIN_MODULE_NAME);\n if (!fs.existsSync(pluginModelFile)) {\n // try to find upwards\n pluginModelFile = findUp([PLUGIN_MODULE_NAME], path.dirname(providerPath));\n }\n }\n\n if (!pluginModelFile) {\n if (typeof import.meta.resolve === 'function') {\n try {\n // try loading as a ESM module\n const resolvedUrl = import.meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);\n pluginModelFile = fileURLToPath(resolvedUrl);\n } catch {\n // noop\n }\n }\n }\n\n if (!pluginModelFile) {\n // try loading as a CJS module\n try {\n const require = createRequire(pathToFileURL(schemaPath));\n pluginModelFile = require.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);\n } catch {\n // noop\n }\n }\n\n if (pluginModelFile && fs.existsSync(pluginModelFile)) {\n result.push(pluginModelFile);\n }\n }\n return result;\n}\n\ntype FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;\n\nfunction findUp<Multiple extends boolean = false>(\n names: string[],\n cwd: string = process.cwd(),\n multiple: Multiple = false as Multiple,\n result: string[] = [],\n): FindUpResult<Multiple> {\n if (!names.some((name) => !!name)) {\n return undefined;\n }\n const target = names.find((name) => fs.existsSync(path.join(cwd, name)));\n if (multiple === false && target) {\n return path.join(cwd, target) as FindUpResult<Multiple>;\n }\n if (target) {\n result.push(path.join(cwd, target));\n }\n const up = path.resolve(cwd, '..');\n if (up === cwd) {\n return (multiple && result.length > 0 ? result : undefined) as FindUpResult<Multiple>;\n }\n return findUp(names, up, multiple, result);\n}\n\n/**\n * Returns the root node of the given AST node by following the `$container` references.\n */\nexport function findRootNode(node: AstNode): AstNode {\n while (node.$container) {\n node = node.$container;\n }\n return node;\n}\n"],"mappings":";;;;;;;;;;;;AAGA,MAAa,sBAAsB;CAAC;CAAU;CAAc;CAAQ;;;;AAKpE,MAAa,eAAe;CAAC;CAAU;CAAO;CAAS;C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I,SAAS,KAAA;AAErD,QAAO,OAAO,OAAO,IAAI,UAAU,OAAO;;;;;AAM9C,SAAgB,aAAa,MAAwB;AACjD,QAAO,KAAK,WACR,QAAO,KAAK;AAEhB,QAAO"}
package/dist/utils.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils = require("./utils-C3bnOGl-.cjs");
2
+ const require_utils = require("./utils-DZ0ZKE35.cjs");
3
3
  exports.findRootNode = require_utils.findRootNode;
4
4
  exports.findUpAst = require_utils.findUpAst;
5
5
  exports.getAllAttributes = require_utils.getAllAttributes;
@@ -25,7 +25,9 @@ exports.getModelUniqueFields = require_utils.getModelUniqueFields;
25
25
  exports.getNumberLiteral = require_utils.getNumberLiteral;
26
26
  exports.getObjectLiteral = require_utils.getObjectLiteral;
27
27
  exports.getPluginDocuments = require_utils.getPluginDocuments;
28
+ exports.getPrimitiveTypeDefThisField = require_utils.getPrimitiveTypeDefThisField;
28
29
  exports.getRecursiveBases = require_utils.getRecursiveBases;
30
+ exports.getRelationName = require_utils.getRelationName;
29
31
  exports.getStringLiteral = require_utils.getStringLiteral;
30
32
  exports.getUniqueFields = require_utils.getUniqueFields;
31
33
  exports.hasAttribute = require_utils.hasAttribute;
@@ -40,8 +42,10 @@ exports.isDelegateModel = require_utils.isDelegateModel;
40
42
  exports.isEnumFieldReference = require_utils.isEnumFieldReference;
41
43
  exports.isFromStdlib = require_utils.isFromStdlib;
42
44
  exports.isLiteAttribute = require_utils.isLiteAttribute;
45
+ exports.isManyToManyField = require_utils.isManyToManyField;
43
46
  exports.isMemberContainer = require_utils.isMemberContainer;
44
47
  exports.isNativeTypeMappingAttribute = require_utils.isNativeTypeMappingAttribute;
48
+ exports.isPrimitiveTypeDef = require_utils.isPrimitiveTypeDef;
45
49
  exports.isPrismaAttribute = require_utils.isPrismaAttribute;
46
50
  exports.isRelationshipField = require_utils.isRelationshipField;
47
51
  exports.mapBuiltinTypeToExpressionType = require_utils.mapBuiltinTypeToExpressionType;
package/dist/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as InternalAttribute, G as Model, I as FunctionDecl, K as ModelImport, M as EnumField, N as Expression, O as DataModel, P as ExpressionType, T as DataFieldAttribute, _ as BuiltinType, b as ConfigExpr, ct as TypeDef, f as AttributeParam, j as Enum, k as DataModelAttribute, m as BinaryExpr, s as AbstractDeclaration, tt as ReferenceExpr, u as Attribute, w as DataField } from "./ast-C3-ORZMv.cjs";
1
+ import { A as DataModelAttribute, F as ExpressionType, K as Model, L as FunctionDecl, M as Enum, N as EnumField, P as Expression, T as DataFieldAttribute, V as InternalAttribute, _ as BuiltinType, b as ConfigExpr, f as AttributeParam, k as DataModel, lt as TypeDef, m as BinaryExpr, nt as ReferenceExpr, q as ModelImport, s as AbstractDeclaration, u as Attribute, w as DataField } from "./ast-DZ3cHwI-.cjs";
2
2
  import { AstNode, LangiumDocument, LangiumDocuments, Reference, URI } from "langium";
3
3
 
4
4
  //#region src/constants.d.ts
@@ -50,6 +50,22 @@ declare function isDataFieldReference(node: AstNode): node is ReferenceExpr;
50
50
  * Returns if the given field is a relation field.
51
51
  */
52
52
  declare function isRelationshipField(field: DataField): boolean;
53
+ /**
54
+ * Returns the name of the relation the given field belongs to, as declared in its `@relation`
55
+ * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.
56
+ *
57
+ * The name argument is matched by its literal name (or absence of a name for the positional
58
+ * argument) rather than by `$resolvedParam`, because this function is also used during schema
59
+ * validation, where `$resolvedParam` may not have been resolved yet for attributes that have
60
+ * not been validated.
61
+ */
62
+ declare function getRelationName(field: DataField): string | undefined;
63
+ /**
64
+ * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an
65
+ * array and whose opposite relation field on the referenced model (belonging to the same relation)
66
+ * is also an array referencing back to the containing model.
67
+ */
68
+ declare function isManyToManyField(field: DataField): boolean;
53
69
  /**
54
70
  * Returns if the given field is a computed field.
55
71
  */
@@ -70,6 +86,10 @@ declare function isNativeTypeMappingAttribute(node: AstNode): node is Attribute;
70
86
  * Returns if the given node is a lite attribute.
71
87
  */
72
88
  declare function isLiteAttribute(node: AstNode): node is Attribute;
89
+ /**
90
+ * Returns if the given node is primitive type def.
91
+ */
92
+ declare function isPrimitiveTypeDef(node: AstNode): node is TypeDef;
73
93
  /**
74
94
  * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
75
95
  * if no datasource is found or its provider is not a literal.
@@ -186,6 +206,7 @@ declare function isMemberContainer(node: unknown): node is DataModel | TypeDef;
186
206
  * Gets all fields of a data model or type def, including inherited fields from base models and mixins.
187
207
  */
188
208
  declare function getAllFields(decl: DataModel | TypeDef, includeIgnored?: boolean, seen?: Set<DataModel | TypeDef>): DataField[];
209
+ declare function getPrimitiveTypeDefThisField(td: TypeDef): DataField | undefined;
189
210
  /**
190
211
  * Gets all attributes of a data model or type def, including inherited attributes
191
212
  * from base models and mixins.
@@ -207,5 +228,5 @@ declare function getPluginDocuments(model: Model, schemaPath: string): string[];
207
228
  */
208
229
  declare function findRootNode(node: AstNode): AstNode;
209
230
  //#endregion
210
- export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
231
+ export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getPrimitiveTypeDefThisField, getRecursiveBases, getRelationName, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isManyToManyField, isMemberContainer, isNativeTypeMappingAttribute, isPrimitiveTypeDef, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
211
232
  //# sourceMappingURL=utils.d.cts.map
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as InternalAttribute, G as Model, I as FunctionDecl, K as ModelImport, M as EnumField, N as Expression, O as DataModel, P as ExpressionType, T as DataFieldAttribute, _ as BuiltinType, b as ConfigExpr, ct as TypeDef, f as AttributeParam, j as Enum, k as DataModelAttribute, m as BinaryExpr, s as AbstractDeclaration, tt as ReferenceExpr, u as Attribute, w as DataField } from "./ast-DoH2ngKH.mjs";
1
+ import { A as DataModelAttribute, F as ExpressionType, K as Model, L as FunctionDecl, M as Enum, N as EnumField, P as Expression, T as DataFieldAttribute, V as InternalAttribute, _ as BuiltinType, b as ConfigExpr, f as AttributeParam, k as DataModel, lt as TypeDef, m as BinaryExpr, nt as ReferenceExpr, q as ModelImport, s as AbstractDeclaration, u as Attribute, w as DataField } from "./ast-B9snHdj1.mjs";
2
2
  import { AstNode, LangiumDocument, LangiumDocuments, Reference, URI } from "langium";
3
3
 
4
4
  //#region src/constants.d.ts
@@ -50,6 +50,22 @@ declare function isDataFieldReference(node: AstNode): node is ReferenceExpr;
50
50
  * Returns if the given field is a relation field.
51
51
  */
52
52
  declare function isRelationshipField(field: DataField): boolean;
53
+ /**
54
+ * Returns the name of the relation the given field belongs to, as declared in its `@relation`
55
+ * attribute, or `undefined` if the field has no `@relation` attribute or no explicit name.
56
+ *
57
+ * The name argument is matched by its literal name (or absence of a name for the positional
58
+ * argument) rather than by `$resolvedParam`, because this function is also used during schema
59
+ * validation, where `$resolvedParam` may not have been resolved yet for attributes that have
60
+ * not been validated.
61
+ */
62
+ declare function getRelationName(field: DataField): string | undefined;
63
+ /**
64
+ * Returns if the given field is a many-to-many relation field, i.e. a relation field that is an
65
+ * array and whose opposite relation field on the referenced model (belonging to the same relation)
66
+ * is also an array referencing back to the containing model.
67
+ */
68
+ declare function isManyToManyField(field: DataField): boolean;
53
69
  /**
54
70
  * Returns if the given field is a computed field.
55
71
  */
@@ -70,6 +86,10 @@ declare function isNativeTypeMappingAttribute(node: AstNode): node is Attribute;
70
86
  * Returns if the given node is a lite attribute.
71
87
  */
72
88
  declare function isLiteAttribute(node: AstNode): node is Attribute;
89
+ /**
90
+ * Returns if the given node is primitive type def.
91
+ */
92
+ declare function isPrimitiveTypeDef(node: AstNode): node is TypeDef;
73
93
  /**
74
94
  * Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
75
95
  * if no datasource is found or its provider is not a literal.
@@ -186,6 +206,7 @@ declare function isMemberContainer(node: unknown): node is DataModel | TypeDef;
186
206
  * Gets all fields of a data model or type def, including inherited fields from base models and mixins.
187
207
  */
188
208
  declare function getAllFields(decl: DataModel | TypeDef, includeIgnored?: boolean, seen?: Set<DataModel | TypeDef>): DataField[];
209
+ declare function getPrimitiveTypeDefThisField(td: TypeDef): DataField | undefined;
189
210
  /**
190
211
  * Gets all attributes of a data model or type def, including inherited attributes
191
212
  * from base models and mixins.
@@ -207,5 +228,5 @@ declare function getPluginDocuments(model: Model, schemaPath: string): string[];
207
228
  */
208
229
  declare function findRootNode(node: AstNode): AstNode;
209
230
  //#endregion
210
- export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
231
+ export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getPrimitiveTypeDefThisField, getRecursiveBases, getRelationName, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isManyToManyField, isMemberContainer, isNativeTypeMappingAttribute, isPrimitiveTypeDef, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
211
232
  //# sourceMappingURL=utils.d.mts.map
package/dist/utils.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as isAuthInvocation, B as isLiteAttribute, C as getNumberLiteral, D as getStringLiteral, E as getRecursiveBases, F as isComputedField, G as mapBuiltinTypeToExpressionType, H as isNativeTypeMappingAttribute, I as isDataFieldReference, J as resolveTransitiveImports, K as resolveImport, L as isDelegateModel, M as isBeforeInvocation, N as isCheckInvocation, O as getUniqueFields, P as isCollectionPredicate, R as isEnumFieldReference, S as getModelUniqueFields, T as getPluginDocuments, U as isPrismaAttribute, V as isMemberContainer, W as isRelationshipField, X as typeAssignable, Y as resolved, _ as getFieldReference, a as getAllDeclarationsIncludingImports, b as getLiteralArray, c as getAllLoadedDataModelsAndTypeDefs, d as getAttributeArgLiteral, f as getAuthDecl, g as getDocument, h as getDataSourceProvider, i as getAllDataModelsIncludingImports, j as isAuthOrAuthMemberAccess, k as hasAttribute, l as getAttribute, m as getDataModelAndTypeDefs, n as findUpAst, o as getAllFields, p as getContainingDataModel, q as resolveImportUri, r as getAllAttributes, s as getAllLoadedAndReachableDataModelsAndTypeDefs, t as findRootNode, u as getAttributeArg, v as getFunctionExpressionContext, w as getObjectLiteral, x as getModelIdFields, y as getLiteral, z as isFromStdlib } from "./utils-jgngKwh1.mjs";
2
- export { findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
1
+ import { $ as resolved, A as getUniqueFields, B as isEnumFieldReference, C as getNumberLiteral, D as getRecursiveBases, E as getPrimitiveTypeDefThisField, F as isCheckInvocation, G as isNativeTypeMappingAttribute, H as isLiteAttribute, I as isCollectionPredicate, J as isRelationshipField, K as isPrimitiveTypeDef, L as isComputedField, M as isAuthInvocation, N as isAuthOrAuthMemberAccess, O as getRelationName, P as isBeforeInvocation, Q as resolveTransitiveImports, R as isDataFieldReference, S as getModelUniqueFields, T as getPluginDocuments, U as isManyToManyField, V as isFromStdlib, W as isMemberContainer, X as resolveImport, Y as mapBuiltinTypeToExpressionType, Z as resolveImportUri, _ as getFieldReference, a as getAllDeclarationsIncludingImports, b as getLiteralArray, c as getAllLoadedDataModelsAndTypeDefs, d as getAttributeArgLiteral, et as typeAssignable, f as getAuthDecl, g as getDocument, h as getDataSourceProvider, i as getAllDataModelsIncludingImports, j as hasAttribute, k as getStringLiteral, l as getAttribute, m as getDataModelAndTypeDefs, n as findUpAst, o as getAllFields, p as getContainingDataModel, q as isPrismaAttribute, r as getAllAttributes, s as getAllLoadedAndReachableDataModelsAndTypeDefs, t as findRootNode, u as getAttributeArg, v as getFunctionExpressionContext, w as getObjectLiteral, x as getModelIdFields, y as getLiteral, z as isDelegateModel } from "./utils-BWba17ro.mjs";
2
+ export { findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getNumberLiteral, getObjectLiteral, getPluginDocuments, getPrimitiveTypeDefThisField, getRecursiveBases, getRelationName, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isLiteAttribute, isManyToManyField, isMemberContainer, isNativeTypeMappingAttribute, isPrimitiveTypeDef, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@zenstackhq/language",
3
3
  "displayName": "ZenStack Language Tooling",
4
4
  "description": "ZenStack ZModel language specification",
5
- "version": "3.9.8",
5
+ "version": "3.10.0",
6
6
  "type": "module",
7
7
  "author": {
8
8
  "name": "ZenStack Team",
@@ -69,7 +69,7 @@
69
69
  "pluralize": "^8.0.0",
70
70
  "ts-pattern": "^5.7.1",
71
71
  "vscode-languageserver": "^9.0.1",
72
- "@zenstackhq/common-helpers": "3.9.8"
72
+ "@zenstackhq/common-helpers": "3.10.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/node": "^20.19.0",
@@ -77,11 +77,11 @@
77
77
  "@types/tmp": "^0.2.6",
78
78
  "glob": "^11.1.0",
79
79
  "langium-cli": "4.2.1",
80
- "tmp": "^0.2.4",
81
- "@zenstackhq/tsdown-config": "3.9.8",
82
- "@zenstackhq/typescript-config": "3.9.8",
83
- "@zenstackhq/vitest-config": "3.9.8",
84
- "@zenstackhq/eslint-config": "3.9.8"
80
+ "tmp": "^0.2.6",
81
+ "@zenstackhq/eslint-config": "3.10.0",
82
+ "@zenstackhq/tsdown-config": "3.10.0",
83
+ "@zenstackhq/typescript-config": "3.10.0",
84
+ "@zenstackhq/vitest-config": "3.10.0"
85
85
  },
86
86
  "funding": "https://github.com/sponsors/zenstackhq",
87
87
  "scripts": {
@@ -89,8 +89,8 @@
89
89
  "watch": "tsdown --watch",
90
90
  "lint": "eslint src --ext ts",
91
91
  "test": "vitest run",
92
- "langium:generate": "langium generate",
93
- "langium:generate:production": "langium generate --mode=production",
92
+ "langium:generate": "langium generate && tsx scripts/patch-generated-tm.ts",
93
+ "langium:generate:production": "langium generate --mode=production && tsx scripts/patch-generated-tm.ts",
94
94
  "pack": "pnpm pack"
95
95
  }
96
96
  }