refacto: look after remanso now

This commit is contained in:
Julien Calixte
2026-02-14 14:40:11 +01:00
parent 4bd79b8f6c
commit 8b921f1adb
8 changed files with 26 additions and 560 deletions

View File

@@ -1,9 +1,9 @@
import { nanoid } from 'nanoid'
import indexedDb from 'pouchdb-adapter-indexeddb'
import PouchDb from 'pouchdb-browser'
import { nanoid } from "nanoid"
import indexedDb from "pouchdb-adapter-indexeddb"
import PouchDb from "pouchdb-browser"
import { DataType } from './DataType.enum'
import { Model } from './models/Model'
import { DataType } from "./DataType.enum"
import { Model } from "./models/Model"
PouchDb.plugin(indexedDb)
@@ -20,11 +20,11 @@ class Data {
constructor() {
try {
this.locale = new PouchDb('lite-note', {
adapter: 'indexeddb'
this.locale = new PouchDb("remanso", {
adapter: "indexeddb",
})
} catch (error) {
console.warn('data error', error)
console.warn("data error", error)
}
}
@@ -40,7 +40,7 @@ class Data {
}
public async update<DT extends DataType, T extends Model<DT>>(
model: T
model: T,
): Promise<boolean> {
try {
if (!model._id) {
@@ -71,7 +71,7 @@ class Data {
}
const result = await this.locale?.put({
...doc,
_deleted: true
_deleted: true,
})
return result?.ok ?? false
} catch {
@@ -80,7 +80,7 @@ class Data {
}
public async get<DT extends DataType, T extends Model<DT>>(
id: string
id: string,
): Promise<T | null> {
try {
return ((await this.locale?.get(id)) as T) || null
@@ -91,7 +91,7 @@ class Data {
public async getOrCreate<DT extends DataType, T extends Model<DT>>(
id: string,
initialValue: T
initialValue: T,
): Promise<T> {
const element = await this.get<DT, T>(id)
@@ -108,7 +108,7 @@ class Data {
prefix,
includeDocs = true,
includeAttachments = false,
keys = []
keys = [],
}: GetAllParams): Promise<T[]> {
if (!this.locale) {
return []
@@ -118,13 +118,13 @@ class Data {
const response = await this.locale.allDocs({
include_docs: includeDocs,
attachments: includeAttachments,
keys: keys.map((key) => this.generateId(prefix, key))
keys: keys.map((key) => this.generateId(prefix, key)),
})
if (includeDocs) {
return response.rows
.map((row) => {
if ('error' in row) {
if ("error" in row) {
return null
}
@@ -134,7 +134,7 @@ class Data {
} else {
return response.rows
.map((row) => {
if ('error' in row) {
if ("error" in row) {
return null
}
@@ -148,7 +148,7 @@ class Data {
include_docs: includeDocs,
attachments: includeAttachments,
startkey: prefix ? prefix : undefined,
endkey: prefix ? `${prefix}\ufff0` : undefined
endkey: prefix ? `${prefix}\ufff0` : undefined,
})
return response.rows.map((row) => row.doc) as T[]