Skip to content

Commit

Permalink
1. rename AllNodesPossiblyReadAsUndefined to ReplaceRemoveAndPossibly…
Browse files Browse the repository at this point in the history
…ReadAsNullableWithNever(internal)

2. AllNodesPossiblyReadAsNullable union the type with null and undefined
3. rename ReplaceRemoveWithUndefined with ReplaceRemoveAndPossiblyReadAsNullableWithNullable(internal)
4. Removable now union with undefined and null
5. Add new field value PossiblyReadAsNullable and its implementation and test
6. update issue template
  • Loading branch information
tylim88 committed Sep 12, 2022
1 parent fa5e401 commit 3e1d0e6
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 107 deletions.
14 changes: 8 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
title: "[BUG] title"
labels: bug
assignees: ''

---
Expand All @@ -12,10 +12,12 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
1. What is your Meta Type
2. What operation you run into problem?
3. What is the library version

**Actual behavior**
A clear and concise description of what happened.

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
title: "[ENHANCEMENT] title"
labels: enhancement
assignees: ''

---
Expand Down
20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/question-about-type-error.md

This file was deleted.

7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# HISTORY

## 1.2.5 12th Sept 22
## 1.3.0 12th Sept 22

1. rename AllNodesPossiblyReadAsUndefined to AllNodesPossiblyReadAsNullable
1. rename AllNodesPossiblyReadAsUndefined to ReplaceRemoveAndPossiblyReadAsNullableWithNever(internal)
2. AllNodesPossiblyReadAsNullable union the type with null and undefined
3. rename ReplaceRemoveWithUndefined with ReplaceRemoveWithNullable
3. rename ReplaceRemoveWithUndefined with ReplaceRemoveAndPossiblyReadAsNullableWithNullable(internal)
4. Removable now union with undefined and null
5. Add new field value PossiblyReadAsNullable and its implementation and test

## 1.2.3 8th Sept 22

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Read [here](https://firelordjs.com/miscellaneous/contributing)

1. The name FireSage is a reference to [Fire Sages of Avatar](https://avatar.fandom.com/wiki/Fire_Sages).
2. This is most likely the only RTDB type safe wrapper in existence.
3. FireSageJS is harder to code than its sister project [FirelordJS](https://github.com/tylim88/FirelordJS) because of non-numeric and numeric string type validation. FirelordJS however is quirkier due to all kind of rules.
3. FireSageJS is harder to code than its sister project [FirelordJS](https://github.com/tylim88/FirelordJS) because of RTDB path and data are deeply interrelated, another major challenge is non-numeric and numeric string type validation. FirelordJS however is quirkier due to all kind of rules.

## Related Projects

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firesagejs",
"version": "1.2.4",
"version": "1.3.0",
"description": "🔥Extreme Type Safe For Realtime Database Web, Write RTDB Code That Stand The Test Of Time",
"source": "src/index.ts",
"main": "dist/index.js",
Expand Down
7 changes: 4 additions & 3 deletions src/operations/remove.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { set, get } from '../operations'
import { set, get, push } from '../operations'
import { initializeApp, usersRef } from '../utilForTests'
import { remove } from './remove'
import { serverTimestamp } from '../fieldValue'

initializeApp()
describe('test remove', () => {
Expand All @@ -23,12 +24,12 @@ describe('test remove', () => {

it('test functionality', async () => {
const ref1 = usersRef('b/h/abc/m')
const ref2 = usersRef('b/d/k')
const ref2 = usersRef('b/h/abc/p')
await set(ref1, { abc: { n: '7' } })
await remove(ref1)
const data1 = (await get(ref1)).val()
expect(data1).toBe(null)
await set(ref2, 'hahaha')
await push(ref2, { r: serverTimestamp() })
await remove(ref2)
const data2 = (await get(ref2)).val()
expect(data2).toBe(null)
Expand Down
28 changes: 19 additions & 9 deletions src/types/fieldValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ declare const incrementSymbol: unique symbol
declare const pushAbleSymbol: unique symbol
declare const pushAbleOnlySymbol: unique symbol
declare const removeSymbol: unique symbol
declare const numericKeyRecord: unique symbol
declare const numericKeyRecordSymbol: unique symbol
declare const possiblyReadAsNullableSymbol: unique symbol

type ServerTimestampSymbol = typeof serverTimestampSymbol
type IncrementSymbol = typeof incrementSymbol
type PushAbleSymbol = typeof pushAbleSymbol
type PushAbleOnlySymbol = typeof pushAbleOnlySymbol
type RemoveSymbol = typeof removeSymbol
type NumericKeyRecordSymbol = typeof numericKeyRecord
type NumericKeyRecordSymbol = typeof numericKeyRecordSymbol
type PossiblyReadAsNullableSymbol = typeof possiblyReadAsNullableSymbol

declare class FieldValue<T extends symbol> {
private constructor()
Expand All @@ -24,15 +26,22 @@ export interface Increment extends FieldValue<IncrementSymbol> {}

export interface Removable extends FieldValue<RemoveSymbol> {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface PushAble<T> extends FieldValue<PushAbleSymbol> {}
export interface PushAble<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
T
> extends FieldValue<PushAbleSymbol> {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface PushAbleOnly<T> extends FieldValue<PushAbleOnlySymbol> {}
export interface PushAbleOnly<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
T
> extends FieldValue<PushAbleOnlySymbol> {}
export interface NumericKeyRecord<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
T
> extends FieldValue<NumericKeyRecordSymbol> {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface NumericKeyRecord<T>
extends FieldValue<NumericKeyRecordSymbol> {}
export interface PossiblyReadAsNullable
extends FieldValue<PossiblyReadAsNullableSymbol> {}

export type AllFieldTypes =
| ServerTimestamp
Expand All @@ -41,3 +50,4 @@ export type AllFieldTypes =
| PushAble<unknown>
| PushAbleOnly<unknown>
| NumericKeyRecord<unknown>
| PossiblyReadAsNullable
25 changes: 12 additions & 13 deletions src/types/metaType/creator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PushAble,
PushAbleOnly,
NumericKeyRecord,
PossiblyReadAsNullable,
} from '../fieldValue'
import { IsTrue, IsSame } from '../tsUtils'
import { Users } from '../../utilForTests'
Expand Down Expand Up @@ -405,28 +406,26 @@ describe('test generated meta type', () => {
| {
e: 'abc' | 'xyz' | 'efg' | 'lmn' | 'rst'
f: { j: number }
k: string | Removable
k: string | PossiblyReadAsNullable
}
| Removable
| PossiblyReadAsNullable
h: Record<
string,
{
i: boolean
l: ServerTimestamp | Removable
m:
| PushAble<{ n: '1' | '2' | '7' | '8' | '9' | Removable }>
| Removable
p: PushAbleOnly<{ r: ServerTimestamp | Removable }> | Removable
s: NumericKeyRecord<{ t: number | Removable }> | Removable
m: PushAble<unknown> | Removable
p: PushAbleOnly<unknown> | Removable
s: NumericKeyRecord<unknown> | Removable
}
>
}
o: PushAble<number>
q: PushAbleOnly<0 | 1 | 4 | 5 | 6>
u: NumericKeyRecord<string>
w: NumericKeyRecord<boolean>
// * Note, the field type can accept any type and the test will still pass
// this is because the type exist only on generic and never pass down to any properties
o: PushAble<unknown>
q: PushAbleOnly<unknown>
u: NumericKeyRecord<unknown>
w: NumericKeyRecord<unknown>
// * Note, the field value can accept any type and the test will still pass
// * this is because the type exist only on generic and never pass down to any properties
}
>
>()
Expand Down
18 changes: 11 additions & 7 deletions src/types/metaType/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
ReplaceInvalidDataTypeBase,
ReplaceInvalidDataTypeWrite,
ReplaceInvalidUnion,
ReplaceRemove,
} from './replaceInvalidDataType'
import {
ReadTypeConverter,
WriteTypeConverter,
AllNodesPossiblyReadAsNullable,
ReplaceAllNodesPossiblyReadAsNullableWithNullable,
CompareTypeConverter,
ReplaceRemoveWithNullable,
ReplaceRemoveAndPossiblyReadAsNullableWithNever,
ReplaceRemoveAndPossiblyReadAsNullableWithNullable,
} from './typeConverter'

export type MetaType = {
Expand All @@ -28,22 +28,26 @@ export type MetaTypeCreator<
AllNodesPossiblyReadAsNullable: false
},
Write = WriteTypeConverter<
ReplaceRemove<ReplaceInvalidDataTypeWrite<ReplaceInvalidUnion<Base>>>
ReplaceRemoveAndPossiblyReadAsNullableWithNever<
ReplaceInvalidDataTypeWrite<ReplaceInvalidUnion<Base>>
>
>,
Read = ReadTypeConverter<
ReplaceRemoveWithNullable<
ReplaceRemoveAndPossiblyReadAsNullableWithNullable<
ReplaceInvalidDataTypeRead<ReplaceInvalidUnion<Base>>
>
>,
Compare = CompareTypeConverter<
ReplaceRemove<ReplaceInvalidDataTypeRead<ReplaceInvalidUnion<Base>>>
ReplaceRemoveAndPossiblyReadAsNullableWithNever<
ReplaceInvalidDataTypeRead<ReplaceInvalidUnion<Base>>
>
>
> = {
base: ReplaceInvalidDataTypeBase<ReplaceInvalidUnion<Base>>
write: Write
flatten_write: ObjectFlatten<Write>
read: Settings['AllNodesPossiblyReadAsNullable'] extends true
? AllNodesPossiblyReadAsNullable<Read>
? ReplaceAllNodesPossiblyReadAsNullableWithNullable<Read>
: Read
compare: Compare
}
25 changes: 8 additions & 17 deletions src/types/metaType/replaceInvalidDataType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Removable,
PushAbleOnly,
NumericKeyRecord,
PossiblyReadAsNullable,
} from '../fieldValue'
import { IsCharacterValid } from '../utils'
import { IsUnion } from '../tsUtils'
Expand All @@ -26,12 +27,14 @@ type ReplaceRecordNumber<T, U> = T extends Record<infer X, unknown>
: U
: never

type ValidUnion = Removable | PossiblyReadAsNullable

export type ReplaceInvalidDataTypeBase<T> = T extends
| boolean
| string
| number
| ServerTimestamp
| Removable
| ValidUnion
| null
? T
: T extends Record<string, unknown>
Expand All @@ -57,7 +60,7 @@ export type ReplaceInvalidDataTypeRead<T> = T extends
| string
| number
| ServerTimestamp
| Removable
| ValidUnion
| null
? T
: T extends Record<string, unknown>
Expand All @@ -83,7 +86,7 @@ export type ReplaceInvalidDataTypeWrite<T> = T extends
| string
| number
| ServerTimestamp
| Removable
| ValidUnion
| null
? T
: T extends Record<string, unknown>
Expand All @@ -104,19 +107,7 @@ export type ReplaceInvalidDataTypeWrite<T> = T extends
? NumericKeyRecord<ReplaceInvalidDataTypeWrite<X>>
: ErrorInvalidDataType

export type ReplaceRemove<T> = T extends Removable
? never
: T extends Record<string, unknown>
? { [K in keyof T]: ReplaceRemove<T[K]> }
: T extends PushAble<infer X>
? PushAble<ReplaceRemove<X>>
: T extends PushAbleOnly<infer X>
? PushAbleOnly<ReplaceRemove<X>>
: T extends NumericKeyRecord<infer X>
? NumericKeyRecord<ReplaceRemove<X>>
: T

export type ReplaceInvalidUnion<T> = Exclude<T, Removable> extends infer R
export type ReplaceInvalidUnion<T> = Exclude<T, ValidUnion> extends infer R
? IsUnion<R> extends true
? Extract<
R,
Expand All @@ -132,6 +123,6 @@ export type ReplaceInvalidUnion<T> = Exclude<T, Removable> extends infer R
| {
[K in keyof R]: ReplaceInvalidUnion<R[K]>
}
| Extract<T, Removable>
| Extract<T, ValidUnion>
: T
: T
Loading

0 comments on commit 3e1d0e6

Please sign in to comment.