forked from EVOgeek/Vmeda.Online
		
	MOBILE-4304 core: Implement SubPartial helper
This commit is contained in:
		
							parent
							
								
									c80674776a
								
							
						
					
					
						commit
						d94402637e
					
				| @ -29,6 +29,7 @@ import { | |||||||
| import { CoreDebugDatabaseTable } from './debug-database-table'; | import { CoreDebugDatabaseTable } from './debug-database-table'; | ||||||
| import { CoreEagerDatabaseTable } from './eager-database-table'; | import { CoreEagerDatabaseTable } from './eager-database-table'; | ||||||
| import { CoreLazyDatabaseTable } from './lazy-database-table'; | import { CoreLazyDatabaseTable } from './lazy-database-table'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Database table proxy used to route database interactions through different implementations. |  * Database table proxy used to route database interactions through different implementations. | ||||||
| @ -155,14 +156,14 @@ export class CoreDatabaseTableProxy< | |||||||
|     /** |     /** | ||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     async insert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): Promise<number> { |     async insert(record: SubPartial<DBRecord, RowIdColumn>): Promise<number> { | ||||||
|         return this.target.insert(record); |         return this.target.insert(record); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     syncInsert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): void { |     syncInsert(record: SubPartial<DBRecord, RowIdColumn>): void { | ||||||
|         this.target.syncInsert(record); |         this.target.syncInsert(record); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| import { CoreError } from '@classes/errors/error'; | import { CoreError } from '@classes/errors/error'; | ||||||
| import { SQLiteDB, SQLiteDBRecordValue, SQLiteDBRecordValues } from '@classes/sqlitedb'; | import { SQLiteDB, SQLiteDBRecordValue, SQLiteDBRecordValues } from '@classes/sqlitedb'; | ||||||
| 
 | 
 | ||||||
| @ -259,7 +260,7 @@ export class CoreDatabaseTable< | |||||||
|      * @param record Database record. |      * @param record Database record. | ||||||
|      * @returns New record row id. |      * @returns New record row id. | ||||||
|      */ |      */ | ||||||
|     async insert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): Promise<number> { |     async insert(record: SubPartial<DBRecord, RowIdColumn>): Promise<number> { | ||||||
|         const rowId = await this.database.insertRecord(this.tableName, record); |         const rowId = await this.database.insertRecord(this.tableName, record); | ||||||
| 
 | 
 | ||||||
|         return rowId; |         return rowId; | ||||||
| @ -270,7 +271,7 @@ export class CoreDatabaseTable< | |||||||
|      * |      * | ||||||
|      * @param record Database record. |      * @param record Database record. | ||||||
|      */ |      */ | ||||||
|     syncInsert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): void { |     syncInsert(record: SubPartial<DBRecord, RowIdColumn>): void { | ||||||
|         // The current database architecture does not support synchronous operations,
 |         // The current database architecture does not support synchronous operations,
 | ||||||
|         // so calling this method will mean that errors will be silenced. Because of that,
 |         // so calling this method will mean that errors will be silenced. Because of that,
 | ||||||
|         // this should only be called if using the asynchronous alternatives is not possible.
 |         // this should only be called if using the asynchronous alternatives is not possible.
 | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ import { | |||||||
|     CoreDatabaseReducer, |     CoreDatabaseReducer, | ||||||
|     CoreDatabaseQueryOptions, |     CoreDatabaseQueryOptions, | ||||||
| } from './database-table'; | } from './database-table'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Database table proxy used to debug runtime operations. |  * Database table proxy used to debug runtime operations. | ||||||
| @ -153,7 +154,7 @@ export class CoreDebugDatabaseTable< | |||||||
|     /** |     /** | ||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     insert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): Promise<number> { |     insert(record: SubPartial<DBRecord, RowIdColumn>): Promise<number> { | ||||||
|         this.logger.log('insert', record); |         this.logger.log('insert', record); | ||||||
| 
 | 
 | ||||||
|         return this.target.insert(record); |         return this.target.insert(record); | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ import { | |||||||
|     CoreDatabaseReducer, |     CoreDatabaseReducer, | ||||||
|     CoreDatabaseQueryOptions, |     CoreDatabaseQueryOptions, | ||||||
| } from './database-table'; | } from './database-table'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Wrapper used to improve performance by caching all the records for faster read operations. |  * Wrapper used to improve performance by caching all the records for faster read operations. | ||||||
| @ -154,7 +155,7 @@ export class CoreEagerDatabaseTable< | |||||||
|     /** |     /** | ||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     async insert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): Promise<number> { |     async insert(record: SubPartial<DBRecord, RowIdColumn>): Promise<number> { | ||||||
|         const rowId = await this.insertAndRemember(record, this.records); |         const rowId = await this.insertAndRemember(record, this.records); | ||||||
| 
 | 
 | ||||||
|         return rowId; |         return rowId; | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ import { CoreConstants } from '@/core/constants'; | |||||||
| import { SQLiteDB, SQLiteDBRecordValues } from '@classes/sqlitedb'; | import { SQLiteDB, SQLiteDBRecordValues } from '@classes/sqlitedb'; | ||||||
| import { CoreLogger } from '@singletons/logger'; | import { CoreLogger } from '@singletons/logger'; | ||||||
| import { CoreDatabaseTable, GetDBRecordPrimaryKey } from './database-table'; | import { CoreDatabaseTable, GetDBRecordPrimaryKey } from './database-table'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Database wrapper that caches database records in memory to speed up read operations. |  * Database wrapper that caches database records in memory to speed up read operations. | ||||||
| @ -79,7 +80,7 @@ export abstract class CoreInMemoryDatabaseTable< | |||||||
|      * @returns New record row id. |      * @returns New record row id. | ||||||
|      */ |      */ | ||||||
|     protected async insertAndRemember( |     protected async insertAndRemember( | ||||||
|         record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>, |         record: SubPartial<DBRecord, RowIdColumn>, | ||||||
|         records: Record<string, DBRecord | null>, |         records: Record<string, DBRecord | null>, | ||||||
|     ): Promise<number> { |     ): Promise<number> { | ||||||
|         const rowId = await super.insert(record); |         const rowId = await super.insert(record); | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ import { | |||||||
|     GetDBRecordPrimaryKey, |     GetDBRecordPrimaryKey, | ||||||
|     CoreDatabaseQueryOptions, |     CoreDatabaseQueryOptions, | ||||||
| } from './database-table'; | } from './database-table'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Wrapper used to improve performance by caching records that are used often for faster read operations. |  * Wrapper used to improve performance by caching records that are used often for faster read operations. | ||||||
| @ -138,7 +139,7 @@ export class CoreLazyDatabaseTable< | |||||||
|     /** |     /** | ||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     async insert(record: Omit<DBRecord, RowIdColumn> & Partial<Pick<DBRecord, RowIdColumn>>): Promise<number> { |     async insert(record: SubPartial<DBRecord, RowIdColumn>): Promise<number> { | ||||||
|         const rowId = await this.insertAndRemember(record, this.records); |         const rowId = await this.insertAndRemember(record, this.records); | ||||||
| 
 | 
 | ||||||
|         return rowId; |         return rowId; | ||||||
|  | |||||||
| @ -47,6 +47,7 @@ import { AsyncInstance, asyncInstance } from '@/core/utils/async-instance'; | |||||||
| import { LazyMap, lazyMap } from '@/core/utils/lazy-map'; | import { LazyMap, lazyMap } from '@/core/utils/lazy-map'; | ||||||
| import { CoreDatabaseTable } from '@classes/database/database-table'; | import { CoreDatabaseTable } from '@classes/database/database-table'; | ||||||
| import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy'; | import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Equivalent to Moodle's implementation of H5PFrameworkInterface. |  * Equivalent to Moodle's implementation of H5PFrameworkInterface. | ||||||
| @ -780,7 +781,7 @@ export class CoreH5PFramework { | |||||||
|             embedTypes = libraryData.embedTypes.join(', '); |             embedTypes = libraryData.embedTypes.join(', '); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const data: Omit<CoreH5PLibraryDBRecord, 'id'> & Partial<Pick<CoreH5PLibraryDBRecord, 'id'>> = { |         const data: SubPartial<CoreH5PLibraryDBRecord, 'id'> = { | ||||||
|             title: libraryData.title, |             title: libraryData.title, | ||||||
|             machinename: libraryData.machineName, |             machinename: libraryData.machineName, | ||||||
|             majorversion: libraryData.majorVersion, |             majorversion: libraryData.majorVersion, | ||||||
| @ -930,7 +931,7 @@ export class CoreH5PFramework { | |||||||
|             throw new CoreError('Attempted to create content of library without id'); |             throw new CoreError('Attempted to create content of library without id'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const data: Omit<CoreH5PContentDBRecord, 'id'> & Partial<Pick<CoreH5PContentDBRecord, 'id'>> = { |         const data: SubPartial<CoreH5PContentDBRecord, 'id'> = { | ||||||
|             jsoncontent: content.params ?? '{}', |             jsoncontent: content.params ?? '{}', | ||||||
|             mainlibraryid: content.library?.libraryId, |             mainlibraryid: content.library?.libraryId, | ||||||
|             timemodified: Date.now(), |             timemodified: Date.now(), | ||||||
|  | |||||||
| @ -19,6 +19,7 @@ import { ModalController, Translate } from '@singletons'; | |||||||
| import { FAQ_QRCODE_IMAGE_HTML, FAQ_URL_IMAGE_HTML, GET_STARTED_URL } from '@features/login/constants'; | import { FAQ_QRCODE_IMAGE_HTML, FAQ_URL_IMAGE_HTML, GET_STARTED_URL } from '@features/login/constants'; | ||||||
| import { CoreDomUtils } from '@services/utils/dom'; | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
| import { CoreCancellablePromise } from '@classes/cancellable-promise'; | import { CoreCancellablePromise } from '@classes/cancellable-promise'; | ||||||
|  | import { SubPartial } from '@/core/utils/types'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Component that displays help to connect to a site. |  * Component that displays help to connect to a site. | ||||||
| @ -217,5 +218,5 @@ enum AnswerFormat { | |||||||
|  * Question definition. |  * Question definition. | ||||||
|  */ |  */ | ||||||
| type QuestionDefinition = Omit<Question, 'id' | 'answer'> & { | type QuestionDefinition = Omit<Question, 'id' | 'answer'> & { | ||||||
|     answer: Omit<Answer, 'class'> & Partial<Pick<Answer, 'class'>>; |     answer: SubPartial<Answer, 'class'>; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -34,6 +34,11 @@ export type GetClosureArgs<T> = T extends (...args: infer TArgs) => any ? TArgs | |||||||
|  */ |  */ | ||||||
| export type Pretty<T> = T extends infer U ? {[K in keyof U]: U[K]} : never; | export type Pretty<T> = T extends infer U ? {[K in keyof U]: U[K]} : never; | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * Helper to convert some keys of an object to optional. | ||||||
|  |  */ | ||||||
|  | export type SubPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Helper type to omit union. |  * Helper type to omit union. | ||||||
|  * You can use it if need to omit an element from types union. |  * You can use it if need to omit an element from types union. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user