notu 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +238 -0
- package/package.json +5 -1
- package/src/Environment.test.ts +0 -76
- package/src/Environment.ts +0 -51
- package/src/index.ts +0 -21
- package/src/models/Attr.test.ts +0 -214
- package/src/models/Attr.ts +0 -125
- package/src/models/ModelWithState.test.ts +0 -66
- package/src/models/ModelWithState.ts +0 -57
- package/src/models/Note.test.ts +0 -407
- package/src/models/Note.ts +0 -204
- package/src/models/NoteAttr.test.ts +0 -358
- package/src/models/NoteAttr.ts +0 -113
- package/src/models/NoteTag.test.ts +0 -245
- package/src/models/NoteTag.ts +0 -86
- package/src/models/Space.test.ts +0 -53
- package/src/models/Space.ts +0 -46
- package/src/models/Tag.test.ts +0 -133
- package/src/models/Tag.ts +0 -69
- package/src/services/HttpClient.test.ts +0 -108
- package/src/services/HttpClient.ts +0 -151
- package/src/services/QueryParser.test.ts +0 -153
- package/src/services/QueryParser.ts +0 -137
- package/tsconfig.json +0 -23
- package/vite.config.ts +0 -10
package/src/models/Note.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import ModelWithState from './ModelWithState';
|
|
4
|
-
import NoteAttr from './NoteAttr';
|
|
5
|
-
import NoteTag from './NoteTag';
|
|
6
|
-
import Space from './Space';
|
|
7
|
-
import Tag from './Tag';
|
|
8
|
-
import Attr from './Attr';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default class Note extends ModelWithState<Note> {
|
|
12
|
-
id: number = 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private _date: Date = new Date();
|
|
16
|
-
get date(): Date { return this._date; }
|
|
17
|
-
set date(value: Date) {
|
|
18
|
-
if (value !== this._date) {
|
|
19
|
-
this._date = value;
|
|
20
|
-
if (this.isClean)
|
|
21
|
-
this.dirty();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private _text: string = '';
|
|
27
|
-
get text(): string { return this._text; }
|
|
28
|
-
set text(value: string) {
|
|
29
|
-
if (value !== this._text) {
|
|
30
|
-
this._text = value;
|
|
31
|
-
if (this.isClean)
|
|
32
|
-
this.dirty();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private _archived: boolean = false;
|
|
38
|
-
get archived(): boolean { return this._archived; }
|
|
39
|
-
set archived(value: boolean) {
|
|
40
|
-
if (value !== this._archived) {
|
|
41
|
-
this._archived = value;
|
|
42
|
-
if (this.isClean)
|
|
43
|
-
this.dirty();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
private _spaceId: number = 0;
|
|
49
|
-
get spaceId(): number { return this._spaceId; }
|
|
50
|
-
set spaceId(value: number) {
|
|
51
|
-
if (value !== this._spaceId) {
|
|
52
|
-
this._spaceId = value;
|
|
53
|
-
if (value !== this.space?.id ?? 0)
|
|
54
|
-
this._space = null;
|
|
55
|
-
if (this.isClean)
|
|
56
|
-
this.dirty();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private _space: Space = null;
|
|
61
|
-
get space(): Space { return this._space; }
|
|
62
|
-
set space(value: Space) {
|
|
63
|
-
this._space = value;
|
|
64
|
-
this.spaceId = value?.id ?? 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
private _ownTag: Tag = null;
|
|
69
|
-
get ownTag(): Tag { return this._ownTag; }
|
|
70
|
-
|
|
71
|
-
setOwnTag(tag: string | Tag): Note {
|
|
72
|
-
if (typeof tag === 'string') {
|
|
73
|
-
if (this.ownTag == null)
|
|
74
|
-
this._ownTag = new Tag();
|
|
75
|
-
this.ownTag.name = tag;
|
|
76
|
-
this.ownTag.id = this.id;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
if (!!this.ownTag)
|
|
80
|
-
throw new Error('Note has already had its tag set. If you would like to change the tag name, call setTag with just a string specifying the new tag name.');
|
|
81
|
-
if (tag.id != 0 && tag.id != this.id)
|
|
82
|
-
throw new Error('Attempted to set tag to note with non-matching ID. Added tag id must either match the note id, which indicates that the tag has already been added to the note. Otherwise the tag id must be zero, indicating that the tag still needs to be added.')
|
|
83
|
-
this._ownTag = tag;
|
|
84
|
-
}
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
removeOwnTag(): Note {
|
|
89
|
-
if (!this.ownTag)
|
|
90
|
-
return;
|
|
91
|
-
if (this.ownTag.isNew)
|
|
92
|
-
this._ownTag = null;
|
|
93
|
-
else
|
|
94
|
-
this.ownTag.delete();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
private _tags: Array<NoteTag> = [];
|
|
99
|
-
get tags(): Array<NoteTag> { return this._tags; }
|
|
100
|
-
|
|
101
|
-
addTag(tag: Tag): NoteTag {
|
|
102
|
-
if (tag.isDeleted)
|
|
103
|
-
throw Error('Cannot add a tag marked as deleted to a note');
|
|
104
|
-
if (tag.isNew)
|
|
105
|
-
throw Error('Cannot add a tag that hasn\'t yet been saved to a note');
|
|
106
|
-
if (tag.id == this.id)
|
|
107
|
-
throw Error('Note cannot add its own tag as a linked tag');
|
|
108
|
-
let nt = this.tags.find(x => x.tagId == tag.id);
|
|
109
|
-
if (!!nt) {
|
|
110
|
-
if (nt.isDeleted)
|
|
111
|
-
nt.dirty();
|
|
112
|
-
return nt;
|
|
113
|
-
}
|
|
114
|
-
nt = new NoteTag();
|
|
115
|
-
nt.note = this;
|
|
116
|
-
nt.tag = tag;
|
|
117
|
-
this._tags.push(nt);
|
|
118
|
-
return nt;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
removeTag(tag: Tag): Note {
|
|
122
|
-
const nt = this.tags.find(x => x.tagId == tag.id);
|
|
123
|
-
if (!nt)
|
|
124
|
-
return this;
|
|
125
|
-
|
|
126
|
-
if (nt.isNew)
|
|
127
|
-
this._tags = this._tags.filter(x => x !== nt);
|
|
128
|
-
else
|
|
129
|
-
nt.delete();
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
private _attrs: Array<NoteAttr> = [];
|
|
135
|
-
get attrs(): Array<NoteAttr> { return this._attrs; }
|
|
136
|
-
|
|
137
|
-
addAttr(attr: Attr): NoteAttr {
|
|
138
|
-
if (attr.isDeleted)
|
|
139
|
-
throw Error('Cannot add an attribute marked as deleted to a note');
|
|
140
|
-
if (attr.isNew)
|
|
141
|
-
throw Error('Cannot add an attribute that hasn\'t yet been saved to a note');
|
|
142
|
-
let na = this.attrs.find(x => x.attrId == attr.id);
|
|
143
|
-
if (!!na) {
|
|
144
|
-
if (na.isDeleted)
|
|
145
|
-
na.dirty();
|
|
146
|
-
return na;
|
|
147
|
-
}
|
|
148
|
-
na = new NoteAttr();
|
|
149
|
-
na.note = this;
|
|
150
|
-
na.attr = attr;
|
|
151
|
-
this._attrs.push(na);
|
|
152
|
-
return na;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
removeAttr(attr: Attr): Note {
|
|
156
|
-
const na = this.attrs.find(x => x.attrId == attr.id);
|
|
157
|
-
if (!na)
|
|
158
|
-
return this;
|
|
159
|
-
|
|
160
|
-
if (na.isNew)
|
|
161
|
-
this._attrs = this._attrs.filter(x => x !== na);
|
|
162
|
-
else
|
|
163
|
-
na.delete();
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
duplicate(): Note {
|
|
169
|
-
const output = new Note();
|
|
170
|
-
output.id = this.id;
|
|
171
|
-
output.date = this.date;
|
|
172
|
-
output.text = this.text;
|
|
173
|
-
output.archived = this.archived;
|
|
174
|
-
output.space = this.space;
|
|
175
|
-
output.state = this.state;
|
|
176
|
-
return output;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
validate(throwError: boolean = false): boolean {
|
|
181
|
-
let output = null;
|
|
182
|
-
|
|
183
|
-
if (this.spaceId <= 0)
|
|
184
|
-
output = 'Note spaceId must be greater than zero.';
|
|
185
|
-
else if (!this.isNew && this.id <= 0)
|
|
186
|
-
output = 'Note id must be greater than zero if in non-new state.';
|
|
187
|
-
|
|
188
|
-
if (throwError && output != null)
|
|
189
|
-
throw Error(output);
|
|
190
|
-
|
|
191
|
-
if (!!this.ownTag && !this.ownTag.validate(throwError))
|
|
192
|
-
return false;
|
|
193
|
-
for (const nt of this.tags) {
|
|
194
|
-
if (!nt.validate(throwError))
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
for (const na of this.attrs) {
|
|
198
|
-
if (!na.validate(throwError))
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return output == null;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
import NoteAttr from './NoteAttr';
|
|
3
|
-
import Note from './Note';
|
|
4
|
-
import Attr from './Attr';
|
|
5
|
-
import Tag from './Tag';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
test('Gets initiated as new', () => {
|
|
9
|
-
const na = new NoteAttr();
|
|
10
|
-
expect(na.isNew).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('Gets initiated with sensible defaults', () => {
|
|
14
|
-
const na = new NoteAttr();
|
|
15
|
-
expect(na.noteId).toBe(0);
|
|
16
|
-
expect(na.attrId).toBe(0);
|
|
17
|
-
expect(na.value).toBe(null);
|
|
18
|
-
expect(na.tagId).toBe(null);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
test('Set noteId marks object as dirty if currently clean', () => {
|
|
23
|
-
const na = new NoteAttr().clean();
|
|
24
|
-
na.noteId = 123;
|
|
25
|
-
expect(na.isDirty).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Set noteId doesnt change state if new', () => {
|
|
29
|
-
const na = new NoteAttr().new();
|
|
30
|
-
na.noteId = 123;
|
|
31
|
-
expect(na.isNew).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('Set noteId doesnt change state if value not different', () => {
|
|
35
|
-
const na = new NoteAttr().clean();
|
|
36
|
-
na.noteId = na.noteId;
|
|
37
|
-
expect(na.isClean).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('Setting note with id different than current noteId updates state', () => {
|
|
41
|
-
const na = new NoteAttr();
|
|
42
|
-
na.noteId = 123;
|
|
43
|
-
na.clean();
|
|
44
|
-
const note = new Note();
|
|
45
|
-
note.id = 234;
|
|
46
|
-
|
|
47
|
-
na.note = note;
|
|
48
|
-
|
|
49
|
-
expect(na.noteId).toBe(234);
|
|
50
|
-
expect(na.isDirty).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('Setting note with id same as current noteId preserves state', () => {
|
|
54
|
-
const na = new NoteAttr();
|
|
55
|
-
na.noteId = 27;
|
|
56
|
-
na.clean();
|
|
57
|
-
const note = new Note();
|
|
58
|
-
note.id = 27;
|
|
59
|
-
|
|
60
|
-
na.note = note;
|
|
61
|
-
|
|
62
|
-
expect(na.noteId).toBe(27);
|
|
63
|
-
expect(na.isClean).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('Setting noteId to new value removes note object', () => {
|
|
67
|
-
const na = new NoteAttr();
|
|
68
|
-
const note = new Note();
|
|
69
|
-
note.id = 80;
|
|
70
|
-
na.note = note;
|
|
71
|
-
|
|
72
|
-
na.noteId = 81;
|
|
73
|
-
|
|
74
|
-
expect(na.note).toBeNull();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('Setting noteId to same as current note id preserves it', () => {
|
|
78
|
-
const na = new NoteAttr();
|
|
79
|
-
const note = new Note();
|
|
80
|
-
note.id = 80;
|
|
81
|
-
na.note = note;
|
|
82
|
-
|
|
83
|
-
na.noteId = 80;
|
|
84
|
-
|
|
85
|
-
expect(na.note).not.toBeNull();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
test('Set attrId marks object as dirty if currently clean', () => {
|
|
90
|
-
const na = new NoteAttr().clean();
|
|
91
|
-
na.attrId = 123;
|
|
92
|
-
expect(na.isDirty).toBe(true);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('Set attrId doesnt change state if new', () => {
|
|
96
|
-
const na = new NoteAttr().new();
|
|
97
|
-
na.attrId = 123;
|
|
98
|
-
expect(na.isNew).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('Set attrId doesnt change state if value not different', () => {
|
|
102
|
-
const na = new NoteAttr().clean();
|
|
103
|
-
na.attrId = na.attrId;
|
|
104
|
-
expect(na.isClean).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('Setting attr with id different than current attrId updates state', () => {
|
|
108
|
-
const na = new NoteAttr();
|
|
109
|
-
na.attrId = 123;
|
|
110
|
-
na.clean();
|
|
111
|
-
const attr = new Attr();
|
|
112
|
-
attr.id = 234;
|
|
113
|
-
|
|
114
|
-
na.attr = attr;
|
|
115
|
-
|
|
116
|
-
expect(na.attrId).toBe(234);
|
|
117
|
-
expect(na.isDirty).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('Setting attr with id same as current attrId preserves state', () => {
|
|
121
|
-
const na = new NoteAttr();
|
|
122
|
-
na.attrId = 27;
|
|
123
|
-
na.value = '';
|
|
124
|
-
na.clean();
|
|
125
|
-
const attr = new Attr();
|
|
126
|
-
attr.id = 27;
|
|
127
|
-
|
|
128
|
-
na.attr = attr;
|
|
129
|
-
|
|
130
|
-
expect(na.attrId).toBe(27);
|
|
131
|
-
expect(na.isClean).toBe(true);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('Setting attrId to new value removes attr object', () => {
|
|
135
|
-
const na = new NoteAttr();
|
|
136
|
-
const attr = new Attr();
|
|
137
|
-
attr.id = 80;
|
|
138
|
-
na.attr = attr;
|
|
139
|
-
|
|
140
|
-
na.attrId = 81;
|
|
141
|
-
|
|
142
|
-
expect(na.attr).toBeNull();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('Setting attrId to same as current attr id preserves it', () => {
|
|
146
|
-
const na = new NoteAttr();
|
|
147
|
-
const attr = new Attr();
|
|
148
|
-
attr.id = 80;
|
|
149
|
-
na.attr = attr;
|
|
150
|
-
|
|
151
|
-
na.attrId = 80;
|
|
152
|
-
|
|
153
|
-
expect(na.attr).not.toBeNull();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('Setting attr updates the default value', () => {
|
|
157
|
-
const na = new NoteAttr();
|
|
158
|
-
const attr1 = new Attr().asNumber();
|
|
159
|
-
attr1.id = 1;
|
|
160
|
-
|
|
161
|
-
na.attr = attr1;
|
|
162
|
-
|
|
163
|
-
expect(na.value).toBe(0);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('Setting attr to null clears out value', () => {
|
|
167
|
-
const na = new NoteAttr();
|
|
168
|
-
const attr = new Attr().asNumber();
|
|
169
|
-
attr.id = 1;
|
|
170
|
-
na.attr = attr;
|
|
171
|
-
|
|
172
|
-
na.attr = null;
|
|
173
|
-
|
|
174
|
-
expect(na.value).toBe(null);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('Setting attr to new value of same type doesnt update value', () => {
|
|
178
|
-
const na = new NoteAttr();
|
|
179
|
-
const attr1 = new Attr().asNumber();
|
|
180
|
-
const attr2 = new Attr().asNumber();
|
|
181
|
-
attr1.id = 1;
|
|
182
|
-
attr2.id = 2;
|
|
183
|
-
na.attr = attr1;
|
|
184
|
-
na.value = 123;
|
|
185
|
-
|
|
186
|
-
na.attr = attr2;
|
|
187
|
-
|
|
188
|
-
expect(na.value).toBe(123);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('Setting attr to new value of different type does update value', () => {
|
|
192
|
-
const na = new NoteAttr();
|
|
193
|
-
const attr1 = new Attr().asNumber();
|
|
194
|
-
const attr2 = new Attr().asText();
|
|
195
|
-
attr1.id = 1;
|
|
196
|
-
attr2.id = 2;
|
|
197
|
-
na.attr = attr1;
|
|
198
|
-
na.value = 123;
|
|
199
|
-
|
|
200
|
-
na.attr = attr2;
|
|
201
|
-
|
|
202
|
-
expect(na.value).toBe('');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
test('Set value marks object as dirty if currently clean', () => {
|
|
207
|
-
const na = new NoteAttr().clean();
|
|
208
|
-
na.value = 123;
|
|
209
|
-
expect(na.isDirty).toBe(true);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test('Set value doesnt change state if new', () => {
|
|
213
|
-
const na = new NoteAttr().new();
|
|
214
|
-
na.value = 123;
|
|
215
|
-
expect(na.isNew).toBe(true);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('Set value doesnt change state if value not different', () => {
|
|
219
|
-
const na = new NoteAttr().clean();
|
|
220
|
-
na.value = na.value;
|
|
221
|
-
expect(na.isClean).toBe(true);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
test('Set tagId marks object as dirty if currently clean', () => {
|
|
226
|
-
const na = new NoteAttr().clean();
|
|
227
|
-
na.tagId = 123;
|
|
228
|
-
expect(na.isDirty).toBe(true);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('Set tagId doesnt change state if new', () => {
|
|
232
|
-
const na = new NoteAttr().new();
|
|
233
|
-
na.tagId = 123;
|
|
234
|
-
expect(na.isNew).toBe(true);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test('Set tagId doesnt change state if value not different', () => {
|
|
238
|
-
const na = new NoteAttr().clean();
|
|
239
|
-
na.tagId = na.tagId;
|
|
240
|
-
expect(na.isClean).toBe(true);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test('Setting tag with id different than current tagId updates state', () => {
|
|
244
|
-
const na = new NoteAttr();
|
|
245
|
-
na.tagId = 123;
|
|
246
|
-
na.clean();
|
|
247
|
-
const tag = new Tag();
|
|
248
|
-
tag.id = 234;
|
|
249
|
-
|
|
250
|
-
na.tag = tag;
|
|
251
|
-
|
|
252
|
-
expect(na.tagId).toBe(234);
|
|
253
|
-
expect(na.isDirty).toBe(true);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test('Setting tag with id same as current tagId preserves state', () => {
|
|
257
|
-
const na = new NoteAttr();
|
|
258
|
-
na.tagId = 27;
|
|
259
|
-
na.clean();
|
|
260
|
-
const tag = new Tag();
|
|
261
|
-
tag.id = 27;
|
|
262
|
-
|
|
263
|
-
na.tag = tag;
|
|
264
|
-
|
|
265
|
-
expect(na.tagId).toBe(27);
|
|
266
|
-
expect(na.isClean).toBe(true);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
test('Setting tagId to new value removes tag object', () => {
|
|
270
|
-
const na = new NoteAttr();
|
|
271
|
-
const tag = new Tag();
|
|
272
|
-
tag.id = 80;
|
|
273
|
-
na.tag = tag;
|
|
274
|
-
|
|
275
|
-
na.tagId = 81;
|
|
276
|
-
|
|
277
|
-
expect(na.tag).toBeNull();
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test('Setting tagId to same as current tag id preserves it', () => {
|
|
281
|
-
const na = new NoteAttr();
|
|
282
|
-
const tag = new Tag();
|
|
283
|
-
tag.id = 80;
|
|
284
|
-
na.tag = tag;
|
|
285
|
-
|
|
286
|
-
na.tagId = 80;
|
|
287
|
-
|
|
288
|
-
expect(na.tag).not.toBeNull();
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
test('Setting tag to null also nulls tagId', () => {
|
|
292
|
-
const na = new NoteAttr();
|
|
293
|
-
const tag = new Tag();
|
|
294
|
-
tag.id = 80;
|
|
295
|
-
na.tag = tag;
|
|
296
|
-
expect(na.tagId).toBe(80);
|
|
297
|
-
|
|
298
|
-
na.tag = null;
|
|
299
|
-
|
|
300
|
-
expect(na.tagId).toBe(null);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
test('Can duplicate itself', () => {
|
|
305
|
-
const na = new NoteAttr();
|
|
306
|
-
const note = new Note();
|
|
307
|
-
note.id = 24;
|
|
308
|
-
const attr = new Attr();
|
|
309
|
-
attr.id = 25;
|
|
310
|
-
const tag = new Tag();
|
|
311
|
-
tag.id = 26;
|
|
312
|
-
na.note = note;
|
|
313
|
-
na.attr = attr;
|
|
314
|
-
na.tag = tag;
|
|
315
|
-
na.value = 'hello';
|
|
316
|
-
|
|
317
|
-
const copy = na.duplicate();
|
|
318
|
-
|
|
319
|
-
expect(copy.note).toBe(na.note);
|
|
320
|
-
expect(copy.noteId).toBe(na.noteId);
|
|
321
|
-
expect(copy.attr).toBe(na.attr);
|
|
322
|
-
expect(copy.attrId).toBe(na.attrId);
|
|
323
|
-
expect(copy.tag).toBe(na.tag);
|
|
324
|
-
expect(copy.tagId).toBe(na.tagId);
|
|
325
|
-
expect(copy.value).toBe(na.value);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
test('validate passes if noteId is 0 and state is new', () => {
|
|
330
|
-
const nt = new NoteAttr();
|
|
331
|
-
nt.attrId = 123;
|
|
332
|
-
expect(nt.validate()).toBe(true);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test('validate fails if noteId is 0 and state is not new', () => {
|
|
336
|
-
const nt = new NoteAttr();
|
|
337
|
-
nt.attrId = 123;
|
|
338
|
-
nt.clean();
|
|
339
|
-
expect(nt.validate()).toBe(false);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
test('validate fails if attrId is 0', () => {
|
|
343
|
-
const nt = new NoteAttr();
|
|
344
|
-
nt.noteId = 123;
|
|
345
|
-
expect(nt.validate()).toBe(false);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test('validate throws error if arg set to true', () => {
|
|
349
|
-
const nt = new NoteAttr();
|
|
350
|
-
expect(() => nt.validate(true)).toThrowError();
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
test('validate succeeds if noteId & attrId are both positive values', () => {
|
|
354
|
-
const nt = new NoteAttr();
|
|
355
|
-
nt.noteId = 123;
|
|
356
|
-
nt.attrId = 234;
|
|
357
|
-
expect(nt.validate()).toBe(true);
|
|
358
|
-
});
|
package/src/models/NoteAttr.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import ModelWithState from './ModelWithState';
|
|
4
|
-
import Note from './Note';
|
|
5
|
-
import Attr from './Attr';
|
|
6
|
-
import Tag from './Tag';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export default class NoteAttr extends ModelWithState<NoteAttr> {
|
|
10
|
-
private _noteId: number = 0;
|
|
11
|
-
get noteId(): number { return this._noteId; }
|
|
12
|
-
set noteId(value: number) {
|
|
13
|
-
if (value !== this._noteId) {
|
|
14
|
-
this._noteId = value;
|
|
15
|
-
if (value !== this.note?.id ?? 0)
|
|
16
|
-
this._note = null;
|
|
17
|
-
if (this.isClean)
|
|
18
|
-
this.dirty();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private _note: Note = null;
|
|
23
|
-
get note(): Note { return this._note; }
|
|
24
|
-
set note(value: Note) {
|
|
25
|
-
this._note = value;
|
|
26
|
-
this.noteId = value?.id ?? 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
private _attrId: number = 0;
|
|
31
|
-
get attrId(): number { return this._attrId; }
|
|
32
|
-
set attrId(value: number) {
|
|
33
|
-
if (value !== this._attrId) {
|
|
34
|
-
this._attrId = value;
|
|
35
|
-
if (value !== this.attr?.id ?? 0)
|
|
36
|
-
this._attr = null;
|
|
37
|
-
if (this.isClean)
|
|
38
|
-
this.dirty();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private _attr: Attr = null;
|
|
43
|
-
get attr(): Attr { return this._attr; }
|
|
44
|
-
set attr(newAttr: Attr) {
|
|
45
|
-
const oldAttr = this._attr;
|
|
46
|
-
this._attr = newAttr;
|
|
47
|
-
if (!!newAttr) {
|
|
48
|
-
if (!oldAttr || newAttr.type != oldAttr.type)
|
|
49
|
-
this.value = newAttr.defaultValue;
|
|
50
|
-
}
|
|
51
|
-
else
|
|
52
|
-
this.value = null;
|
|
53
|
-
this.attrId = newAttr?.id ?? 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
private _value: any = null;
|
|
58
|
-
get value(): any { return this._value; }
|
|
59
|
-
set value(newVal: any) {
|
|
60
|
-
if (newVal != this._value) {
|
|
61
|
-
this._value = newVal;
|
|
62
|
-
if (this.isClean)
|
|
63
|
-
this.dirty();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
private _tagId: number = null;
|
|
69
|
-
get tagId(): number { return this._tagId; }
|
|
70
|
-
set tagId(value: number) {
|
|
71
|
-
if (value !== this._tagId) {
|
|
72
|
-
this._tagId = value;
|
|
73
|
-
if (value !== this.tag?.id)
|
|
74
|
-
this._tag = null;
|
|
75
|
-
if (this.isClean)
|
|
76
|
-
this.dirty();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private _tag: Tag = null;
|
|
81
|
-
get tag(): Tag { return this._tag; }
|
|
82
|
-
set tag(value: Tag) {
|
|
83
|
-
this._tag = value;
|
|
84
|
-
this.tagId = value?.id ?? null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
duplicate(): NoteAttr {
|
|
89
|
-
const output = new NoteAttr();
|
|
90
|
-
output.noteId = this.noteId;
|
|
91
|
-
output.note = this.note;
|
|
92
|
-
output.attrId = this.attrId;
|
|
93
|
-
output.attr = this.attr;
|
|
94
|
-
output.tagId = this.tagId;
|
|
95
|
-
output.tag = this.tag;
|
|
96
|
-
output.value = this.value;
|
|
97
|
-
return output;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
validate(throwError: boolean = false): boolean {
|
|
102
|
-
let output = null;
|
|
103
|
-
|
|
104
|
-
if (this.noteId <= 0 && !this.isNew)
|
|
105
|
-
output = 'NoteAttr noteId must be greater than zero';
|
|
106
|
-
else if (this.attrId <= 0)
|
|
107
|
-
output = 'NoteAttr attrId must be greater than zero';
|
|
108
|
-
|
|
109
|
-
if (throwError && output != null)
|
|
110
|
-
throw Error(output);
|
|
111
|
-
return output == null;
|
|
112
|
-
}
|
|
113
|
-
}
|