-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#151 into [email protected] π§ add orm in interceptor #171
base: [email protected]
Are you sure you want to change the base?
Conversation
ΠΡΠΌΠ°Ρ Π½Π°Π΄ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π΅ΡΠ΅ ΡΠ΅ΡΡΡ (Π° ΡΠΎ ΡΠΆΠ΅ Π΅ΡΡΡ Π±Π°Π³ΠΈ Ρ findIndexById) ΠΈ README ΠΎΠ±Π½ΠΎΠ²ΠΈΡΡ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qwe
@@ -7,6 +7,7 @@ module.exports = { | |||
{ | |||
files: ['*.ts'], | |||
rules: { | |||
'@typescript-eslint/no-namespace': 'off', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }]
- Ρ Π΄ΡΠΌΠ°Ρ Π»ΡΡΡΠ΅ ΡΠ΄Π΅Π»Π°ΡΡ ΡΠ°ΠΊ, ΡΡΠΎΠ±Ρ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎ ΡΠ½ΡΡΡ ΠΎΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΡ, Π° Π½Π΅ ΠΏΠΎΠ»Π½ΠΎΡΡΡΡ ΠΎΡΠΊΠ»ΡΡΠ°ΡΡ ΠΏΡΠ°Π²ΠΈΠ»ΠΎ
@@ -35,7 +35,7 @@ | |||
"dist" | |||
], | |||
"engines": { | |||
"node": ">=12" | |||
"node": ">=10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Π ΠΏΠΎΡΠ΅ΠΌΡ Π²Π΅ΡΡΠΈΡ ΡΠ½ΠΈΠ·ΠΈΠ»ΠΈ? ΠΠ°ΠΊ ΠΌΠΈΠ½ΠΈΠΌΡΠΌ esbuild, ΠΊΠΎΡΠΎΡΡΠΉ Ρ Π½Π°Ρ Π² dependencies ΠΈΠΌΠ΅Π΅Ρ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΡΡ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅ΠΌΡΡ Π²Π΅ΡΡΠΈΡ 12
export class FileStorage<T extends Record<StorageIndex, any> = Record<StorageIndex, any>> | ||
implements Storage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ΠΠ°Π²Π°ΠΉ ΡΡΡ ΡΠΎΠ³Π΄Π° Π΄ΠΆΠ΅Π½Π΅ΡΠΈΠΊ ΡΠΈΠΏ T
ΡΠΎΠΆΠ΅ Π² Data
ΠΏΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΡΠ΅ΠΌ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Π£ Π‘Π΅ΡΠ΅Π³ΠΈ ΠΏΡΠΈΠΌΠ΅ΡΠ½ΠΎ ΡΠ°ΠΊΠ°Ρ ΠΆΠ΅ middleware Π΅ΡΡΡ Π² PR Π»ΠΎΠ³Π³Π΅ΡΠ°. ΠΡΠΌΠ°Ρ ΠΌΠΎΠΆΠ½ΠΎ Π² ΠΎΠ΄Π½Ρ ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΠΈΡΡ Π²Π°ΡΠΈ ΡΠ΅ΡΠ΅Π½ΠΈΡ
export type Orm<Database extends Record<string, unknown>> = { | ||
[Key in keyof Database]: Database[Key] extends Array<infer Item> | ||
? Item extends { id: string | number } | ||
? NestedOrm<Item> | ||
: ShallowOrm<Item> | ||
: ShallowOrm<Database[Key]>; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ΠΠΎΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°ΡΡ
Item extends { id: StorageIndex }
- ΠΡΠ»ΠΈ
Item extends { id: string | number }
= false, ΡΠΎ Π½Π°Π΄ΠΎ Π΄Π΅Π»Π°ΡΡShallowOrm<Database[Key]>
, ΠΏΠΎΡΠΎΠΌΡ ΡΡΠΎ Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ shallow database ΠΎΠ±ΡΠ΅ΠΊΡΠ° Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°ΡΡΡΡ ΠΌΠ°ΡΡΠΈΠ² ΡΠ΅Π»ΠΈΠΊΠΎΠΌ, Π° Π½Π΅ Π΅Π³ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½Ρ(-Ρ)
delete: (id) => storage.delete([key, id]), | ||
update: (id, data) => { | ||
const currentResource = storage.read([key, id]); | ||
const updatedResource = { ...data, id: currentResource.id }; | ||
storage.write([key, id], updatedResource); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Π’ΡΡ Π½Π°Π΄ΠΎ Π΅ΡΠ΅ Π²ΡΠ·ΡΠ²Π°ΡΡ ΡΡΠ½ΠΊΡΠΈΡ findIndexById
ΠΊΠ°ΠΊ Π² createNestedDatabaseRoutes
delete: (id) => storage.delete([key, id]), | ||
update: (id, data) => { | ||
const currentResource = storage.read([key, id]); | ||
const updatedResource = { ...data, id: currentResource.id }; | ||
storage.write([key, id], updatedResource); | ||
}, | ||
create: (data) => { | ||
const collection = storage.read(key); | ||
const newResourceId = createNewId(collection); | ||
const newResource = { ...data, id: newResourceId }; | ||
storage.write([key, value.length], newResource); | ||
}, | ||
createMany: (data) => | ||
data.forEach((element) => { | ||
const collection = storage.read(key); | ||
const newResourceId = createNewId(collection); | ||
const newResource = { ...element, id: newResourceId }; | ||
storage.write([key, value.length], newResource); | ||
}), | ||
deleteMany: (ids) => | ||
ids.forEach((id) => { | ||
storage.delete([key, id]); | ||
}), | ||
updateMany: (ids, data) => | ||
ids.forEach((id) => { | ||
const currentResource = storage.read([key, id]); | ||
const updatedResource = { ...data, id: currentResource.id }; | ||
storage.write([key, id], updatedResource); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Π₯ΠΎΡΠ΅ΡΡΡ ΠΆΠ΅ΡΡΠΊΠΎ ΡΡΡΡΠΊΡΡΡΠΈΠ·ΠΈΡΠΎΠ²Π°ΡΡ ΠΎΠ΄Π½ΠΈΠΌ ΠΈΠ· Π΄Π²ΡΡ Π²Π°ΡΠΈΠ°Π½ΡΠΎΠ²:
- create ΡΡΠ΄ΠΎΠΌ Ρ createMany ΠΈ ΡΠ΄
- create -> update -> delete -> createMany -> updateMany -> deleteMany
(orm, [key, value]) => { | ||
orm[key] = { | ||
get: () => value, | ||
update: (data) => storage.write([key], data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ΠΏΠ΅ΡΠ²ΡΠΉ Π°Π³ΡΡΠΌΠ΅Π½Ρ storage.write Π½Π΅ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ ΠΌΠ°ΡΡΠΈΠ² - ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΏΡΠΎΡΡΠΎ key
|
||
create: (data: Omit<Item, 'id'>) => void; | ||
update: (id: StorageIndex, data: Partial<Omit<Item, 'id'>>) => void; | ||
delete: (id: string) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string => StorageIndex
@@ -8,6 +10,7 @@ export interface RequestInterceptorParams { | |||
getCookie: (name: string) => RequestInterceptorCookieValue; | |||
getHeader: (field: string) => RequestInterceptorHeaderValue; | |||
getHeaders: () => Record<string, RequestInterceptorHeaderValue>; | |||
orm: Orm<Database>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orm ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ undefined
createMany: (data) => | ||
data.forEach((element) => { | ||
const collection = storage.read(key); | ||
const newResourceId = createNewId(collection); | ||
const newResource = { ...element, id: newResourceId }; | ||
storage.write([key, value.length], newResource); | ||
}), | ||
deleteMany: (ids) => | ||
ids.forEach((id) => { | ||
storage.delete([key, id]); | ||
}), | ||
updateMany: (ids, data) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ρ createMany Π°ΡΠ³ΡΠΌΠ΅Π½Ρ Π½Π΅ Π²ΠΎ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π΅Π½Π½ΠΎΠΌ ΡΠΈΡΠ»Π΅ ΠΊΠ°ΠΊ Π½ΠΈΠΆΠ΅ Ρ deleteMany ΠΈ updateMany. datas ΠΈΠ»ΠΈ dataArray ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±ΠΎΠ·Π²Π°ΡΡ
No description provided.