inkdrop-model 2.11.1 → 2.11.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/lib/book.d.ts +3 -0
- package/lib/file.d.ts +3 -0
- package/lib/index.esm.js +115 -75
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +127 -74
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/note.d.ts +3 -0
- package/lib/tag.d.ts +3 -0
- package/lib/utils.d.ts +1 -0
- package/lib/validator.d.ts +1 -0
- package/package.json +10 -7
package/lib/book.d.ts
CHANGED
|
@@ -27,5 +27,8 @@ export type Book = BookMetadata & {
|
|
|
27
27
|
export type EncryptedBook = BookMetadata & {
|
|
28
28
|
encryptedData: EncryptedData;
|
|
29
29
|
};
|
|
30
|
+
export declare const BOOK_DOCID_PREFIX = "book:";
|
|
30
31
|
declare const validateBook: ValidateFunction<Book>;
|
|
31
32
|
export { BookSchema, validateBook };
|
|
33
|
+
export declare function createBookId(): string;
|
|
34
|
+
export declare function validateBookId(docId: string): boolean;
|
package/lib/file.d.ts
CHANGED
|
@@ -29,5 +29,8 @@ export type File = {
|
|
|
29
29
|
export type EncryptedFile = File & {
|
|
30
30
|
encryptionData: EncryptionMetadata;
|
|
31
31
|
};
|
|
32
|
+
export declare const FILE_DOCID_PREFIX = "file:";
|
|
32
33
|
declare const validateFile: ValidateFunction<File>;
|
|
33
34
|
export { FileSchema, validateFile };
|
|
35
|
+
export declare function createFileId(): string;
|
|
36
|
+
export declare function validateFileId(docId: string): boolean;
|
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import validator from '../validators/note';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
2
3
|
import validator$1 from '../validators/book';
|
|
3
4
|
import validator$2 from '../validators/tag';
|
|
4
5
|
import validator$3 from '../validators/file';
|
|
@@ -129,6 +130,93 @@ var note = {
|
|
|
129
130
|
required: required$3
|
|
130
131
|
};
|
|
131
132
|
|
|
133
|
+
function createDocId(prefix) {
|
|
134
|
+
var id = nanoid(8);
|
|
135
|
+
return "".concat(prefix).concat(id);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/******************************************************************************
|
|
139
|
+
Copyright (c) Microsoft Corporation.
|
|
140
|
+
|
|
141
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
142
|
+
purpose with or without fee is hereby granted.
|
|
143
|
+
|
|
144
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
145
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
146
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
147
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
148
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
149
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
150
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
151
|
+
***************************************************************************** */
|
|
152
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
153
|
+
|
|
154
|
+
var extendStatics = function(d, b) {
|
|
155
|
+
extendStatics = Object.setPrototypeOf ||
|
|
156
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
157
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
158
|
+
return extendStatics(d, b);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
function __extends(d, b) {
|
|
162
|
+
if (typeof b !== "function" && b !== null)
|
|
163
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
164
|
+
extendStatics(d, b);
|
|
165
|
+
function __() { this.constructor = d; }
|
|
166
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var __assign = function() {
|
|
170
|
+
__assign = Object.assign || function __assign(t) {
|
|
171
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
172
|
+
s = arguments[i];
|
|
173
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
174
|
+
}
|
|
175
|
+
return t;
|
|
176
|
+
};
|
|
177
|
+
return __assign.apply(this, arguments);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
181
|
+
var e = new Error(message);
|
|
182
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
function validationErrorsToMessage(errors) {
|
|
186
|
+
if (errors instanceof Array) {
|
|
187
|
+
return errors
|
|
188
|
+
.map(function (e) {
|
|
189
|
+
if (typeof e === 'object') {
|
|
190
|
+
return "\"".concat(e.instancePath, "\" ").concat(e.message);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return e;
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
.join(', ');
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
return errors;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
var InvalidDataError = /** @class */ (function (_super) {
|
|
203
|
+
__extends(InvalidDataError, _super);
|
|
204
|
+
function InvalidDataError(message, errors) {
|
|
205
|
+
var _this = _super.call(this, message + ' ' + validationErrorsToMessage(errors)) || this;
|
|
206
|
+
_this.name = 'InvalidDataError';
|
|
207
|
+
_this.errors = errors;
|
|
208
|
+
return _this;
|
|
209
|
+
}
|
|
210
|
+
return InvalidDataError;
|
|
211
|
+
}(Error));
|
|
212
|
+
function validateDocId(prefix, docId) {
|
|
213
|
+
if (!docId.startsWith(prefix) || docId.length <= 5 || docId.length > 128) {
|
|
214
|
+
throw new Error('Invalid document ID');
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var NOTE_DOCID_PREFIX = 'note:';
|
|
132
220
|
var TRASH_BOOK_ID = 'trash';
|
|
133
221
|
var NOTE_STATUS = {
|
|
134
222
|
NONE: 'none',
|
|
@@ -143,6 +231,12 @@ var NOTE_VISIBILITY = {
|
|
|
143
231
|
};
|
|
144
232
|
var validateNote = validator;
|
|
145
233
|
var NOTE_TITLE_MAX_LENGTH = 256;
|
|
234
|
+
function createNoteId() {
|
|
235
|
+
return createDocId(NOTE_DOCID_PREFIX);
|
|
236
|
+
}
|
|
237
|
+
function validateNoteId(docId) {
|
|
238
|
+
return validateDocId(NOTE_DOCID_PREFIX, docId);
|
|
239
|
+
}
|
|
146
240
|
|
|
147
241
|
var $schema$2 = "http://json-schema.org/draft-07/schema#";
|
|
148
242
|
var $id$2 = "book";
|
|
@@ -249,7 +343,14 @@ var book = {
|
|
|
249
343
|
required: required$2
|
|
250
344
|
};
|
|
251
345
|
|
|
346
|
+
var BOOK_DOCID_PREFIX = 'book:';
|
|
252
347
|
var validateBook = validator$1;
|
|
348
|
+
function createBookId() {
|
|
349
|
+
return createDocId(BOOK_DOCID_PREFIX);
|
|
350
|
+
}
|
|
351
|
+
function validateBookId(docId) {
|
|
352
|
+
return validateDocId(BOOK_DOCID_PREFIX, docId);
|
|
353
|
+
}
|
|
253
354
|
|
|
254
355
|
var $schema$1 = "http://json-schema.org/draft-07/schema#";
|
|
255
356
|
var $id$1 = "tag";
|
|
@@ -339,54 +440,14 @@ var TAG_COLOR = {
|
|
|
339
440
|
GREY: 'grey',
|
|
340
441
|
BLACK: 'black'
|
|
341
442
|
};
|
|
443
|
+
var TAG_DOCID_PREFIX = 'tag:';
|
|
342
444
|
var validateTag = validator$2;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
351
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
352
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
353
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
354
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
355
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
356
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
357
|
-
***************************************************************************** */
|
|
358
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
359
|
-
|
|
360
|
-
var extendStatics = function(d, b) {
|
|
361
|
-
extendStatics = Object.setPrototypeOf ||
|
|
362
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
363
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
364
|
-
return extendStatics(d, b);
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
function __extends(d, b) {
|
|
368
|
-
if (typeof b !== "function" && b !== null)
|
|
369
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
370
|
-
extendStatics(d, b);
|
|
371
|
-
function __() { this.constructor = d; }
|
|
372
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
var __assign = function() {
|
|
376
|
-
__assign = Object.assign || function __assign(t) {
|
|
377
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
378
|
-
s = arguments[i];
|
|
379
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
380
|
-
}
|
|
381
|
-
return t;
|
|
382
|
-
};
|
|
383
|
-
return __assign.apply(this, arguments);
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
387
|
-
var e = new Error(message);
|
|
388
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
389
|
-
};
|
|
445
|
+
function createTagId() {
|
|
446
|
+
return createDocId(TAG_DOCID_PREFIX);
|
|
447
|
+
}
|
|
448
|
+
function validateTagId(docId) {
|
|
449
|
+
return validateDocId(TAG_DOCID_PREFIX, docId);
|
|
450
|
+
}
|
|
390
451
|
|
|
391
452
|
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
392
453
|
var $id = "file";
|
|
@@ -515,35 +576,14 @@ var SUPPORTED_IMAGE_MIME_TYPES = __assign(__assign({}, supportedImageFileTypes.r
|
|
|
515
576
|
return (__assign(__assign({}, hash), (_a = {}, _a[ft.split('/')[1]] = ft, _a)));
|
|
516
577
|
}, {})), { jpg: 'image/jpeg' });
|
|
517
578
|
var maxAttachmentFileSize = 10 * 1024 * 1024;
|
|
579
|
+
var FILE_DOCID_PREFIX = 'file:';
|
|
518
580
|
var validateFile = validator$3;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (typeof e === 'object') {
|
|
525
|
-
return "\"".concat(e.instancePath, "\" ").concat(e.message);
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
return e;
|
|
529
|
-
}
|
|
530
|
-
})
|
|
531
|
-
.join(', ');
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
return errors;
|
|
535
|
-
}
|
|
581
|
+
function createFileId() {
|
|
582
|
+
return createDocId(FILE_DOCID_PREFIX);
|
|
583
|
+
}
|
|
584
|
+
function validateFileId(docId) {
|
|
585
|
+
return validateDocId(FILE_DOCID_PREFIX, docId);
|
|
536
586
|
}
|
|
537
|
-
var InvalidDataError = /** @class */ (function (_super) {
|
|
538
|
-
__extends(InvalidDataError, _super);
|
|
539
|
-
function InvalidDataError(message, errors) {
|
|
540
|
-
var _this = _super.call(this, message + ' ' + validationErrorsToMessage(errors)) || this;
|
|
541
|
-
_this.name = 'InvalidDataError';
|
|
542
|
-
_this.errors = errors;
|
|
543
|
-
return _this;
|
|
544
|
-
}
|
|
545
|
-
return InvalidDataError;
|
|
546
|
-
}(Error));
|
|
547
587
|
|
|
548
|
-
export { book as BookSchema, file as FileSchema, InvalidDataError, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, note as NoteSchema, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TRASH_BOOK_ID, tag as TagSchema, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateFile, validateNote, validateTag, validationErrorsToMessage };
|
|
588
|
+
export { BOOK_DOCID_PREFIX, book as BookSchema, FILE_DOCID_PREFIX, file as FileSchema, InvalidDataError, NOTE_DOCID_PREFIX, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, note as NoteSchema, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TAG_DOCID_PREFIX, TRASH_BOOK_ID, tag as TagSchema, createBookId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
|
|
549
589
|
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/note.ts","../src/book.ts","../src/tag.ts","../src/file.ts","../src/validator.ts"],"sourcesContent":["import type { ValidateFunction } from 'ajv'\nimport NoteSchema from '../json-schema/note.json'\nimport validator from '../validators/note'\nimport type { EncryptedData } from './crypto'\nexport type TrashBookId = 'trash'\nexport type NoteStatus = 'none' | 'active' | 'onHold' | 'completed' | 'dropped'\nexport type NoteVisibility = 'private' | 'public'\nexport type NoteMetadata = {\n _id: string\n _rev?: string\n bookId: string\n doctype: string\n updatedAt: number\n createdAt: number\n tags?: string[]\n numOfTasks?: number\n numOfCheckedTasks?: number\n migratedBy?: string\n status?: NoteStatus\n share?: NoteVisibility\n pinned?: boolean\n timestamp: number\n _conflicts?: string[]\n}\nexport type Note = NoteMetadata & {\n title: string\n body: string\n}\nexport type EncryptedNote = NoteMetadata & {\n encryptedData: EncryptedData\n}\nexport const TRASH_BOOK_ID = 'trash'\n\nexport const NOTE_STATUS: Readonly<{\n NONE: 'none'\n ACTIVE: 'active'\n ON_HOLD: 'onHold'\n COMPLETED: 'completed'\n DROPPED: 'dropped'\n}> = {\n NONE: 'none',\n ACTIVE: 'active',\n ON_HOLD: 'onHold',\n COMPLETED: 'completed',\n DROPPED: 'dropped'\n}\nexport const NOTE_VISIBILITY: Readonly<{\n PRIVATE: 'private'\n PUBLIC: 'public'\n}> = {\n PRIVATE: 'private',\n PUBLIC: 'public'\n}\nconst validateNote: ValidateFunction<Note> = validator as any\nexport { NoteSchema, validateNote }\n\nexport const NOTE_TITLE_MAX_LENGTH: number = 256\n","import type { ValidateFunction } from 'ajv'\nimport BookSchema from '../json-schema/book.json'\nimport validator from '../validators/book'\n\nimport type { EncryptedData } from './crypto'\n\nexport type BookIconInline = {\n type: 'inline'\n svg: string\n}\nexport type BookIconFile = {\n type: 'file'\n docId: string\n}\nexport type BookIcon = BookIconInline | BookIconFile\n\nexport type BookMetadata = {\n _id: string\n _rev?: string\n updatedAt: number\n createdAt: number\n count?: number\n parentBookId?: null | string\n migratedBy?: string\n icon?: BookIcon\n order?: number\n}\nexport type Book = BookMetadata & {\n name: string\n}\nexport type EncryptedBook = BookMetadata & {\n encryptedData: EncryptedData\n}\n\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n","import type { ValidateFunction } from 'ajv'\nimport TagSchema from '../json-schema/tag.json'\nimport validator from '../validators/tag'\nimport type { EncryptedData } from './crypto'\nexport type TagColor =\n | 'default'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'olive'\n | 'green'\n | 'teal'\n | 'blue'\n | 'violet'\n | 'purple'\n | 'pink'\n | 'brown'\n | 'grey'\n | 'black'\nexport const TAG_COLOR: Readonly<{\n DEFAULT: 'default'\n RED: 'red'\n ORANGE: 'orange'\n YELLOW: 'yellow'\n OLIVE: 'olive'\n GREEN: 'green'\n TEAL: 'teal'\n BLUE: 'blue'\n VIOLET: 'violet'\n PURPLE: 'purple'\n PINK: 'pink'\n BROWN: 'brown'\n GREY: 'grey'\n BLACK: 'black'\n}> = {\n DEFAULT: 'default',\n RED: 'red',\n ORANGE: 'orange',\n YELLOW: 'yellow',\n OLIVE: 'olive',\n GREEN: 'green',\n TEAL: 'teal',\n BLUE: 'blue',\n VIOLET: 'violet',\n PURPLE: 'purple',\n PINK: 'pink',\n BROWN: 'brown',\n GREY: 'grey',\n BLACK: 'black'\n}\nexport type TagMetadata = {\n _id: string\n _rev?: string\n count?: number\n color: TagColor\n updatedAt: number\n createdAt: number\n}\nexport type Tag = TagMetadata & {\n name: string\n}\nexport type EncryptedTag = TagMetadata & {\n encryptedData: EncryptedData\n}\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n","import type { ValidateFunction } from 'ajv'\nimport FileSchema from '../json-schema/file.json'\nimport validator from '../validators/file'\nimport type { EncryptionMetadata } from './crypto'\nexport type ImageFileType =\n | 'image/png'\n | 'image/jpeg'\n | 'image/jpg'\n | 'image/svg+xml'\n | 'image/gif'\n | 'image/heic'\n | 'image/heif'\nexport const supportedImageFileTypes: ReadonlyArray<ImageFileType> = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/svg+xml',\n 'image/gif',\n 'image/heic',\n 'image/heif'\n]\nexport const SUPPORTED_IMAGE_MIME_TYPES: {\n readonly [mime: string]: ImageFileType\n} = {\n ...supportedImageFileTypes.reduce(\n (hash, ft) => ({ ...hash, [ft.split('/')[1]]: ft }),\n {} as Record<string, ImageFileType>\n ),\n jpg: 'image/jpeg'\n}\nexport const maxAttachmentFileSize: number = 10 * 1024 * 1024\nexport type FileAttachmentItem = {\n digest?: string\n content_type: ImageFileType\n data: Buffer | string\n length?: number\n}\nexport type File = {\n _id: string\n _rev?: string\n name: string\n createdAt: number\n contentType: ImageFileType\n contentLength: number\n publicIn: string[]\n _attachments: {\n index: FileAttachmentItem\n }\n md5digest?: string\n}\nexport type EncryptedFile = File & {\n encryptionData: EncryptionMetadata\n}\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n","import type { ErrorObject } from 'ajv'\n\nexport function validationErrorsToMessage(errors: ErrorObject[]): string {\n if (errors instanceof Array) {\n return errors\n .map(e => {\n if (typeof e === 'object') {\n return `\"${e.instancePath}\" ${e.message}`\n } else {\n return e\n }\n })\n .join(', ')\n } else {\n return errors\n }\n}\nexport class InvalidDataError extends Error {\n name = 'InvalidDataError'\n errors: ErrorObject[]\n\n constructor(message: string, errors: ErrorObject[]) {\n super(message + ' ' + validationErrorsToMessage(errors))\n this.errors = errors\n }\n}\n"],"names":["validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,IAAM,aAAa,GAAG;AAEtB,IAAM,WAAW,GAMnB;AACH,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,OAAO,EAAE;;AAEJ,IAAM,eAAe,GAGvB;AACH,IAAA,OAAO,EAAE,SAAS;AACl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/file.ts"],"sourcesContent":["import { nanoid } from 'nanoid'\n\nexport function createDocId(prefix: string): string {\n const id = nanoid(8)\n return `${prefix}${id}`\n}\n","import type { ErrorObject } from 'ajv'\n\nexport function validationErrorsToMessage(errors: ErrorObject[]): string {\n if (errors instanceof Array) {\n return errors\n .map(e => {\n if (typeof e === 'object') {\n return `\"${e.instancePath}\" ${e.message}`\n } else {\n return e\n }\n })\n .join(', ')\n } else {\n return errors\n }\n}\nexport class InvalidDataError extends Error {\n name = 'InvalidDataError'\n errors: ErrorObject[]\n\n constructor(message: string, errors: ErrorObject[]) {\n super(message + ' ' + validationErrorsToMessage(errors))\n this.errors = errors\n }\n}\n\nexport function validateDocId(prefix: string, docId: string): boolean {\n if (!docId.startsWith(prefix) || docId.length <= 5 || docId.length > 128) {\n throw new Error('Invalid document ID')\n }\n return true\n}\n","import type { ValidateFunction } from 'ajv'\nimport NoteSchema from '../json-schema/note.json'\nimport validator from '../validators/note'\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type TrashBookId = 'trash'\nexport type NoteStatus = 'none' | 'active' | 'onHold' | 'completed' | 'dropped'\nexport type NoteVisibility = 'private' | 'public'\nexport type NoteMetadata = {\n _id: string\n _rev?: string\n bookId: string\n doctype: string\n updatedAt: number\n createdAt: number\n tags?: string[]\n numOfTasks?: number\n numOfCheckedTasks?: number\n migratedBy?: string\n status?: NoteStatus\n share?: NoteVisibility\n pinned?: boolean\n timestamp: number\n _conflicts?: string[]\n}\nexport const NOTE_DOCID_PREFIX = 'note:'\nexport type Note = NoteMetadata & {\n title: string\n body: string\n}\nexport type EncryptedNote = NoteMetadata & {\n encryptedData: EncryptedData\n}\nexport const TRASH_BOOK_ID = 'trash'\n\nexport const NOTE_STATUS: Readonly<{\n NONE: 'none'\n ACTIVE: 'active'\n ON_HOLD: 'onHold'\n COMPLETED: 'completed'\n DROPPED: 'dropped'\n}> = {\n NONE: 'none',\n ACTIVE: 'active',\n ON_HOLD: 'onHold',\n COMPLETED: 'completed',\n DROPPED: 'dropped'\n}\nexport const NOTE_VISIBILITY: Readonly<{\n PRIVATE: 'private'\n PUBLIC: 'public'\n}> = {\n PRIVATE: 'private',\n PUBLIC: 'public'\n}\nconst validateNote: ValidateFunction<Note> = validator as any\nexport { NoteSchema, validateNote }\n\nexport const NOTE_TITLE_MAX_LENGTH: number = 256\n\nexport function createNoteId(): string {\n return createDocId(NOTE_DOCID_PREFIX)\n}\n\nexport function validateNoteId(docId: string): boolean {\n return validateDocId(NOTE_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport BookSchema from '../json-schema/book.json'\nimport validator from '../validators/book'\n\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\n\nexport type BookIconInline = {\n type: 'inline'\n svg: string\n}\nexport type BookIconFile = {\n type: 'file'\n docId: string\n}\nexport type BookIcon = BookIconInline | BookIconFile\n\nexport type BookMetadata = {\n _id: string\n _rev?: string\n updatedAt: number\n createdAt: number\n count?: number\n parentBookId?: null | string\n migratedBy?: string\n icon?: BookIcon\n order?: number\n}\nexport type Book = BookMetadata & {\n name: string\n}\nexport type EncryptedBook = BookMetadata & {\n encryptedData: EncryptedData\n}\n\nexport const BOOK_DOCID_PREFIX = 'book:'\n\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n\nexport function createBookId(): string {\n return createDocId(BOOK_DOCID_PREFIX)\n}\n\nexport function validateBookId(docId: string): boolean {\n return validateDocId(BOOK_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport TagSchema from '../json-schema/tag.json'\nimport validator from '../validators/tag'\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type TagColor =\n | 'default'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'olive'\n | 'green'\n | 'teal'\n | 'blue'\n | 'violet'\n | 'purple'\n | 'pink'\n | 'brown'\n | 'grey'\n | 'black'\nexport const TAG_COLOR: Readonly<{\n DEFAULT: 'default'\n RED: 'red'\n ORANGE: 'orange'\n YELLOW: 'yellow'\n OLIVE: 'olive'\n GREEN: 'green'\n TEAL: 'teal'\n BLUE: 'blue'\n VIOLET: 'violet'\n PURPLE: 'purple'\n PINK: 'pink'\n BROWN: 'brown'\n GREY: 'grey'\n BLACK: 'black'\n}> = {\n DEFAULT: 'default',\n RED: 'red',\n ORANGE: 'orange',\n YELLOW: 'yellow',\n OLIVE: 'olive',\n GREEN: 'green',\n TEAL: 'teal',\n BLUE: 'blue',\n VIOLET: 'violet',\n PURPLE: 'purple',\n PINK: 'pink',\n BROWN: 'brown',\n GREY: 'grey',\n BLACK: 'black'\n}\nexport type TagMetadata = {\n _id: string\n _rev?: string\n count?: number\n color: TagColor\n updatedAt: number\n createdAt: number\n}\nexport type Tag = TagMetadata & {\n name: string\n}\nexport type EncryptedTag = TagMetadata & {\n encryptedData: EncryptedData\n}\n\nexport const TAG_DOCID_PREFIX = 'tag:'\n\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n\nexport function createTagId(): string {\n return createDocId(TAG_DOCID_PREFIX)\n}\n\nexport function validateTagId(docId: string): boolean {\n return validateDocId(TAG_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport FileSchema from '../json-schema/file.json'\nimport validator from '../validators/file'\nimport type { EncryptionMetadata } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type ImageFileType =\n | 'image/png'\n | 'image/jpeg'\n | 'image/jpg'\n | 'image/svg+xml'\n | 'image/gif'\n | 'image/heic'\n | 'image/heif'\nexport const supportedImageFileTypes: ReadonlyArray<ImageFileType> = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/svg+xml',\n 'image/gif',\n 'image/heic',\n 'image/heif'\n]\nexport const SUPPORTED_IMAGE_MIME_TYPES: {\n readonly [mime: string]: ImageFileType\n} = {\n ...supportedImageFileTypes.reduce(\n (hash, ft) => ({ ...hash, [ft.split('/')[1]]: ft }),\n {} as Record<string, ImageFileType>\n ),\n jpg: 'image/jpeg'\n}\nexport const maxAttachmentFileSize: number = 10 * 1024 * 1024\nexport type FileAttachmentItem = {\n digest?: string\n content_type: ImageFileType\n data: Buffer | string\n length?: number\n}\nexport type File = {\n _id: string\n _rev?: string\n name: string\n createdAt: number\n contentType: ImageFileType\n contentLength: number\n publicIn: string[]\n _attachments: {\n index: FileAttachmentItem\n }\n md5digest?: string\n}\nexport type EncryptedFile = File & {\n encryptionData: EncryptionMetadata\n}\n\nexport const FILE_DOCID_PREFIX = 'file:'\n\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n\nexport function createFileId(): string {\n return createDocId(FILE_DOCID_PREFIX)\n}\n\nexport function validateFileId(docId: string): boolean {\n return validateDocId(FILE_DOCID_PREFIX, docId)\n}\n"],"names":["validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,SAAU,WAAW,CAAC,MAAc,EAAA;AACxC,IAAA,IAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;AACpB,IAAA,OAAO,EAAA,CAAA,MAAA,CAAG,MAAM,CAAA,CAAA,MAAA,CAAG,EAAE,CAAE;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACHM,SAAU,yBAAyB,CAAC,MAAqB,EAAA;AAC7D,IAAA,IAAI,MAAM,YAAY,KAAK,EAAE;AAC3B,QAAA,OAAO;aACJ,GAAG,CAAC,UAAA,CAAC,EAAA;AACJ,YAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO,IAAA,CAAA,MAAA,CAAI,CAAC,CAAC,YAAY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CAAC;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AChEO,IAAM,uBAAuB,GAAiC;IACnE,WAAW;IACX,YAAY;IACZ,WAAW;IACX,eAAe;IACf,WAAW;IACX,YAAY;IACZ;;AAEK,IAAM,0BAA0B,GAAA,QAAA,CAAA,QAAA,CAAA,EAAA,EAGlC,uBAAuB,CAAC,MAAM,CAC/B,UAAC,IAAI,EAAE,EAAE,EAAA;;AAAK,IAAA,QAAA,QAAA,CAAA,QAAA,CAAA,EAAA,EAAM,IAAI,CAAA,GAAA,EAAA,GAAA,EAAA,EAAA,EAAA,CAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA,GAAG,EAAE,EAAA,EAAA,EAAA;AAAlC,CAAqC,EACnD,EAAmC,CACpC,CAAA,EAAA,EACD,GAAG,EAAE,YAAY;IAEN,qBAAqB,GAAW,EAAE,GAAG,IAAI,GAAG;AAwBlD,IAAM,iBAAiB,GAAG;AAEjC,IAAM,YAAY,GAA2BA;SAG7B,YAAY,GAAA;AAC1B,IAAA,OAAO,WAAW,CAAC,iBAAiB,CAAC;AACvC;AAEM,SAAU,cAAc,CAAC,KAAa,EAAA;AAC1C,IAAA,OAAO,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC;AAChD;;;;"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var validator = require('../validators/note');
|
|
4
|
+
var nanoid = require('nanoid');
|
|
4
5
|
var validator$1 = require('../validators/book');
|
|
5
6
|
var validator$2 = require('../validators/tag');
|
|
6
7
|
var validator$3 = require('../validators/file');
|
|
@@ -131,6 +132,93 @@ var note = {
|
|
|
131
132
|
required: required$3
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
function createDocId(prefix) {
|
|
136
|
+
var id = nanoid.nanoid(8);
|
|
137
|
+
return "".concat(prefix).concat(id);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/******************************************************************************
|
|
141
|
+
Copyright (c) Microsoft Corporation.
|
|
142
|
+
|
|
143
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
144
|
+
purpose with or without fee is hereby granted.
|
|
145
|
+
|
|
146
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
147
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
148
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
149
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
150
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
151
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
152
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
153
|
+
***************************************************************************** */
|
|
154
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
155
|
+
|
|
156
|
+
var extendStatics = function(d, b) {
|
|
157
|
+
extendStatics = Object.setPrototypeOf ||
|
|
158
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
159
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
160
|
+
return extendStatics(d, b);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function __extends(d, b) {
|
|
164
|
+
if (typeof b !== "function" && b !== null)
|
|
165
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
166
|
+
extendStatics(d, b);
|
|
167
|
+
function __() { this.constructor = d; }
|
|
168
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var __assign = function() {
|
|
172
|
+
__assign = Object.assign || function __assign(t) {
|
|
173
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
174
|
+
s = arguments[i];
|
|
175
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
176
|
+
}
|
|
177
|
+
return t;
|
|
178
|
+
};
|
|
179
|
+
return __assign.apply(this, arguments);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
183
|
+
var e = new Error(message);
|
|
184
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
function validationErrorsToMessage(errors) {
|
|
188
|
+
if (errors instanceof Array) {
|
|
189
|
+
return errors
|
|
190
|
+
.map(function (e) {
|
|
191
|
+
if (typeof e === 'object') {
|
|
192
|
+
return "\"".concat(e.instancePath, "\" ").concat(e.message);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return e;
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
.join(', ');
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return errors;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
var InvalidDataError = /** @class */ (function (_super) {
|
|
205
|
+
__extends(InvalidDataError, _super);
|
|
206
|
+
function InvalidDataError(message, errors) {
|
|
207
|
+
var _this = _super.call(this, message + ' ' + validationErrorsToMessage(errors)) || this;
|
|
208
|
+
_this.name = 'InvalidDataError';
|
|
209
|
+
_this.errors = errors;
|
|
210
|
+
return _this;
|
|
211
|
+
}
|
|
212
|
+
return InvalidDataError;
|
|
213
|
+
}(Error));
|
|
214
|
+
function validateDocId(prefix, docId) {
|
|
215
|
+
if (!docId.startsWith(prefix) || docId.length <= 5 || docId.length > 128) {
|
|
216
|
+
throw new Error('Invalid document ID');
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var NOTE_DOCID_PREFIX = 'note:';
|
|
134
222
|
var TRASH_BOOK_ID = 'trash';
|
|
135
223
|
var NOTE_STATUS = {
|
|
136
224
|
NONE: 'none',
|
|
@@ -145,6 +233,12 @@ var NOTE_VISIBILITY = {
|
|
|
145
233
|
};
|
|
146
234
|
var validateNote = validator;
|
|
147
235
|
var NOTE_TITLE_MAX_LENGTH = 256;
|
|
236
|
+
function createNoteId() {
|
|
237
|
+
return createDocId(NOTE_DOCID_PREFIX);
|
|
238
|
+
}
|
|
239
|
+
function validateNoteId(docId) {
|
|
240
|
+
return validateDocId(NOTE_DOCID_PREFIX, docId);
|
|
241
|
+
}
|
|
148
242
|
|
|
149
243
|
var $schema$2 = "http://json-schema.org/draft-07/schema#";
|
|
150
244
|
var $id$2 = "book";
|
|
@@ -251,7 +345,14 @@ var book = {
|
|
|
251
345
|
required: required$2
|
|
252
346
|
};
|
|
253
347
|
|
|
348
|
+
var BOOK_DOCID_PREFIX = 'book:';
|
|
254
349
|
var validateBook = validator$1;
|
|
350
|
+
function createBookId() {
|
|
351
|
+
return createDocId(BOOK_DOCID_PREFIX);
|
|
352
|
+
}
|
|
353
|
+
function validateBookId(docId) {
|
|
354
|
+
return validateDocId(BOOK_DOCID_PREFIX, docId);
|
|
355
|
+
}
|
|
255
356
|
|
|
256
357
|
var $schema$1 = "http://json-schema.org/draft-07/schema#";
|
|
257
358
|
var $id$1 = "tag";
|
|
@@ -341,54 +442,14 @@ var TAG_COLOR = {
|
|
|
341
442
|
GREY: 'grey',
|
|
342
443
|
BLACK: 'black'
|
|
343
444
|
};
|
|
445
|
+
var TAG_DOCID_PREFIX = 'tag:';
|
|
344
446
|
var validateTag = validator$2;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
353
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
354
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
355
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
356
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
357
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
358
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
359
|
-
***************************************************************************** */
|
|
360
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
361
|
-
|
|
362
|
-
var extendStatics = function(d, b) {
|
|
363
|
-
extendStatics = Object.setPrototypeOf ||
|
|
364
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
365
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
366
|
-
return extendStatics(d, b);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
function __extends(d, b) {
|
|
370
|
-
if (typeof b !== "function" && b !== null)
|
|
371
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
372
|
-
extendStatics(d, b);
|
|
373
|
-
function __() { this.constructor = d; }
|
|
374
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
var __assign = function() {
|
|
378
|
-
__assign = Object.assign || function __assign(t) {
|
|
379
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
380
|
-
s = arguments[i];
|
|
381
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
382
|
-
}
|
|
383
|
-
return t;
|
|
384
|
-
};
|
|
385
|
-
return __assign.apply(this, arguments);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
389
|
-
var e = new Error(message);
|
|
390
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
391
|
-
};
|
|
447
|
+
function createTagId() {
|
|
448
|
+
return createDocId(TAG_DOCID_PREFIX);
|
|
449
|
+
}
|
|
450
|
+
function validateTagId(docId) {
|
|
451
|
+
return validateDocId(TAG_DOCID_PREFIX, docId);
|
|
452
|
+
}
|
|
392
453
|
|
|
393
454
|
var $schema = "http://json-schema.org/draft-07/schema#";
|
|
394
455
|
var $id = "file";
|
|
@@ -517,52 +578,44 @@ var SUPPORTED_IMAGE_MIME_TYPES = __assign(__assign({}, supportedImageFileTypes.r
|
|
|
517
578
|
return (__assign(__assign({}, hash), (_a = {}, _a[ft.split('/')[1]] = ft, _a)));
|
|
518
579
|
}, {})), { jpg: 'image/jpeg' });
|
|
519
580
|
var maxAttachmentFileSize = 10 * 1024 * 1024;
|
|
581
|
+
var FILE_DOCID_PREFIX = 'file:';
|
|
520
582
|
var validateFile = validator$3;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (typeof e === 'object') {
|
|
527
|
-
return "\"".concat(e.instancePath, "\" ").concat(e.message);
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
return e;
|
|
531
|
-
}
|
|
532
|
-
})
|
|
533
|
-
.join(', ');
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
return errors;
|
|
537
|
-
}
|
|
583
|
+
function createFileId() {
|
|
584
|
+
return createDocId(FILE_DOCID_PREFIX);
|
|
585
|
+
}
|
|
586
|
+
function validateFileId(docId) {
|
|
587
|
+
return validateDocId(FILE_DOCID_PREFIX, docId);
|
|
538
588
|
}
|
|
539
|
-
var InvalidDataError = /** @class */ (function (_super) {
|
|
540
|
-
__extends(InvalidDataError, _super);
|
|
541
|
-
function InvalidDataError(message, errors) {
|
|
542
|
-
var _this = _super.call(this, message + ' ' + validationErrorsToMessage(errors)) || this;
|
|
543
|
-
_this.name = 'InvalidDataError';
|
|
544
|
-
_this.errors = errors;
|
|
545
|
-
return _this;
|
|
546
|
-
}
|
|
547
|
-
return InvalidDataError;
|
|
548
|
-
}(Error));
|
|
549
589
|
|
|
590
|
+
exports.BOOK_DOCID_PREFIX = BOOK_DOCID_PREFIX;
|
|
550
591
|
exports.BookSchema = book;
|
|
592
|
+
exports.FILE_DOCID_PREFIX = FILE_DOCID_PREFIX;
|
|
551
593
|
exports.FileSchema = file;
|
|
552
594
|
exports.InvalidDataError = InvalidDataError;
|
|
595
|
+
exports.NOTE_DOCID_PREFIX = NOTE_DOCID_PREFIX;
|
|
553
596
|
exports.NOTE_STATUS = NOTE_STATUS;
|
|
554
597
|
exports.NOTE_TITLE_MAX_LENGTH = NOTE_TITLE_MAX_LENGTH;
|
|
555
598
|
exports.NOTE_VISIBILITY = NOTE_VISIBILITY;
|
|
556
599
|
exports.NoteSchema = note;
|
|
557
600
|
exports.SUPPORTED_IMAGE_MIME_TYPES = SUPPORTED_IMAGE_MIME_TYPES;
|
|
558
601
|
exports.TAG_COLOR = TAG_COLOR;
|
|
602
|
+
exports.TAG_DOCID_PREFIX = TAG_DOCID_PREFIX;
|
|
559
603
|
exports.TRASH_BOOK_ID = TRASH_BOOK_ID;
|
|
560
604
|
exports.TagSchema = tag;
|
|
605
|
+
exports.createBookId = createBookId;
|
|
606
|
+
exports.createFileId = createFileId;
|
|
607
|
+
exports.createNoteId = createNoteId;
|
|
608
|
+
exports.createTagId = createTagId;
|
|
561
609
|
exports.maxAttachmentFileSize = maxAttachmentFileSize;
|
|
562
610
|
exports.supportedImageFileTypes = supportedImageFileTypes;
|
|
563
611
|
exports.validateBook = validateBook;
|
|
612
|
+
exports.validateBookId = validateBookId;
|
|
613
|
+
exports.validateDocId = validateDocId;
|
|
564
614
|
exports.validateFile = validateFile;
|
|
615
|
+
exports.validateFileId = validateFileId;
|
|
565
616
|
exports.validateNote = validateNote;
|
|
617
|
+
exports.validateNoteId = validateNoteId;
|
|
566
618
|
exports.validateTag = validateTag;
|
|
619
|
+
exports.validateTagId = validateTagId;
|
|
567
620
|
exports.validationErrorsToMessage = validationErrorsToMessage;
|
|
568
621
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/note.ts","../src/book.ts","../src/tag.ts","../src/file.ts","../src/validator.ts"],"sourcesContent":["import type { ValidateFunction } from 'ajv'\nimport NoteSchema from '../json-schema/note.json'\nimport validator from '../validators/note'\nimport type { EncryptedData } from './crypto'\nexport type TrashBookId = 'trash'\nexport type NoteStatus = 'none' | 'active' | 'onHold' | 'completed' | 'dropped'\nexport type NoteVisibility = 'private' | 'public'\nexport type NoteMetadata = {\n _id: string\n _rev?: string\n bookId: string\n doctype: string\n updatedAt: number\n createdAt: number\n tags?: string[]\n numOfTasks?: number\n numOfCheckedTasks?: number\n migratedBy?: string\n status?: NoteStatus\n share?: NoteVisibility\n pinned?: boolean\n timestamp: number\n _conflicts?: string[]\n}\nexport type Note = NoteMetadata & {\n title: string\n body: string\n}\nexport type EncryptedNote = NoteMetadata & {\n encryptedData: EncryptedData\n}\nexport const TRASH_BOOK_ID = 'trash'\n\nexport const NOTE_STATUS: Readonly<{\n NONE: 'none'\n ACTIVE: 'active'\n ON_HOLD: 'onHold'\n COMPLETED: 'completed'\n DROPPED: 'dropped'\n}> = {\n NONE: 'none',\n ACTIVE: 'active',\n ON_HOLD: 'onHold',\n COMPLETED: 'completed',\n DROPPED: 'dropped'\n}\nexport const NOTE_VISIBILITY: Readonly<{\n PRIVATE: 'private'\n PUBLIC: 'public'\n}> = {\n PRIVATE: 'private',\n PUBLIC: 'public'\n}\nconst validateNote: ValidateFunction<Note> = validator as any\nexport { NoteSchema, validateNote }\n\nexport const NOTE_TITLE_MAX_LENGTH: number = 256\n","import type { ValidateFunction } from 'ajv'\nimport BookSchema from '../json-schema/book.json'\nimport validator from '../validators/book'\n\nimport type { EncryptedData } from './crypto'\n\nexport type BookIconInline = {\n type: 'inline'\n svg: string\n}\nexport type BookIconFile = {\n type: 'file'\n docId: string\n}\nexport type BookIcon = BookIconInline | BookIconFile\n\nexport type BookMetadata = {\n _id: string\n _rev?: string\n updatedAt: number\n createdAt: number\n count?: number\n parentBookId?: null | string\n migratedBy?: string\n icon?: BookIcon\n order?: number\n}\nexport type Book = BookMetadata & {\n name: string\n}\nexport type EncryptedBook = BookMetadata & {\n encryptedData: EncryptedData\n}\n\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n","import type { ValidateFunction } from 'ajv'\nimport TagSchema from '../json-schema/tag.json'\nimport validator from '../validators/tag'\nimport type { EncryptedData } from './crypto'\nexport type TagColor =\n | 'default'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'olive'\n | 'green'\n | 'teal'\n | 'blue'\n | 'violet'\n | 'purple'\n | 'pink'\n | 'brown'\n | 'grey'\n | 'black'\nexport const TAG_COLOR: Readonly<{\n DEFAULT: 'default'\n RED: 'red'\n ORANGE: 'orange'\n YELLOW: 'yellow'\n OLIVE: 'olive'\n GREEN: 'green'\n TEAL: 'teal'\n BLUE: 'blue'\n VIOLET: 'violet'\n PURPLE: 'purple'\n PINK: 'pink'\n BROWN: 'brown'\n GREY: 'grey'\n BLACK: 'black'\n}> = {\n DEFAULT: 'default',\n RED: 'red',\n ORANGE: 'orange',\n YELLOW: 'yellow',\n OLIVE: 'olive',\n GREEN: 'green',\n TEAL: 'teal',\n BLUE: 'blue',\n VIOLET: 'violet',\n PURPLE: 'purple',\n PINK: 'pink',\n BROWN: 'brown',\n GREY: 'grey',\n BLACK: 'black'\n}\nexport type TagMetadata = {\n _id: string\n _rev?: string\n count?: number\n color: TagColor\n updatedAt: number\n createdAt: number\n}\nexport type Tag = TagMetadata & {\n name: string\n}\nexport type EncryptedTag = TagMetadata & {\n encryptedData: EncryptedData\n}\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n","import type { ValidateFunction } from 'ajv'\nimport FileSchema from '../json-schema/file.json'\nimport validator from '../validators/file'\nimport type { EncryptionMetadata } from './crypto'\nexport type ImageFileType =\n | 'image/png'\n | 'image/jpeg'\n | 'image/jpg'\n | 'image/svg+xml'\n | 'image/gif'\n | 'image/heic'\n | 'image/heif'\nexport const supportedImageFileTypes: ReadonlyArray<ImageFileType> = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/svg+xml',\n 'image/gif',\n 'image/heic',\n 'image/heif'\n]\nexport const SUPPORTED_IMAGE_MIME_TYPES: {\n readonly [mime: string]: ImageFileType\n} = {\n ...supportedImageFileTypes.reduce(\n (hash, ft) => ({ ...hash, [ft.split('/')[1]]: ft }),\n {} as Record<string, ImageFileType>\n ),\n jpg: 'image/jpeg'\n}\nexport const maxAttachmentFileSize: number = 10 * 1024 * 1024\nexport type FileAttachmentItem = {\n digest?: string\n content_type: ImageFileType\n data: Buffer | string\n length?: number\n}\nexport type File = {\n _id: string\n _rev?: string\n name: string\n createdAt: number\n contentType: ImageFileType\n contentLength: number\n publicIn: string[]\n _attachments: {\n index: FileAttachmentItem\n }\n md5digest?: string\n}\nexport type EncryptedFile = File & {\n encryptionData: EncryptionMetadata\n}\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n","import type { ErrorObject } from 'ajv'\n\nexport function validationErrorsToMessage(errors: ErrorObject[]): string {\n if (errors instanceof Array) {\n return errors\n .map(e => {\n if (typeof e === 'object') {\n return `\"${e.instancePath}\" ${e.message}`\n } else {\n return e\n }\n })\n .join(', ')\n } else {\n return errors\n }\n}\nexport class InvalidDataError extends Error {\n name = 'InvalidDataError'\n errors: ErrorObject[]\n\n constructor(message: string, errors: ErrorObject[]) {\n super(message + ' ' + validationErrorsToMessage(errors))\n this.errors = errors\n }\n}\n"],"names":["validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,IAAM,aAAa,GAAG;AAEtB,IAAM,WAAW,GAMnB;AACH,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,OAAO,EAAE;;AAEJ,IAAM,eAAe,GAGvB;AACH,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,MAAM,EAAE;;AAEV,IAAM,YAAY,GAA2B;AAGtC,IAAM,qBAAqB,GAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtB7C,IAAM,YAAY,GAA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACftC,IAAM,SAAS,GAejB;AACH,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,IAAI,EAAE,MAAM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AI,CAAC;IACf;SAAO;AACL,QAAA,OAAO,MAAM;IACf;AACF;AACA,IAAA,gBAAA,kBAAA,UAAA,MAAA,EAAA;IAAsC,SAAA,CAAA,gBAAA,EAAA,MAAA,CAAA;IAIpC,SAAA,gBAAA,CAAY,OAAe,EAAE,MAAqB,EAAA;QAChD,IAAA,KAAA,GAAA,MAAK,CAAA,IAAA,CAAA,IAAA,EAAC,OAAO,GAAG,GAAG,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC,IAAA,IAAA;QAJ1D,KAAA,CAAA,IAAI,GAAG,kBAAkB;AAKvB,QAAA,KAAI,CAAC,MAAM,GAAG,MAAM;;IACtB;IACF,OAAA,gBAAC;AAAD,CARA,CAAsC,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/validator.ts","../src/note.ts","../src/book.ts","../src/tag.ts","../src/file.ts"],"sourcesContent":["import { nanoid } from 'nanoid'\n\nexport function createDocId(prefix: string): string {\n const id = nanoid(8)\n return `${prefix}${id}`\n}\n","import type { ErrorObject } from 'ajv'\n\nexport function validationErrorsToMessage(errors: ErrorObject[]): string {\n if (errors instanceof Array) {\n return errors\n .map(e => {\n if (typeof e === 'object') {\n return `\"${e.instancePath}\" ${e.message}`\n } else {\n return e\n }\n })\n .join(', ')\n } else {\n return errors\n }\n}\nexport class InvalidDataError extends Error {\n name = 'InvalidDataError'\n errors: ErrorObject[]\n\n constructor(message: string, errors: ErrorObject[]) {\n super(message + ' ' + validationErrorsToMessage(errors))\n this.errors = errors\n }\n}\n\nexport function validateDocId(prefix: string, docId: string): boolean {\n if (!docId.startsWith(prefix) || docId.length <= 5 || docId.length > 128) {\n throw new Error('Invalid document ID')\n }\n return true\n}\n","import type { ValidateFunction } from 'ajv'\nimport NoteSchema from '../json-schema/note.json'\nimport validator from '../validators/note'\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type TrashBookId = 'trash'\nexport type NoteStatus = 'none' | 'active' | 'onHold' | 'completed' | 'dropped'\nexport type NoteVisibility = 'private' | 'public'\nexport type NoteMetadata = {\n _id: string\n _rev?: string\n bookId: string\n doctype: string\n updatedAt: number\n createdAt: number\n tags?: string[]\n numOfTasks?: number\n numOfCheckedTasks?: number\n migratedBy?: string\n status?: NoteStatus\n share?: NoteVisibility\n pinned?: boolean\n timestamp: number\n _conflicts?: string[]\n}\nexport const NOTE_DOCID_PREFIX = 'note:'\nexport type Note = NoteMetadata & {\n title: string\n body: string\n}\nexport type EncryptedNote = NoteMetadata & {\n encryptedData: EncryptedData\n}\nexport const TRASH_BOOK_ID = 'trash'\n\nexport const NOTE_STATUS: Readonly<{\n NONE: 'none'\n ACTIVE: 'active'\n ON_HOLD: 'onHold'\n COMPLETED: 'completed'\n DROPPED: 'dropped'\n}> = {\n NONE: 'none',\n ACTIVE: 'active',\n ON_HOLD: 'onHold',\n COMPLETED: 'completed',\n DROPPED: 'dropped'\n}\nexport const NOTE_VISIBILITY: Readonly<{\n PRIVATE: 'private'\n PUBLIC: 'public'\n}> = {\n PRIVATE: 'private',\n PUBLIC: 'public'\n}\nconst validateNote: ValidateFunction<Note> = validator as any\nexport { NoteSchema, validateNote }\n\nexport const NOTE_TITLE_MAX_LENGTH: number = 256\n\nexport function createNoteId(): string {\n return createDocId(NOTE_DOCID_PREFIX)\n}\n\nexport function validateNoteId(docId: string): boolean {\n return validateDocId(NOTE_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport BookSchema from '../json-schema/book.json'\nimport validator from '../validators/book'\n\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\n\nexport type BookIconInline = {\n type: 'inline'\n svg: string\n}\nexport type BookIconFile = {\n type: 'file'\n docId: string\n}\nexport type BookIcon = BookIconInline | BookIconFile\n\nexport type BookMetadata = {\n _id: string\n _rev?: string\n updatedAt: number\n createdAt: number\n count?: number\n parentBookId?: null | string\n migratedBy?: string\n icon?: BookIcon\n order?: number\n}\nexport type Book = BookMetadata & {\n name: string\n}\nexport type EncryptedBook = BookMetadata & {\n encryptedData: EncryptedData\n}\n\nexport const BOOK_DOCID_PREFIX = 'book:'\n\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n\nexport function createBookId(): string {\n return createDocId(BOOK_DOCID_PREFIX)\n}\n\nexport function validateBookId(docId: string): boolean {\n return validateDocId(BOOK_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport TagSchema from '../json-schema/tag.json'\nimport validator from '../validators/tag'\nimport type { EncryptedData } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type TagColor =\n | 'default'\n | 'red'\n | 'orange'\n | 'yellow'\n | 'olive'\n | 'green'\n | 'teal'\n | 'blue'\n | 'violet'\n | 'purple'\n | 'pink'\n | 'brown'\n | 'grey'\n | 'black'\nexport const TAG_COLOR: Readonly<{\n DEFAULT: 'default'\n RED: 'red'\n ORANGE: 'orange'\n YELLOW: 'yellow'\n OLIVE: 'olive'\n GREEN: 'green'\n TEAL: 'teal'\n BLUE: 'blue'\n VIOLET: 'violet'\n PURPLE: 'purple'\n PINK: 'pink'\n BROWN: 'brown'\n GREY: 'grey'\n BLACK: 'black'\n}> = {\n DEFAULT: 'default',\n RED: 'red',\n ORANGE: 'orange',\n YELLOW: 'yellow',\n OLIVE: 'olive',\n GREEN: 'green',\n TEAL: 'teal',\n BLUE: 'blue',\n VIOLET: 'violet',\n PURPLE: 'purple',\n PINK: 'pink',\n BROWN: 'brown',\n GREY: 'grey',\n BLACK: 'black'\n}\nexport type TagMetadata = {\n _id: string\n _rev?: string\n count?: number\n color: TagColor\n updatedAt: number\n createdAt: number\n}\nexport type Tag = TagMetadata & {\n name: string\n}\nexport type EncryptedTag = TagMetadata & {\n encryptedData: EncryptedData\n}\n\nexport const TAG_DOCID_PREFIX = 'tag:'\n\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n\nexport function createTagId(): string {\n return createDocId(TAG_DOCID_PREFIX)\n}\n\nexport function validateTagId(docId: string): boolean {\n return validateDocId(TAG_DOCID_PREFIX, docId)\n}\n","import type { ValidateFunction } from 'ajv'\nimport FileSchema from '../json-schema/file.json'\nimport validator from '../validators/file'\nimport type { EncryptionMetadata } from './crypto'\nimport { createDocId } from './utils'\nimport { validateDocId } from './validator'\nexport type ImageFileType =\n | 'image/png'\n | 'image/jpeg'\n | 'image/jpg'\n | 'image/svg+xml'\n | 'image/gif'\n | 'image/heic'\n | 'image/heif'\nexport const supportedImageFileTypes: ReadonlyArray<ImageFileType> = [\n 'image/png',\n 'image/jpeg',\n 'image/jpg',\n 'image/svg+xml',\n 'image/gif',\n 'image/heic',\n 'image/heif'\n]\nexport const SUPPORTED_IMAGE_MIME_TYPES: {\n readonly [mime: string]: ImageFileType\n} = {\n ...supportedImageFileTypes.reduce(\n (hash, ft) => ({ ...hash, [ft.split('/')[1]]: ft }),\n {} as Record<string, ImageFileType>\n ),\n jpg: 'image/jpeg'\n}\nexport const maxAttachmentFileSize: number = 10 * 1024 * 1024\nexport type FileAttachmentItem = {\n digest?: string\n content_type: ImageFileType\n data: Buffer | string\n length?: number\n}\nexport type File = {\n _id: string\n _rev?: string\n name: string\n createdAt: number\n contentType: ImageFileType\n contentLength: number\n publicIn: string[]\n _attachments: {\n index: FileAttachmentItem\n }\n md5digest?: string\n}\nexport type EncryptedFile = File & {\n encryptionData: EncryptionMetadata\n}\n\nexport const FILE_DOCID_PREFIX = 'file:'\n\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n\nexport function createFileId(): string {\n return createDocId(FILE_DOCID_PREFIX)\n}\n\nexport function validateFileId(docId: string): boolean {\n return validateDocId(FILE_DOCID_PREFIX, docId)\n}\n"],"names":["nanoid","validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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N,qBAAqB,GAAW,EAAE,GAAG,IAAI,GAAG;AAwBlD,IAAM,iBAAiB,GAAG;AAEjC,IAAM,YAAY,GAA2BA;SAG7B,YAAY,GAAA;AAC1B,IAAA,OAAO,WAAW,CAAC,iBAAiB,CAAC;AACvC;AAEM,SAAU,cAAc,CAAC,KAAa,EAAA;AAC1C,IAAA,OAAO,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC;AAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../validators/note"),require("../validators/book"),require("../validators/tag"),require("../validators/file")):"function"==typeof define&&define.amd?define(["exports","../validators/note","../validators/book","../validators/tag","../validators/file"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).InkdropModel={},e.validator,e.validator$1,e.validator$2,e.validator$3)}(this,function(e,t,i,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../validators/note"),require("nanoid"),require("../validators/book"),require("../validators/tag"),require("../validators/file")):"function"==typeof define&&define.amd?define(["exports","../validators/note","nanoid","../validators/book","../validators/tag","../validators/file"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).InkdropModel={},e.validator,e.nanoid,e.validator$1,e.validator$2,e.validator$3)}(this,function(e,t,n,i,r,o){"use strict";var a={$schema:"http://json-schema.org/draft-07/schema#",$id:"note",title:"Note",description:"A note data",type:"object",properties:{_id:{description:"The unique document ID which should start with `note:` and the remains are randomly generated string",type:"string",minLength:6,maxLength:128,pattern:"^note:"},_rev:{description:"This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).",type:"string"},bookId:{description:"The notebook ID",type:"string",minLength:5,maxLength:128,pattern:"^(book:|trash$)"},title:{description:"The note title",type:"string",maxLength:256},doctype:{description:"The format type of the body field. It currently can take markdown only, reserved for the future",type:"string",enum:["markdown"]},body:{description:"The content of the note represented with Markdown",type:"string",maxLength:1048576},updatedAt:{description:"The date time when the note was last updated, represented with Unix timestamps in milliseconds",type:"number"},createdAt:{description:"The date time when the note was created, represented with Unix timestamps in milliseconds",type:"number"},tags:{description:"The list of tag IDs",type:"array",items:{type:"string"},uniqueItems:!0},numOfTasks:{description:"The number of tasks, extracted from body",type:"number"},numOfCheckedTasks:{description:"The number of checked tasks, extracted from body",type:"number"},migratedBy:{description:"The type of the data migration",type:"string",maxLength:128},status:{description:"The status of the note",type:"string",enum:["none","active","onHold","completed","dropped"]},share:{description:"The sharing mode of the note",type:"string",enum:["private","public"]},pinned:{description:"Whether the note is pinned to top",type:"boolean"},timestamp:{description:"The date time when the revision was written, represented with Unix timestamps in milliseconds",type:"number"},_conflicts:{description:"Conflicted revisions",type:"array",items:{type:"string"},uniqueItems:!0}},required:["_id","bookId","title","doctype","body","updatedAt","createdAt","timestamp"]};function s(e){var t=n.nanoid(8);return"".concat(e).concat(t)}var d=function(e,t){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},d(e,t)};var p=function(){return p=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},p.apply(this,arguments)};function c(e){return e instanceof Array?e.map(function(e){return"object"==typeof e?'"'.concat(e.instancePath,'" ').concat(e.message):e}).join(", "):e}"function"==typeof SuppressedError&&SuppressedError;var h=function(e){function t(t,n){var i=e.call(this,t+" "+c(n))||this;return i.name="InvalidDataError",i.errors=n,i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}d(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(Error);function m(e,t){if(!t.startsWith(e)||t.length<=5||t.length>128)throw new Error("Invalid document ID");return!0}var u="note:",l=t;var g={$schema:"http://json-schema.org/draft-07/schema#",$id:"book",title:"Book",description:"A notebook data",type:"object",properties:{_id:{description:"The unique notebook ID which should start with `book:` and the remains are randomly generated string",type:"string",minLength:6,maxLength:128,pattern:"^book:"},_rev:{description:"This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable)",type:"string"},name:{description:"The notebook name",type:"string",minLength:1,maxLength:64},updatedAt:{description:"The date time when the notebook was last updated, represented with Unix timestamps in milliseconds",type:"number"},createdAt:{description:"The date time when the notebook was created, represented with Unix timestamps in milliseconds",type:"number"},count:{description:"It indicates the number of notes in the notebook",type:"number"},parentBookId:{description:"The ID of the parent notebook",type:["string","null"]},order:{description:"A number used to manually sort notebooks. Notebooks are ordered by this value in ascending order. If not specified, notebooks fall back to alphabetical sorting by name.",type:"number"},icon:{description:"Custom icon for the notebook",type:"object",oneOf:[{properties:{type:{description:"Icon storage type",const:"inline"},svg:{description:"The SVG icon data. Must be less than 256kb",type:"string",maxLength:262144}},required:["type","svg"]},{properties:{type:{description:"Icon storage type",const:"file"},docId:{description:"The document ID for the attachment file",type:"string",pattern:"^file:",minLength:6,maxLength:128}},required:["type","docId"]}]}},required:["_id","name","updatedAt","createdAt"]},f="book:",y=i;var b={$schema:"http://json-schema.org/draft-07/schema#",$id:"tag",title:"Tag",description:"A note tag",type:"object",properties:{_id:{description:"The unique tag ID which should start with `tag:` and the remains are randomly generated string",type:"string",minLength:6,maxLength:128,pattern:"^tag:"},_rev:{description:"This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable)",type:"string"},name:{description:"The name of the tag",type:"string",maxLength:64},count:{description:"It indicates the number of notes with the tag",type:"number"},color:{description:"The color type of the tag",type:"string",enum:["default","red","orange","yellow","olive","green","teal","blue","violet","purple","pink","brown","grey","black"]},updatedAt:{description:"The date time when the tag was last updated, represented with Unix timestamps in milliseconds",type:"number"},createdAt:{description:"The date time when the tag was created, represented with Unix timestamps in milliseconds",type:"number"}},required:["_id","name","count","updatedAt","createdAt"]},T="tag:",v=r;var I={$schema:"http://json-schema.org/draft-07/schema#",$id:"file",title:"File",description:"An attachment file",type:"object",properties:{_id:{description:"The unique document ID which should start with `file:` and the remains are randomly generated string",type:"string",minLength:6,maxLength:128,pattern:"^file:"},_rev:{description:"This is a CouchDB specific field. The current MVCC-token/revision of this document (mandatory and immutable).",type:"string"},name:{description:"The file name",type:"string",minLength:1,maxLength:128},createdAt:{description:"The date time when the note was created, represented with Unix timestamps in milliseconds",type:"number"},contentType:{description:"The MIME type of the content",type:"string",enum:["image/png","image/jpeg","image/jpg","image/svg+xml","image/gif","image/heic","image/heif"],maxLength:128},contentLength:{description:"The content length of the file",type:"number",maximum:10485760},publicIn:{description:"An array of the note IDs where the file is included",type:"array",items:{type:"string"},uniqueItems:!0},_attachments:{description:"The attachment file",type:"object",properties:{index:{description:"The attachment file",type:"object",properties:{content_type:{description:"The content type of the file",type:"string",enum:["image/png","image/jpeg","image/jpg","image/svg+xml","image/gif","image/heic","image/heif"]},data:{description:"The file data",type:["string","object"]}},required:["content_type","data"]}},required:["index"]}},required:["_id","name","createdAt","contentType","contentLength","publicIn","_attachments"]},w=["image/png","image/jpeg","image/jpg","image/svg+xml","image/gif","image/heic","image/heif"],k=p(p({},w.reduce(function(e,t){var n;return p(p({},e),((n={})[t.split("/")[1]]=t,n))},{})),{jpg:"image/jpeg"}),_="file:",E=o;e.BOOK_DOCID_PREFIX=f,e.BookSchema=g,e.FILE_DOCID_PREFIX=_,e.FileSchema=I,e.InvalidDataError=h,e.NOTE_DOCID_PREFIX=u,e.NOTE_STATUS={NONE:"none",ACTIVE:"active",ON_HOLD:"onHold",COMPLETED:"completed",DROPPED:"dropped"},e.NOTE_TITLE_MAX_LENGTH=256,e.NOTE_VISIBILITY={PRIVATE:"private",PUBLIC:"public"},e.NoteSchema=a,e.SUPPORTED_IMAGE_MIME_TYPES=k,e.TAG_COLOR={DEFAULT:"default",RED:"red",ORANGE:"orange",YELLOW:"yellow",OLIVE:"olive",GREEN:"green",TEAL:"teal",BLUE:"blue",VIOLET:"violet",PURPLE:"purple",PINK:"pink",BROWN:"brown",GREY:"grey",BLACK:"black"},e.TAG_DOCID_PREFIX=T,e.TRASH_BOOK_ID="trash",e.TagSchema=b,e.createBookId=function(){return s(f)},e.createFileId=function(){return s(_)},e.createNoteId=function(){return s(u)},e.createTagId=function(){return s(T)},e.maxAttachmentFileSize=10485760,e.supportedImageFileTypes=w,e.validateBook=y,e.validateBookId=function(e){return m(f,e)},e.validateDocId=m,e.validateFile=E,e.validateFileId=function(e){return m(_,e)},e.validateNote=l,e.validateNoteId=function(e){return m(u,e)},e.validateTag=v,e.validateTagId=function(e){return m(T,e)},e.validationErrorsToMessage=c});
|
package/lib/note.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export type NoteMetadata = {
|
|
|
21
21
|
timestamp: number;
|
|
22
22
|
_conflicts?: string[];
|
|
23
23
|
};
|
|
24
|
+
export declare const NOTE_DOCID_PREFIX = "note:";
|
|
24
25
|
export type Note = NoteMetadata & {
|
|
25
26
|
title: string;
|
|
26
27
|
body: string;
|
|
@@ -43,3 +44,5 @@ export declare const NOTE_VISIBILITY: Readonly<{
|
|
|
43
44
|
declare const validateNote: ValidateFunction<Note>;
|
|
44
45
|
export { NoteSchema, validateNote };
|
|
45
46
|
export declare const NOTE_TITLE_MAX_LENGTH: number;
|
|
47
|
+
export declare function createNoteId(): string;
|
|
48
|
+
export declare function validateNoteId(docId: string): boolean;
|
package/lib/tag.d.ts
CHANGED
|
@@ -32,5 +32,8 @@ export type Tag = TagMetadata & {
|
|
|
32
32
|
export type EncryptedTag = TagMetadata & {
|
|
33
33
|
encryptedData: EncryptedData;
|
|
34
34
|
};
|
|
35
|
+
export declare const TAG_DOCID_PREFIX = "tag:";
|
|
35
36
|
declare const validateTag: ValidateFunction<Tag>;
|
|
36
37
|
export { TagSchema, validateTag };
|
|
38
|
+
export declare function createTagId(): string;
|
|
39
|
+
export declare function validateTagId(docId: string): boolean;
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createDocId(prefix: string): string;
|
package/lib/validator.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inkdrop-model",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.3",
|
|
4
4
|
"description": "Data model for Inkdrop",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm-run-all build:schema build:lib doc",
|
|
@@ -17,23 +17,26 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "https://github.com/inkdropapp/inkdrop-model.git"
|
|
19
19
|
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"nanoid": "^5.1.6"
|
|
22
|
+
},
|
|
20
23
|
"devDependencies": {
|
|
21
24
|
"@rollup/plugin-json": "^6.1.0",
|
|
22
25
|
"@rollup/plugin-terser": "^0.4.4",
|
|
23
|
-
"@types/jest": "^
|
|
24
|
-
"ajv": "^8.
|
|
26
|
+
"@types/jest": "^29.5.14",
|
|
27
|
+
"ajv": "^8.18.0",
|
|
25
28
|
"ajv-cli": "^5.0.0",
|
|
26
29
|
"ajv-formats": "^3.0.1",
|
|
27
|
-
"eslint": "^9.39.
|
|
30
|
+
"eslint": "^9.39.3",
|
|
28
31
|
"eslint-config-prettier": "^10.1.8",
|
|
29
|
-
"jest": "^
|
|
32
|
+
"jest": "^29.7.0",
|
|
30
33
|
"npm-run-all": "^4.1.5",
|
|
31
34
|
"prettier": "^3.8.1",
|
|
32
|
-
"rollup": "^4.
|
|
35
|
+
"rollup": "^4.59.0",
|
|
33
36
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
34
37
|
"ts-jest": "^29.4.6",
|
|
35
38
|
"typescript": "^5.9.3",
|
|
36
|
-
"typescript-eslint": "^8.
|
|
39
|
+
"typescript-eslint": "^8.56.0",
|
|
37
40
|
"yaml": "^2.8.2"
|
|
38
41
|
},
|
|
39
42
|
"types": "lib/index.d.ts",
|