@nocobase/plugin-ui-schema-storage 0.7.0-alpha.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.
- package/LICENSE +201 -0
- package/esm/actions/ui-schema-action.d.ts +16 -0
- package/esm/actions/ui-schema-action.js +100 -0
- package/esm/actions/ui-schema-action.js.map +1 -0
- package/esm/collections/uiSchemaServerHooks.d.ts +3 -0
- package/esm/collections/uiSchemaServerHooks.js +27 -0
- package/esm/collections/uiSchemaServerHooks.js.map +1 -0
- package/esm/collections/uiSchemaTemplates.d.ts +2 -0
- package/esm/collections/uiSchemaTemplates.js +39 -0
- package/esm/collections/uiSchemaTemplates.js.map +1 -0
- package/esm/collections/uiSchemaTreePath.d.ts +3 -0
- package/esm/collections/uiSchemaTreePath.js +42 -0
- package/esm/collections/uiSchemaTreePath.js.map +1 -0
- package/esm/collections/uiSchemas.d.ts +3 -0
- package/esm/collections/uiSchemas.js +32 -0
- package/esm/collections/uiSchemas.js.map +1 -0
- package/esm/dao/ui_schema_dao.d.ts +4 -0
- package/esm/dao/ui_schema_dao.js +6 -0
- package/esm/dao/ui_schema_dao.js.map +1 -0
- package/esm/dao/ui_schema_node_dao.d.ts +22 -0
- package/esm/dao/ui_schema_node_dao.js +6 -0
- package/esm/dao/ui_schema_node_dao.js.map +1 -0
- package/esm/helper.d.ts +0 -0
- package/esm/helper.js +1 -0
- package/esm/helper.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/esm/model.d.ts +6 -0
- package/esm/model.js +9 -0
- package/esm/model.js.map +1 -0
- package/esm/repository.d.ts +72 -0
- package/esm/repository.js +858 -0
- package/esm/repository.js.map +1 -0
- package/esm/server-hooks/hooks/bind-menu-to-role.d.ts +5 -0
- package/esm/server-hooks/hooks/bind-menu-to-role.js +26 -0
- package/esm/server-hooks/hooks/bind-menu-to-role.js.map +1 -0
- package/esm/server-hooks/hooks/factory.d.ts +6 -0
- package/esm/server-hooks/hooks/factory.js +8 -0
- package/esm/server-hooks/hooks/factory.js.map +1 -0
- package/esm/server-hooks/hooks/index.d.ts +6 -0
- package/esm/server-hooks/hooks/index.js +12 -0
- package/esm/server-hooks/hooks/index.js.map +1 -0
- package/esm/server-hooks/hooks/remove-parents-if-no-children.d.ts +6 -0
- package/esm/server-hooks/hooks/remove-parents-if-no-children.js +21 -0
- package/esm/server-hooks/hooks/remove-parents-if-no-children.js.map +1 -0
- package/esm/server-hooks/hooks/remove-schema.d.ts +6 -0
- package/esm/server-hooks/hooks/remove-schema.js +29 -0
- package/esm/server-hooks/hooks/remove-schema.js.map +1 -0
- package/esm/server-hooks/index.d.ts +23 -0
- package/esm/server-hooks/index.js +133 -0
- package/esm/server-hooks/index.js.map +1 -0
- package/esm/server-hooks/model.d.ts +3 -0
- package/esm/server-hooks/model.js +4 -0
- package/esm/server-hooks/model.js.map +1 -0
- package/esm/server.d.ts +10 -0
- package/esm/server.js +78 -0
- package/esm/server.js.map +1 -0
- package/lib/actions/ui-schema-action.d.ts +16 -0
- package/lib/actions/ui-schema-action.js +106 -0
- package/lib/actions/ui-schema-action.js.map +1 -0
- package/lib/collections/uiSchemaServerHooks.d.ts +3 -0
- package/lib/collections/uiSchemaServerHooks.js +29 -0
- package/lib/collections/uiSchemaServerHooks.js.map +1 -0
- package/lib/collections/uiSchemaTemplates.d.ts +2 -0
- package/lib/collections/uiSchemaTemplates.js +41 -0
- package/lib/collections/uiSchemaTemplates.js.map +1 -0
- package/lib/collections/uiSchemaTreePath.d.ts +3 -0
- package/lib/collections/uiSchemaTreePath.js +44 -0
- package/lib/collections/uiSchemaTreePath.js.map +1 -0
- package/lib/collections/uiSchemas.d.ts +3 -0
- package/lib/collections/uiSchemas.js +34 -0
- package/lib/collections/uiSchemas.js.map +1 -0
- package/lib/dao/ui_schema_dao.d.ts +4 -0
- package/lib/dao/ui_schema_dao.js +10 -0
- package/lib/dao/ui_schema_dao.js.map +1 -0
- package/lib/dao/ui_schema_node_dao.d.ts +22 -0
- package/lib/dao/ui_schema_node_dao.js +10 -0
- package/lib/dao/ui_schema_node_dao.js.map +1 -0
- package/lib/helper.d.ts +0 -0
- package/lib/helper.js +1 -0
- package/lib/helper.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/model.d.ts +6 -0
- package/lib/model.js +12 -0
- package/lib/model.js.map +1 -0
- package/lib/repository.d.ts +72 -0
- package/lib/repository.js +865 -0
- package/lib/repository.js.map +1 -0
- package/lib/server-hooks/hooks/bind-menu-to-role.d.ts +5 -0
- package/lib/server-hooks/hooks/bind-menu-to-role.js +30 -0
- package/lib/server-hooks/hooks/bind-menu-to-role.js.map +1 -0
- package/lib/server-hooks/hooks/factory.d.ts +6 -0
- package/lib/server-hooks/hooks/factory.js +12 -0
- package/lib/server-hooks/hooks/factory.js.map +1 -0
- package/lib/server-hooks/hooks/index.d.ts +6 -0
- package/lib/server-hooks/hooks/index.js +15 -0
- package/lib/server-hooks/hooks/index.js.map +1 -0
- package/lib/server-hooks/hooks/remove-parents-if-no-children.d.ts +6 -0
- package/lib/server-hooks/hooks/remove-parents-if-no-children.js +25 -0
- package/lib/server-hooks/hooks/remove-parents-if-no-children.js.map +1 -0
- package/lib/server-hooks/hooks/remove-schema.d.ts +6 -0
- package/lib/server-hooks/hooks/remove-schema.js +33 -0
- package/lib/server-hooks/hooks/remove-schema.js.map +1 -0
- package/lib/server-hooks/index.d.ts +23 -0
- package/lib/server-hooks/index.js +137 -0
- package/lib/server-hooks/index.js.map +1 -0
- package/lib/server-hooks/model.d.ts +3 -0
- package/lib/server-hooks/model.js +8 -0
- package/lib/server-hooks/model.js.map +1 -0
- package/lib/server.d.ts +10 -0
- package/lib/server.js +85 -0
- package/lib/server.js.map +1 -0
- package/package.json +22 -0
- package/tsconfig.build.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":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AE;2DAGb;AAGD;IADC,WAAW,EAAE;wDAGb;AAGD;IADC,WAAW,EAAE;qDAgBb;AAGD;IADC,WAAW,EAAE;gDAOb;AAGD;IADC,WAAW,EAAE;yDAoEb;AAtpBH,gDA87BC;AAED,kBAAe,kBAAkB,CAAC","sourcesContent":["import { Repository, TransactionAble } from '@nocobase/database';\nimport { uid } from '@nocobase/utils';\nimport lodash from 'lodash';\nimport { Transaction } from 'sequelize';\nimport { ChildOptions, SchemaNode, TargetPosition } from './dao/ui_schema_node_dao';\n\ninterface GetJsonSchemaOptions {\n includeAsyncNode?: boolean;\n transaction?: Transaction;\n}\n\ntype BreakRemoveOnType = {\n [key: string]: any;\n};\n\nexport interface removeParentOptions extends TransactionAble {\n removeParentsIfNoChildren?: boolean;\n breakRemoveOn?: BreakRemoveOnType;\n}\n\ninterface InsertAdjacentOptions extends removeParentOptions {\n wrap?: any;\n}\n\nconst nodeKeys = ['properties', 'definitions', 'patternProperties', 'additionalProperties', 'items'];\n\nfunction transaction(transactionAbleArgPosition?: number) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n const originalMethod = descriptor.value;\n\n descriptor.value = async function (...args) {\n if (!lodash.isNumber(transactionAbleArgPosition)) {\n transactionAbleArgPosition = originalMethod.length - 1;\n }\n\n let transaction = lodash.get(args, [transactionAbleArgPosition, 'transaction']);\n let handleTransaction = false;\n if (!transaction) {\n transaction = await this.database.sequelize.transaction();\n handleTransaction = true;\n\n lodash.set(args, transactionAbleArgPosition, {\n ...lodash.get(args, transactionAbleArgPosition, {}),\n transaction,\n });\n }\n\n if (handleTransaction) {\n try {\n const results = await originalMethod.apply(this, args);\n await transaction.commit();\n return results;\n } catch (e) {\n await transaction.rollback();\n throw e;\n }\n } else {\n return await originalMethod.apply(this, args);\n }\n };\n\n return descriptor;\n };\n}\n\nexport class UiSchemaRepository extends Repository {\n tableNameAdapter(tableName) {\n if (this.database.sequelize.getDialect() === 'postgres') {\n return `\"${tableName}\"`;\n }\n return tableName;\n }\n\n get uiSchemasTableName() {\n return this.tableNameAdapter(this.model.tableName);\n }\n\n get uiSchemaTreePathTableName() {\n const model = this.database.getCollection('uiSchemaTreePath').model;\n return this.tableNameAdapter(model.tableName);\n }\n\n sqlAdapter(sql: string) {\n if (this.database.sequelize.getDialect() === 'mysql') {\n return lodash.replace(sql, /\"/g, '`');\n }\n\n return sql;\n }\n\n static schemaToSingleNodes(schema: any, carry: SchemaNode[] = [], childOptions: ChildOptions = null): SchemaNode[] {\n const node = lodash.cloneDeep(\n lodash.isString(schema)\n ? {\n 'x-uid': schema,\n }\n : schema,\n );\n\n if (!lodash.get(node, 'name')) {\n node.name = uid();\n }\n\n if (!lodash.get(node, 'x-uid')) {\n node['x-uid'] = uid();\n }\n\n if (childOptions) {\n node.childOptions = childOptions;\n }\n\n carry.push(node);\n\n for (const nodeKey of nodeKeys) {\n const nodeProperty = lodash.get(node, nodeKey);\n const childNodeChildOptions = {\n parentUid: node['x-uid'],\n parentPath: [node['x-uid'], ...lodash.get(childOptions, 'parentPath', [])],\n type: nodeKey,\n };\n\n // array items\n if (nodeKey === 'items' && nodeProperty) {\n const handleItems = lodash.isArray(nodeProperty) ? nodeProperty : [nodeProperty];\n for (const [i, item] of handleItems.entries()) {\n carry = this.schemaToSingleNodes(item, carry, { ...childNodeChildOptions, sort: i + 1 });\n }\n } else if (lodash.isPlainObject(nodeProperty)) {\n const subNodeNames = lodash.keys(lodash.get(node, nodeKey));\n\n delete node[nodeKey];\n\n for (const [i, subNodeName] of subNodeNames.entries()) {\n const subSchema = {\n name: subNodeName,\n ...lodash.get(nodeProperty, subNodeName),\n };\n\n carry = this.schemaToSingleNodes(subSchema, carry, { ...childNodeChildOptions, sort: i + 1 });\n }\n }\n }\n\n return carry;\n }\n\n async getProperties(uid: string, options: TransactionAble = {}) {\n const { transaction } = options;\n\n const db = this.database;\n\n const rawSql = `\n SELECT \"SchemaTable\".\"x-uid\" as \"x-uid\", \"SchemaTable\".\"name\" as \"name\", \"SchemaTable\".\"schema\" as \"schema\",\n TreePath.depth as depth,\n NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort\n FROM ${this.uiSchemaTreePathTableName} as TreePath\n LEFT JOIN ${this.uiSchemasTableName} as \"SchemaTable\" ON \"SchemaTable\".\"x-uid\" = TreePath.descendant\n LEFT JOIN ${this.uiSchemaTreePathTableName} as NodeInfo ON NodeInfo.descendant = \"SchemaTable\".\"x-uid\" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0\n LEFT JOIN ${this.uiSchemaTreePathTableName} as ParentPath ON (ParentPath.descendant = \"SchemaTable\".\"x-uid\" AND ParentPath.depth = 1)\n WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth = 1)`;\n\n const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {\n replacements: {\n ancestor: uid,\n },\n transaction,\n });\n\n if (nodes[0].length == 0) {\n return {};\n }\n\n const schema = this.nodesToSchema(nodes[0], uid);\n return lodash.pick(schema, ['type', 'properties']);\n }\n\n async getJsonSchema(uid: string, options?: GetJsonSchemaOptions): Promise<any> {\n const db = this.database;\n\n const treeTable = this.uiSchemaTreePathTableName;\n\n const rawSql = `\n SELECT \"SchemaTable\".\"x-uid\" as \"x-uid\", \"SchemaTable\".\"name\" as name, \"SchemaTable\".\"schema\" as \"schema\" ,\n TreePath.depth as depth,\n NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort\n FROM ${treeTable} as TreePath\n LEFT JOIN ${this.uiSchemasTableName} as \"SchemaTable\" ON \"SchemaTable\".\"x-uid\" = TreePath.descendant\n LEFT JOIN ${treeTable} as NodeInfo ON NodeInfo.descendant = \"SchemaTable\".\"x-uid\" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0\n LEFT JOIN ${treeTable} as ParentPath ON (ParentPath.descendant = \"SchemaTable\".\"x-uid\" AND ParentPath.depth = 1)\n WHERE TreePath.ancestor = :ancestor ${options?.includeAsyncNode ? '' : 'AND (NodeInfo.async != true )'}\n `;\n\n const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {\n replacements: {\n ancestor: uid,\n },\n transaction: options?.transaction,\n });\n\n if (nodes[0].length == 0) {\n return {};\n }\n\n const schema = this.nodesToSchema(nodes[0], uid);\n return schema;\n }\n\n private ignoreSchemaProperties(schemaProperties) {\n return lodash.omit(schemaProperties, nodeKeys);\n }\n\n nodesToSchema(nodes, rootUid) {\n const nodeAttributeSanitize = (node) => {\n const schema = {\n ...this.ignoreSchemaProperties(lodash.isPlainObject(node.schema) ? node.schema : JSON.parse(node.schema)),\n ...lodash.pick(node, [...nodeKeys, 'name']),\n ['x-uid']: node['x-uid'],\n ['x-async']: !!node.async,\n };\n\n if (lodash.isNumber(node.sort)) {\n schema['x-index'] = node.sort;\n }\n\n return schema;\n };\n\n const buildTree = (rootNode) => {\n const children = nodes.filter((node) => node.parent == rootNode['x-uid']);\n\n if (children.length > 0) {\n const childrenGroupByType = lodash.groupBy(children, 'type');\n\n for (const childType of Object.keys(childrenGroupByType)) {\n const properties = childrenGroupByType[childType]\n .map((child) => buildTree(child))\n .sort((a, b) => a['x-index'] - b['x-index']) as any;\n\n rootNode[childType] =\n childType == 'items'\n ? properties.length == 1\n ? properties[0]\n : properties\n : properties.reduce((carry, item) => {\n carry[item.name] = item;\n delete item['name'];\n return carry;\n }, {});\n }\n }\n\n return nodeAttributeSanitize(rootNode);\n };\n\n return buildTree(nodes.find((node) => node['x-uid'] == rootUid));\n }\n\n @transaction()\n async clearAncestor(uid: string, options?: TransactionAble) {\n const db = this.database;\n const treeTable = this.uiSchemaTreePathTableName;\n\n await db.sequelize.query(\n `DELETE\n FROM ${treeTable}\n WHERE descendant IN\n (SELECT descendant FROM (SELECT descendant FROM ${treeTable} WHERE ancestor = :uid) as descendantTable)\n AND ancestor IN (SELECT ancestor\n FROM (SELECT ancestor FROM ${treeTable} WHERE descendant = :uid AND ancestor != descendant) as ancestorTable)\n `,\n {\n type: 'DELETE',\n replacements: {\n uid,\n },\n transaction: options.transaction,\n },\n );\n }\n\n @transaction()\n async patch(newSchema: any, options?) {\n const { transaction } = options;\n\n const rootUid = newSchema['x-uid'];\n const oldTree = await this.getJsonSchema(rootUid);\n\n const traverSchemaTree = async (schema, path = []) => {\n const node = schema;\n const oldNode = path.length == 0 ? oldTree : lodash.get(oldTree, path);\n const oldNodeUid = oldNode['x-uid'];\n\n await this.updateNode(oldNodeUid, node, transaction);\n\n const properties = node.properties;\n if (lodash.isPlainObject(properties)) {\n for (const name of Object.keys(properties)) {\n await traverSchemaTree(properties[name], [...path, 'properties', name]);\n }\n }\n };\n\n await traverSchemaTree(newSchema);\n }\n\n async updateNode(uid: string, schema: any, transaction?: Transaction) {\n const nodeModel = await this.findOne({\n filter: {\n 'x-uid': uid,\n },\n });\n\n await nodeModel.update(\n {\n schema: {\n ...(nodeModel.get('schema') as any),\n ...lodash.omit(schema, ['x-async', 'name', 'x-uid', 'properties']),\n },\n },\n {\n hooks: false,\n transaction,\n },\n );\n }\n\n protected async childrenCount(uid, transaction) {\n const db = this.database;\n\n const countResult = await db.sequelize.query(\n `SELECT COUNT(*) as count FROM ${this.uiSchemaTreePathTableName} where ancestor = :ancestor and depth = 1`,\n {\n replacements: {\n ancestor: uid,\n },\n type: 'SELECT',\n transaction,\n },\n );\n\n return parseInt(countResult[0]['count']);\n }\n\n protected async isLeafNode(uid, transaction) {\n const childrenCount = await this.childrenCount(uid, transaction);\n return childrenCount === 0;\n }\n\n async findParentUid(uid, transaction?) {\n const parent = await this.database.getRepository('uiSchemaTreePath').findOne({\n filter: {\n descendant: uid,\n depth: 1,\n },\n transaction,\n });\n\n return parent ? (parent.get('ancestor') as string) : null;\n }\n\n protected async findNodeSchemaWithParent(uid, transaction) {\n const schema = await this.database.getRepository('uiSchemas').findOne({\n filter: {\n 'x-uid': uid,\n },\n transaction,\n });\n\n return {\n parentUid: await this.findParentUid(uid, transaction),\n schema,\n };\n }\n\n protected async isSingleChild(uid, transaction) {\n const db = this.database;\n\n const parent = await this.findParentUid(uid, transaction);\n\n if (!parent) {\n return null;\n }\n\n const parentChildrenCount = await this.childrenCount(parent, transaction);\n\n if (parentChildrenCount == 1) {\n const schema = await db.getRepository('uiSchemas').findOne({\n filter: {\n 'x-uid': parent,\n },\n transaction,\n });\n\n return schema;\n }\n\n return null;\n }\n\n async removeEmptyParents(options: TransactionAble & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {\n const { transaction, uid, breakRemoveOn } = options;\n\n const removeParent = async (nodeUid: string) => {\n const parent = await this.isSingleChild(nodeUid, transaction);\n\n if (parent && !this.breakOnMatched(parent, breakRemoveOn)) {\n await removeParent(parent.get('x-uid') as string);\n } else {\n await this.remove(nodeUid, { transaction });\n }\n };\n\n await removeParent(uid);\n }\n\n private breakOnMatched(schemaInstance, breakRemoveOn: BreakRemoveOnType): boolean {\n if (!breakRemoveOn) {\n return false;\n }\n\n for (const key of Object.keys(breakRemoveOn)) {\n const instanceValue = schemaInstance.get(key);\n const breakRemoveOnValue = breakRemoveOn[key];\n if (instanceValue !== breakRemoveOnValue) {\n return false;\n }\n }\n\n return true;\n }\n\n async recursivelyRemoveIfNoChildren(options: TransactionAble & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {\n const { uid, transaction, breakRemoveOn } = options;\n\n const removeLeafNode = async (nodeUid: string) => {\n const isLeafNode = await this.isLeafNode(nodeUid, transaction);\n\n if (isLeafNode) {\n const { parentUid, schema } = await this.findNodeSchemaWithParent(nodeUid, transaction);\n\n if (this.breakOnMatched(schema, breakRemoveOn)) {\n // break at here\n return;\n } else {\n // remove current node\n await this.remove(nodeUid, {\n transaction,\n });\n // continue remove\n await removeLeafNode(parentUid);\n }\n }\n };\n\n await removeLeafNode(uid);\n }\n\n @transaction()\n async remove(uid: string, options?: TransactionAble & removeParentOptions) {\n let { transaction } = options;\n\n if (options?.removeParentsIfNoChildren) {\n await this.removeEmptyParents({ transaction, uid, breakRemoveOn: options.breakRemoveOn });\n return;\n }\n\n await this.database.sequelize.query(\n this.sqlAdapter(`DELETE FROM ${this.uiSchemasTableName} WHERE \"x-uid\" IN (\n SELECT descendant FROM ${this.uiSchemaTreePathTableName} WHERE ancestor = :uid\n )`),\n {\n replacements: {\n uid,\n },\n transaction,\n },\n );\n\n await this.database.sequelize.query(\n ` DELETE FROM ${this.uiSchemaTreePathTableName}\n WHERE descendant IN (\n select descendant FROM\n (SELECT descendant\n FROM ${this.uiSchemaTreePathTableName}\n WHERE ancestor = :uid)as descendantTable) `,\n {\n replacements: {\n uid,\n },\n transaction,\n },\n );\n }\n\n @transaction()\n async insertBeside(targetUid: string, schema: any, side: 'before' | 'after', options?: InsertAdjacentOptions) {\n const { transaction } = options;\n const targetParent = await this.findParentUid(targetUid, transaction);\n\n const db = this.database;\n\n const treeTable = this.uiSchemaTreePathTableName;\n\n const typeQuery = await db.sequelize.query(`SELECT type from ${treeTable} WHERE ancestor = :uid AND depth = 0;`, {\n type: 'SELECT',\n replacements: {\n uid: targetUid,\n },\n transaction,\n });\n\n const nodes = UiSchemaRepository.schemaToSingleNodes(schema);\n\n const rootNode = nodes[0];\n\n rootNode.childOptions = {\n parentUid: targetParent,\n type: typeQuery[0]['type'],\n position: {\n type: side,\n target: targetUid,\n },\n };\n\n const insertedNodes = await this.insertNodes(nodes, options);\n return await this.getJsonSchema(insertedNodes[0].get('x-uid'), {\n transaction,\n });\n }\n\n @transaction()\n async insertInner(targetUid: string, schema: any, position: 'first' | 'last', options?: InsertAdjacentOptions) {\n const { transaction } = options;\n\n const nodes = UiSchemaRepository.schemaToSingleNodes(schema);\n const rootNode = nodes[0];\n\n rootNode.childOptions = {\n parentUid: targetUid,\n type: lodash.get(schema, 'x-node-type', 'properties'),\n position,\n };\n\n const insertedNodes = await this.insertNodes(nodes, options);\n\n return await this.getJsonSchema(insertedNodes[0].get('x-uid'), {\n transaction,\n });\n }\n\n private async schemaExists(schema: any, options?: TransactionAble): Promise<boolean> {\n if (lodash.isObject(schema) && !schema['x-uid']) {\n return false;\n }\n\n const { transaction } = options;\n const result = await this.database.sequelize.query(\n this.sqlAdapter(`select \"x-uid\" from ${this.uiSchemasTableName} where \"x-uid\" = :uid`),\n {\n type: 'SELECT',\n replacements: {\n uid: lodash.isString(schema) ? schema : schema['x-uid'],\n },\n transaction,\n },\n );\n\n return result.length > 0;\n }\n\n @transaction()\n async insertAdjacent(\n position: 'beforeBegin' | 'afterBegin' | 'beforeEnd' | 'afterEnd',\n target: string,\n schema: any,\n options?: InsertAdjacentOptions,\n ) {\n const { transaction } = options;\n\n if (options.wrap) {\n // insert wrap schema using insertNewSchema\n const wrapSchemaNodes = await this.insertNewSchema(options.wrap, {\n transaction,\n returnNode: true,\n });\n\n const lastWrapNode = wrapSchemaNodes[wrapSchemaNodes.length - 1];\n\n // insert schema into wrap schema\n await this.insertAdjacent('afterBegin', lastWrapNode['x-uid'], schema, lodash.omit(options, 'wrap'));\n\n schema = wrapSchemaNodes[0]['x-uid'];\n\n options.removeParentsIfNoChildren = false;\n } else {\n const schemaExists = await this.schemaExists(schema, { transaction });\n\n if (schemaExists) {\n schema = lodash.isString(schema) ? schema : schema['x-uid'];\n } else {\n const insertedSchema = await this.insertNewSchema(schema, {\n transaction,\n returnNode: true,\n });\n\n schema = insertedSchema[0]['x-uid'];\n }\n }\n\n return await this[`insert${lodash.upperFirst(position)}`](target, schema, options);\n }\n\n @transaction()\n protected async insertAfterBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions) {\n return await this.insertInner(targetUid, schema, 'first', options);\n }\n\n @transaction()\n protected async insertBeforeEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions) {\n return await this.insertInner(targetUid, schema, 'last', options);\n }\n\n @transaction()\n protected async insertBeforeBegin(targetUid: string, schema: any, options?: InsertAdjacentOptions) {\n return await this.insertBeside(targetUid, schema, 'before', options);\n }\n\n @transaction()\n protected async insertAfterEnd(targetUid: string, schema: any, options?: InsertAdjacentOptions) {\n return await this.insertBeside(targetUid, schema, 'after', options);\n }\n\n @transaction()\n async insertNodes(nodes: SchemaNode[], options?: TransactionAble) {\n const { transaction } = options;\n\n const insertedNodes = [];\n\n for (const node of nodes) {\n insertedNodes.push(\n await this.insertSingleNode(node, {\n ...options,\n transaction,\n }),\n );\n }\n\n return insertedNodes;\n }\n\n @transaction()\n async insert(schema: any, options?: TransactionAble) {\n const nodes = UiSchemaRepository.schemaToSingleNodes(schema);\n const insertedNodes = await this.insertNodes(nodes, options);\n return this.getJsonSchema(insertedNodes[0].get('x-uid'), {\n transaction: options?.transaction,\n });\n }\n\n @transaction()\n async insertNewSchema(\n schema: any,\n options?: TransactionAble & {\n returnNode?: boolean;\n },\n ) {\n const { transaction } = options;\n\n const nodes = UiSchemaRepository.schemaToSingleNodes(schema);\n // insert schema fist\n await this.database.sequelize.query(\n this.sqlAdapter(\n `INSERT INTO ${this.uiSchemasTableName} (\"x-uid\", \"name\", \"schema\") VALUES ${nodes\n .map((n) => '(?)')\n .join(',')};`,\n ),\n {\n replacements: lodash.cloneDeep(nodes).map((node) => {\n const { uid, name } = this.prepareSingleNodeForInsert(node);\n return [uid, name, JSON.stringify(node)];\n }),\n type: 'insert',\n transaction,\n },\n );\n\n const treePathData: Array<any> = lodash.cloneDeep(nodes).reduce((carry, item) => {\n const { uid, childOptions, async } = this.prepareSingleNodeForInsert(item);\n\n return [\n ...carry,\n // self reference\n [uid, uid, 0, childOptions?.type || null, async, null],\n // parent references\n ...lodash.get(childOptions, 'parentPath', []).map((parentUid, index) => {\n return [parentUid, uid, index + 1, null, null, childOptions.sort];\n }),\n ];\n }, []);\n\n // insert tree path\n await this.database.sequelize.query(\n this.sqlAdapter(\n `INSERT INTO ${\n this.uiSchemaTreePathTableName\n } (ancestor, descendant, depth, type, async, sort) VALUES ${treePathData.map((item) => '(?)').join(',')}`,\n ),\n {\n replacements: treePathData,\n type: 'insert',\n transaction,\n },\n );\n\n const rootNode = nodes[0];\n if (rootNode['x-server-hooks']) {\n const rootModel = await this.findOne({ filter: { 'x-uid': rootNode['x-uid'] }, transaction });\n await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, rootModel, options);\n }\n\n if (options?.returnNode) {\n return nodes;\n }\n\n return this.getJsonSchema(nodes[0]['x-uid'], {\n transaction,\n });\n }\n\n private async insertSchemaRecord(name, uid, schema, transaction) {\n const serverHooks = schema['x-server-hooks'] || [];\n\n const node = await this.create({\n values: {\n name,\n ['x-uid']: uid,\n schema,\n serverHooks,\n },\n transaction,\n context: {\n disableInsertHook: true,\n },\n });\n\n return node;\n }\n\n private prepareSingleNodeForInsert(schema: SchemaNode) {\n const uid = schema['x-uid'];\n const name = schema['name'];\n const async = lodash.get(schema, 'x-async', false);\n const childOptions = schema['childOptions'];\n\n delete schema['x-uid'];\n delete schema['x-async'];\n delete schema['name'];\n delete schema['childOptions'];\n\n return { uid, name, async, childOptions };\n }\n\n async insertSingleNode(schema: SchemaNode, options: TransactionAble & removeParentOptions) {\n const { transaction } = options;\n\n const db = this.database;\n\n const { uid, name, async, childOptions } = this.prepareSingleNodeForInsert(schema);\n let savedNode;\n\n // check node exists or not\n const existsNode = await this.findOne({\n filter: {\n 'x-uid': uid,\n },\n transaction,\n });\n\n const treeTable = this.uiSchemaTreePathTableName;\n\n if (existsNode) {\n savedNode = existsNode;\n } else {\n savedNode = await this.insertSchemaRecord(name, uid, schema, transaction);\n }\n\n if (childOptions) {\n const oldParentUid = await this.findParentUid(uid, transaction);\n const parentUid = childOptions.parentUid;\n\n const childrenCount = await this.childrenCount(uid, transaction);\n\n const isTree = childrenCount > 0;\n\n // if node is a tree root move tree to new path\n if (isTree) {\n await this.clearAncestor(uid, { transaction });\n\n // insert new tree path\n await db.sequelize.query(\n `INSERT INTO ${treeTable} (ancestor, descendant, depth)\n SELECT supertree.ancestor, subtree.descendant, supertree.depth + subtree.depth + 1\n FROM ${treeTable} AS supertree\n CROSS JOIN ${treeTable} AS subtree\n WHERE supertree.descendant = :parentUid\n AND subtree.ancestor = :uid;`,\n {\n type: 'INSERT',\n replacements: {\n uid,\n parentUid,\n },\n transaction,\n },\n );\n }\n\n // update type\n await db.sequelize.query(\n `UPDATE ${treeTable} SET type = :type WHERE depth = 0 AND ancestor = :uid AND descendant = :uid`,\n {\n type: 'update',\n transaction,\n replacements: {\n type: childOptions.type,\n uid,\n },\n },\n );\n\n if (!isTree) {\n if (existsNode) {\n // remove old path\n await db.sequelize.query(`DELETE FROM ${treeTable} WHERE descendant = :uid AND ancestor != descendant`, {\n type: 'DELETE',\n replacements: {\n uid,\n },\n transaction,\n });\n }\n\n // insert tree path\n await db.sequelize.query(\n `INSERT INTO ${treeTable} (ancestor, descendant, depth)\n SELECT t.ancestor, :modelKey, depth + 1 FROM ${treeTable} AS t WHERE t.descendant = :modelParentKey `,\n {\n type: 'INSERT',\n transaction,\n replacements: {\n modelKey: savedNode.get('x-uid'),\n modelParentKey: parentUid,\n },\n },\n );\n }\n\n if (!existsNode) {\n // insert type && async\n await db.sequelize.query(\n `INSERT INTO ${treeTable}(ancestor, descendant, depth, type, async) VALUES (:modelKey, :modelKey, 0, :type, :async )`,\n {\n type: 'INSERT',\n replacements: {\n modelKey: savedNode.get('x-uid'),\n type: childOptions.type,\n async,\n },\n transaction,\n },\n );\n }\n\n const nodePosition = childOptions.position || 'last';\n\n let sort;\n\n // insert at first\n if (nodePosition === 'first') {\n sort = 1;\n\n let updateSql = `UPDATE ${treeTable} as TreeTable\n SET sort = TreeTable.sort + 1\n FROM ${treeTable} as NodeInfo\n WHERE NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0\n AND TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`;\n\n // Compatible with mysql\n if (this.database.sequelize.getDialect() === 'mysql') {\n updateSql = `UPDATE ${treeTable} as TreeTable\n JOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)\n SET TreeTable.sort = TreeTable.sort + 1\n WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`;\n }\n\n // move all child last index\n await db.sequelize.query(updateSql, {\n replacements: {\n ancestor: childOptions.parentUid,\n type: childOptions.type,\n },\n transaction,\n });\n }\n\n if (nodePosition === 'last') {\n const maxSort = await db.sequelize.query(\n `SELECT ${\n this.database.sequelize.getDialect() === 'postgres' ? 'coalesce' : 'ifnull'\n }(MAX(TreeTable.sort), 0) as maxsort FROM ${treeTable} as TreeTable\n LEFT JOIN ${treeTable} as NodeInfo\n ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0\n WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and NodeInfo.type = :type`,\n {\n type: 'SELECT',\n replacements: {\n ancestor: childOptions.parentUid,\n type: childOptions.type,\n },\n transaction,\n },\n );\n\n sort = parseInt(maxSort[0]['maxsort']) + 1;\n }\n\n if (lodash.isPlainObject(nodePosition)) {\n const targetPosition = nodePosition as TargetPosition;\n const target = targetPosition.target;\n\n const targetSort = await db.sequelize.query(\n `SELECT TreeTable.sort as sort FROM ${treeTable} as TreeTable\n LEFT JOIN ${treeTable} as NodeInfo\n ON NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0 WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor AND TreeTable.descendant = :descendant and NodeInfo.type = :type`,\n {\n type: 'SELECT',\n replacements: {\n ancestor: childOptions.parentUid,\n descendant: target,\n type: childOptions.type,\n },\n transaction,\n },\n );\n\n sort = targetSort[0].sort;\n\n if (targetPosition.type == 'after') {\n sort += 1;\n }\n\n let updateSql = `UPDATE ${treeTable} as TreeTable\n SET sort = TreeTable.sort + 1\n FROM ${treeTable} as NodeInfo\n WHERE NodeInfo.descendant = TreeTable.descendant\n and NodeInfo.depth = 0\n AND TreeTable.depth = 1\n AND TreeTable.ancestor = :ancestor\n and TreeTable.sort >= :sort\n and NodeInfo.type = :type`;\n\n if (this.database.sequelize.getDialect() === 'mysql') {\n updateSql = `UPDATE ${treeTable} as TreeTable\nJOIN ${treeTable} as NodeInfo ON (NodeInfo.descendant = TreeTable.descendant and NodeInfo.depth = 0)\nSET TreeTable.sort = TreeTable.sort + 1\nWHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort >= :sort and NodeInfo.type = :type`;\n }\n\n await db.sequelize.query(updateSql, {\n replacements: {\n ancestor: childOptions.parentUid,\n sort,\n type: childOptions.type,\n },\n transaction,\n });\n }\n\n // update order\n const updateSql = `UPDATE ${treeTable} SET sort = :sort WHERE depth = 1 AND ancestor = :ancestor AND descendant = :descendant`;\n await db.sequelize.query(updateSql, {\n type: 'UPDATE',\n replacements: {\n ancestor: childOptions.parentUid,\n sort,\n descendant: uid,\n },\n transaction,\n });\n\n // move node to new parent\n if (oldParentUid !== null && oldParentUid !== parentUid) {\n await this.database.emitAsync('uiSchemaMove', savedNode, {\n transaction,\n oldParentUid,\n parentUid,\n });\n\n if (options.removeParentsIfNoChildren) {\n await this.recursivelyRemoveIfNoChildren({\n transaction,\n uid: oldParentUid,\n breakRemoveOn: options.breakRemoveOn,\n });\n }\n }\n } else {\n // insert root node path\n await db.sequelize.query(\n `INSERT INTO ${treeTable}(ancestor, descendant, depth, async) VALUES (:modelKey, :modelKey, 0, :async )`,\n {\n type: 'INSERT',\n replacements: {\n modelKey: savedNode.get('x-uid'),\n async,\n },\n transaction,\n },\n );\n }\n\n return savedNode;\n }\n}\n\nexport default UiSchemaRepository;\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.bindMenuToRole = void 0;
|
|
13
|
+
function bindMenuToRole({ schemaInstance, db, options }) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { transaction } = options;
|
|
16
|
+
const addNewMenuRoles = yield db.getRepository('roles').find({
|
|
17
|
+
filter: {
|
|
18
|
+
allowNewMenu: true,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
for (const role of addNewMenuRoles) {
|
|
22
|
+
yield db.getRepository('roles.menuUiSchemas', role.get('name')).add({
|
|
23
|
+
tk: schemaInstance.get('x-uid'),
|
|
24
|
+
transaction,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.bindMenuToRole = bindMenuToRole;
|
|
30
|
+
//# sourceMappingURL=bind-menu-to-role.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bind-menu-to-role.js","sourceRoot":"","sources":["../../../src/server-hooks/hooks/bind-menu-to-role.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,SAAsB,cAAc,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE;;QAClE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAChC,MAAM,eAAe,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;YAC3D,MAAM,EAAE;gBACN,YAAY,EAAE,IAAI;aACnB;SACF,CAAC,CAAC;QAEH,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE;YAClC,MAAM,EAAE,CAAC,aAAa,CAAC,qBAAqB,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;gBAClE,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC/B,WAAW;aACZ,CAAC,CAAC;SACJ;IACH,CAAC;CAAA;AAdD,wCAcC","sourcesContent":["export async function bindMenuToRole({ schemaInstance, db, options }) {\n const { transaction } = options;\n const addNewMenuRoles = await db.getRepository('roles').find({\n filter: {\n allowNewMenu: true,\n },\n });\n\n for (const role of addNewMenuRoles) {\n await db.getRepository('roles.menuUiSchemas', role.get('name')).add({\n tk: schemaInstance.get('x-uid'),\n transaction,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookFactory = void 0;
|
|
4
|
+
function hookFactory(hookType, hookName, hookFunc) {
|
|
5
|
+
return {
|
|
6
|
+
hookType,
|
|
7
|
+
hookName,
|
|
8
|
+
hookFunc,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.hookFactory = hookFactory;
|
|
12
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/server-hooks/hooks/factory.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,QAAkB,EAAE,QAAgB,EAAE,QAAQ;IACxE,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,QAAQ;KACT,CAAC;AACJ,CAAC;AAND,kCAMC","sourcesContent":["import { HookType } from '../index';\n\nexport function hookFactory(hookType: HookType, hookName: string, hookFunc) {\n return {\n hookType,\n hookName,\n hookFunc,\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hooks = void 0;
|
|
4
|
+
const bind_menu_to_role_1 = require("./bind-menu-to-role");
|
|
5
|
+
const factory_1 = require("./factory");
|
|
6
|
+
const remove_parents_if_no_children_1 = require("./remove-parents-if-no-children");
|
|
7
|
+
const remove_schema_1 = require("./remove-schema");
|
|
8
|
+
const hooks = [
|
|
9
|
+
(0, factory_1.hookFactory)('onCollectionDestroy', 'removeSchema', remove_schema_1.removeSchema),
|
|
10
|
+
(0, factory_1.hookFactory)('onCollectionFieldDestroy', 'removeSchema', remove_schema_1.removeSchema),
|
|
11
|
+
(0, factory_1.hookFactory)('onSelfCreate', 'bindMenuToRole', bind_menu_to_role_1.bindMenuToRole),
|
|
12
|
+
(0, factory_1.hookFactory)('onSelfMove', 'removeParentsIfNoChildren', remove_parents_if_no_children_1.removeParentsIfNoChildren),
|
|
13
|
+
];
|
|
14
|
+
exports.hooks = hooks;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server-hooks/hooks/index.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,uCAAwC;AACxC,mFAA4E;AAC5E,mDAA+C;AAE/C,MAAM,KAAK,GAAG;IACZ,IAAA,qBAAW,EAAC,qBAAqB,EAAE,cAAc,EAAE,4BAAY,CAAC;IAChE,IAAA,qBAAW,EAAC,0BAA0B,EAAE,cAAc,EAAE,4BAAY,CAAC;IACrE,IAAA,qBAAW,EAAC,cAAc,EAAE,gBAAgB,EAAE,kCAAc,CAAC;IAC7D,IAAA,qBAAW,EAAC,YAAY,EAAE,2BAA2B,EAAE,yDAAyB,CAAC;CAClF,CAAC;AAEO,sBAAK","sourcesContent":["import { bindMenuToRole } from './bind-menu-to-role';\nimport { hookFactory } from './factory';\nimport { removeParentsIfNoChildren } from './remove-parents-if-no-children';\nimport { removeSchema } from './remove-schema';\n\nconst hooks = [\n hookFactory('onCollectionDestroy', 'removeSchema', removeSchema),\n hookFactory('onCollectionFieldDestroy', 'removeSchema', removeSchema),\n hookFactory('onSelfCreate', 'bindMenuToRole', bindMenuToRole),\n hookFactory('onSelfMove', 'removeParentsIfNoChildren', removeParentsIfNoChildren),\n];\n\nexport { hooks };\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.removeParentsIfNoChildren = void 0;
|
|
13
|
+
function removeParentsIfNoChildren({ schemaInstance, db, options, params }) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { transaction, oldParentUid } = options;
|
|
16
|
+
const uiSchemaRepository = db.getRepository('uiSchemas');
|
|
17
|
+
yield uiSchemaRepository.recursivelyRemoveIfNoChildren({
|
|
18
|
+
transaction,
|
|
19
|
+
uid: oldParentUid,
|
|
20
|
+
breakRemoveOn: params === null || params === void 0 ? void 0 : params.breakRemoveOn,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.removeParentsIfNoChildren = removeParentsIfNoChildren;
|
|
25
|
+
//# sourceMappingURL=remove-parents-if-no-children.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-parents-if-no-children.js","sourceRoot":"","sources":["../../../src/server-hooks/hooks/remove-parents-if-no-children.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,yBAAyB,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;;QACrF,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,kBAAkB,GAAuB,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC7E,MAAM,kBAAkB,CAAC,6BAA6B,CAAC;YACrD,WAAW;YACX,GAAG,EAAE,YAAY;YACjB,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa;SACrC,CAAC,CAAC;IACL,CAAC;CAAA;AARD,8DAQC","sourcesContent":["import { UiSchemaRepository } from '../../repository';\n\nexport async function removeParentsIfNoChildren({ schemaInstance, db, options, params }) {\n const { transaction, oldParentUid } = options;\n const uiSchemaRepository: UiSchemaRepository = db.getRepository('uiSchemas');\n await uiSchemaRepository.recursivelyRemoveIfNoChildren({\n transaction,\n uid: oldParentUid,\n breakRemoveOn: params?.breakRemoveOn,\n });\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.removeSchema = void 0;
|
|
13
|
+
function removeSchema({ schemaInstance, options, db, params }) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { transaction } = options;
|
|
16
|
+
const uiSchemaRepository = db.getRepository('uiSchemas');
|
|
17
|
+
const uid = schemaInstance.get('x-uid');
|
|
18
|
+
if (params === null || params === void 0 ? void 0 : params.removeParentsIfNoChildren) {
|
|
19
|
+
yield uiSchemaRepository.removeEmptyParents({
|
|
20
|
+
uid,
|
|
21
|
+
breakRemoveOn: params['breakRemoveOn'],
|
|
22
|
+
transaction,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
yield uiSchemaRepository.remove(uid, {
|
|
27
|
+
transaction,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.removeSchema = removeSchema;
|
|
33
|
+
//# sourceMappingURL=remove-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-schema.js","sourceRoot":"","sources":["../../../src/server-hooks/hooks/remove-schema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,YAAY,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE;;QACxE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAChC,MAAM,kBAAkB,GAAuB,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC7E,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAW,CAAC;QAElD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,yBAAyB,EAAE;YACrC,MAAM,kBAAkB,CAAC,kBAAkB,CAAC;gBAC1C,GAAG;gBACH,aAAa,EAAE,MAAM,CAAC,eAAe,CAAC;gBACtC,WAAW;aACZ,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,kBAAkB,CAAC,MAAM,CAAC,GAAG,EAAE;gBACnC,WAAW;aACZ,CAAC,CAAC;SACJ;IACH,CAAC;CAAA;AAhBD,oCAgBC","sourcesContent":["import { UiSchemaRepository } from '../../repository';\n\nexport async function removeSchema({ schemaInstance, options, db, params }) {\n const { transaction } = options;\n const uiSchemaRepository: UiSchemaRepository = db.getRepository('uiSchemas');\n const uid = schemaInstance.get('x-uid') as string;\n\n if (params?.removeParentsIfNoChildren) {\n await uiSchemaRepository.removeEmptyParents({\n uid,\n breakRemoveOn: params['breakRemoveOn'],\n transaction,\n });\n } else {\n await uiSchemaRepository.remove(uid, {\n transaction,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Database } from '@nocobase/database';
|
|
2
|
+
export declare type HookType = 'onSelfDestroy' | 'onCollectionDestroy' | 'onCollectionFieldDestroy' | 'onAnyCollectionFieldDestroy' | 'onSelfCreate' | 'onSelfMove';
|
|
3
|
+
export declare class ServerHooks {
|
|
4
|
+
protected db: Database;
|
|
5
|
+
hooks: Map<HookType, Map<string, any>>;
|
|
6
|
+
constructor(db: Database);
|
|
7
|
+
registerHooks(): void;
|
|
8
|
+
listen(): void;
|
|
9
|
+
protected callSchemaInstanceHooksByType(schemaInstance: any, options: any, type: HookType): Promise<void>;
|
|
10
|
+
protected onUiSchemaMove(schemaInstance: any, options: any): Promise<void>;
|
|
11
|
+
protected onCollectionDestroy(collectionModel: any, options: any): Promise<void>;
|
|
12
|
+
protected onAnyCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
|
|
13
|
+
protected onCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
|
|
14
|
+
protected onUiSchemaCreate(schemaInstance: any, options: any): Promise<void>;
|
|
15
|
+
protected findHooksAndCall(hooksFilter: any, hooksArgs: any, transaction: any): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* register a server hook function
|
|
18
|
+
* @param type type of server hook
|
|
19
|
+
* @param name name of server hook
|
|
20
|
+
* @param hookFunc server hook function
|
|
21
|
+
*/
|
|
22
|
+
register(type: HookType, name: string, hookFunc: any): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ServerHooks = void 0;
|
|
13
|
+
const hooks_1 = require("./hooks");
|
|
14
|
+
class ServerHooks {
|
|
15
|
+
constructor(db) {
|
|
16
|
+
this.db = db;
|
|
17
|
+
this.hooks = new Map();
|
|
18
|
+
this.listen();
|
|
19
|
+
this.registerHooks();
|
|
20
|
+
}
|
|
21
|
+
registerHooks() {
|
|
22
|
+
hooks_1.hooks.forEach((hook) => this.register(hook.hookType, hook.hookName, hook.hookFunc));
|
|
23
|
+
}
|
|
24
|
+
listen() {
|
|
25
|
+
this.db.on('fields.afterDestroy', (model, options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.onCollectionFieldDestroy(model, options);
|
|
27
|
+
yield this.onAnyCollectionFieldDestroy(model, options);
|
|
28
|
+
}));
|
|
29
|
+
this.db.on('collections.afterDestroy', (model, options) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
yield this.onCollectionDestroy(model, options);
|
|
31
|
+
}));
|
|
32
|
+
this.db.on('uiSchemas.afterCreateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
yield this.onUiSchemaCreate(model, options);
|
|
34
|
+
}));
|
|
35
|
+
this.db.on('uiSchemaMove', (model, options) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
yield this.onUiSchemaMove(model, options);
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
callSchemaInstanceHooksByType(schemaInstance, options, type) {
|
|
40
|
+
var _a;
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { transaction } = options;
|
|
43
|
+
const hooks = schemaInstance.getServerHooksByType(type);
|
|
44
|
+
for (const hook of hooks) {
|
|
45
|
+
const hookFunc = (_a = this.hooks.get(type)) === null || _a === void 0 ? void 0 : _a.get(hook['method']);
|
|
46
|
+
yield hookFunc({
|
|
47
|
+
schemaInstance,
|
|
48
|
+
options,
|
|
49
|
+
db: this.db,
|
|
50
|
+
params: hook['params'],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
onUiSchemaMove(schemaInstance, options) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfMove');
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
onCollectionDestroy(collectionModel, options) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const { transaction } = options;
|
|
63
|
+
yield this.findHooksAndCall({
|
|
64
|
+
type: 'onCollectionDestroy',
|
|
65
|
+
collection: collectionModel.get('name'),
|
|
66
|
+
}, {
|
|
67
|
+
collectionInstance: collectionModel,
|
|
68
|
+
options,
|
|
69
|
+
}, transaction);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
onAnyCollectionFieldDestroy(fieldModel, options) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const { transaction } = options;
|
|
75
|
+
const collectionName = fieldModel.get('collectionName');
|
|
76
|
+
yield this.findHooksAndCall({
|
|
77
|
+
type: 'onAnyCollectionFieldDestroy',
|
|
78
|
+
collection: collectionName,
|
|
79
|
+
}, {
|
|
80
|
+
collectionFieldInstance: fieldModel,
|
|
81
|
+
options,
|
|
82
|
+
}, transaction);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
onCollectionFieldDestroy(fieldModel, options) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const { transaction } = options;
|
|
88
|
+
const collectionName = fieldModel.get('collectionName');
|
|
89
|
+
const fieldName = fieldModel.get('name');
|
|
90
|
+
yield this.findHooksAndCall({
|
|
91
|
+
type: 'onCollectionFieldDestroy',
|
|
92
|
+
collection: collectionName,
|
|
93
|
+
field: fieldName,
|
|
94
|
+
}, {
|
|
95
|
+
collectionFieldInstance: fieldModel,
|
|
96
|
+
options,
|
|
97
|
+
}, transaction);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
onUiSchemaCreate(schemaInstance, options) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
yield this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfCreate');
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
findHooksAndCall(hooksFilter, hooksArgs, transaction) {
|
|
106
|
+
var _a;
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const hooks = (yield this.db.getRepository('uiSchemaServerHooks').find({
|
|
109
|
+
filter: hooksFilter,
|
|
110
|
+
appends: ['uiSchema'],
|
|
111
|
+
transaction,
|
|
112
|
+
}));
|
|
113
|
+
for (const hookRecord of hooks) {
|
|
114
|
+
const hoodMethodName = hookRecord.get('method');
|
|
115
|
+
const hookFunc = (_a = this.hooks.get(hookRecord.get('type'))) === null || _a === void 0 ? void 0 : _a.get(hoodMethodName);
|
|
116
|
+
if (hookFunc) {
|
|
117
|
+
yield hookFunc(Object.assign(Object.assign({}, hooksArgs), { schemaInstance: hookRecord.uiSchema, db: this.db, params: hookRecord.get('params') }));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* register a server hook function
|
|
124
|
+
* @param type type of server hook
|
|
125
|
+
* @param name name of server hook
|
|
126
|
+
* @param hookFunc server hook function
|
|
127
|
+
*/
|
|
128
|
+
register(type, name, hookFunc) {
|
|
129
|
+
if (!this.hooks.has(type)) {
|
|
130
|
+
this.hooks.set(type, new Map());
|
|
131
|
+
}
|
|
132
|
+
const hookTypeMap = this.hooks.get(type);
|
|
133
|
+
hookTypeMap.set(name, hookFunc);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.ServerHooks = ServerHooks;
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server-hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mCAAgC;AAWhC,MAAa,WAAW;IAGtB,YAAsB,EAAY;QAAZ,OAAE,GAAF,EAAE,CAAU;QAFlC,UAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;QAG5C,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED,aAAa;QACX,aAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,qBAAqB,EAAE,CAAO,KAAK,EAAE,OAAO,EAAE,EAAE;YACzD,MAAM,IAAI,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACpD,MAAM,IAAI,CAAC,2BAA2B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACzD,CAAC,CAAA,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,0BAA0B,EAAE,CAAO,KAAK,E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GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC;gBACrE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,CAAC,UAAU,CAAC;gBACrB,WAAW;aACZ,CAAC,CAAsB,CAAC;YAEzB,KAAK,MAAM,UAAU,IAAI,KAAK,EAAE;gBAC9B,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAW,CAAC;gBAC1D,MAAM,QAAQ,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAa,CAAC,0CAAE,GAAG,CAAC,cAAc,CAAC,CAAC;gBAEzF,IAAI,QAAQ,EAAE;oBACZ,MAAM,QAAQ,iCACT,SAAS,KACZ,cAAc,EAAQ,UAAW,CAAC,QAAQ,EAC1C,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAChC,CAAC;iBACJ;aACF;;KACF;IAED;;;;;OAKG;IACH,QAAQ,CAAC,IAAc,EAAE,IAAY,EAAE,QAAa;QAClD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;SACjC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;CACF;AA/ID,kCA+IC","sourcesContent":["import { Database } from '@nocobase/database';\nimport { hooks } from './hooks';\nimport { ServerHookModel } from './model';\n\nexport type HookType =\n | 'onSelfDestroy'\n | 'onCollectionDestroy'\n | 'onCollectionFieldDestroy'\n | 'onAnyCollectionFieldDestroy'\n | 'onSelfCreate'\n | 'onSelfMove';\n\nexport class ServerHooks {\n hooks = new Map<HookType, Map<string, any>>();\n\n constructor(protected db: Database) {\n this.listen();\n this.registerHooks();\n }\n\n registerHooks() {\n hooks.forEach((hook) => this.register(hook.hookType, hook.hookName, hook.hookFunc));\n }\n\n listen() {\n this.db.on('fields.afterDestroy', async (model, options) => {\n await this.onCollectionFieldDestroy(model, options);\n await this.onAnyCollectionFieldDestroy(model, options);\n });\n\n this.db.on('collections.afterDestroy', async (model, options) => {\n await this.onCollectionDestroy(model, options);\n });\n\n this.db.on('uiSchemas.afterCreateWithAssociations', async (model, options) => {\n await this.onUiSchemaCreate(model, options);\n });\n\n this.db.on('uiSchemaMove', async (model, options) => {\n await this.onUiSchemaMove(model, options);\n });\n }\n\n protected async callSchemaInstanceHooksByType(schemaInstance, options, type: HookType) {\n const { transaction } = options;\n\n const hooks = schemaInstance.getServerHooksByType(type);\n\n for (const hook of hooks) {\n const hookFunc = this.hooks.get(type)?.get(hook['method']);\n await hookFunc({\n schemaInstance,\n options,\n db: this.db,\n params: hook['params'],\n });\n }\n }\n\n protected async onUiSchemaMove(schemaInstance, options) {\n await this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfMove');\n }\n\n protected async onCollectionDestroy(collectionModel, options) {\n const { transaction } = options;\n\n await this.findHooksAndCall(\n {\n type: 'onCollectionDestroy',\n collection: collectionModel.get('name'),\n },\n {\n collectionInstance: collectionModel,\n options,\n },\n transaction,\n );\n }\n\n protected async onAnyCollectionFieldDestroy(fieldModel, options) {\n const { transaction } = options;\n const collectionName = fieldModel.get('collectionName');\n\n await this.findHooksAndCall(\n {\n type: 'onAnyCollectionFieldDestroy',\n collection: collectionName,\n },\n {\n collectionFieldInstance: fieldModel,\n options,\n },\n transaction,\n );\n }\n\n protected async onCollectionFieldDestroy(fieldModel, options) {\n const { transaction } = options;\n const collectionName = fieldModel.get('collectionName');\n const fieldName = fieldModel.get('name');\n\n await this.findHooksAndCall(\n {\n type: 'onCollectionFieldDestroy',\n collection: collectionName,\n field: fieldName,\n },\n {\n collectionFieldInstance: fieldModel,\n options,\n },\n transaction,\n );\n }\n\n protected async onUiSchemaCreate(schemaInstance, options) {\n await this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfCreate');\n }\n\n protected async findHooksAndCall(hooksFilter, hooksArgs, transaction) {\n const hooks = (await this.db.getRepository('uiSchemaServerHooks').find({\n filter: hooksFilter,\n appends: ['uiSchema'],\n transaction,\n })) as ServerHookModel[];\n\n for (const hookRecord of hooks) {\n const hoodMethodName = hookRecord.get('method') as string;\n const hookFunc = this.hooks.get(hookRecord.get('type') as HookType)?.get(hoodMethodName);\n\n if (hookFunc) {\n await hookFunc({\n ...hooksArgs,\n schemaInstance: (<any>hookRecord).uiSchema,\n db: this.db,\n params: hookRecord.get('params'),\n });\n }\n }\n }\n\n /**\n * register a server hook function\n * @param type type of server hook\n * @param name name of server hook\n * @param hookFunc server hook function\n */\n register(type: HookType, name: string, hookFunc: any) {\n if (!this.hooks.has(type)) {\n this.hooks.set(type, new Map());\n }\n\n const hookTypeMap = this.hooks.get(type);\n hookTypeMap.set(name, hookFunc);\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerHookModel = void 0;
|
|
4
|
+
const database_1 = require("@nocobase/database");
|
|
5
|
+
class ServerHookModel extends database_1.Model {
|
|
6
|
+
}
|
|
7
|
+
exports.ServerHookModel = ServerHookModel;
|
|
8
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/server-hooks/model.ts"],"names":[],"mappings":";;;AAAA,iDAA2C;AAE3C,MAAa,eAAgB,SAAQ,gBAAK;CAAG;AAA7C,0CAA6C","sourcesContent":["import { Model } from '@nocobase/database';\n\nexport class ServerHookModel extends Model {}\n"]}
|
package/lib/server.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from '@nocobase/server';
|
|
2
|
+
import { ServerHooks } from './server-hooks';
|
|
3
|
+
export declare class UiSchemaStoragePlugin extends Plugin {
|
|
4
|
+
serverHooks: ServerHooks;
|
|
5
|
+
registerRepository(): void;
|
|
6
|
+
beforeLoad(): Promise<void>;
|
|
7
|
+
load(): Promise<void>;
|
|
8
|
+
getName(): string;
|
|
9
|
+
}
|
|
10
|
+
export default UiSchemaStoragePlugin;
|
package/lib/server.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UiSchemaStoragePlugin = void 0;
|
|
16
|
+
const database_1 = require("@nocobase/database");
|
|
17
|
+
const server_1 = require("@nocobase/server");
|
|
18
|
+
const utils_1 = require("@nocobase/utils");
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const ui_schema_action_1 = require("./actions/ui-schema-action");
|
|
21
|
+
const model_1 = require("./model");
|
|
22
|
+
const repository_1 = __importDefault(require("./repository"));
|
|
23
|
+
const server_hooks_1 = require("./server-hooks");
|
|
24
|
+
const model_2 = require("./server-hooks/model");
|
|
25
|
+
class UiSchemaStoragePlugin extends server_1.Plugin {
|
|
26
|
+
registerRepository() {
|
|
27
|
+
this.app.db.registerRepositories({
|
|
28
|
+
UiSchemaRepository: repository_1.default,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
beforeLoad() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const db = this.app.db;
|
|
34
|
+
this.serverHooks = new server_hooks_1.ServerHooks(db);
|
|
35
|
+
this.app.db.registerModels({ MagicAttributeModel: database_1.MagicAttributeModel, UiSchemaModel: model_1.UiSchemaModel, ServerHookModel: model_2.ServerHookModel });
|
|
36
|
+
this.registerRepository();
|
|
37
|
+
db.on('uiSchemas.beforeCreate', function setUid(model) {
|
|
38
|
+
if (!model.get('name')) {
|
|
39
|
+
model.set('name', (0, utils_1.uid)());
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
db.on('uiSchemas.afterCreate', function insertSchema(model, options) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { transaction } = options;
|
|
45
|
+
const uiSchemaRepository = db.getCollection('uiSchemas').repository;
|
|
46
|
+
const context = options.context;
|
|
47
|
+
if (context === null || context === void 0 ? void 0 : context.disableInsertHook) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
yield uiSchemaRepository.insert(model.toJSON(), {
|
|
51
|
+
transaction,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
db.on('uiSchemas.afterUpdate', function patchSchema(model, options) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const { transaction } = options;
|
|
58
|
+
const uiSchemaRepository = db.getCollection('uiSchemas').repository;
|
|
59
|
+
yield uiSchemaRepository.patch(model.toJSON(), {
|
|
60
|
+
transaction,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
this.app.resourcer.define({
|
|
65
|
+
name: 'uiSchemas',
|
|
66
|
+
actions: ui_schema_action_1.uiSchemaActions,
|
|
67
|
+
});
|
|
68
|
+
this.app.acl.allow('uiSchemas', '*', 'loggedIn');
|
|
69
|
+
this.app.acl.allow('uiSchemaTemplates', '*', 'loggedIn');
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
load() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
yield this.db.import({
|
|
75
|
+
directory: path_1.default.resolve(__dirname, 'collections'),
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getName() {
|
|
80
|
+
return this.getPackageName(__dirname);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.UiSchemaStoragePlugin = UiSchemaStoragePlugin;
|
|
84
|
+
exports.default = UiSchemaStoragePlugin;
|
|
85
|
+
//# sourceMappingURL=server.js.map
|