@strapi/utils
Version:
Shared utilities for the Strapi packages
1 lines • 2.97 kB
Source Map (JSON)
{"version":3,"file":"relations.mjs","sources":["../src/relations.ts"],"sourcesContent":["import { isBoolean } from 'lodash/fp';\nimport type { Attribute, Model } from './types';\n\nimport { isRelationalAttribute } from './content-types';\n\nconst MANY_RELATIONS = ['oneToMany', 'manyToMany'];\n\nexport const getRelationalFields = (contentType: Model) => {\n return Object.keys(contentType.attributes).filter((attributeName) => {\n return contentType.attributes[attributeName].type === 'relation';\n });\n};\n\nexport const isOneToAny = (attribute: Attribute) =>\n isRelationalAttribute(attribute) && ['oneToOne', 'oneToMany'].includes(attribute.relation);\n\nexport const isManyToAny = (attribute: Attribute) =>\n isRelationalAttribute(attribute) && ['manyToMany', 'manyToOne'].includes(attribute.relation);\n\nexport const isAnyToOne = (attribute: Attribute) =>\n isRelationalAttribute(attribute) && ['oneToOne', 'manyToOne'].includes(attribute.relation);\n\nexport const isAnyToMany = (attribute: Attribute) =>\n isRelationalAttribute(attribute) && ['oneToMany', 'manyToMany'].includes(attribute.relation);\n\nexport const isPolymorphic = (attribute: any): any =>\n ['morphOne', 'morphMany', 'morphToOne', 'morphToMany'].includes(attribute.relation);\n\nexport const constants = {\n MANY_RELATIONS,\n};\n\n// Valid keys in the `options` property of relations reordering\n// The value for each key must be a function that returns true if it is a valid value\nexport const VALID_RELATION_ORDERING_KEYS: { [key: string]: (value: any) => boolean } = {\n strict: isBoolean,\n};\n"],"names":["MANY_RELATIONS","getRelationalFields","contentType","Object","keys","attributes","filter","attributeName","type","isOneToAny","attribute","isRelationalAttribute","includes","relation","isManyToAny","isAnyToOne","isAnyToMany","isPolymorphic","constants","VALID_RELATION_ORDERING_KEYS","strict","isBoolean"],"mappings":";;;AAKA,MAAMA,cAAiB,GAAA;AAAC,IAAA,WAAA;AAAa,IAAA;AAAa,CAAA;AAE3C,MAAMC,sBAAsB,CAACC,WAAAA,GAAAA;IAClC,OAAOC,MAAAA,CAAOC,IAAI,CAACF,WAAA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