inkdrop-model 2.11.2 → 2.11.4

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 CHANGED
@@ -27,6 +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;
32
34
  export declare function validateBookId(docId: string): boolean;
package/lib/file.d.ts CHANGED
@@ -29,6 +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;
34
36
  export declare function validateFileId(docId: string): boolean;
package/lib/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './tag';
4
4
  export * from './file';
5
5
  export * from './crypto';
6
6
  export * from './validator';
7
+ export * from './utils';
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,11 @@ 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
+
132
138
  /******************************************************************************
133
139
  Copyright (c) Microsoft Corporation.
134
140
 
@@ -210,6 +216,7 @@ function validateDocId(prefix, docId) {
210
216
  return true;
211
217
  }
212
218
 
219
+ var NOTE_DOCID_PREFIX = 'note:';
213
220
  var TRASH_BOOK_ID = 'trash';
214
221
  var NOTE_STATUS = {
215
222
  NONE: 'none',
@@ -224,8 +231,11 @@ var NOTE_VISIBILITY = {
224
231
  };
225
232
  var validateNote = validator;
226
233
  var NOTE_TITLE_MAX_LENGTH = 256;
234
+ function createNoteId() {
235
+ return createDocId(NOTE_DOCID_PREFIX);
236
+ }
227
237
  function validateNoteId(docId) {
228
- return validateDocId('note:', docId);
238
+ return validateDocId(NOTE_DOCID_PREFIX, docId);
229
239
  }
230
240
 
231
241
  var $schema$2 = "http://json-schema.org/draft-07/schema#";
@@ -333,9 +343,13 @@ var book = {
333
343
  required: required$2
334
344
  };
335
345
 
346
+ var BOOK_DOCID_PREFIX = 'book:';
336
347
  var validateBook = validator$1;
348
+ function createBookId() {
349
+ return createDocId(BOOK_DOCID_PREFIX);
350
+ }
337
351
  function validateBookId(docId) {
338
- return validateDocId('book:', docId);
352
+ return validateDocId(BOOK_DOCID_PREFIX, docId);
339
353
  }
340
354
 
341
355
  var $schema$1 = "http://json-schema.org/draft-07/schema#";
@@ -426,9 +440,13 @@ var TAG_COLOR = {
426
440
  GREY: 'grey',
427
441
  BLACK: 'black'
428
442
  };
443
+ var TAG_DOCID_PREFIX = 'tag:';
429
444
  var validateTag = validator$2;
445
+ function createTagId() {
446
+ return createDocId(TAG_DOCID_PREFIX);
447
+ }
430
448
  function validateTagId(docId) {
431
- return validateDocId('tag:', docId);
449
+ return validateDocId(TAG_DOCID_PREFIX, docId);
432
450
  }
433
451
 
434
452
  var $schema = "http://json-schema.org/draft-07/schema#";
@@ -558,10 +576,14 @@ var SUPPORTED_IMAGE_MIME_TYPES = __assign(__assign({}, supportedImageFileTypes.r
558
576
  return (__assign(__assign({}, hash), (_a = {}, _a[ft.split('/')[1]] = ft, _a)));
559
577
  }, {})), { jpg: 'image/jpeg' });
560
578
  var maxAttachmentFileSize = 10 * 1024 * 1024;
579
+ var FILE_DOCID_PREFIX = 'file:';
561
580
  var validateFile = validator$3;
581
+ function createFileId() {
582
+ return createDocId(FILE_DOCID_PREFIX);
583
+ }
562
584
  function validateFileId(docId) {
563
- return validateDocId('file:', docId);
585
+ return validateDocId(FILE_DOCID_PREFIX, docId);
564
586
  }
565
587
 
566
- 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, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, 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, createDocId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
567
589
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/validator.ts","../src/note.ts","../src/book.ts","../src/tag.ts","../src/file.ts"],"sourcesContent":["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 { 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 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 validateNoteId(docId: string): boolean {\n return validateDocId('note:', 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 { 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\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n\nexport function validateBookId(docId: string): boolean {\n return validateDocId('book:', 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 { 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}\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n\nexport function validateTagId(docId: string): boolean {\n return validateDocId('tag:', 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 { 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}\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n\nexport function validateFileId(docId: string): boolean {\n return validateDocId('file:', docId)\n}\n"],"names":["validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,SAAU,yBAAyB,CAAC,MAAqB,EAAA;AAC7D,IAAA,IAAI,MAAM,YAAY,KAAK,EAAE;AAC3B,QAAA,OAAO;aACJ,GAAG,CAAC,UAAA,CAAC,EAAA;AACJ,YAAA,IAAI,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ACX,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;AAuBzD,IAAM,YAAY,GAA2BA;AAGvC,SAAU,cAAc,CAAC,KAAa,EAAA;AAC1C,IAAA,OAAO,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC;AACtC;;;;"}
1
+ {"version":3,"file":"index.esm.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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AA,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,11 @@ 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
+
134
140
  /******************************************************************************
135
141
  Copyright (c) Microsoft Corporation.
136
142
 
@@ -212,6 +218,7 @@ function validateDocId(prefix, docId) {
212
218
  return true;
213
219
  }
214
220
 
221
+ var NOTE_DOCID_PREFIX = 'note:';
215
222
  var TRASH_BOOK_ID = 'trash';
216
223
  var NOTE_STATUS = {
217
224
  NONE: 'none',
@@ -226,8 +233,11 @@ var NOTE_VISIBILITY = {
226
233
  };
227
234
  var validateNote = validator;
228
235
  var NOTE_TITLE_MAX_LENGTH = 256;
236
+ function createNoteId() {
237
+ return createDocId(NOTE_DOCID_PREFIX);
238
+ }
229
239
  function validateNoteId(docId) {
230
- return validateDocId('note:', docId);
240
+ return validateDocId(NOTE_DOCID_PREFIX, docId);
231
241
  }
232
242
 
233
243
  var $schema$2 = "http://json-schema.org/draft-07/schema#";
@@ -335,9 +345,13 @@ var book = {
335
345
  required: required$2
336
346
  };
337
347
 
348
+ var BOOK_DOCID_PREFIX = 'book:';
338
349
  var validateBook = validator$1;
350
+ function createBookId() {
351
+ return createDocId(BOOK_DOCID_PREFIX);
352
+ }
339
353
  function validateBookId(docId) {
340
- return validateDocId('book:', docId);
354
+ return validateDocId(BOOK_DOCID_PREFIX, docId);
341
355
  }
342
356
 
343
357
  var $schema$1 = "http://json-schema.org/draft-07/schema#";
@@ -428,9 +442,13 @@ var TAG_COLOR = {
428
442
  GREY: 'grey',
429
443
  BLACK: 'black'
430
444
  };
445
+ var TAG_DOCID_PREFIX = 'tag:';
431
446
  var validateTag = validator$2;
447
+ function createTagId() {
448
+ return createDocId(TAG_DOCID_PREFIX);
449
+ }
432
450
  function validateTagId(docId) {
433
- return validateDocId('tag:', docId);
451
+ return validateDocId(TAG_DOCID_PREFIX, docId);
434
452
  }
435
453
 
436
454
  var $schema = "http://json-schema.org/draft-07/schema#";
@@ -560,22 +578,35 @@ var SUPPORTED_IMAGE_MIME_TYPES = __assign(__assign({}, supportedImageFileTypes.r
560
578
  return (__assign(__assign({}, hash), (_a = {}, _a[ft.split('/')[1]] = ft, _a)));
561
579
  }, {})), { jpg: 'image/jpeg' });
562
580
  var maxAttachmentFileSize = 10 * 1024 * 1024;
581
+ var FILE_DOCID_PREFIX = 'file:';
563
582
  var validateFile = validator$3;
583
+ function createFileId() {
584
+ return createDocId(FILE_DOCID_PREFIX);
585
+ }
564
586
  function validateFileId(docId) {
565
- return validateDocId('file:', docId);
587
+ return validateDocId(FILE_DOCID_PREFIX, docId);
566
588
  }
567
589
 
590
+ exports.BOOK_DOCID_PREFIX = BOOK_DOCID_PREFIX;
568
591
  exports.BookSchema = book;
592
+ exports.FILE_DOCID_PREFIX = FILE_DOCID_PREFIX;
569
593
  exports.FileSchema = file;
570
594
  exports.InvalidDataError = InvalidDataError;
595
+ exports.NOTE_DOCID_PREFIX = NOTE_DOCID_PREFIX;
571
596
  exports.NOTE_STATUS = NOTE_STATUS;
572
597
  exports.NOTE_TITLE_MAX_LENGTH = NOTE_TITLE_MAX_LENGTH;
573
598
  exports.NOTE_VISIBILITY = NOTE_VISIBILITY;
574
599
  exports.NoteSchema = note;
575
600
  exports.SUPPORTED_IMAGE_MIME_TYPES = SUPPORTED_IMAGE_MIME_TYPES;
576
601
  exports.TAG_COLOR = TAG_COLOR;
602
+ exports.TAG_DOCID_PREFIX = TAG_DOCID_PREFIX;
577
603
  exports.TRASH_BOOK_ID = TRASH_BOOK_ID;
578
604
  exports.TagSchema = tag;
605
+ exports.createBookId = createBookId;
606
+ exports.createDocId = createDocId;
607
+ exports.createFileId = createFileId;
608
+ exports.createNoteId = createNoteId;
609
+ exports.createTagId = createTagId;
579
610
  exports.maxAttachmentFileSize = maxAttachmentFileSize;
580
611
  exports.supportedImageFileTypes = supportedImageFileTypes;
581
612
  exports.validateBook = validateBook;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/validator.ts","../src/note.ts","../src/book.ts","../src/tag.ts","../src/file.ts"],"sourcesContent":["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 { 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 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 validateNoteId(docId: string): boolean {\n return validateDocId('note:', 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 { 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\nconst validateBook: ValidateFunction<Book> = validator as any\nexport { BookSchema, validateBook }\n\nexport function validateBookId(docId: string): boolean {\n return validateDocId('book:', 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 { 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}\nconst validateTag: ValidateFunction<Tag> = validator as any\nexport { TagSchema, validateTag }\n\nexport function validateTagId(docId: string): boolean {\n return validateDocId('tag:', 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 { 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}\nconst validateFile: ValidateFunction<File> = validator as any\nexport { FileSchema, validateFile }\n\nexport function validateFileId(docId: string): boolean {\n return validateDocId('file:', docId)\n}\n"],"names":["validator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,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,gBAAK,CAAC,CAAC,OAAO,CAAE;YAC3C;iBAAO;AACL,gBAAA,OAAO,CAAC;YACV;AACF,QAAA,C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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;AAuBzD,IAAM,YAAY,GAA2BA;AAGvC,SAAU,cAAc,CAAC,KAAa,EAAA;AAC1C,IAAA,OAAO,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC;AACtC;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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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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,n,r){"use strict";var o={$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"]},a=function(e,t){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},a(e,t)};var s=function(){return s=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function d(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 p=function(e){function t(t,i){var n=e.call(this,t+" "+d(i))||this;return n.name="InvalidDataError",n.errors=i,n}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 i(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(t,e),t}(Error);function c(e,t){if(!t.startsWith(e)||t.length<=5||t.length>128)throw new Error("Invalid document ID");return!0}var h=t;var m={$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"]},l=i;var u={$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"]},g=n;var f={$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"]},y=["image/png","image/jpeg","image/jpg","image/svg+xml","image/gif","image/heic","image/heif"],b=s(s({},y.reduce(function(e,t){var i;return s(s({},e),((i={})[t.split("/")[1]]=t,i))},{})),{jpg:"image/jpeg"}),T=r;e.BookSchema=m,e.FileSchema=f,e.InvalidDataError=p,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=o,e.SUPPORTED_IMAGE_MIME_TYPES=b,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.TRASH_BOOK_ID="trash",e.TagSchema=u,e.maxAttachmentFileSize=10485760,e.supportedImageFileTypes=y,e.validateBook=l,e.validateBookId=function(e){return c("book:",e)},e.validateDocId=c,e.validateFile=T,e.validateFileId=function(e){return c("file:",e)},e.validateNote=h,e.validateNoteId=function(e){return c("note:",e)},e.validateTag=g,e.validateTagId=function(e){return c("tag:",e)},e.validationErrorsToMessage=d});
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.createDocId=s,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,4 +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;
46
48
  export declare function validateNoteId(docId: string): boolean;
package/lib/tag.d.ts CHANGED
@@ -32,6 +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;
37
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inkdrop-model",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
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": "^30.0.0",
24
- "ajv": "^8.17.1",
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.2",
30
+ "eslint": "^9.39.3",
28
31
  "eslint-config-prettier": "^10.1.8",
29
- "jest": "^30.2.0",
32
+ "jest": "^29.7.0",
30
33
  "npm-run-all": "^4.1.5",
31
34
  "prettier": "^3.8.1",
32
- "rollup": "^4.57.0",
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.54.0",
39
+ "typescript-eslint": "^8.56.0",
37
40
  "yaml": "^2.8.2"
38
41
  },
39
42
  "types": "lib/index.d.ts",