Skip to content

Commit

Permalink
chore(pinia-orm): Update lint rules & packages
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDredd committed Aug 31, 2023
1 parent a2e7b9d commit be0ca45
Show file tree
Hide file tree
Showing 199 changed files with 3,886 additions and 4,222 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
]
},
"pnpm": {
"packageExtensions": {
"@vue/composition-api": {
"peerDependencies": {
"vue": "*"
}
}
},
"overrides": {
"ufo": "^0.8.4",
"std-env": "^3.1.1"
Expand Down
10 changes: 5 additions & 5 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@
"pinia-orm": ">=1.6.7"
},
"dependencies": {
"@nuxt/kit": "^3.5.2"
"@nuxt/kit": "^3.7.0"
},
"devDependencies": {
"@nuxt/devtools": "^0.5.5",
"@nuxt/module-builder": "^0.4.0",
"@nuxt/devtools": "^0.8.2",
"@nuxt/module-builder": "^0.5.0",
"@nuxt/schema": "^3.5.2",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@pinia/nuxt": "^0.4.11",
"@types/prettier": "^2.7.2",
"eslint": "^8.41.0",
"nuxt": "^3.3.2",
"nuxt": "^3.7.0",
"pinia": "^2.1.3",
"pinia-orm": "^1.0.0",
"prettier": "^3.0.0",
"std-env": "^3.3.3",
"typescript": "^5.0.4",
"typescript": "^5.2.2",
"vite": "^4.3.9",
"vue": "^3.3.4"
},
Expand Down
8 changes: 6 additions & 2 deletions packages/pinia-orm/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"extends": "@antfu",
"extends": "@nuxtjs/eslint-config-typescript",
"parser": "@typescript-eslint/parser",
"rules": {
"no-useless-constructor": "off",
"no-use-before-define": "off",
"no-self-compare": "off",
"func-call-spacing": "off",
"no-console": [
"warn",
{ "allow": ["clear", "info", "error", "dir", "trace", "log", "time", "timeEnd"] }
{ "allow": ["clear", "info", "error", "dir", "trace", "time", "timeEnd", "warn"] }
]
}
}
11 changes: 5 additions & 6 deletions packages/pinia-orm/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ export default defineBuildConfig({
{ input: 'src/packages/nanoid/async', name: 'nanoid/async' },
{ input: 'src/packages/nanoid/non-secure', name: 'nanoid/non-secure' },
{ input: 'src/packages/uuid/v1', name: 'uuid/v1' },
{ input: 'src/packages/uuid/v4', name: 'uuid/v4' },
{ input: 'src/packages/uuid/v4', name: 'uuid/v4' }
],
declaration: true,
failOnWarn: false,
clean: true,
externals: ['@/composables', 'nanoid', 'uuid', 'nanoid/async', 'nanoid/non-secure', 'pinia'],
rollup: {
emitCJS: true,
emitCJS: true
},
hooks: {
'build:done': (ctx) => {
ctx.buildEntries.filter(entry => entry.path.includes('.cjs') && !entry.path.includes('shared')).forEach((entry) => {
fs.rename(`${ctx.options.outDir}/${entry.path}`, `${ctx.options.outDir}/${entry.path}`.replace('cjs', 'js'), (err) => {
if (err)
console.log(`ERROR: ${err}`)
if (err) { console.error(`ERROR: ${err}`) }
})
})
},
},
}
}
})
22 changes: 7 additions & 15 deletions packages/pinia-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@
"@pinia-orm/normalizr": ">=1.6.0"
},
"devDependencies": {
"@antfu/eslint-config": "^0.39.3",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@pinia/testing": "^0.1.2",
"@size-limit/preset-small-lib": "^8.2.4",
"@types/node": "^18.16.16",
"@types/prettier": "^2.7.2",
"@types/uuid": "^9.0.1",
"@vitest/coverage-c8": "^0.31.2",
"@typescript-eslint/parser": "^6.5.1-alpha.11",
"@vitest/coverage-v8": "^0.34.3",
"@vitest/ui": "^0.31.2",
"@vue/composition-api": "^1.7.1",
"@vue/test-utils": "^2.3.2",
"c8": "^8.0.0",
"core-js": "^3.30.2",
"eslint": "^8.41.0",
"eslint": "^8.48.0",
"happy-dom": "^10.0.3",
"mkdist": "^1.2.0",
"nanoid": "^4.0.2",
Expand All @@ -84,11 +85,11 @@
"size-limit": "^8.2.4",
"std-env": "^3.3.3",
"tsup": "^7.0.0",
"typescript": "^5.0.4",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"uuid": "^9.0.0",
"vite": "^4.3.9",
"vitest": "^0.31.2",
"vitest": "^0.34.3",
"vue": "^3.3.4",
"vue-demi": "^0.14.5",
"vue2": "npm:vue@^2.7.3"
Expand Down Expand Up @@ -121,14 +122,5 @@
"bugs": {
"url": "https://github.com/CodeDredd/pinia-orm/issues"
},
"homepage": "https://github.com/CodeDredd/pinia-orm#readme",
"pnpm": {
"packageExtensions": {
"@vue/composition-api": {
"peerDependencies": {
"vue": "*"
}
}
}
}
"homepage": "https://github.com/CodeDredd/pinia-orm#readme"
}
14 changes: 7 additions & 7 deletions packages/pinia-orm/src/cache/SimpleCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ export interface StoredData<T> {
const DEFAULT_EXPIRATION_SECONDS = 5 * 60

export class SimpleCache {
constructor(private cache = new Map()) {}
constructor (private cache = new Map()) {}

clear(): void {
clear (): void {
this.cache = new Map()
}

size(): number {
size (): number {
return this.cache.size
}

private computeExpirationTime(expiresInSeconds: number): number {
private computeExpirationTime (expiresInSeconds: number): number {
return new Date().getTime() + expiresInSeconds * 1000
}

// Store the data in memory and attach to the object expiration containing the
// expiration time.
set<T>({ key, data, expiration = DEFAULT_EXPIRATION_SECONDS }: StoredData<T>): T {
set<T> ({ key, data, expiration = DEFAULT_EXPIRATION_SECONDS }: StoredData<T>): T {
this.cache.set(key, { data, expiration: this.computeExpirationTime(expiration) })

return data
}

// Will get specific data from the Map object based on a key and return null if
// the data has expired.
get<T>(key: string): T | null {
get<T> (key: string): T | null {
if (this.cache.has(key)) {
const { data, expiration } = this.cache.get(key) as StoredData<T>

Expand All @@ -42,7 +42,7 @@ export class SimpleCache {
return null
}

private hasExpired(expiration: number): boolean {
private hasExpired (expiration: number): boolean {
return expiration < new Date().getTime()
}
}
36 changes: 18 additions & 18 deletions packages/pinia-orm/src/cache/WeakCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@ export class WeakCache<K, V extends object> implements Map<K, V> {

#map = new Map<K, WeakRef<V>>()

has(key: K) {
has (key: K) {
return !!(this.#map.has(key) && this.#map.get(key)?.deref())
}

get(key: K): V {
get (key: K): V {
const weakRef = this.#map.get(key)
if (!weakRef)
if (!weakRef) {
// @ts-expect-error object has no undefined
return undefined
}

const value = weakRef.deref()
if (value)
return value
if (value) { return value }

// If it cant be dereference, remove the key
this.#map.delete(key)
// @ts-expect-error object has no undefined
return undefined
}

set(key: K, value: V) {
set (key: K, value: V) {
this.#map.set(key, new WeakRef<V>(value))
return this
}

get size(): number {
get size (): number {
return this.#map.size
}

clear(): void {
clear (): void {
this.#map.clear()
}

delete(key: K): boolean {
delete (key: K): boolean {
this.#map.delete(key)
return false
}

forEach(cb: (value: V, key: K, map: Map<K, V>) => void): void {
for (const [key, value] of this) cb(value, key, this)
forEach (cb: (value: V, key: K, map: Map<K, V>) => void): void {
for (const [key, value] of this) { cb(value, key, this) }
}

* [Symbol.iterator](): IterableIterator<[K, V]> {
* [Symbol.iterator] (): IterableIterator<[K, V]> {
for (const [key, weakRef] of this.#map) {
const ref = weakRef.deref()

Expand All @@ -59,15 +59,15 @@ export class WeakCache<K, V extends object> implements Map<K, V> {
}
}

* entries(): IterableIterator<[K, V]> {
for (const [key, value] of this) yield [key, value]
* entries (): IterableIterator<[K, V]> {
for (const [key, value] of this) { yield [key, value] }
}

* keys(): IterableIterator<K> {
for (const [key] of this) yield key
* keys (): IterableIterator<K> {
for (const [key] of this) { yield key }
}

* values(): IterableIterator<V> {
for (const [, value] of this) yield value
* values (): IterableIterator<V> {
for (const [, value] of this) { yield value }
}
}
4 changes: 2 additions & 2 deletions packages/pinia-orm/src/composables/collection/useCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export interface UseCollect<M extends Model = Model> {
/**
* Return all possible helper functions for the collection
*/
export function useCollect<M extends Model = Model>(models: Collection<M>): UseCollect<M> {
export function useCollect<M extends Model = Model> (models: Collection<M>): UseCollect<M> {
return {
sum: field => useSum(models, field),
min: field => useMin(models, field),
max: field => useMax(models, field),
pluck: field => usePluck(models, field),
groupBy: fields => useGroupBy(models, fields),
sortBy: (sort, flags: SortFlags = 'SORT_REGULAR') => useSortBy(models, sort, flags),
keys: () => useKeys(models),
keys: () => useKeys(models)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The useGroupBy method groups the collection's items by a given key.
*/
export function useGroupBy<T extends Record<string, any>>(models: T[], fields: string[] | string): Record<string, T[]> {
export function useGroupBy<T extends Record<string, any>> (models: T[], fields: string[] | string): Record<string, T[]> {
const grouped: Record<string, T[]> = {}
const props = Array.isArray(fields) ? fields : [fields]

Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/composables/collection/useKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type { Collection } from '../../../src'
/**
* The keys method returns all of the collection's primary keys
*/
export function useKeys(models: Collection): string[] {
export function useKeys (models: Collection): string[] {
return models.map(model => model[model.$getLocalKey()])
}
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/composables/collection/useMax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { usePluck } from './usePluck'
/**
* Get the max value of the specified filed.
*/
export function useMax(models: Collection, field: string): number {
export function useMax (models: Collection, field: string): number {
const numbers = usePluck(models, field).filter(item => typeof item === 'number')

return numbers.length === 0 ? 0 : Math.max(...numbers)
Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/composables/collection/useMin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { usePluck } from './usePluck'
/**
* Get the min value of the specified filed.
*/
export function useMin(models: Collection, field: string): number {
export function useMin (models: Collection, field: string): number {
const numbers = usePluck(models, field).filter(item => typeof item === 'number')

return numbers.length === 0 ? 0 : Math.min(...numbers)
Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/composables/collection/usePluck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { getValue } from '../../support/Utils'
/**
* The pluck method retrieves all of the values for a given key.
*/
export function usePluck(models: Collection, field: string): any[] {
export function usePluck (models: Collection, field: string): any[] {
return models.map(model => getValue(model, field)).filter((item: any) => item)
}
2 changes: 1 addition & 1 deletion packages/pinia-orm/src/composables/collection/useSortBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type sorting<T> = ((record: T) => any) | string | [string, 'asc' | 'desc'
* Creates an array of elements, sorted in specified order by the results
* of running each element in a collection thru each iteratee.
*/
export function useSortBy<T extends Record<string, any>>(collection: T[], sort: sorting<T>, flags?: SortFlags): T[] {
export function useSortBy<T extends Record<string, any>> (collection: T[], sort: sorting<T>, flags?: SortFlags): T[] {
const directions = []
const iteratees = []

Expand Down
5 changes: 2 additions & 3 deletions packages/pinia-orm/src/composables/collection/useSum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import type { Collection } from '../../../src'
/**
* Get the sum value of the specified filed.
*/
export function useSum(models: Collection, field: string): number {
export function useSum (models: Collection, field: string): number {
return models.reduce<number>((sum, item) => {
if (typeof item[field] === 'number')
sum += item[field]
if (typeof item[field] === 'number') { sum += item[field] }

return sum
}, 0)
Expand Down
4 changes: 2 additions & 2 deletions packages/pinia-orm/src/composables/mapRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export type MappedRepositories<MR extends ModelsOrRepositories> = {
/**
* Map given models or repositories to the Vue Component.
*/
export function mapRepos<MR extends ModelsOrRepositories>(
modelsOrRepositories: MR,
export function mapRepos<MR extends ModelsOrRepositories> (
modelsOrRepositories: MR
): MappedRepositories<MR> {
const repositories = {} as MappedRepositories<MR>

Expand Down
6 changes: 3 additions & 3 deletions packages/pinia-orm/src/composables/useDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { defineStore } from 'pinia'
import type { Query } from '../query/Query'
import { useStoreActions } from './useStoreActions'

export function useDataStore<S extends DataStoreState, T extends DataStore = DataStore>(
export function useDataStore<S extends DataStoreState, T extends DataStore = DataStore> (
id: string,
options: DefineStoreOptionsBase<S, T>,
query?: Query,
query?: Query
) {
return defineStore(id, {
state: () => ({ data: {} } as S),
actions: useStoreActions(query),
...options,
...options
})
}

Expand Down
Loading

0 comments on commit be0ca45

Please sign in to comment.