-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow sets to continue to be native javascript arrays
This should help with users migrating to Dyngoose v3 Fixes #667
- Loading branch information
1 parent
e1599c7
commit c137a74
Showing
8 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect } from 'chai' | ||
import { TestableTable } from '../../setup-tests.spec' | ||
import { isArray, toArray } from 'lodash' | ||
|
||
describe('AttributeType/StringSet', () => { | ||
let record: TestableTable | ||
|
||
beforeEach(() => { | ||
record = TestableTable.new() | ||
}) | ||
|
||
describe('setting', () => { | ||
it('should allow values to be a Set', () => { | ||
expect(record.testStringSet).eq(null) | ||
record.testStringSet = new Set<string>(['some value']) | ||
expect(toArray(record.testStringSet)).deep.eq(['some value']) | ||
}) | ||
|
||
it('should allow values to be an Array', () => { | ||
expect(record.testStringSet).eq(null) | ||
record.testStringSet = ['some value'] as any | ||
expect(toArray(record.testStringSet)).deep.eq(['some value']) | ||
}) | ||
}) | ||
|
||
describe('getting', () => { | ||
it('should allow values to read as a Set', () => { | ||
expect(record.testStringSet).eq(null) | ||
record.testStringSet = new Set<string>(['some value']) | ||
expect(record.testStringSet).to.be.instanceOf(Set) | ||
}) | ||
|
||
it('should allow values to be an Array', () => { | ||
expect(record.testStringSetArray).eq(null) | ||
record.testStringSetArray = ['some value'] | ||
expect(isArray(record.testStringSetArray)).eq(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { type AttributeMetadata } from '../attribute' | ||
|
||
export type BinarySetValue = Set<Uint8Array> | ||
export type BinarySetValue = Set<Uint8Array> | Uint8Array[] | ||
|
||
export interface BinarySetAttributeMetadata extends AttributeMetadata<BinarySetValue> { | ||
/** | ||
* Return a native JavaScript array, rather than a Set. | ||
*/ | ||
array?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { type AttributeMetadata } from '../attribute' | ||
import { type NumberValue } from './number.metadata' | ||
|
||
export type NumberSetValue = Set<NumberValue> | ||
export type NumberSetValue = Set<NumberValue> | number[] | ||
|
||
export interface NumberSetAttributeMetadata extends AttributeMetadata<NumberSetValue> { | ||
/** | ||
* Return a native JavaScript array, rather than a Set. | ||
*/ | ||
array?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { type AttributeMetadata } from '../attribute' | ||
|
||
export type StringSetValue = Set<string> | ||
export type StringSetValue = Set<string> | string[] | ||
|
||
export interface StringSetAttributeMetadata extends AttributeMetadata<StringSetValue> { | ||
trim?: boolean | ||
lowercase?: boolean | ||
uppercase?: boolean | ||
/** | ||
* Return a native JavaScript array, rather than a Set. | ||
*/ | ||
array?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters