Skip to content

Commit

Permalink
Merge pull request #35 from MacFJA/add-serializable-class-type
Browse files Browse the repository at this point in the history
Fix class definition type
  • Loading branch information
MacFJA authored Oct 11, 2022
2 parents 2bc3f3a + ab449e9 commit 9b76ffb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .docs/How-To/05-Missing-Encryption-Behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Change behavior with missing encryption
order: 5
---

# This article is not applicable anymore. (since v2.1.?)
# This article is not applicable anymore. (since v2.2.0)

---

Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup node with version 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
node-version: 16
- name: Install dependencies
run: npm ci
- name: Run Lint
Expand All @@ -26,12 +25,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup node with version 16
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
node-version: 16
- name: Install dependencies
run: npm ci
- name: Prepare test
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix class definition type not wide enough ([Issue#32])

### Changed

- (dev) Update Github actions versions.

## [2.2.0]

### Added
Expand Down Expand Up @@ -160,4 +168,5 @@ First version
[Issue#23]: https://github.com/MacFJA/svelte-persistent-store/issues/23
[Issue#26]: https://github.com/MacFJA/svelte-persistent-store/issues/26
[Issue#31]: https://github.com/MacFJA/svelte-persistent-store/issues/31
[Issue#32]: https://github.com/MacFJA/svelte-persistent-store/issues/32
[PR#8]: https://github.com/MacFJA/svelte-persistent-store/pull/8
14 changes: 7 additions & 7 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
Expand Up @@ -19,7 +19,7 @@
"README.md"
],
"dependencies": {
"@macfja/serializer": "^1.1.1",
"@macfja/serializer": "^1.1.2",
"browser-cookies": "^1.2.0",
"idb-keyval": "^5.1.3",
"sjcl-codec-hex": "^1.0.0",
Expand Down
9 changes: 5 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
serialize as defaultSerializer,
deserialize as defaultDeserializer,
addGlobalAllowedClass,
type ClassDefinition,
} from "@macfja/serializer"
import { get as getCookie, set as setCookie, erase as removeCookie } from "browser-cookies"
import { get, set, createStore, del } from "idb-keyval"
Expand Down Expand Up @@ -48,7 +49,7 @@ const warnStorageNotFound = (storageName) => {
* Add a class to the allowed list of classes to be serialized
* @param classDef The class to add to the list
*/
export const addSerializableClass = (classDef: FunctionConstructor): void => {
export const addSerializableClass = (classDef: ClassDefinition<any>): void => {
addSerializable(classDef)
}

Expand All @@ -68,20 +69,20 @@ export let serialize = defaultSerializer
export let deserialize = defaultDeserializer
/**
* The function used to add a class in the serializer allowed class
* @type {(classConstructor: FunctionConstructor) => void}
* @type {(classConstructor: ClassDefinition<any>) => void}
*/
let addSerializable = addGlobalAllowedClass

/**
* Set the serialization functions to use
* @param {(data: any) => string} serializer The function to use to transform any data into a string
* @param {(input: string) => any} deserializer The function to use to transform back string into the original data (reverse of the serializer)
* @param {(classConstructor: FunctionConstructor) => void} [addSerializableClass] The function to use to add a class in the serializer/deserializer allowed class
* @param {(classConstructor: ClassDefinition<any>) => void} [addSerializableClass] The function to use to add a class in the serializer/deserializer allowed class
*/
export function setSerialization(
serializer: (data: any) => string,
deserializer: (input: string) => any,
addSerializableClass?: (classConstructor: FunctionConstructor) => void
addSerializableClass?: (classConstructor: ClassDefinition<any>) => void
): void {
serialize = serializer
deserialize = deserializer
Expand Down

0 comments on commit 9b76ffb

Please sign in to comment.