async downloadQueryResults(query, values) { const res = await this.queryResponse(query, values); return { rows: res.rows, types: res.fields.map(f => ({ name: f.name, type: this.toGenericType(DataTypeMapping[f.dataTypeID].toLowerCase()) })), }; }
async validateDelete({ existingItem, context, operation }) { const { listKey } = this; const args = { existingItem, context, operation, listKey }; const fields = this.fields; await this._validateHook({ args, fields, operation, hookName: 'validateDelete' }); }
getFieldsWithAccess({ schemaName, access }) { return this.fields .filter(({ path }) => path !== 'id') // Exclude the id fields update types .filter(field => field.access[schemaName][access]); // If it's globally set to false, makes sense to never let it be updated }
const checkCTPermsDeleteHaveFieldsToNull = permissions => !Array.isArray(permissions) || permissions.every( perm => perm.action !== 'plugins::content-manager.explorer.delete' || _.isNil(perm.fields) )
constructor({ fields, hooks, listKey }) { this.fields = fields; this.hooks = hooks; this.listKey = listKey; this.fieldsByPath = arrayToObject(this.fields, 'path'); }
const transformPointerString = (schema, field, pointerString) => { const objData = pointerString.split('$'); if (objData[0] !== schema.fields[field].targetClass) { throw 'pointer to incorrect className'; } return { __type: 'Pointer', className: objData[0], objectId: objData[1], }; }
const convertParseSchemaToMongoSchema = ({ ...schema }) => { delete schema.fields._rperm; delete schema.fields._wperm; if (schema.className === '_User') { // Legacy mongo adapter knows about the difference between password and _hashed_password. // Future database adapters will only know about _hashed_password. // Note: Parse Server will bring back password with injectDefaultSchema, so we don't need // to add _hashed_password back ever. delete schema.fields._hashed_password; } return schema; }
// Returns the expected type for a className+key combination // or undefined if the schema is not set getExpectedType(className, fieldName) { if (this.schemaData[className]) { const expectedType = this.schemaData[className].fields[fieldName]; return expectedType === 'map' ? 'Object' : expectedType; } return undefined; }
const parseFields = (fields, list) => { const fieldPaths = fields.split(','); return fieldPaths .map(path => (path === '_label_' ? pseudoLabelField : list.fields.find(f => f.path === path))) .filter(f => !!f); // remove anything that was not found. }
getInitialItemData({ originalInput = {}, prefill = {} } = {}) { return this.fields .filter(({ isPrimaryKey }) => !isPrimaryKey) .reduce( (memo, field) => ({ ...memo, [field.path]: field.getDefaultValue({ originalInput, prefill }), }), {} ); }
getFieldsRelatedTo(listKey) { return this.fields.filter( ({ isRelationship, refListKey }) => isRelationship && refListKey === listKey ); }
const parseFields = (fields, list) => { const fieldPaths = fields.split(','); return fieldPaths .map(path => (path === '_label_' ? pseudoLabelField : list.fields.find(f => f.path === path))) .filter(f => !!f); // remove anything that was not found. }
const transformPointerString = (schema, field, pointerString) => { const objData = pointerString.split('$'); if (objData[0] !== schema.fields[field].targetClass) { throw 'pointer to incorrect className'; } return { __type: 'Pointer', className: objData[0], objectId: objData[1] }; }