Skip to content

Commit

Permalink
refactor, fixes & code governance (#38)
Browse files Browse the repository at this point in the history
refactor src/module.database/_model for better typescript support
removed @nestjs/cqrs
cleanup governance.yml
fixed .github/workflows/jellyfish-dependencies.yml
fixed labeler.yml being in the wrong directory
  • Loading branch information
fuxingloh authored May 7, 2021
1 parent 4824d71 commit 2e9ab07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions apps/whale-api/src/module.database/database.spec/_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const PartitionMapping: ModelMapping<Partition> = {
}

export interface Partition extends Model {
id: string
a: string
b: number

Expand Down Expand Up @@ -77,6 +78,7 @@ export const PartitionSortMapping: ModelMapping<PartitionSort> = {
}

export interface PartitionSort extends Model {
id: string
a_partition: string
a_sort: string

Expand Down
21 changes: 13 additions & 8 deletions apps/whale-api/src/module.database/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
export type ModelKey = string | number
export type ModelKeyType = 'string' | 'number'

interface ModelIndexString<M extends Model> {
type: 'string'
key: (model: M) => string
}

interface ModelIndexNumber<M extends Model> {
type: 'number'
key: (model: M) => number
}

/**
* @see Model
*/
Expand All @@ -17,19 +27,14 @@ export interface ModelIndex<M extends Model> {
/**
* Partition key of the model index.
*/
partition: {
type: ModelKeyType
key: (model: M) => ModelKey
}
partition: ModelIndexString<M> | ModelIndexNumber<M>

/**
* Sort key of the model index, where present indicates composite key.
* This attribute must be sorted in lexicographically order, which is a
* typical implementation of most key-value store.
*/
sort?: {
type: ModelKeyType
key: (model: M) => ModelKey
}
sort?: ModelIndexString<M> | ModelIndexNumber<M>
}

export interface ModelMapping<M extends Model> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export abstract class LevelUpDatabase extends Database {
* Sub root space for type.
*/
protected subRoot<M extends Model> (mapping: ModelMapping<M>): LevelUp {
// TODO(fuxingloh): sub root indexing might dup too much indexed data as root indexes and sub indexes can be shared.
// We could allow a sub index to act as root. Need to revisit this in the future.
// Other providers like dynamodb where the indexes are manually setup it won't be such an issue.
return sub(this.root, mapping.type, {
valueEncoding: 'json',
keyEncoding: 'binary'
Expand Down

0 comments on commit 2e9ab07

Please sign in to comment.