Skip to content
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

Open
wants to merge 2 commits into
base: [email protected]
Choose a base branch
from

Conversation

debabin
Copy link
Member

@debabin debabin commented May 26, 2024

No description provided.

@MiaInturi
Copy link
Collaborator

Π”ΡƒΠΌΠ°ΡŽ Π½Π°Π΄ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π΅Ρ‰Π΅ тСсты (Π° Ρ‚ΠΎ ΡƒΠΆΠ΅ Π΅ΡΡ‚ΡŒ Π±Π°Π³ΠΈ с findIndexById) ΠΈ README ΠΎΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ

Copy link
Collaborator

@MiaInturi MiaInturi left a 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',
Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А ΠΏΠΎΡ‡Π΅ΠΌΡƒ Π²Π΅Ρ€ΡΠΈΡŽ снизили? Как ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ esbuild, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Ρƒ нас Π² dependencies ΠΈΠΌΠ΅Π΅Ρ‚ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½ΡƒΡŽ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅ΠΌΡƒΡŽ Π²Π΅Ρ€ΡΠΈΡŽ 12

Comment on lines +11 to +12
export class FileStorage<T extends Record<StorageIndex, any> = Record<StorageIndex, any>>
implements Storage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Π”Π°Π²Π°ΠΉ Ρ‚ΡƒΡ‚ Ρ‚ΠΎΠ³Π΄Π° Π΄ΠΆΠ΅Π½Π΅Ρ€ΠΈΠΊ Ρ‚ΠΈΠΏ T Ρ‚ΠΎΠΆΠ΅ Π² Data ΠΏΠ΅Ρ€Π΅ΠΈΠΌΠ΅Π½ΡƒΠ΅ΠΌ

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Π£ Π‘Π΅Ρ€Π΅Π³ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π½ΠΎ такая ΠΆΠ΅ middleware Π΅ΡΡ‚ΡŒ Π² PR Π»ΠΎΠ³Π³Π΅Ρ€Π°. Π”ΡƒΠΌΠ°ΡŽ ΠΌΠΎΠΆΠ½ΠΎ Π² ΠΎΠ΄Π½Ρƒ ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΠΈΡ‚ΡŒ ваши Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ

Comment on lines +33 to +39
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]>;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. МоТно ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Item extends { id: StorageIndex }
  2. Если Item extends { id: string | number } = false, Ρ‚ΠΎ Π½Π°Π΄ΠΎ Π΄Π΅Π»Π°Ρ‚ΡŒ ShallowOrm<Database[Key]>, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ Π² качСствС shallow database ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° Π΄ΠΎΠ»ΠΆΠ΅Π½ Ρ€Π°ΡΡΠΌΠ°Ρ‚Ρ€ΠΈΠ²Π°Ρ‚ΡŒΡΡ массив Ρ†Π΅Π»ΠΈΠΊΠΎΠΌ, Π° Π½Π΅ Π΅Π³ΠΎ элСмСнт(-Ρ‹)

Comment on lines +13 to +18
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);
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Π’ΡƒΡ‚ Π½Π°Π΄ΠΎ Π΅Ρ‰Π΅ Π²Ρ‹Π·Ρ‹Π²Π°Ρ‚ΡŒ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ findIndexById ΠΊΠ°ΠΊ Π² createNestedDatabaseRoutes

Comment on lines +13 to +41
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);
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Π₯очСтся ТСстко ΡΡ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΎΠ΄Π½ΠΈΠΌ ΠΈΠ· Π΄Π²ΡƒΡ… Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ΠΎΠ²:

  1. create рядом с createMany ΠΈ Ρ‚Π΄
  2. create -> update -> delete -> createMany -> updateMany -> deleteMany

(orm, [key, value]) => {
orm[key] = {
get: () => value,
update: (data) => storage.write([key], data)
Copy link
Collaborator

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;
Copy link
Collaborator

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>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orm ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ undefined

Comment on lines +25 to +36
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) =>
Copy link
Collaborator

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 ΠΌΠΎΠΆΠ½ΠΎ ΠΎΠ±ΠΎΠ·Π²Π°Ρ‚ΡŒ

@MiaInturi MiaInturi linked an issue Jul 1, 2024 that may be closed by this pull request
@MiaInturi MiaInturi added enhancement New feature or request [email protected] issues for [email protected] labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request [email protected] issues for [email protected]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get database orm in interceptor
3 participants