@zenstackhq/language 3.9.0 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{utils-CkhGyuL2.mjs → utils-BrAxz9iX.mjs} +8 -2
- package/dist/utils-BrAxz9iX.mjs.map +1 -0
- package/dist/{utils-BvdQdCtT.cjs → utils-DSpz4Ig6.cjs} +13 -1
- package/dist/utils-DSpz4Ig6.cjs.map +1 -0
- package/dist/utils.cjs +2 -1
- package/dist/utils.d.cts +5 -1
- package/dist/utils.d.mts +5 -1
- package/dist/utils.mjs +2 -2
- package/package.json +6 -6
- package/res/stdlib.zmodel +33 -23
- package/dist/utils-BvdQdCtT.cjs.map +0 -1
- package/dist/utils-CkhGyuL2.mjs.map +0 -1
|
@@ -162,6 +162,12 @@ function isNativeTypeMappingAttribute(node) {
|
|
|
162
162
|
return isPrismaAttribute(node) && node.name.startsWith("@db.");
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
|
+
* Returns if the given node is a lite attribute.
|
|
166
|
+
*/
|
|
167
|
+
function isLiteAttribute(node) {
|
|
168
|
+
return isAttribute(node) && hasAttribute(node, "@@@lite");
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
165
171
|
* Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
|
|
166
172
|
* if no datasource is found or its provider is not a literal.
|
|
167
173
|
*/
|
|
@@ -547,6 +553,6 @@ function findRootNode(node) {
|
|
|
547
553
|
return node;
|
|
548
554
|
}
|
|
549
555
|
//#endregion
|
|
550
|
-
export {
|
|
556
|
+
export { PLUGIN_MODULE_NAME as $, isAuthOrAuthMemberAccess as A, isMemberContainer as B, getObjectLiteral as C, getUniqueFields as D, getStringLiteral as E, isDataFieldReference as F, resolveImport as G, isPrismaAttribute as H, isDelegateModel as I, resolved as J, resolveImportUri as K, isEnumFieldReference as L, isCheckInvocation as M, isCollectionPredicate as N, hasAttribute as O, isComputedField as P, IssueCodes as Q, isFromStdlib as R, getModelUniqueFields as S, getRecursiveBases as T, isRelationshipField as U, isNativeTypeMappingAttribute as V, mapBuiltinTypeToExpressionType as W, DB_PROVIDERS_SUPPORTING_LIST_TYPE as X, typeAssignable as Y, ExpressionContext as Z, getFieldReference as _, getAllDeclarationsIncludingImports as a, getLiteralArray as b, getAllLoadedDataModelsAndTypeDefs as c, getAttributeArgLiteral as d, SCALAR_TYPES as et, getAuthDecl as f, getDocument as g, getDataSourceProvider as h, getAllDataModelsIncludingImports as i, isBeforeInvocation as j, isAuthInvocation as k, getAttribute as l, getDataModelAndTypeDefs as m, findUpAst as n, SUPPORTED_PROVIDERS as nt, getAllFields as o, getContainingDataModel as p, resolveTransitiveImports as q, getAllAttributes as r, getAllLoadedAndReachableDataModelsAndTypeDefs as s, findRootNode as t, STD_LIB_MODULE_NAME as tt, getAttributeArg as u, getFunctionExpressionContext as v, getPluginDocuments as w, getModelIdFields as x, getLiteral as y, isLiteAttribute as z };
|
|
551
557
|
|
|
552
|
-
//# sourceMappingURL=utils-
|
|
558
|
+
//# sourceMappingURL=utils-BrAxz9iX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BrAxz9iX.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 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\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 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 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\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) {\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;;;ACgB/D,SAAgB,aAAa,MAAuB,MAAc;AAC9D,QAAO,CAAC,CAAC,aAAa,MAAM,KAAK;;AAGrC,SAAgB,aAAa,MAAuB,MAAc;AAC9D,QAAQ,KAAK,WAA2D,MAAM,SAAS,KAAK,KAAK,aAAa,KAAK;;AAGvH,SAAgB,aAAa,MAAe;CACxC,MAAM,QAAQ,SAAS,mBAAmB,MAAM,QAAQ;AACxD,QAAO,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,aAAa,MAAM,UAAU,IAAI,KAAK,SAAA,gBAA6B;;AAGjG,SAAgB,iBAAiB,MAAe;AAC5C,QAAO,iBAAiB,KAAK,IAAI,KAAK,SAAS,KAAK,SAAS,UAAU,aAAa,KAAK,SAAS,IAAI;;;;;AAM1G,SAAgB,iBAAiB,MAA+C;AAC5E,QAAO,gBAAgB,KAAK,GAAG,KAAK,QAAQ,KAAA;;AAGhD,MAAM,mBAAmB;;;;AAKzB,SAAgB,eAAe,UAA0B,YAA4B,YAAkC;AAEnH,KAAI,aAAa,cAAc,eAAe,YAAY,cAAc,gBAAgB,WAAW,EAAE;EACjG,MAAM,UAAU,iBAAiB,WAAW;AAC5C,MAAI,WAAW,iBAAiB,KAA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{
|
|
|
164
164
|
return isPrismaAttribute(node) && node.name.startsWith("@db.");
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
+
* Returns if the given node is a lite attribute.
|
|
168
|
+
*/
|
|
169
|
+
function isLiteAttribute(node) {
|
|
170
|
+
return require_ast.isAttribute(node) && hasAttribute(node, "@@@lite");
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
167
173
|
* Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
|
|
168
174
|
* if no datasource is found or its provider is not a literal.
|
|
169
175
|
*/
|
|
@@ -819,6 +825,12 @@ Object.defineProperty(exports, "isFromStdlib", {
|
|
|
819
825
|
return isFromStdlib;
|
|
820
826
|
}
|
|
821
827
|
});
|
|
828
|
+
Object.defineProperty(exports, "isLiteAttribute", {
|
|
829
|
+
enumerable: true,
|
|
830
|
+
get: function() {
|
|
831
|
+
return isLiteAttribute;
|
|
832
|
+
}
|
|
833
|
+
});
|
|
822
834
|
Object.defineProperty(exports, "isMemberContainer", {
|
|
823
835
|
enumerable: true,
|
|
824
836
|
get: function() {
|
|
@@ -880,4 +892,4 @@ Object.defineProperty(exports, "typeAssignable", {
|
|
|
880
892
|
}
|
|
881
893
|
});
|
|
882
894
|
|
|
883
|
-
//# sourceMappingURL=utils-
|
|
895
|
+
//# sourceMappingURL=utils-DSpz4Ig6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DSpz4Ig6.cjs","names":["AstUtils","isModel","isInvocationExpr","isStringLiteral","isMemberAccessExpr","isReferenceExpr","isEnumField","isDataField","isDataModel","isAttribute","isDataSource","isTypeDef","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 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\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 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 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\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) {\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;;;ACgB/D,SAAgB,aAAa,MAAuB,MAAc;AAC9D,QAAO,CAAC,CAAC,aAAa,MAAM,KAAK;;AAGrC,SAAgB,aAAa,MAAuB,MAAc;AAC9D,QAAQ,KAAK,WAA2D,MAAM,SAAS,KAAK,KAAK,aAAa,KAAK;;AAGvH,SAAgB,aAAa,MAAe;CACxC,MAAM,QAAQA,QAAAA,SAAS,mBAAmB,MAAMC,YAAAA,QAAQ;AACxD,QAAO,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,aAAa,MAAM,UAAU,IAAI,KAAK,SAAA,gBAA6B;;AAGjG,SAAgB,iBAAiB,MAAe;AAC5C,QAAOC,YAAAA,iBAAiB,KAAK,IAAI,KAAK,SAAS,KAAK,SAAS,UAAU,aAAa,KAAK,SAAS,IAAI;;;;;AAM1G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G,qBAAqB,CAChC;WACxC;;AAMhB,MAAI,CAAC,gBAED,KAAI;AAEA,sBAAA,GAAA,YAAA,gBAAA,GAAA,SAAA,eAD4C,WAAW,CAAC,CAC9B,QAAQ,GAAG,SAAS,GAAG,qBAAqB;UAClE;AAKZ,MAAI,mBAAmBD,QAAAA,QAAG,WAAW,gBAAgB,CACjD,QAAO,KAAK,gBAAgB;;AAGpC,QAAO;;AAKX,SAAS,OACL,OACA,MAAc,QAAQ,KAAK,EAC3B,WAAqB,OACrB,SAAmB,EAAE,EACC;AACtB,KAAI,CAAC,MAAM,MAAM,SAAS,CAAC,CAAC,KAAK,CAC7B;CAEJ,MAAM,SAAS,MAAM,MAAM,SAASA,QAAAA,QAAG,WAAWC,UAAAA,QAAK,KAAK,KAAK,KAAK,CAAC,CAAC;AACxE,KAAI,aAAa,SAAS,OACtB,QAAOA,UAAAA,QAAK,KAAK,KAAK,OAAO;AAEjC,KAAI,OACA,QAAO,KAAKA,UAAAA,QAAK,KAAK,KAAK,OAAO,CAAC;CAEvC,MAAM,KAAKA,UAAAA,QAAK,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"}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_utils = require("./utils-
|
|
2
|
+
const require_utils = require("./utils-DSpz4Ig6.cjs");
|
|
3
3
|
exports.findRootNode = require_utils.findRootNode;
|
|
4
4
|
exports.findUpAst = require_utils.findUpAst;
|
|
5
5
|
exports.getAllAttributes = require_utils.getAllAttributes;
|
|
@@ -38,6 +38,7 @@ exports.isDataFieldReference = require_utils.isDataFieldReference;
|
|
|
38
38
|
exports.isDelegateModel = require_utils.isDelegateModel;
|
|
39
39
|
exports.isEnumFieldReference = require_utils.isEnumFieldReference;
|
|
40
40
|
exports.isFromStdlib = require_utils.isFromStdlib;
|
|
41
|
+
exports.isLiteAttribute = require_utils.isLiteAttribute;
|
|
41
42
|
exports.isMemberContainer = require_utils.isMemberContainer;
|
|
42
43
|
exports.isNativeTypeMappingAttribute = require_utils.isNativeTypeMappingAttribute;
|
|
43
44
|
exports.isPrismaAttribute = require_utils.isPrismaAttribute;
|
package/dist/utils.d.cts
CHANGED
|
@@ -62,6 +62,10 @@ declare function isPrismaAttribute(node: AstNode): node is Attribute;
|
|
|
62
62
|
* Returns if the given node is a native type mapping attribute.
|
|
63
63
|
*/
|
|
64
64
|
declare function isNativeTypeMappingAttribute(node: AstNode): node is Attribute;
|
|
65
|
+
/**
|
|
66
|
+
* Returns if the given node is a lite attribute.
|
|
67
|
+
*/
|
|
68
|
+
declare function isLiteAttribute(node: AstNode): node is Attribute;
|
|
65
69
|
/**
|
|
66
70
|
* Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
|
|
67
71
|
* if no datasource is found or its provider is not a literal.
|
|
@@ -199,5 +203,5 @@ declare function getPluginDocuments(model: Model, schemaPath: string): string[];
|
|
|
199
203
|
*/
|
|
200
204
|
declare function findRootNode(node: AstNode): AstNode;
|
|
201
205
|
//#endregion
|
|
202
|
-
export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
|
|
206
|
+
export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, 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 };
|
|
203
207
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.mts
CHANGED
|
@@ -62,6 +62,10 @@ declare function isPrismaAttribute(node: AstNode): node is Attribute;
|
|
|
62
62
|
* Returns if the given node is a native type mapping attribute.
|
|
63
63
|
*/
|
|
64
64
|
declare function isNativeTypeMappingAttribute(node: AstNode): node is Attribute;
|
|
65
|
+
/**
|
|
66
|
+
* Returns if the given node is a lite attribute.
|
|
67
|
+
*/
|
|
68
|
+
declare function isLiteAttribute(node: AstNode): node is Attribute;
|
|
65
69
|
/**
|
|
66
70
|
* Returns the datasource provider literal (e.g. `'postgresql'`) declared in the schema, or undefined
|
|
67
71
|
* if no datasource is found or its provider is not a literal.
|
|
@@ -199,5 +203,5 @@ declare function getPluginDocuments(model: Model, schemaPath: string): string[];
|
|
|
199
203
|
*/
|
|
200
204
|
declare function findRootNode(node: AstNode): AstNode;
|
|
201
205
|
//#endregion
|
|
202
|
-
export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
|
|
206
|
+
export { AttributeTarget, findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, 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 };
|
|
203
207
|
//# sourceMappingURL=utils.d.mts.map
|
package/dist/utils.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as isAuthOrAuthMemberAccess, B as
|
|
2
|
-
export { findRootNode, findUpAst, getAllAttributes, getAllDataModelsIncludingImports, getAllDeclarationsIncludingImports, getAllFields, getAllLoadedAndReachableDataModelsAndTypeDefs, getAllLoadedDataModelsAndTypeDefs, getAttribute, getAttributeArg, getAttributeArgLiteral, getAuthDecl, getContainingDataModel, getDataModelAndTypeDefs, getDataSourceProvider, getDocument, getFieldReference, getFunctionExpressionContext, getLiteral, getLiteralArray, getModelIdFields, getModelUniqueFields, getObjectLiteral, getPluginDocuments, getRecursiveBases, getStringLiteral, getUniqueFields, hasAttribute, isAuthInvocation, isAuthOrAuthMemberAccess, isBeforeInvocation, isCheckInvocation, isCollectionPredicate, isComputedField, isDataFieldReference, isDelegateModel, isEnumFieldReference, isFromStdlib, isMemberContainer, isNativeTypeMappingAttribute, isPrismaAttribute, isRelationshipField, mapBuiltinTypeToExpressionType, resolveImport, resolveImportUri, resolveTransitiveImports, resolved, typeAssignable };
|
|
1
|
+
import { A as isAuthOrAuthMemberAccess, B as isMemberContainer, C as getObjectLiteral, D as getUniqueFields, E as getStringLiteral, F as isDataFieldReference, G as resolveImport, H as isPrismaAttribute, I as isDelegateModel, J as resolved, K as resolveImportUri, L as isEnumFieldReference, M as isCheckInvocation, N as isCollectionPredicate, O as hasAttribute, P as isComputedField, R as isFromStdlib, S as getModelUniqueFields, T as getRecursiveBases, U as isRelationshipField, V as isNativeTypeMappingAttribute, W as mapBuiltinTypeToExpressionType, Y as typeAssignable, _ 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 isBeforeInvocation, k as isAuthInvocation, l as getAttribute, m as getDataModelAndTypeDefs, n as findUpAst, o as getAllFields, p as getContainingDataModel, q as resolveTransitiveImports, r as getAllAttributes, s as getAllLoadedAndReachableDataModelsAndTypeDefs, t as findRootNode, u as getAttributeArg, v as getFunctionExpressionContext, w as getPluginDocuments, x as getModelIdFields, y as getLiteral, z as isLiteAttribute } from "./utils-BrAxz9iX.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, 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 };
|
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.
|
|
5
|
+
"version": "3.9.2",
|
|
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.
|
|
72
|
+
"@zenstackhq/common-helpers": "3.9.2"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "^20.19.0",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"glob": "^11.1.0",
|
|
79
79
|
"langium-cli": "4.2.1",
|
|
80
80
|
"tmp": "^0.2.4",
|
|
81
|
-
"@zenstackhq/
|
|
82
|
-
"@zenstackhq/
|
|
83
|
-
"@zenstackhq/typescript-config": "3.9.
|
|
84
|
-
"@zenstackhq/
|
|
81
|
+
"@zenstackhq/vitest-config": "3.9.2",
|
|
82
|
+
"@zenstackhq/eslint-config": "3.9.2",
|
|
83
|
+
"@zenstackhq/typescript-config": "3.9.2",
|
|
84
|
+
"@zenstackhq/tsdown-config": "3.9.2"
|
|
85
85
|
},
|
|
86
86
|
"funding": "https://github.com/sponsors/zenstackhq",
|
|
87
87
|
"scripts": {
|
package/res/stdlib.zmodel
CHANGED
|
@@ -224,7 +224,7 @@ attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?)
|
|
|
224
224
|
* Defines a default value for a field.
|
|
225
225
|
* @param value: An expression (e.g. 5, true, now(), auth()).
|
|
226
226
|
*/
|
|
227
|
-
attribute @default(_ value: ContextType, map: String?) @@@prisma @@@once
|
|
227
|
+
attribute @default(_ value: ContextType, map: String?) @@@prisma @@@once @@@lite
|
|
228
228
|
|
|
229
229
|
/**
|
|
230
230
|
* Defines a unique constraint for this field.
|
|
@@ -427,7 +427,7 @@ attribute @fullText() @@@targetField([StringField]) @@@once
|
|
|
427
427
|
* updates have been made to a record. An update that only contains ignored fields does not change the
|
|
428
428
|
* timestamp.
|
|
429
429
|
*/
|
|
430
|
-
attribute @updatedAt(ignore: FieldReference[]?) @@@targetField([DateTimeField]) @@@prisma
|
|
430
|
+
attribute @updatedAt(ignore: FieldReference[]?) @@@targetField([DateTimeField]) @@@prisma @@@lite
|
|
431
431
|
|
|
432
432
|
/**
|
|
433
433
|
* Add full text index (MySQL only).
|
|
@@ -520,97 +520,97 @@ attribute @@schema(_ map: String) @@@prisma
|
|
|
520
520
|
/**
|
|
521
521
|
* Validates length of a string field or list field.
|
|
522
522
|
*/
|
|
523
|
-
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
|
|
523
|
+
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation @@@lite
|
|
524
524
|
|
|
525
525
|
/**
|
|
526
526
|
* Validates a string field value starts with the given text.
|
|
527
527
|
*/
|
|
528
|
-
attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
528
|
+
attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
529
529
|
|
|
530
530
|
/**
|
|
531
531
|
* Validates a string field value ends with the given text.
|
|
532
532
|
*/
|
|
533
|
-
attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
533
|
+
attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
534
534
|
|
|
535
535
|
/**
|
|
536
536
|
* Validates a string field value contains the given text.
|
|
537
537
|
*/
|
|
538
|
-
attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
538
|
+
attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
539
539
|
|
|
540
540
|
/**
|
|
541
541
|
* Validates a string field value matches a regex.
|
|
542
542
|
*/
|
|
543
|
-
attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
543
|
+
attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
544
544
|
|
|
545
545
|
/**
|
|
546
546
|
* Validates a string field value is a valid email address.
|
|
547
547
|
*/
|
|
548
|
-
attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
548
|
+
attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
549
549
|
|
|
550
550
|
/**
|
|
551
551
|
* Validates a string field value is a valid ISO datetime.
|
|
552
552
|
*/
|
|
553
|
-
attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
553
|
+
attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
554
554
|
|
|
555
555
|
/**
|
|
556
556
|
* Validates a string field value is a valid ISO date.
|
|
557
557
|
*/
|
|
558
|
-
attribute @date(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
558
|
+
attribute @date(_ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
559
559
|
|
|
560
560
|
/**
|
|
561
561
|
* Validates a string field value is a valid ISO time.
|
|
562
562
|
*/
|
|
563
|
-
attribute @time(_ precision: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
563
|
+
attribute @time(_ precision: Int?, _ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
564
564
|
|
|
565
565
|
/**
|
|
566
566
|
* Validates a string field value is a valid url.
|
|
567
567
|
*/
|
|
568
|
-
attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
568
|
+
attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
569
569
|
|
|
570
570
|
/**
|
|
571
571
|
* Validates a string field value is a valid E.164 phone number.
|
|
572
572
|
*/
|
|
573
|
-
attribute @phone(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
573
|
+
attribute @phone(_ message: String?) @@@targetField([StringField]) @@@validation @@@lite
|
|
574
574
|
|
|
575
575
|
/**
|
|
576
576
|
* Trims whitespaces from the start and end of the string.
|
|
577
577
|
*/
|
|
578
|
-
attribute @trim() @@@targetField([StringField]) @@@validation
|
|
578
|
+
attribute @trim() @@@targetField([StringField]) @@@validation @@@lite
|
|
579
579
|
|
|
580
580
|
/**
|
|
581
581
|
* Transform entire string toLowerCase.
|
|
582
582
|
*/
|
|
583
|
-
attribute @lower() @@@targetField([StringField]) @@@validation
|
|
583
|
+
attribute @lower() @@@targetField([StringField]) @@@validation @@@lite
|
|
584
584
|
|
|
585
585
|
/**
|
|
586
586
|
* Transform entire string toUpperCase.
|
|
587
587
|
*/
|
|
588
|
-
attribute @upper() @@@targetField([StringField]) @@@validation
|
|
588
|
+
attribute @upper() @@@targetField([StringField]) @@@validation @@@lite
|
|
589
589
|
|
|
590
590
|
/**
|
|
591
591
|
* Validates a number field is greater than the given value.
|
|
592
592
|
*/
|
|
593
|
-
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
593
|
+
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation @@@lite
|
|
594
594
|
|
|
595
595
|
/**
|
|
596
596
|
* Validates a number field is greater than or equal to the given value.
|
|
597
597
|
*/
|
|
598
|
-
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
598
|
+
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation @@@lite
|
|
599
599
|
|
|
600
600
|
/**
|
|
601
601
|
* Validates a number field is less than the given value.
|
|
602
602
|
*/
|
|
603
|
-
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
603
|
+
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation @@@lite
|
|
604
604
|
|
|
605
605
|
/**
|
|
606
606
|
* Validates a number field is less than or equal to the given value.
|
|
607
607
|
*/
|
|
608
|
-
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
608
|
+
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation @@@lite
|
|
609
609
|
|
|
610
610
|
/**
|
|
611
611
|
* Validates the entity with a complex condition.
|
|
612
612
|
*/
|
|
613
|
-
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
|
|
613
|
+
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation @@@lite
|
|
614
614
|
|
|
615
615
|
/**
|
|
616
616
|
* Returns the length of a string field or a list field.
|
|
@@ -718,14 +718,24 @@ attribute @@auth()
|
|
|
718
718
|
/**
|
|
719
719
|
* Attaches arbitrary metadata to a model or type def.
|
|
720
720
|
*/
|
|
721
|
-
attribute @@meta(_ name: String, _ value: Any)
|
|
721
|
+
attribute @@meta(_ name: String, _ value: Any) @@@lite
|
|
722
722
|
|
|
723
723
|
/**
|
|
724
724
|
* Attaches arbitrary metadata to a field.
|
|
725
725
|
*/
|
|
726
|
-
attribute @meta(_ name: String, _ value: Any)
|
|
726
|
+
attribute @meta(_ name: String, _ value: Any) @@@lite
|
|
727
727
|
|
|
728
728
|
/**
|
|
729
729
|
* Marks an attribute as deprecated.
|
|
730
730
|
*/
|
|
731
731
|
attribute @@@deprecated(_ message: String)
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Indicates an attribute should not be stripped when generating lite schemas.
|
|
735
|
+
*/
|
|
736
|
+
attribute @@@lite()
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Indicates a type def should reject unknown fields.
|
|
740
|
+
*/
|
|
741
|
+
attribute @@strict() @@@once @@@validation
|