40 changed files with 664 additions and 659 deletions
@ -1,3 +1,3 @@ |
|||
export async function initDB() { |
|||
return null; |
|||
return null; |
|||
} |
@ -1,135 +1,135 @@ |
|||
// https://github.com/realm/realm-js/issues/370#issuecomment-270849466
|
|||
export default class MockRealm { |
|||
constructor(params) { |
|||
this.schema = {}; |
|||
this.schemaVersion = params.schemaVersion; |
|||
this.callbackList = []; |
|||
this.data = {}; |
|||
this.schemaCallbackList = {}; |
|||
params.schema.forEach((schema) => { |
|||
this.data[schema.name] = {}; |
|||
}); |
|||
params.schema.forEach((schema) => { |
|||
this.schema[schema.name] = schema; |
|||
}); |
|||
this.lastLookedUpModel = null; |
|||
} |
|||
constructor(params) { |
|||
this.schema = {}; |
|||
this.schemaVersion = params.schemaVersion; |
|||
this.callbackList = []; |
|||
this.data = {}; |
|||
this.schemaCallbackList = {}; |
|||
params.schema.forEach((schema) => { |
|||
this.data[schema.name] = {}; |
|||
}); |
|||
params.schema.forEach((schema) => { |
|||
this.schema[schema.name] = schema; |
|||
}); |
|||
this.lastLookedUpModel = null; |
|||
} |
|||
|
|||
objects(schemaName) { |
|||
this.lastLookedUpModel = schemaName; |
|||
const objects = Object.values(this.data[schemaName]); |
|||
objects.values = () => objects; |
|||
objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort(); |
|||
objects.addListener = (cb) => { |
|||
if (this.schemaCallbackList[schemaName]) { |
|||
this.schemaCallbackList[schemaName].push(cb); |
|||
} else { |
|||
this.schemaCallbackList[schemaName] = [cb]; |
|||
} |
|||
}; |
|||
objects.removeListener = () => {}; |
|||
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects; |
|||
return objects; |
|||
objects(schemaName) { |
|||
this.lastLookedUpModel = schemaName; |
|||
const objects = Object.values(this.data[schemaName]); |
|||
objects.values = () => objects; |
|||
objects.sorted = () => this.compareFunc ? objects.sort(this.compareFunc) : objects.sort(); |
|||
objects.addListener = (cb) => { |
|||
if (this.schemaCallbackList[schemaName]) { |
|||
this.schemaCallbackList[schemaName].push(cb); |
|||
} else { |
|||
this.schemaCallbackList[schemaName] = [cb]; |
|||
} |
|||
}; |
|||
objects.removeListener = () => {}; |
|||
objects.filtered = this.filtered ? this.filtered.bind(this, schemaName) : () => objects; |
|||
return objects; |
|||
} |
|||
|
|||
write(fn) { |
|||
this.writing = true; |
|||
fn(); |
|||
this.writing = false; |
|||
} |
|||
write(fn) { |
|||
this.writing = true; |
|||
fn(); |
|||
this.writing = false; |
|||
} |
|||
|
|||
create(schemaName, object) { |
|||
const modelObject = object; |
|||
const properties = this.schema[schemaName].schema.properties; |
|||
Object.keys(properties).forEach((key) => { |
|||
if (modelObject[key] && modelObject[key].model) { |
|||
this.data[modelObject[key].model][modelObject[key].id] = this.create( |
|||
modelObject[key].model, modelObject[key], |
|||
); |
|||
} else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) { |
|||
modelObject[key].forEach((obj) => { |
|||
this.data[modelObject[key][0].model][obj.id] = obj; |
|||
}); |
|||
modelObject[key].filtered = this.filtered ? this.filtered : () => modelObject[key]; |
|||
modelObject[key].sorted = () => modelObject[key].sort(); |
|||
} else if (modelObject[key] === undefined) { |
|||
if (typeof properties[key] === 'object' && properties[key].optional) { |
|||
modelObject[key] = null; |
|||
} |
|||
if (typeof properties[key] === 'object' && ['list', 'linkingObjects'].includes(properties[key].type)) { |
|||
modelObject[key] = []; |
|||
modelObject[key].filtered = () => []; |
|||
modelObject[key].sorted = () => []; |
|||
} |
|||
} |
|||
create(schemaName, object) { |
|||
const modelObject = object; |
|||
const properties = this.schema[schemaName].schema.properties; |
|||
Object.keys(properties).forEach((key) => { |
|||
if (modelObject[key] && modelObject[key].model) { |
|||
this.data[modelObject[key].model][modelObject[key].id] = this.create( |
|||
modelObject[key].model, modelObject[key], |
|||
); |
|||
} else if (modelObject[key] && modelObject[key].length && modelObject[key][0].model) { |
|||
modelObject[key].forEach((obj) => { |
|||
this.data[modelObject[key][0].model][obj.id] = obj; |
|||
}); |
|||
|
|||
this.data[schemaName][modelObject.id] = modelObject; |
|||
if (this.writing) { |
|||
if (this.schemaCallbackList[schemaName]) { |
|||
this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, { |
|||
insertions: { length: 1 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: 0 }, |
|||
})); |
|||
} |
|||
this.callbackList.forEach((cb) => { cb(); }); |
|||
modelObject[key].filtered = this.filtered ? this.filtered : () => modelObject[key]; |
|||
modelObject[key].sorted = () => modelObject[key].sort(); |
|||
} else if (modelObject[key] === undefined) { |
|||
if (typeof properties[key] === 'object' && properties[key].optional) { |
|||
modelObject[key] = null; |
|||
} |
|||
if (typeof properties[key] === 'object' && ['list', 'linkingObjects'].includes(properties[key].type)) { |
|||
modelObject[key] = []; |
|||
modelObject[key].filtered = () => []; |
|||
modelObject[key].sorted = () => []; |
|||
} |
|||
return modelObject; |
|||
} |
|||
}); |
|||
|
|||
objectForPrimaryKey(model, id) { |
|||
this.lastLookedUpModel = model; |
|||
return this.data[model][id]; |
|||
this.data[schemaName][modelObject.id] = modelObject; |
|||
if (this.writing) { |
|||
if (this.schemaCallbackList[schemaName]) { |
|||
this.schemaCallbackList[schemaName].forEach(cb => cb(schemaName, { |
|||
insertions: { length: 1 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: 0 }, |
|||
})); |
|||
} |
|||
|
|||
delete(object) { |
|||
if (this.lastLookedUpModel || object.model) { |
|||
const model = object.model ? object.model : this.lastLookedUpModel |
|||
if (Array.isArray(object)) { |
|||
object.forEach((item) => { |
|||
delete this.data[model][item.id]; |
|||
}); |
|||
} |
|||
delete this.data[model][object.id]; |
|||
if (this.writing) { |
|||
if (this.schemaCallbackList[model]) { |
|||
this.schemaCallbackList[model].forEach(cb => cb(model, { |
|||
insertions: { length: 0 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: 1 }, |
|||
})); |
|||
} |
|||
this.callbackList.forEach((cb) => { cb(); }); |
|||
} |
|||
} |
|||
this.callbackList.forEach((cb) => { cb(); }); |
|||
} |
|||
return modelObject; |
|||
} |
|||
|
|||
deleteAll() { |
|||
Object.keys(this.schema).forEach((key) => { |
|||
if (this.writing && this.schemaCallbackList[this.schema[key].name]) { |
|||
this.schemaCallbackList[this.schema[key].name].forEach(cb => cb(key, { |
|||
insertions: { length: 0 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: Object.values(this.data[this.schema[key].name]).length }, |
|||
})); |
|||
} |
|||
this.data[this.schema[key].name] = {}; |
|||
objectForPrimaryKey(model, id) { |
|||
this.lastLookedUpModel = model; |
|||
return this.data[model][id]; |
|||
} |
|||
|
|||
delete(object) { |
|||
if (this.lastLookedUpModel || object.model) { |
|||
const model = object.model ? object.model : this.lastLookedUpModel |
|||
if (Array.isArray(object)) { |
|||
object.forEach((item) => { |
|||
delete this.data[model][item.id]; |
|||
}); |
|||
if (this.writing) this.callbackList.forEach((cb) => { cb(); }); |
|||
} |
|||
|
|||
addListener(event, callback) { |
|||
this.callbackList.push(callback); |
|||
delete this.data[model][object.id]; |
|||
if (this.writing) { |
|||
if (this.schemaCallbackList[model]) { |
|||
this.schemaCallbackList[model].forEach(cb => cb(model, { |
|||
insertions: { length: 0 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: 1 }, |
|||
})); |
|||
} |
|||
this.callbackList.forEach((cb) => { cb(); }); |
|||
} |
|||
} |
|||
} |
|||
|
|||
prepareData(schemaName, objects) { |
|||
objects.forEach((object) => { |
|||
this.create(schemaName, object); |
|||
}); |
|||
deleteAll() { |
|||
Object.keys(this.schema).forEach((key) => { |
|||
if (this.writing && this.schemaCallbackList[this.schema[key].name]) { |
|||
this.schemaCallbackList[this.schema[key].name].forEach(cb => cb(key, { |
|||
insertions: { length: 0 }, |
|||
modifications: { length: 0 }, |
|||
deletions: { length: Object.values(this.data[this.schema[key].name]).length }, |
|||
})); |
|||
} |
|||
this.data[this.schema[key].name] = {}; |
|||
}); |
|||
if (this.writing) this.callbackList.forEach((cb) => { cb(); }); |
|||
} |
|||
|
|||
addListener(event, callback) { |
|||
this.callbackList.push(callback); |
|||
} |
|||
|
|||
prepareData(schemaName, objects) { |
|||
objects.forEach((object) => { |
|||
this.create(schemaName, object); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
MockRealm.Object = class Object { |
|||
isValid() { return true; } |
|||
isValid() { return true; } |
|||
}; |
@ -0,0 +1,7 @@ |
|||
import { initDB } from "../src/realm/dbInit"; |
|||
|
|||
test('Realm DB inits', async () => { |
|||
let realmDB = await initDB(); |
|||
|
|||
expect |
|||
}); |
@ -1,16 +1,16 @@ |
|||
module.exports = { |
|||
// setupFiles: ['./jestSetup.js'],
|
|||
preset: 'react-native', |
|||
verbose: true, |
|||
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'], |
|||
moduleDirectories: ['node_modules', 'src'], |
|||
moduleNameMapper: { |
|||
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js',
|
|||
'../services/Keystore': '<rootDir>/__mock__/mockKeyStore.js', |
|||
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js' |
|||
}, |
|||
transform: { |
|||
'^.+\\.(ts|tsx)?$': 'ts-jest', |
|||
'^.+\\.(js|jsx)$': 'babel-jest', |
|||
} |
|||
// setupFiles: ['./jestSetup.js'],
|
|||
preset: 'react-native', |
|||
verbose: true, |
|||
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'], |
|||
moduleDirectories: ['node_modules', 'src'], |
|||
moduleNameMapper: { |
|||
// '@react-native-firebase/messaging: '<rootDir>/__mock__/mockFirebase.js',
|
|||
'../services/Keystore': '<rootDir>/__mock__/mockKeyStore.js', |
|||
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mock__/file.js' |
|||
}, |
|||
transform: { |
|||
'^.+\\.(ts|tsx)?$': 'ts-jest', |
|||
'^.+\\.(js|jsx)$': 'babel-jest', |
|||
} |
|||
} |
@ -1,13 +1,13 @@ |
|||
export function generateKey() { |
|||
let result = []; |
|||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|||
let charactersLength = characters.length; |
|||
let result = []; |
|||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|||
let charactersLength = characters.length; |
|||
|
|||
for (let i = 0; i < 64; i++) { |
|||
result.push( |
|||
characters.charAt(Math.floor(Math.random() * charactersLength)), |
|||
); |
|||
} |
|||
for (let i = 0; i < 64; i++) { |
|||
result.push( |
|||
characters.charAt(Math.floor(Math.random() * charactersLength)), |
|||
); |
|||
} |
|||
|
|||
return result.join(''); |
|||
return result.join(''); |
|||
} |
@ -1,29 +1,29 @@ |
|||
import {systemRepo, userRepo, scoreRepo} from './dbInit'; |
|||
|
|||
class realmAPI { |
|||
constructor(){ |
|||
if (realmDB === null) { |
|||
realmDB = this; |
|||
} |
|||
|
|||
return realmDB; |
|||
constructor(){ |
|||
if (realmDB === null) { |
|||
realmDB = this; |
|||
} |
|||
|
|||
getAllSystemValues() { |
|||
return systemRepo.getAllSystemValues(); |
|||
} |
|||
|
|||
createSystemValue(key, value) { |
|||
systemRepo.createSystemValue(key, value); |
|||
} |
|||
return realmDB; |
|||
} |
|||
|
|||
deleteSystemValue(key) { |
|||
systemRepo.deleteSystemValue(key); |
|||
} |
|||
getAllSystemValues() { |
|||
return systemRepo.getAllSystemValues(); |
|||
} |
|||
|
|||
createSystemValue(key, value) { |
|||
systemRepo.createSystemValue(key, value); |
|||
} |
|||
|
|||
getSystemValue(key) { |
|||
return systemRepo.getSystemKeyValue(key); |
|||
} |
|||
deleteSystemValue(key) { |
|||
systemRepo.deleteSystemValue(key); |
|||
} |
|||
|
|||
getSystemValue(key) { |
|||
return systemRepo.getSystemKeyValue(key); |
|||
} |
|||
} |
|||
|
|||
export let realmDB = new realmAPI(); |
@ -1,9 +1,9 @@ |
|||
export const Score = { |
|||
name: 'Score', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
user: 'string', |
|||
value: 'string' |
|||
} |
|||
name: 'Score', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
user: 'string', |
|||
value: 'string' |
|||
} |
|||
}; |
@ -1,9 +1,9 @@ |
|||
export const System = { |
|||
name: 'System', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
key: 'string', |
|||
value: 'string' |
|||
} |
|||
name: 'System', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
key: 'string', |
|||
value: 'string' |
|||
} |
|||
}; |
@ -1,8 +1,8 @@ |
|||
export const User = { |
|||
name: 'User', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
name: 'string' |
|||
} |
|||
name: 'User', |
|||
primaryKey: 'id', |
|||
properties: { |
|||
id: 'string', |
|||
name: 'string' |
|||
} |
|||
} |
@ -1,3 +1,3 @@ |
|||
export function migratev0(oldRealm, newRealm) { |
|||
Function.prototype |
|||
Function.prototype |
|||
} |
@ -1,14 +1,14 @@ |
|||
import { APP_INIT } from "../types/SystemTypes"; |
|||
|
|||
function sys(state = {}, action) { |
|||
switch (action.type) { |
|||
case APP_INIT: |
|||
return {...state, ...action.system}; |
|||
default: |
|||
return state; |
|||
} |
|||
switch (action.type) { |
|||
case APP_INIT: |
|||
return {...state, ...action.system}; |
|||
default: |
|||
return state; |
|||
} |
|||
} |
|||
|
|||
export const systemReducer = { |
|||
system: sys |
|||
system: sys |
|||
}; |
@ -1,31 +1,31 @@ |
|||
export const material = { |
|||
dark: '#212121', |
|||
light: '#ffffff', |
|||
dark: '#212121', |
|||
light: '#ffffff', |
|||
|
|||
//200
|
|||
blue200: '#90caf9', |
|||
//200
|
|||
blue200: '#90caf9', |
|||
|
|||
//400
|
|||
blue400: '#5c6bc0', |
|||
grey400: '#bdbdbd', |
|||
//400
|
|||
blue400: '#5c6bc0', |
|||
grey400: '#bdbdbd', |
|||
|
|||
//600
|
|||
grey600: '#757575', |
|||
//600
|
|||
grey600: '#757575', |
|||
|
|||
//700
|
|||
grey700: '#616161', |
|||
//700
|
|||
grey700: '#616161', |
|||
|
|||
//800
|
|||
amber800: '#ff8f00', |
|||
blue800: '#1565c0', |
|||
red800: '#c62828', |
|||
red800dark: '#7f0000', |
|||
grey800: '#424242', |
|||
grey800dark: '#1b1b1b', |
|||
green800: '#2e7d32', |
|||
//800
|
|||
amber800: '#ff8f00', |
|||
blue800: '#1565c0', |
|||
red800: '#c62828', |
|||
red800dark: '#7f0000', |
|||
grey800: '#424242', |
|||
grey800dark: '#1b1b1b', |
|||
green800: '#2e7d32', |
|||
} |
|||
|
|||
export const fonts = { |
|||
dark: '#000000', |
|||
light: '#ffffff' |
|||
dark: '#000000', |
|||
light: '#ffffff' |
|||
}; |
@ -1,5 +1,5 @@ |
|||
export const squareIcons = { |
|||
settings: 'cog-outline', |
|||
toggleOn: 'toggle-switch-on', |
|||
toggleOfff: 'toggle-switch-off' |
|||
settings: 'cog-outline', |
|||
toggleOn: 'toggle-switch-on', |
|||
toggleOfff: 'toggle-switch-off' |
|||
}; |
Loading…
Reference in new issue