Skip to content

Commit

Permalink
Merge pull request #80 from ninesunsabiu/main
Browse files Browse the repository at this point in the history
feat(remesh): serializable support readonly keyword
  • Loading branch information
Lucifier129 committed Jul 7, 2023
2 parents 7b26fbf + b6cd8f8 commit e5e7576
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/remesh/__tests__/extern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { map, tap } from 'rxjs'
describe('extern', () => {
it('define an extern and use it', () => {
const memoryCache = (() => {
const cache = {}
const cache: Record<string, any> = {}
return {
get(key: string) {
return cache[key]
Expand Down
37 changes: 37 additions & 0 deletions packages/remesh/__tests__/modules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ describe('modules', () => {
id: number
content: string
completed: boolean
readonly tags: readonly string[]
window?: readonly [number, number]
}

const TestHistoryDomain = Remesh.domain({
Expand Down Expand Up @@ -883,6 +885,7 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
}),
)

Expand All @@ -891,6 +894,7 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
])

Expand All @@ -901,6 +905,7 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
])
Expand All @@ -916,6 +921,7 @@ describe('modules', () => {
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
}),
)

Expand All @@ -924,11 +930,13 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
])

Expand All @@ -939,18 +947,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -968,6 +979,7 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
])

Expand All @@ -978,18 +990,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1011,18 +1026,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1044,18 +1062,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1073,6 +1094,7 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
])

Expand All @@ -1083,18 +1105,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1112,11 +1137,13 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
])

Expand All @@ -1127,18 +1154,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1160,18 +1190,21 @@ describe('modules', () => {
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
],
[
{
id: 0,
content: 'todo-0',
completed: true,
tags: ['DDD'],
},
{
id: 1,
content: 'todo-1',
completed: false,
tags: ['CQRS'],
},
],
])
Expand All @@ -1187,6 +1220,7 @@ describe('modules', () => {
id: 2,
content: 'todo-2',
completed: true,
tags: ['DDD', 'CQRS'],
}),
)

Expand All @@ -1195,6 +1229,7 @@ describe('modules', () => {
id: 2,
content: 'todo-2',
completed: true,
tags: ['DDD', 'CQRS'],
},
])

Expand All @@ -1205,6 +1240,7 @@ describe('modules', () => {
id: 2,
content: 'todo-2',
completed: true,
tags: ['DDD', 'CQRS'],
},
],
])
Expand All @@ -1222,6 +1258,7 @@ describe('modules', () => {
id: 2,
content: 'todo-2',
completed: true,
tags: ['DDD', 'CQRS'],
},
])

Expand Down
2 changes: 1 addition & 1 deletion packages/remesh/__tests__/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('store', () => {
},
})

const cache = {}
const cache: Record<string, any> = {}
const store2 = RemeshStore({
name: 'store',
externs: [
Expand Down
5 changes: 3 additions & 2 deletions packages/remesh/src/remesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { DomainConceptName } from './type'

export type SerializablePrimitives = void | undefined | number | string | boolean | null

export type SerializableArray = Serializable[]
export type ReadonlySerializableArray = readonly Serializable[]
export type SerializableArray = Serializable[] | ReadonlySerializableArray

export type SerializableObject = { [key: string]: Serializable }

export type Serializable = SerializablePrimitives | SerializableArray | SerializableObject | Serializable[]
export type Serializable = SerializablePrimitives | SerializableArray | SerializableObject

export type ToType<T> = T extends object | unknown[]
? {
Expand Down

0 comments on commit e5e7576

Please sign in to comment.