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.
@@ -0,0 +1,238 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { AxiosResponse } from 'axios';
3
+
4
+ declare class Attr_2 extends ModelWithState<Attr_2> {
5
+ id: number;
6
+ private _name;
7
+ get name(): string;
8
+ set name(value: string);
9
+ private _type;
10
+ get type(): AttrType;
11
+ set type(value: AttrType);
12
+ get isText(): boolean;
13
+ get isNumber(): boolean;
14
+ get isBoolean(): boolean;
15
+ get isDate(): boolean;
16
+ asText(): Attr_2;
17
+ asNumber(): Attr_2;
18
+ asBoolean(): Attr_2;
19
+ asDate(): Attr_2;
20
+ private _spaceId;
21
+ get spaceId(): number;
22
+ set spaceId(value: number);
23
+ private _space;
24
+ get space(): Space;
25
+ set space(value: Space);
26
+ duplicate(): Attr_2;
27
+ validate(throwError?: boolean): boolean;
28
+ get defaultValue(): any;
29
+ }
30
+ export { Attr_2 as Attr }
31
+
32
+ declare const ATTR_TYPE: {
33
+ TEXT: string;
34
+ NUMBER: string;
35
+ BOOLEAN: string;
36
+ DATE: string;
37
+ };
38
+
39
+ declare type AttrType = keyof typeof ATTR_TYPE;
40
+
41
+ export declare class Environment {
42
+ private _client;
43
+ get client(): NotuClient;
44
+ private _spaces;
45
+ get spaces(): Array<Space>;
46
+ constructor(client: NotuClient);
47
+ loadSpaces(): Promise<Array<Space>>;
48
+ saveSpace(space: Space): Promise<Space>;
49
+ getNotes(query: string, spaceId: number): Promise<Array<Note>>;
50
+ getNoteCount(query: string, spaceId: number): Promise<number>;
51
+ saveNote(note: Note): Promise<Note>;
52
+ saveNotes(notes: Array<Note>): Promise<Array<Note>>;
53
+ customJob(name: string, data: any): Promise<any>;
54
+ }
55
+
56
+ export declare class HttpClient {
57
+ private _url;
58
+ get url(): string;
59
+ private _token;
60
+ get token(): string;
61
+ set token(value: string);
62
+ private _httpRequester;
63
+ constructor(url: string, httpRequester?: (config: AxiosRequestConfig<any>) => Promise<AxiosResponse<any, any>>);
64
+ login(username: string, password: string): Promise<NotuLoginResult>;
65
+ getSpaces(): Promise<Array<Space>>;
66
+ saveSpace(space: Space): Promise<Space>;
67
+ getNotes(query: string, spaceId: number): Promise<Array<Note>>;
68
+ getNoteCount(query: string, spaceId: number): Promise<number>;
69
+ saveNotes(notes: Array<Note>): Promise<Array<Note>>;
70
+ customJob(name: string, data: any): Promise<any>;
71
+ }
72
+
73
+ declare const MODEL_STATE: {
74
+ NEW: string;
75
+ CLEAN: string;
76
+ DIRTY: string;
77
+ DELETED: string;
78
+ };
79
+
80
+ declare type ModelState = keyof typeof MODEL_STATE;
81
+
82
+ declare class ModelWithState<T extends ModelWithState<T>> {
83
+ state: ModelState;
84
+ new(): T;
85
+ clean(): T;
86
+ dirty(): T;
87
+ delete(): T;
88
+ get isNew(): boolean;
89
+ get isClean(): boolean;
90
+ get isDirty(): boolean;
91
+ get isDeleted(): boolean;
92
+ validate(throwError?: boolean): boolean;
93
+ }
94
+
95
+ export declare class Note extends ModelWithState<Note> {
96
+ id: number;
97
+ private _date;
98
+ get date(): Date;
99
+ set date(value: Date);
100
+ private _text;
101
+ get text(): string;
102
+ set text(value: string);
103
+ private _archived;
104
+ get archived(): boolean;
105
+ set archived(value: boolean);
106
+ private _spaceId;
107
+ get spaceId(): number;
108
+ set spaceId(value: number);
109
+ private _space;
110
+ get space(): Space;
111
+ set space(value: Space);
112
+ private _ownTag;
113
+ get ownTag(): Tag;
114
+ setOwnTag(tag: string | Tag): Note;
115
+ removeOwnTag(): Note;
116
+ private _tags;
117
+ get tags(): Array<NoteTag>;
118
+ addTag(tag: Tag): NoteTag;
119
+ removeTag(tag: Tag): Note;
120
+ private _attrs;
121
+ get attrs(): Array<NoteAttr>;
122
+ addAttr(attr: Attr_2): NoteAttr;
123
+ removeAttr(attr: Attr_2): Note;
124
+ duplicate(): Note;
125
+ validate(throwError?: boolean): boolean;
126
+ }
127
+
128
+ export declare class NoteAttr extends ModelWithState<NoteAttr> {
129
+ private _noteId;
130
+ get noteId(): number;
131
+ set noteId(value: number);
132
+ private _note;
133
+ get note(): Note;
134
+ set note(value: Note);
135
+ private _attrId;
136
+ get attrId(): number;
137
+ set attrId(value: number);
138
+ private _attr;
139
+ get attr(): Attr_2;
140
+ set attr(newAttr: Attr_2);
141
+ private _value;
142
+ get value(): any;
143
+ set value(newVal: any);
144
+ private _tagId;
145
+ get tagId(): number;
146
+ set tagId(value: number);
147
+ private _tag;
148
+ get tag(): Tag;
149
+ set tag(value: Tag);
150
+ duplicate(): NoteAttr;
151
+ validate(throwError?: boolean): boolean;
152
+ }
153
+
154
+ export declare class NoteTag extends ModelWithState<NoteTag> {
155
+ private _noteId;
156
+ get noteId(): number;
157
+ set noteId(value: number);
158
+ private _note;
159
+ get note(): Note;
160
+ set note(value: Note);
161
+ private _tagId;
162
+ get tagId(): number;
163
+ set tagId(value: number);
164
+ private _tag;
165
+ get tag(): Tag;
166
+ set tag(value: Tag);
167
+ get attrs(): Array<NoteAttr>;
168
+ addAttr(attr: Attr_2): NoteAttr;
169
+ duplicate(): NoteTag;
170
+ validate(throwError?: boolean): boolean;
171
+ }
172
+
173
+ declare interface NotuClient {
174
+ login(username: string, password: string): Promise<NotuLoginResult>;
175
+ getSpaces(): Promise<Array<Space>>;
176
+ saveSpace(space: Space): Promise<Space>;
177
+ getNotes(query: string, spaceId: number): Promise<Array<Note>>;
178
+ getNoteCount(query: string, spaceId: number): Promise<number>;
179
+ saveNotes(notes: Array<Note>): Promise<Array<Note>>;
180
+ customJob(name: string, data: any): Promise<any>;
181
+ }
182
+
183
+ declare interface NotuLoginResult {
184
+ success: boolean;
185
+ error: string;
186
+ token: string;
187
+ }
188
+
189
+ declare class ParsedAttr {
190
+ space: string;
191
+ name: string;
192
+ exists: boolean;
193
+ tagNameFilters: Array<ParsedTag>;
194
+ }
195
+
196
+ declare class ParsedQuery {
197
+ where: string;
198
+ order: string;
199
+ tags: Array<ParsedTag>;
200
+ attrs: Array<ParsedAttr>;
201
+ }
202
+
203
+ declare class ParsedTag {
204
+ space: string;
205
+ name: string;
206
+ searchDepth: number;
207
+ strictSearchDepth: boolean;
208
+ includeOwner: boolean;
209
+ }
210
+
211
+ export declare function parseQuery(query: string): ParsedQuery;
212
+
213
+ export declare class Space extends ModelWithState<Space> {
214
+ id: number;
215
+ private _name;
216
+ get name(): string;
217
+ set name(value: string);
218
+ constructor(name?: string);
219
+ duplicate(): Space;
220
+ validate(throwError?: boolean): boolean;
221
+ }
222
+
223
+ export declare class Tag extends ModelWithState<Tag> {
224
+ private _id;
225
+ get id(): number;
226
+ set id(value: number);
227
+ private _name;
228
+ get name(): string;
229
+ set name(value: string);
230
+ private _color;
231
+ get color(): string;
232
+ set color(value: string);
233
+ constructor(name?: string);
234
+ duplicate(): Tag;
235
+ validate(throwError?: boolean): boolean;
236
+ }
237
+
238
+ export { }
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "notu",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/notu.js",
6
6
  "unpkg": "dist/notu.js",
7
+ "files": [
8
+ "/dist"
9
+ ],
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "https://github.com/jamescoyle1989/notu.git"
@@ -18,6 +21,7 @@
18
21
  "devDependencies": {
19
22
  "typescript": "^5.0.2",
20
23
  "vite": "^4.4.5",
24
+ "vite-plugin-dts": "^3.6.3",
21
25
  "vitest": "^0.34.4"
22
26
  },
23
27
  "dependencies": {
@@ -1,76 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import Environment from './Environment';
3
- import { NotuClient, NotuLoginResult } from './services/HttpClient';
4
- import Space from './models/Space';
5
- import { Note } from '.';
6
-
7
-
8
- class TestClient implements NotuClient {
9
- login(username: string, password: string): Promise<NotuLoginResult> {
10
- return Promise.resolve({ success: true, error: null, token: 'qwer.asdf.zxcv' });
11
- }
12
-
13
- getSpaces(): Promise<Array<Space>> {
14
- const output = [
15
- new Space('Space 1'),
16
- new Space('Space 2')
17
- ];
18
- output[0].id = 1;
19
- output[1].id = 2;
20
- for (const space of output)
21
- space.clean();
22
- return Promise.resolve(output);
23
- }
24
-
25
- saveSpace(space: Space): Promise<Space> {
26
- return Promise.resolve(space.duplicate());
27
- }
28
-
29
- getNotes(query: string, spaceId: number): Promise<Array<Note>> {
30
- const output = [
31
- new Note(),
32
- new Note(),
33
- new Note()
34
- ];
35
- for (let i = 0; i < output.length; i++) {
36
- output[i].text = 'Note ' + (i+1);
37
- output[i].id = i+1;
38
- output[i].spaceId = (i % 2) + 1;
39
- output[i].clean();
40
- }
41
- return Promise.resolve(output);
42
- }
43
-
44
- getNoteCount(query: string, spaceId: number): Promise<number> {
45
- return Promise.resolve(3);
46
- }
47
-
48
- saveNotes(notes: Array<Note>): Promise<Array<Note>> {
49
- return Promise.resolve(notes.map(n => n.duplicate()));
50
- }
51
-
52
- customJob(name: string, data: any): Promise<any> {
53
- return Promise.resolve({ test: 123 });
54
- }
55
- }
56
-
57
-
58
- test('constructor takes client parameter', () => {
59
- const client = new TestClient();
60
- const env = new Environment(client);
61
-
62
- expect(env.client).toBe(client);
63
- });
64
-
65
- test('constructor throws error if client not set', () => {
66
- expect(() => new Environment(null)).toThrowError();
67
- });
68
-
69
-
70
- test('loadSpaces stores the list of spaces on the environment', async () => {
71
- const env = new Environment(new TestClient());
72
-
73
- await env.loadSpaces();
74
-
75
- expect(env.spaces.length).toBe(2);
76
- });
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- import { Note } from '.';
4
- import Space from './models/Space';
5
- import { NotuClient } from './services/HttpClient';
6
-
7
-
8
- export default class Environment {
9
-
10
- private _client: NotuClient = null;
11
- get client(): NotuClient { return this._client; }
12
-
13
- private _spaces: Array<Space> = [];
14
- get spaces(): Array<Space> { return this._spaces; }
15
-
16
- constructor(client: NotuClient) {
17
- if (!client)
18
- throw Error('Client must be set on Environment constructor');
19
- this._client = client;
20
- }
21
-
22
- async loadSpaces(): Promise<Array<Space>> {
23
- this._spaces = await this.client.getSpaces();
24
- return this.spaces;
25
- }
26
-
27
- async saveSpace(space: Space): Promise<Space> {
28
- return await this.client.saveSpace(space);
29
- }
30
-
31
- async getNotes(query: string, spaceId: number): Promise<Array<Note>> {
32
- return await this.client.getNotes(query, spaceId);
33
- }
34
-
35
- async getNoteCount(query: string, spaceId: number): Promise<number> {
36
- return await this.client.getNoteCount(query, spaceId);
37
- }
38
-
39
- async saveNote(note: Note): Promise<Note> {
40
- return (await this.client.saveNotes([note]))[0];
41
- }
42
-
43
- async saveNotes(notes: Array<Note>): Promise<Array<Note>> {
44
- return await this.client.saveNotes(notes);
45
- }
46
-
47
- async customJob(name: string, data: any): Promise<any> {
48
- return await this.client.customJob(name, data);
49
- }
50
-
51
- }
package/src/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import Attr from './models/Attr';
2
- import Environment from './Environment';
3
- import HttpClient from './services/HttpClient';
4
- import Note from './models/Note';
5
- import NoteAttr from './models/NoteAttr';
6
- import NoteTag from './models/NoteTag';
7
- import parseQuery from './services/QueryParser';
8
- import Space from './models/Space';
9
- import Tag from './models/Tag';
10
-
11
- export {
12
- Attr,
13
- Environment,
14
- HttpClient,
15
- Note,
16
- NoteAttr,
17
- NoteTag,
18
- parseQuery,
19
- Space,
20
- Tag
21
- };
@@ -1,214 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import Attr from './Attr';
3
- import Space from './Space';
4
-
5
-
6
- test('Gets initiated as new', () => {
7
- const attr = new Attr();
8
- expect(attr.isNew).toBe(true);
9
- });
10
-
11
-
12
- test('Set name marks attr as dirty if currently clean', () => {
13
- const attr = new Attr().clean();
14
- attr.name = 'asdf';
15
- expect(attr.isDirty).toBe(true);
16
- });
17
-
18
- test('Set name doesnt change attr state if new', () => {
19
- const attr = new Attr().new();
20
- attr.name = 'asdf';
21
- expect(attr.isNew).toBe(true);
22
- });
23
-
24
- test('Set name doesnt change attr state if value not different', () => {
25
- const attr = new Attr().clean();
26
- attr.name = '';
27
- expect(attr.isClean).toBe(true);
28
- });
29
-
30
-
31
- test('Set type is allowed if attr is new', () => {
32
- const attr = new Attr().new();
33
- attr.type = 'BOOLEAN';
34
- expect(attr.type).toBe('BOOLEAN');
35
- });
36
-
37
- test('Set type is not allowed if attr is not new', () => {
38
- const attr = new Attr().clean();
39
- expect(() => attr.type = 'BOOLEAN').toThrowError();
40
- });
41
-
42
- test('isText returns true if type is text', () => {
43
- const attr = new Attr();
44
- attr.type = 'TEXT';
45
- expect(attr.isText).toBe(true);
46
- attr.type = 'NUMBER';
47
- expect(attr.isText).toBe(false);
48
- });
49
-
50
- test('isNumber returns true if type is number', () => {
51
- const attr = new Attr();
52
- attr.type = 'TEXT';
53
- expect(attr.isNumber).toBe(false);
54
- attr.type = 'NUMBER';
55
- expect(attr.isNumber).toBe(true);
56
- });
57
-
58
- test('isBoolean returns true if type is boolean', () => {
59
- const attr = new Attr();
60
- attr.type = 'TEXT';
61
- expect(attr.isBoolean).toBe(false);
62
- attr.type = 'BOOLEAN';
63
- expect(attr.isBoolean).toBe(true);
64
- });
65
-
66
- test('isDate returns true if type is date', () => {
67
- const attr = new Attr();
68
- attr.type = 'TEXT';
69
- expect(attr.isDate).toBe(false);
70
- attr.type = 'DATE';
71
- expect(attr.isDate).toBe(true);
72
- });
73
-
74
- test('asText sets type', () => {
75
- const attr = new Attr().asText();
76
- expect(attr.type).toBe('TEXT');
77
- });
78
-
79
- test('asNumber sets type', () => {
80
- const attr = new Attr().asNumber();
81
- expect(attr.type).toBe('NUMBER');
82
- });
83
-
84
- test('asBoolean sets type', () => {
85
- const attr = new Attr().asBoolean();
86
- expect(attr.type).toBe('BOOLEAN');
87
- });
88
-
89
- test('asDate sets type', () => {
90
- const attr = new Attr().asDate();
91
- expect(attr.type).toBe('DATE');
92
- });
93
-
94
-
95
- test('Set spaceId marks attr as dirty if currently clean', () => {
96
- const attr = new Attr().clean();
97
- attr.spaceId = 123;
98
- expect(attr.isDirty).toBe(true);
99
- });
100
-
101
- test('Set spaceId doesnt change attr state if new', () => {
102
- const attr = new Attr().new();
103
- attr.spaceId = 123;
104
- expect(attr.isNew).toBe(true);
105
- });
106
-
107
- test('Set spaceId doesnt change attr state if value not different', () => {
108
- const attr = new Attr().clean();
109
- attr.spaceId = attr.spaceId;
110
- expect(attr.isClean).toBe(true);
111
- });
112
-
113
- test('Setting space with id different than current spaceId updates state', () => {
114
- const attr = new Attr();
115
- attr.spaceId = 57;
116
- attr.clean();
117
- const space = new Space('hello');
118
- space.id = 60;
119
-
120
- attr.space = space;
121
-
122
- expect(attr.spaceId).toBe(60);
123
- expect(attr.isDirty).toBe(true);
124
- });
125
-
126
- test('Setting space with id same as current spaceId preserves state', () => {
127
- const attr = new Attr();
128
- attr.spaceId = 80;
129
- attr.clean();
130
- const space = new Space('hello');
131
- space.id = 80;
132
-
133
- attr.space = space;
134
-
135
- expect(attr.spaceId).toBe(80);
136
- expect(attr.isClean).toBe(true);
137
- });
138
-
139
- test('Setting spaceId to new value removes space object', () => {
140
- const attr = new Attr();
141
- const space = new Space('hello');
142
- space.id = 80;
143
- attr.space = space;
144
-
145
- attr.spaceId = 81;
146
-
147
- expect(attr.space).toBeNull();
148
- });
149
-
150
- test('Setting spaceId to same as current space id preserves it', () => {
151
- const attr = new Attr();
152
- const space = new Space('hello');
153
- space.id = 80;
154
- attr.space = space;
155
-
156
- attr.spaceId = 80;
157
-
158
- expect(attr.space.name).toBe('hello');
159
- });
160
-
161
-
162
- test('Can duplicate itself', () => {
163
- const attr = new Attr();
164
- const space = new Space('hello');
165
- space.id = 123;
166
- attr.space = space;
167
- const copy = attr.duplicate();
168
- expect(copy.id).toBe(attr.id);
169
- expect(copy.name).toBe(attr.name);
170
- expect(copy.type).toBe(attr.type);
171
- expect(copy.space).toBe(attr.space);
172
- expect(copy.spaceId).toBe(attr.spaceId);
173
- });
174
-
175
-
176
- test('validate fails if spaceId is 0', () => {
177
- const model = new Attr();
178
- model.spaceId = 0;
179
- expect(model.validate()).toBe(false);
180
- });
181
-
182
- test('validate fails if not new and id <= 0', () => {
183
- const model = new Attr().clean();
184
- model.id = 0;
185
- model.spaceId = 123;
186
- expect(model.validate()).toBe(false);
187
- });
188
-
189
- test('validate throws error if arg set to true', () => {
190
- const model = new Attr();
191
- model.spaceId = 0;
192
- expect(() => model.validate(true)).toThrowError();
193
- });
194
-
195
-
196
- test('defaultValue returns correct value for text', () => {
197
- const model = new Attr().asText();
198
- expect(model.defaultValue).toBe('');
199
- });
200
-
201
- test('defaultValue returns correct value for number', () => {
202
- const model = new Attr().asNumber();
203
- expect(model.defaultValue).toBe(0);
204
- });
205
-
206
- test('defaultValue returns correct value for boolean', () => {
207
- const model = new Attr().asBoolean();
208
- expect(model.defaultValue).toBe(false);
209
- });
210
-
211
- test('defaultValue returns correct value for date', () => {
212
- const model = new Attr().asDate();
213
- expect(model.defaultValue.getSeconds()).toBe(new Date().getSeconds());
214
- });