Skip to content

Commit ba618f8

Browse files
committed
chore: remove legacy node attributes deprecation
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 9361d39 commit ba618f8

3 files changed

Lines changed: 8 additions & 52 deletions

File tree

__tests__/files/cloning.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ describe('File serialization and deserialization', () => {
208208
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
209209
mime: 'image/jpeg',
210210
owner: 'emma',
211-
attributes: {
212-
displayname: 'My Vacation Photo',
213-
},
211+
displayname: 'My Vacation Photo',
214212
})
215213

216214
const parsed = JSON.parse(file.toJSON()) as [NodeData, RegExp?]

__tests__/files/node.spec.ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import type { Attribute, NodeData } from '../../lib/node/index.ts'
77

8-
import { describe, expect, test, vi } from 'vitest'
8+
import { describe, expect, test } from 'vitest'
99
import { File, Folder, NodeStatus } from '../../lib/node/index.ts'
1010
import { Permission } from '../../lib/permissions.ts'
1111

@@ -251,21 +251,6 @@ describe('Permissions attribute', () => {
251251
})
252252

253253
describe('Displayname attribute', () => {
254-
test('legacy displayname attribute', () => {
255-
// TODO: This logic can be removed with next major release (v4)
256-
const file = new File({
257-
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
258-
mime: 'image/jpeg',
259-
owner: 'emma',
260-
attributes: {
261-
displayname: 'image.png',
262-
},
263-
})
264-
expect(file.basename).toBe('picture.jpg')
265-
expect(file.displayname).toBe('image.png')
266-
expect(file.attributes.displayname).toBe('image.png')
267-
})
268-
269254
test('Read displayname attribute', () => {
270255
const file = new File({
271256
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
@@ -820,26 +805,9 @@ describe('Attributes update', () => {
820805
})
821806

822807
expect(file.attributes?.etag).toBe('5678')
823-
expect(file.attributes?.size).toBe(9999)
824-
expect(file.attributes?.owner).toBe('emma')
825-
expect(file.attributes?.fileid).toBeUndefined()
826-
})
827-
828-
test('Deprecated access to toplevel attributes', () => {
829-
const spy = vi.spyOn(window.console, 'warn')
830-
const file = new File({
831-
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
832-
mime: 'image/jpeg',
833-
owner: 'emma',
834-
size: 9999,
835-
attributes: {
836-
etag: '1234',
837-
size: 9999,
838-
},
839-
})
840-
841-
expect(file.attributes.size).toBe(9999)
842-
expect(spy).toBeCalledTimes(1)
808+
expect(file?.size).toBe(9999)
809+
expect(file?.owner).toBe('emma')
810+
expect(file?.fileid).toBeUndefined()
843811
})
844812

845813
test('Changing a protected attributes is not possible', () => {
@@ -853,9 +821,10 @@ describe('Attributes update', () => {
853821
})
854822

855823
// We can not update the owner
856-
expect(() => { file.attributes.owner = 'admin' }).toThrowError()
824+
// @ts-expect-error owner is a read-only property
825+
expect(() => { file.owner = 'admin' }).toThrowError()
857826
// The owner is still the original one
858-
expect(file.attributes?.owner).toBe('emma')
827+
expect(file?.owner).toBe('emma')
859828
})
860829

861830
})

lib/node/node.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { encodePath } from '@nextcloud/paths'
88
import { Permission } from '../permissions'
99
import { FileType } from './fileType'
1010
import { Attribute, fixDates, fixRegExp, isDavResource, NodeData, validateData } from './nodeData'
11-
import logger from '../utils/logger'
1211

1312
export enum NodeStatus {
1413
/** This is a new node and it doesn't exists on the filesystem yet */
@@ -51,14 +50,6 @@ export abstract class Node {
5150
// Apply original changes
5251
return Reflect.deleteProperty(target, prop)
5352
},
54-
// TODO: This is deprecated and only needed for files v3
55-
get: (target: Attribute, prop: string, receiver) => {
56-
if (this.readonlyAttributes.includes(prop)) {
57-
logger.warn(`Accessing "Node.attributes.${prop}" is deprecated, access it directly on the Node instance.`)
58-
return Reflect.get(this, prop)
59-
}
60-
return Reflect.get(target, prop, receiver)
61-
},
6253
} as ProxyHandler<Attribute>
6354

6455
protected constructor(...[data, davService]: NodeConstructorData) {
@@ -74,8 +65,6 @@ export abstract class Node {
7465
validateData(data, davService)
7566

7667
this._data = {
77-
// TODO: Remove with next major release, this is just for compatibility
78-
displayname: data.attributes?.displayname,
7968
...data,
8069
attributes: {},
8170
}

0 commit comments

Comments
 (0)