@ -19392,8 +19392,8 @@ var app = (function (crypto$1) {
const common = ( ) => commonPlus ( [ ] ) ;
const _ events = {
record Api : {
save : commonPlus ( [ "onInvalid" , "onRecordUpdated" , "onRecord Created" ] ) ,
row Api : {
save : commonPlus ( [ "onInvalid" , "onRowUpdated" , "onRow Created" ] ) ,
delete : common ( ) ,
getContext : common ( ) ,
getNew : common ( ) ,
@ -19409,7 +19409,7 @@ var app = (function (crypto$1) {
aggregates : common ( ) ,
} ,
collectionApi : {
getAllowedRecord Types : common ( ) ,
getAllowedRow Types : common ( ) ,
initialise : common ( ) ,
delete : common ( ) ,
} ,
@ -21240,7 +21240,7 @@ var app = (function (crypto$1) {
) ,
makerule (
"indexType" ,
"reference index may only exist on a record node" ,
"reference index may only exist on a row node" ,
index =>
isTable ( index . parent ( ) ) || index . indexType !== indexTypes . reference
) ,
@ -21298,7 +21298,7 @@ var app = (function (crypto$1) {
getFlattenedHierarchy ,
fp_1 (
n =>
isCollectionRecord ( n ) &&
isCollectionRow ( n ) &&
new RegExp ( ` ${ n . collectionPathRegx ( ) } $ ` ) . test ( collectionKey )
) ,
] ) ;
@ -21309,7 +21309,7 @@ var app = (function (crypto$1) {
fp_1 (
n =>
n . nodeKey ( ) === nodeKey ||
( isCollectionRecord ( n ) && n . collectionNodeKey ( ) === nodeKey )
( isCollectionRow ( n ) && n . collectionNodeKey ( ) === nodeKey )
) ,
] ) ;
@ -21321,20 +21321,20 @@ var app = (function (crypto$1) {
const isNode = ( appHierarchy , key ) =>
isSomething ( getExactNodeForKey ( appHierarchy ) ( key ) ) ;
const isTable = node => isSomething ( node ) && node . type === "record " ;
const isSingleRecord = node => isTable ( node ) && node . isSingle ;
const isCollectionRecord = node => isTable ( node ) && ! node . isSingle ;
const isTable = node => isSomething ( node ) && node . type === "row " ;
const isSingleRow = node => isTable ( node ) && node . isSingle ;
const isCollectionRow = node => isTable ( node ) && ! node . isSingle ;
const isRoot = node => isSomething ( node ) && node . isRoot ( ) ;
const getSafeFieldParser = ( tryParse , defaultValueFunctions ) => (
field ,
record
row
) => {
if ( fp_25 ( field . name ) ( record ) ) {
if ( fp_25 ( field . name ) ( row ) ) {
return getSafeValueParser (
tryParse ,
defaultValueFunctions
) ( record [ field . name ] )
) ( row [ field . name ] )
}
return defaultValueFunctions [ field . getUndefinedValue ] ( )
} ;
@ -21372,10 +21372,10 @@ var app = (function (crypto$1) {
const validateTypeConstraints = validationRules => async (
field ,
record ,
row ,
context
) => {
const fieldValue = record [ field . name ] ;
const fieldValue = row [ field . name ] ;
const validateRule = async r =>
! ( await r . isValid ( fieldValue , field . typeOptions , context ) )
? r . getMessage ( fieldValue , field . typeOptions )
@ -21880,10 +21880,10 @@ var app = (function (crypto$1) {
) ;
const permissionTypes = {
CREATE_RECORD : "create record " ,
UPDATE_RECORD : "update record " ,
READ_RECORD : "read record " ,
DELETE_RECORD : "delete record " ,
CREATE_ROW : "create row " ,
UPDATE_ROW : "update row " ,
READ_ROW : "read row " ,
DELETE_ROW : "delete row " ,
READ_INDEX : "read index" ,
MANAGE_INDEX : "manage index" ,
MANAGE_COLLECTION : "manage collection" ,
@ -21953,13 +21953,13 @@ var app = (function (crypto$1) {
get : ( ) => ( { type } ) ,
} ) ;
const createRecord = nodePermission ( permissionTypes . CREATE_RECORD ) ;
const createRow = nodePermission ( permissionTypes . CREATE_ROW ) ;
const updateRecord = nodePermission ( permissionTypes . UPDATE_RECORD ) ;
const updateRow = nodePermission ( permissionTypes . UPDATE_ROW ) ;
const deleteRecord = nodePermission ( permissionTypes . DELETE_RECORD ) ;
const deleteRow = nodePermission ( permissionTypes . DELETE_ROW ) ;
const readRecord = nodePermission ( permissionTypes . READ_RECORD ) ;
const readRow = nodePermission ( permissionTypes . READ_ROW ) ;
const writeTemplates = staticPermission ( permissionTypes . WRITE_TEMPLATES ) ;
@ -21994,10 +21994,10 @@ var app = (function (crypto$1) {
const alwaysAuthorized = ( ) => true ;
const permission = {
createRecord ,
updateRecord ,
deleteRecord ,
readRecord ,
createRow ,
updateRow ,
deleteRow ,
readRow ,
writeTemplates ,
createUser ,
setPassword ,
@ -22013,41 +22013,41 @@ var app = (function (crypto$1) {
setUserAccessLevels ,
} ;
const getNew = app => ( collectionKey , record TypeName ) => {
const recordNode = getRecord Node ( app , collectionKey ) ;
const getNew = app => ( collectionKey , row TypeName ) => {
const rowNode = getRow Node ( app , collectionKey ) ;
collectionKey = safeKey ( collectionKey ) ;
return apiWrapperSync (
app ,
events . record Api . getNew ,
permission . createRecord . isAuthorized ( record Node . nodeKey ( ) ) ,
{ collectionKey , record TypeName } ,
events . row Api . getNew ,
permission . createRow . isAuthorized ( row Node . nodeKey ( ) ) ,
{ collectionKey , row TypeName } ,
_ getNew ,
record Node ,
row Node ,
collectionKey
)
} ;
const _ getNew = ( record Node , collectionKey ) =>
constructRecord ( record Node , getNewFieldValue , collectionKey ) ;
const _ getNew = ( row Node , collectionKey ) =>
constructRow ( row Node , getNewFieldValue , collectionKey ) ;
const getRecord Node = ( app , collectionKey ) => {
const getRow Node = ( app , collectionKey ) => {
collectionKey = safeKey ( collectionKey ) ;
return getNodeForCollectionPath ( app . hierarchy ) ( collectionKey )
} ;
const getNewChild = app => ( record Key , collectionName , record TypeName ) =>
getNew ( app ) ( joinKey ( record Key , collectionName ) , record TypeName ) ;
const getNewChild = app => ( row Key , collectionName , row TypeName ) =>
getNew ( app ) ( joinKey ( row Key , collectionName ) , row TypeName ) ;
const constructRecord = ( record Node , getFieldValue , collectionKey ) => {
const record = $ ( record Node . fields , [ fp_35 ( "name" ) , fp_26 ( getFieldValue ) ] ) ;
const constructRow = ( row Node , getFieldValue , collectionKey ) => {
const row = $ ( row Node . fields , [ fp_35 ( "name" ) , fp_26 ( getFieldValue ) ] ) ;
record . id = ` ${ record Node . nodeId } - ${ shortid_1 ( ) } ` ;
record . key = isSingleRecord ( record Node )
? joinKey ( collectionKey , record Node . name )
: joinKey ( collectionKey , record . id ) ;
record . isNew = true ;
record . type = record Node . name ;
return record
row . id = ` ${ row Node . nodeId } - ${ shortid_1 ( ) } ` ;
row . key = isSingleRow ( row Node )
? joinKey ( collectionKey , row Node . name )
: joinKey ( collectionKey , row . id ) ;
row . isNew = true ;
row . type = row Node . name ;
return row
} ;
const pathRegxMaker = node => ( ) =>
@ -22056,7 +22056,7 @@ var app = (function (crypto$1) {
const nodeKeyMaker = node => ( ) =>
switchCase (
[
n => isTable ( n ) && ! isSingleRecord ( n ) ,
n => isTable ( n ) && ! isSingleRow ( n ) ,
n =>
joinKey (
node . parent ( ) . nodeKey ( ) ,
@ -22076,7 +22076,7 @@ var app = (function (crypto$1) {
node . parent = fp_21 ( parent ) ;
node . isRoot = ( ) =>
isNothing ( parent ) && node . name === "root" && node . type === "root" ;
if ( isCollectionRecord ( node ) ) {
if ( isCollectionRow ( node ) ) {
node . collectionNodeKey = ( ) =>
joinKey ( parent . nodeKey ( ) , node . collectionName ) ;
node . collectionPathRegx = ( ) =>
@ -22116,7 +22116,7 @@ var app = (function (crypto$1) {
const app = createCoreApp ( backendDefinition , user ) ;
return {
record Api : {
row Api : {
getNew : getNew ( app ) ,
getNewChild : getNewChild ( app ) ,
} ,
@ -22232,40 +22232,40 @@ var app = (function (crypto$1) {
const ERROR = "##error_message" ;
const loadRecord = api => async ( { record Key , statePath } ) => {
if ( ! record Key ) {
api . error ( "Load Record: record key not set" ) ;
const loadRow = api => async ( { row Key , statePath } ) => {
if ( ! row Key ) {
api . error ( "Load Row: row key not set" ) ;
return
}
if ( ! statePath ) {
api . error ( "Load Record : state path not set" ) ;
api . error ( "Load Row : state path not set" ) ;
return
}
const record = await api . get ( {
url : ` /api/record / ${ trimSlash ( record Key ) } ` ,
const row = await api . get ( {
url : ` /api/row / ${ trimSlash ( row Key ) } ` ,
} ) ;
if ( api . isSuccess ( record ) ) api . setState ( statePath , record ) ;
if ( api . isSuccess ( row ) ) api . setState ( statePath , row ) ;
} ;
const listRecord s = api => async ( { indexKey , statePath } ) => {
const listRow s = api => async ( { indexKey , statePath } ) => {
if ( ! indexKey ) {
api . error ( "Load Record: record key not set" ) ;
api . error ( "Load Row: row key not set" ) ;
return
}
if ( ! statePath ) {
api . error ( "Load Record : state path not set" ) ;
api . error ( "Load Row : state path not set" ) ;
return
}
const record s = await api . get ( {
url : ` /api/listRecord s/ ${ trimSlash ( indexKey ) } ` ,
const row s = await api . get ( {
url : ` /api/listRow s/ ${ trimSlash ( indexKey ) } ` ,
} ) ;
if ( api . isSuccess ( record s ) ) api . setState ( statePath , record s ) ;
if ( api . isSuccess ( row s ) ) api . setState ( statePath , row s ) ;
} ;
const USER_STATE_PATH = "_bbuser" ;
@ -22291,32 +22291,32 @@ var app = (function (crypto$1) {
localStorage . setItem ( "budibase:user" , JSON . stringify ( user ) ) ;
} ;
const saveRecord = api => async ( { statePath } ) => {
const saveRow = api => async ( { statePath } ) => {
if ( ! statePath ) {
api . error ( "Load Record : state path not set" ) ;
api . error ( "Load Row : state path not set" ) ;
return
}
const record toSave = api . getState ( statePath ) ;
const row toSave = api . getState ( statePath ) ;
if ( ! record toSave ) {
api . error ( ` there is no record in state: ${ statePath } ` ) ;
if ( ! row toSave ) {
api . error ( ` there is no row in state: ${ statePath } ` ) ;
return
}
if ( ! record toSave . key ) {
if ( ! row toSave . key ) {
api . error (
` item in state does not appear to be a record - it has no key ( ${ statePath } ) `
` item in state does not appear to be a row - it has no key ( ${ statePath } ) `
) ;
return
}
const savedRecord = await api . post ( {
url : ` /api/record / ${ trimSlash ( record toSave . key ) } ` ,
body : record toSave ,
const savedRow = await api . post ( {
url : ` /api/row / ${ trimSlash ( row toSave . key ) } ` ,
body : row toSave ,
} ) ;
if ( api . isSuccess ( savedRecord ) ) api . setState ( statePath , savedRecord ) ;
if ( api . isSuccess ( savedRow ) ) api . setState ( statePath , savedRow ) ;
} ;
const createApi = ( { rootPath , setState , getState } ) => {
@ -22383,23 +22383,23 @@ var app = (function (crypto$1) {
} ;
return {
loadRecord : loadRecord ( apiOpts ) ,
listRecords : listRecord s ( apiOpts ) ,
loadRow : loadRow ( apiOpts ) ,
listRows : listRow s ( apiOpts ) ,
authenticate : authenticate ( apiOpts ) ,
saveRecord : saveRecord ( apiOpts ) ,
saveRow : saveRow ( apiOpts ) ,
}
} ;
const getNewChildRecord ToState = ( coreApi , setState ) => ( {
record Key ,
const getNewChildRow ToState = ( coreApi , setState ) => ( {
row Key ,
collectionName ,
childRecord Type ,
childRow Type ,
statePath ,
} ) => {
const error = errorHandler ( setState ) ;
try {
if ( ! record Key ) {
error ( "getNewChild > record Key not set" ) ;
if ( ! row Key ) {
error ( "getNewChild > row Key not set" ) ;
return
}
@ -22408,8 +22408,8 @@ var app = (function (crypto$1) {
return
}
if ( ! childRecord Type ) {
error ( "getNewChild > childRecord Type not set" ) ;
if ( ! childRow Type ) {
error ( "getNewChild > childRow Type not set" ) ;
return
}
@ -22418,10 +22418,10 @@ var app = (function (crypto$1) {
return
}
const rec = coreApi . record Api . getNewChild (
record Key ,
const rec = coreApi . row Api . getNewChild (
row Key ,
collectionName ,
childRecord Type
childRow Type
) ;
setState ( statePath , rec ) ;
} catch ( e ) {
@ -22429,9 +22429,9 @@ var app = (function (crypto$1) {
}
} ;
const getNewRecord ToState = ( coreApi , setState ) => ( {
const getNewRow ToState = ( coreApi , setState ) => ( {
collectionKey ,
childRecord Type ,
childRow Type ,
statePath ,
} ) => {
const error = errorHandler ( setState ) ;
@ -22441,8 +22441,8 @@ var app = (function (crypto$1) {
return
}
if ( ! childRecord Type ) {
error ( "getNewChild > childRecord Type not set" ) ;
if ( ! childRow Type ) {
error ( "getNewChild > childRow Type not set" ) ;
return
}
@ -22451,7 +22451,7 @@ var app = (function (crypto$1) {
return
}
const rec = coreApi . record Api . getNew ( collectionKey , childRecord Type ) ;
const rec = coreApi . row Api . getNew ( collectionKey , childRow Type ) ;
setState ( statePath , rec ) ;
} catch ( e ) {
error ( e . message ) ;
@ -22485,18 +22485,18 @@ var app = (function (crypto$1) {
return {
"Set State" : handler ( [ "path" , "value" ] , setStateHandler ) ,
"Load Record " : handler ( [ "record Key" , "statePath" ] , api . loadRecord ) ,
"List Record s" : handler ( [ "indexKey" , "statePath" ] , api . listRecord s ) ,
"Save Record " : handler ( [ "statePath" ] , api . saveRecord ) ,
"Load Row " : handler ( [ "row Key" , "statePath" ] , api . loadRow ) ,
"List Row s" : handler ( [ "indexKey" , "statePath" ] , api . listRow s ) ,
"Save Row " : handler ( [ "statePath" ] , api . saveRow ) ,
"Get New Child Record " : handler (
[ "record Key" , "collectionName" , "childRecord Type" , "statePath" ] ,
getNewChildRecord ToState ( coreApi , setStateWithStore )
"Get New Child Row " : handler (
[ "row Key" , "collectionName" , "childRow Type" , "statePath" ] ,
getNewChildRow ToState ( coreApi , setStateWithStore )
) ,
"Get New Record " : handler (
[ "collectionKey" , "childRecord Type" , "statePath" ] ,
getNewRecord ToState ( coreApi , setStateWithStore )
"Get New Row " : handler (
[ "collectionKey" , "childRow Type" , "statePath" ] ,
getNewRow ToState ( coreApi , setStateWithStore )
) ,
Authenticate : handler ( [ "username" , "password" ] , api . authenticate ) ,