inkdrop-model 2.11.6 → 2.12.0
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/json-schema/note.json +1 -1
- package/lib/index.browser.js +5 -3
- package/lib/index.browser.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.esm.js +93 -26
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +93 -25
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/package.json +9 -11
- package/validators/note.js +1 -1
package/json-schema/note.json
CHANGED
package/lib/index.browser.js
CHANGED
|
@@ -53,7 +53,7 @@ var note_default = {
|
|
|
53
53
|
"type": "string",
|
|
54
54
|
"minLength": 5,
|
|
55
55
|
"maxLength": 128,
|
|
56
|
-
"pattern": "^(book:|trash$)"
|
|
56
|
+
"pattern": "^(book:|trash$|template$)"
|
|
57
57
|
},
|
|
58
58
|
"title": {
|
|
59
59
|
"description": "The note title",
|
|
@@ -140,10 +140,10 @@ var note_default = {
|
|
|
140
140
|
]
|
|
141
141
|
};
|
|
142
142
|
//#endregion
|
|
143
|
-
//#region node_modules/.pnpm/nanoid@
|
|
143
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js
|
|
144
144
|
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
145
145
|
//#endregion
|
|
146
|
-
//#region node_modules/.pnpm/nanoid@
|
|
146
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.browser.js
|
|
147
147
|
let nanoid = (size = 21) => {
|
|
148
148
|
let id = "";
|
|
149
149
|
let bytes = crypto.getRandomValues(new Uint8Array(size |= 0));
|
|
@@ -179,6 +179,7 @@ function validateDocId(prefix, docId) {
|
|
|
179
179
|
//#region src/note.ts
|
|
180
180
|
const NOTE_DOCID_PREFIX = "note:";
|
|
181
181
|
const TRASH_BOOK_ID = "trash";
|
|
182
|
+
const TEMPLATE_BOOK_ID = "template";
|
|
182
183
|
const NOTE_STATUS = {
|
|
183
184
|
NONE: "none",
|
|
184
185
|
ACTIVE: "active",
|
|
@@ -538,6 +539,7 @@ Object.defineProperty(exports, "NoteSchema", {
|
|
|
538
539
|
exports.SUPPORTED_IMAGE_MIME_TYPES = SUPPORTED_IMAGE_MIME_TYPES;
|
|
539
540
|
exports.TAG_COLOR = TAG_COLOR;
|
|
540
541
|
exports.TAG_DOCID_PREFIX = TAG_DOCID_PREFIX;
|
|
542
|
+
exports.TEMPLATE_BOOK_ID = TEMPLATE_BOOK_ID;
|
|
541
543
|
exports.TRASH_BOOK_ID = TRASH_BOOK_ID;
|
|
542
544
|
Object.defineProperty(exports, "TagSchema", {
|
|
543
545
|
enumerable: true,
|
package/lib/index.browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","names":["scopedUrlAlphabet","validator","validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/index.browser.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","\n\nimport { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet } from './url-alphabet/index.js'\n\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\n\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let j = size\n while (j--) {\n id += alphabet[bytes[j] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n if (bytes[j] < safeByteCutoff) {\n id += alphabet[bytes[j] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size | 0, random)\n\nexport let nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))\n while (size--) {\n id += scopedUrlAlphabet[bytes[size] & 63]\n }\n return id\n}\n","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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACgDF,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uCC,gBAAAA;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AE1BA,MAAa,YAeR;CACH,SAAS;CACT,KAAK;CACL,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,OAAO;CACP,MAAM;CACN,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,OAAO;CACP,MAAM;CACN,OAAO;AACT;AAgBA,MAAa,mBAAmB;AAEhC,MAAM,cAAqCC,eAAAA;AAG3C,SAAgB,cAAsB;CACpC,OAAO,YAAY,gBAAgB;AACrC;AAEA,SAAgB,cAAc,OAAwB;CACpD,OAAO,cAAc,kBAAkB,KAAK;AAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEhEA,MAAa,0BAAwD;CACnE;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAa,6BAET;CACF,GAAG,wBAAwB,QACxB,MAAM,QAAQ;EAAE,GAAG;GAAO,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK;CAAG,IACjD,CAAC,CACH;CACA,KAAK;AACP;AACA,MAAa,wBAAgC,KAAK,OAAO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC,gBAAAA;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
|
1
|
+
{"version":3,"file":"index.browser.js","names":["validator","validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.browser.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","\n\nimport { urlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet }\n\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\n\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let j = size\n while (j--) {\n id += alphabet[bytes[j] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step\n while (j--) {\n if (bytes[j] < safeByteCutoff) {\n id += alphabet[bytes[j] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size | 0, random)\n\nexport let nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))\n while (size--) {\n id += urlAlphabet[bytes[size] & 63]\n }\n return id\n}\n","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 TemplateBookId = 'template'\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'\nexport const TEMPLATE_BOOK_ID = 'template'\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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACgDF,IAAW,UAAU,OAAO,OAAO;CACjC,IAAI,KAAK;CACT,IAAI,QAAQ,OAAO,gBAAgB,IAAI,WAAY,QAAQ,CAAE,CAAC;CAC9D,OAAO,QACL,MAAM,YAAY,MAAM,QAAQ;CAElC,OAAO;AACT;;;ACtDA,SAAgB,YAAY,QAAwB;CAElD,OAAO,GAAG,SADC,OAAO,CACE;AACtB;;;ACHA,SAAgB,0BAA0B,QAA+B;CACvE,IAAI,kBAAkB,OACpB,OAAO,OACJ,KAAI,MAAK;EACR,IAAI,OAAO,MAAM,UACf,OAAO,IAAI,EAAE,aAAa,IAAI,EAAE;OAEhC,OAAO;CAEX,CAAC,CAAC,CACD,KAAK,IAAI;MAEZ,OAAO;AAEX;AACA,IAAa,mBAAb,cAAsC,MAAM;CAI1C,YAAY,SAAiB,QAAuB;EAClD,MAAM,UAAU,MAAM,0BAA0B,MAAM,CAAC;cAJlD;EAKL,KAAK,SAAS;CAChB;AACF;AAEA,SAAgB,cAAc,QAAgB,OAAwB;CACpE,IAAI,CAAC,MAAM,WAAW,MAAM,KAAK,M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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEhEA,MAAa,0BAAwD;CACnE;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAa,6BAET;CACF,GAAG,wBAAwB,QACxB,MAAM,QAAQ;EAAE,GAAG;GAAO,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK;CAAG,IACjD,CAAC,CACH;CACA,KAAK;AACP;AACA,MAAa,wBAAgC,KAAK,OAAO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC,gBAAAA;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ErrorObject, ValidateFunction } from "ajv";
|
|
2
|
-
|
|
3
2
|
//#region json-schema/note.json.d.ts
|
|
4
3
|
declare let $schema$3: string;
|
|
5
4
|
declare let $id$3: string;
|
|
@@ -161,6 +160,7 @@ type EncryptedData = EncryptionMetadata & {
|
|
|
161
160
|
//#endregion
|
|
162
161
|
//#region src/note.d.ts
|
|
163
162
|
type TrashBookId = 'trash';
|
|
163
|
+
type TemplateBookId = 'template';
|
|
164
164
|
type NoteStatus = 'none' | 'active' | 'onHold' | 'completed' | 'dropped';
|
|
165
165
|
type NoteVisibility = 'private' | 'public';
|
|
166
166
|
type NoteMetadata = {
|
|
@@ -189,6 +189,7 @@ type EncryptedNote = NoteMetadata & {
|
|
|
189
189
|
encryptedData: EncryptedData;
|
|
190
190
|
};
|
|
191
191
|
declare const TRASH_BOOK_ID = "trash";
|
|
192
|
+
declare const TEMPLATE_BOOK_ID = "template";
|
|
192
193
|
declare const NOTE_STATUS: Readonly<{
|
|
193
194
|
NONE: 'none';
|
|
194
195
|
ACTIVE: 'active';
|
|
@@ -594,5 +595,5 @@ declare function validateDocId(prefix: string, docId: string): boolean;
|
|
|
594
595
|
//#region src/utils.d.ts
|
|
595
596
|
declare function createDocId(prefix: string): string;
|
|
596
597
|
//#endregion
|
|
597
|
-
export { BOOK_DOCID_PREFIX, Book, BookIcon, BookIconFile, BookIconInline, BookMetadata, __json_default_export as BookSchema, EncryptedBook, EncryptedData, EncryptedFile, EncryptedNote, EncryptedTag, EncryptionMetadata, FILE_DOCID_PREFIX, File, FileAttachmentItem, __json_default_export$1 as FileSchema, ImageFileType, InvalidDataError, NOTE_DOCID_PREFIX, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, Note, NoteMetadata, __json_default_export$2 as NoteSchema, NoteStatus, NoteVisibility, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TAG_DOCID_PREFIX, TRASH_BOOK_ID, Tag, TagColor, TagMetadata, __json_default_export$3 as TagSchema, TrashBookId, createBookId, createDocId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
|
|
598
|
+
export { BOOK_DOCID_PREFIX, Book, BookIcon, BookIconFile, BookIconInline, BookMetadata, __json_default_export as BookSchema, EncryptedBook, EncryptedData, EncryptedFile, EncryptedNote, EncryptedTag, EncryptionMetadata, FILE_DOCID_PREFIX, File, FileAttachmentItem, __json_default_export$1 as FileSchema, ImageFileType, InvalidDataError, NOTE_DOCID_PREFIX, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, Note, NoteMetadata, __json_default_export$2 as NoteSchema, NoteStatus, NoteVisibility, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TAG_DOCID_PREFIX, TEMPLATE_BOOK_ID, TRASH_BOOK_ID, Tag, TagColor, TagMetadata, __json_default_export$3 as TagSchema, TemplateBookId, TrashBookId, createBookId, createDocId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
|
|
598
599
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.esm.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import validator from "../validators/note";
|
|
2
|
-
import { webcrypto } from "node:crypto";
|
|
3
2
|
import validator$1 from "../validators/book";
|
|
4
3
|
import validator$2 from "../validators/tag";
|
|
5
4
|
import validator$3 from "../validators/file";
|
|
@@ -27,7 +26,7 @@ var note_default = {
|
|
|
27
26
|
"type": "string",
|
|
28
27
|
"minLength": 5,
|
|
29
28
|
"maxLength": 128,
|
|
30
|
-
"pattern": "^(book:|trash$)"
|
|
29
|
+
"pattern": "^(book:|trash$|template$)"
|
|
31
30
|
},
|
|
32
31
|
"title": {
|
|
33
32
|
"description": "The note title",
|
|
@@ -114,35 +113,102 @@ var note_default = {
|
|
|
114
113
|
]
|
|
115
114
|
};
|
|
116
115
|
//#endregion
|
|
117
|
-
//#region node_modules/.pnpm/nanoid@
|
|
116
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js
|
|
118
117
|
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
119
118
|
//#endregion
|
|
120
|
-
//#region node_modules/.pnpm/nanoid@
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.js
|
|
120
|
+
const GET_RANDOM_LIMIT = 65536;
|
|
121
|
+
function fillRandom(buffer) {
|
|
122
|
+
let from = 0;
|
|
123
|
+
while (from < buffer.length) {
|
|
124
|
+
let to = Math.min(from + GET_RANDOM_LIMIT, buffer.length);
|
|
125
|
+
crypto.getRandomValues(buffer.subarray(from, to));
|
|
126
|
+
from = to;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function random(bytes) {
|
|
130
|
+
bytes |= 0;
|
|
124
131
|
if (bytes < 0) throw new RangeError("Wrong ID size");
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
let buffer = Buffer.allocUnsafe(bytes);
|
|
133
|
+
fillRandom(buffer);
|
|
134
|
+
return buffer;
|
|
135
|
+
}
|
|
136
|
+
function customRandom(alphabet, defaultSize, getRandom) {
|
|
137
|
+
let safeByteCutoff = 256 - 256 % alphabet.length;
|
|
138
|
+
if (safeByteCutoff === 256) {
|
|
139
|
+
let mask = alphabet.length - 1;
|
|
140
|
+
return (size = defaultSize) => {
|
|
141
|
+
if (!size) return "";
|
|
142
|
+
let id = "";
|
|
143
|
+
while (true) {
|
|
144
|
+
let bytes = getRandom(size);
|
|
145
|
+
let i = size;
|
|
146
|
+
while (i--) {
|
|
147
|
+
id += alphabet[bytes[i] & mask];
|
|
148
|
+
if (id.length >= size) return id;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
137
152
|
}
|
|
138
|
-
|
|
153
|
+
let step = Math.ceil(1.6 * 256 * defaultSize / safeByteCutoff);
|
|
154
|
+
return (size = defaultSize) => {
|
|
155
|
+
if (!size) return "";
|
|
156
|
+
let id = "";
|
|
157
|
+
while (true) {
|
|
158
|
+
let bytes = getRandom(step);
|
|
159
|
+
let i = step;
|
|
160
|
+
while (i--) if (bytes[i] < safeByteCutoff) {
|
|
161
|
+
id += alphabet[bytes[i] % alphabet.length];
|
|
162
|
+
if (id.length >= size) return id;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
139
166
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
for (let i =
|
|
144
|
-
|
|
167
|
+
const POOL_MAX = GET_RANDOM_LIMIT / 2;
|
|
168
|
+
function customAlphabet(alphabet, defaultSize = 21) {
|
|
169
|
+
if (typeof alphabet !== "string" || !alphabet.length || alphabet.length > 256) return customRandom(alphabet, defaultSize, random);
|
|
170
|
+
for (let i = 0; i < alphabet.length; i++) if (alphabet.charCodeAt(i) > 255) return customRandom(alphabet, defaultSize, random);
|
|
171
|
+
let charCodes = Uint8Array.from(alphabet, (str) => {
|
|
172
|
+
return str.charCodeAt(0);
|
|
173
|
+
});
|
|
174
|
+
let alphabetLen = alphabet.length;
|
|
175
|
+
let mask = (2 << 31 - Math.clz32(alphabetLen - 1 | 1)) - 1;
|
|
176
|
+
let pool = "";
|
|
177
|
+
let poolOffset = 0;
|
|
178
|
+
let poolNext = 0;
|
|
179
|
+
return (size = defaultSize) => {
|
|
180
|
+
size |= 0;
|
|
181
|
+
if (size < 0) throw new RangeError("Wrong ID size");
|
|
182
|
+
if (size === 0) return "";
|
|
183
|
+
if (poolOffset + size > pool.length) {
|
|
184
|
+
let target = Math.max(poolNext, size);
|
|
185
|
+
poolNext = Math.min(target * 16, POOL_MAX);
|
|
186
|
+
let buffer = Buffer.allocUnsafe(target);
|
|
187
|
+
if (mask === alphabetLen - 1) {
|
|
188
|
+
fillRandom(buffer);
|
|
189
|
+
for (let i = 0; i < target; i++) buffer[i] = charCodes[buffer[i] & mask];
|
|
190
|
+
} else {
|
|
191
|
+
let randomBytes = Buffer.allocUnsafe(Math.ceil(1.6 * (mask + 1) * target / alphabetLen));
|
|
192
|
+
let accepted = 0;
|
|
193
|
+
while (accepted < target) {
|
|
194
|
+
fillRandom(randomBytes);
|
|
195
|
+
for (let i = 0; i < randomBytes.length; i++) {
|
|
196
|
+
let index = randomBytes[i] & mask;
|
|
197
|
+
if (index < alphabetLen) {
|
|
198
|
+
buffer[accepted++] = charCodes[index];
|
|
199
|
+
if (accepted === target) break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
pool = buffer.toString("latin1");
|
|
205
|
+
poolOffset = 0;
|
|
206
|
+
}
|
|
207
|
+
poolOffset += size;
|
|
208
|
+
return pool.substring(poolOffset - size, poolOffset);
|
|
209
|
+
};
|
|
145
210
|
}
|
|
211
|
+
const nanoid = customAlphabet(urlAlphabet);
|
|
146
212
|
//#endregion
|
|
147
213
|
//#region src/utils.ts
|
|
148
214
|
function createDocId(prefix) {
|
|
@@ -172,6 +238,7 @@ function validateDocId(prefix, docId) {
|
|
|
172
238
|
//#region src/note.ts
|
|
173
239
|
const NOTE_DOCID_PREFIX = "note:";
|
|
174
240
|
const TRASH_BOOK_ID = "trash";
|
|
241
|
+
const TEMPLATE_BOOK_ID = "template";
|
|
175
242
|
const NOTE_STATUS = {
|
|
176
243
|
NONE: "none",
|
|
177
244
|
ACTIVE: "active",
|
|
@@ -503,6 +570,6 @@ function validateFileId(docId) {
|
|
|
503
570
|
return validateDocId(FILE_DOCID_PREFIX, docId);
|
|
504
571
|
}
|
|
505
572
|
//#endregion
|
|
506
|
-
export { BOOK_DOCID_PREFIX, book_default as BookSchema, FILE_DOCID_PREFIX, file_default as FileSchema, InvalidDataError, NOTE_DOCID_PREFIX, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, note_default as NoteSchema, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TAG_DOCID_PREFIX, TRASH_BOOK_ID, tag_default as TagSchema, createBookId, createDocId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
|
|
573
|
+
export { BOOK_DOCID_PREFIX, book_default as BookSchema, FILE_DOCID_PREFIX, file_default as FileSchema, InvalidDataError, NOTE_DOCID_PREFIX, NOTE_STATUS, NOTE_TITLE_MAX_LENGTH, NOTE_VISIBILITY, note_default as NoteSchema, SUPPORTED_IMAGE_MIME_TYPES, TAG_COLOR, TAG_DOCID_PREFIX, TEMPLATE_BOOK_ID, TRASH_BOOK_ID, tag_default as TagSchema, createBookId, createDocId, createFileId, createNoteId, createTagId, maxAttachmentFileSize, supportedImageFileTypes, validateBook, validateBookId, validateDocId, validateFile, validateFileId, validateNote, validateNoteId, validateTag, validateTagId, validationErrorsToMessage };
|
|
507
574
|
|
|
508
575
|
//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["scopedUrlAlphabet","validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/index.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { webcrypto as crypto } from 'node:crypto'\n\nimport { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet } from './url-alphabet/index.js'\n\nconst POOL_SIZE_MULTIPLIER = 128\nlet pool, poolOffset\n\nfunction fillPool(bytes) {\n if (bytes < 0) throw new RangeError('Wrong ID size')\n try {\n if (!pool || pool.length < bytes) {\n pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)\n crypto.getRandomValues(pool)\n poolOffset = 0\n } else if (poolOffset + bytes > pool.length) {\n crypto.getRandomValues(pool)\n poolOffset = 0\n }\n } catch (e) {\n pool = undefined\n throw e\n }\n poolOffset += bytes\n}\n\nexport function random(bytes) {\n fillPool((bytes |= 0))\n return pool.subarray(poolOffset - bytes, poolOffset)\n}\n\nexport function customRandom(alphabet, defaultSize, getRandom) {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let i = size\n while (i--) {\n id += alphabet[bytes[i] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let i = step\n while (i--) {\n if (bytes[i] < safeByteCutoff) {\n id += alphabet[bytes[i] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\nexport function customAlphabet(alphabet, size = 21) {\n return customRandom(alphabet, size, random)\n}\n\nexport function nanoid(size = 21) {\n fillPool((size |= 0))\n\n let id = ''\n for (let i = poolOffset - size; i < poolOffset; i++) {\n id += scopedUrlAlphabet[pool[i] & 63]\n }\n return id\n}\n","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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACK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;CAAG,IACjD,CAAC,CACH;CACA,KAAK;AACP;AACA,MAAa,wBAAgC,KAAK,OAAO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { urlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet }\n\nconst GET_RANDOM_LIMIT = 65536\n\nfunction fillRandom(buffer) {\n let from = 0\n while (from < buffer.length) {\n let to = Math.min(from + GET_RANDOM_LIMIT, buffer.length)\n crypto.getRandomValues(buffer.subarray(from, to))\n from = to\n }\n}\n\nexport function random(bytes) {\n bytes |= 0\n if (bytes < 0) throw new RangeError('Wrong ID size')\n let buffer = Buffer.allocUnsafe(bytes)\n fillRandom(buffer)\n return buffer\n}\n\nexport function customRandom(alphabet, defaultSize, getRandom) {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let i = size\n while (i--) {\n id += alphabet[bytes[i] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let i = step\n while (i--) {\n if (bytes[i] < safeByteCutoff) {\n id += alphabet[bytes[i] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\n\nconst POOL_MAX = GET_RANDOM_LIMIT / 2\n\nexport function customAlphabet(alphabet, defaultSize = 21) {\n if (\n typeof alphabet !== 'string' ||\n !alphabet.length ||\n alphabet.length > 256\n ) {\n return customRandom(alphabet, defaultSize, random)\n }\n for (let i = 0; i < alphabet.length; i++) {\n if (alphabet.charCodeAt(i) > 255) {\n return customRandom(alphabet, defaultSize, random)\n }\n }\n\n let charCodes = Uint8Array.from(alphabet, str => {\n return str.charCodeAt(0)\n })\n let alphabetLen = alphabet.length\n let mask = (2 << (31 - Math.clz32((alphabetLen - 1) | 1))) - 1\n\n let pool = ''\n let poolOffset = 0\n let poolNext = 0\n\n return (size = defaultSize) => {\n size |= 0\n if (size < 0) throw new RangeError('Wrong ID size')\n if (size === 0) return ''\n if (poolOffset + size > pool.length) {\n let target = Math.max(poolNext, size)\n poolNext = Math.min(target * 16, POOL_MAX)\n let buffer = Buffer.allocUnsafe(target)\n if (mask === alphabetLen - 1) {\n fillRandom(buffer)\n for (let i = 0; i < target; i++) {\n buffer[i] = charCodes[buffer[i] & mask]\n }\n } else {\n let randomBytes = Buffer.allocUnsafe(\n Math.ceil((1.6 * (mask + 1) * target) / alphabetLen)\n )\n let accepted = 0\n while (accepted < target) {\n fillRandom(randomBytes)\n for (let i = 0; i < randomBytes.length; i++) {\n let index = randomBytes[i] & mask\n if (index < alphabetLen) {\n buffer[accepted++] = charCodes[index]\n if (accepted === target) break\n }\n }\n }\n }\n pool = buffer.toString('latin1')\n poolOffset = 0\n }\n poolOffset += size\n return pool.substring(poolOffset - size, poolOffset)\n }\n}\n\nexport const nanoid = customAlphabet(urlAlphabet)\n","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 TemplateBookId = 'template'\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'\nexport const TEMPLATE_BOOK_ID = 'template'\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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACGF,MAAM,mBAAmB;AAEzB,SAAS,WAAW,QAAQ;CAC1B,IAAI,OAAO;CACX,OAAO,OAAO,OAAO,QAAQ;EAC3B,IAAI,KAAK,KAAK,IAAI,OAAO,kBAAkB,OAAO,MAAM;EACxD,OAAO,gBAAgB,OAAO,SAAS,MAAM,EAAE,CAAC;EAChD,OAAO;CACT;AACF;AAEA,SAAgB,OAAO,OAAO;CAC5B,SAAS;CACT,IAAI,QAAQ,GAAG,MAAM,IAAI,WAAW,eAAe;CACnD,IAAI,SAAS,OAAO,YAAY,KAAK;CACrC,WAAW,MAAM;CACjB,OAAO;AACT;AAEA,SAAgB,aAAa,UAAU,aAAa,WAAW;CAC7D,IAAI,iBAAiB,MAAO,MAAM,SAAS;CAE3C,IAAI,mBAAmB,KAAK;EAC1B,IAAI,OAAO,SAAS,SAAS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;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEhEA,MAAa,0BAAwD;CACnE;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAa,6BAET;CACF,GAAG,wBAAwB,QACxB,MAAM,QAAQ;EAAE,GAAG;GAAO,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK;CAAG,IACjD,CAAC,CACH;CACA,KAAK;AACP;AACA,MAAa,wBAAgC,KAAK,OAAO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let validators_note = require("../validators/note");
|
|
25
25
|
validators_note = __toESM(validators_note);
|
|
26
|
-
let node_crypto = require("node:crypto");
|
|
27
26
|
let validators_book = require("../validators/book");
|
|
28
27
|
validators_book = __toESM(validators_book);
|
|
29
28
|
let validators_tag = require("../validators/tag");
|
|
@@ -54,7 +53,7 @@ var note_default = {
|
|
|
54
53
|
"type": "string",
|
|
55
54
|
"minLength": 5,
|
|
56
55
|
"maxLength": 128,
|
|
57
|
-
"pattern": "^(book:|trash$)"
|
|
56
|
+
"pattern": "^(book:|trash$|template$)"
|
|
58
57
|
},
|
|
59
58
|
"title": {
|
|
60
59
|
"description": "The note title",
|
|
@@ -141,35 +140,102 @@ var note_default = {
|
|
|
141
140
|
]
|
|
142
141
|
};
|
|
143
142
|
//#endregion
|
|
144
|
-
//#region node_modules/.pnpm/nanoid@
|
|
143
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js
|
|
145
144
|
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
146
145
|
//#endregion
|
|
147
|
-
//#region node_modules/.pnpm/nanoid@
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
//#region node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.js
|
|
147
|
+
const GET_RANDOM_LIMIT = 65536;
|
|
148
|
+
function fillRandom(buffer) {
|
|
149
|
+
let from = 0;
|
|
150
|
+
while (from < buffer.length) {
|
|
151
|
+
let to = Math.min(from + GET_RANDOM_LIMIT, buffer.length);
|
|
152
|
+
crypto.getRandomValues(buffer.subarray(from, to));
|
|
153
|
+
from = to;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function random(bytes) {
|
|
157
|
+
bytes |= 0;
|
|
151
158
|
if (bytes < 0) throw new RangeError("Wrong ID size");
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
let buffer = Buffer.allocUnsafe(bytes);
|
|
160
|
+
fillRandom(buffer);
|
|
161
|
+
return buffer;
|
|
162
|
+
}
|
|
163
|
+
function customRandom(alphabet, defaultSize, getRandom) {
|
|
164
|
+
let safeByteCutoff = 256 - 256 % alphabet.length;
|
|
165
|
+
if (safeByteCutoff === 256) {
|
|
166
|
+
let mask = alphabet.length - 1;
|
|
167
|
+
return (size = defaultSize) => {
|
|
168
|
+
if (!size) return "";
|
|
169
|
+
let id = "";
|
|
170
|
+
while (true) {
|
|
171
|
+
let bytes = getRandom(size);
|
|
172
|
+
let i = size;
|
|
173
|
+
while (i--) {
|
|
174
|
+
id += alphabet[bytes[i] & mask];
|
|
175
|
+
if (id.length >= size) return id;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
164
179
|
}
|
|
165
|
-
|
|
180
|
+
let step = Math.ceil(1.6 * 256 * defaultSize / safeByteCutoff);
|
|
181
|
+
return (size = defaultSize) => {
|
|
182
|
+
if (!size) return "";
|
|
183
|
+
let id = "";
|
|
184
|
+
while (true) {
|
|
185
|
+
let bytes = getRandom(step);
|
|
186
|
+
let i = step;
|
|
187
|
+
while (i--) if (bytes[i] < safeByteCutoff) {
|
|
188
|
+
id += alphabet[bytes[i] % alphabet.length];
|
|
189
|
+
if (id.length >= size) return id;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
166
193
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
for (let i =
|
|
171
|
-
|
|
194
|
+
const POOL_MAX = GET_RANDOM_LIMIT / 2;
|
|
195
|
+
function customAlphabet(alphabet, defaultSize = 21) {
|
|
196
|
+
if (typeof alphabet !== "string" || !alphabet.length || alphabet.length > 256) return customRandom(alphabet, defaultSize, random);
|
|
197
|
+
for (let i = 0; i < alphabet.length; i++) if (alphabet.charCodeAt(i) > 255) return customRandom(alphabet, defaultSize, random);
|
|
198
|
+
let charCodes = Uint8Array.from(alphabet, (str) => {
|
|
199
|
+
return str.charCodeAt(0);
|
|
200
|
+
});
|
|
201
|
+
let alphabetLen = alphabet.length;
|
|
202
|
+
let mask = (2 << 31 - Math.clz32(alphabetLen - 1 | 1)) - 1;
|
|
203
|
+
let pool = "";
|
|
204
|
+
let poolOffset = 0;
|
|
205
|
+
let poolNext = 0;
|
|
206
|
+
return (size = defaultSize) => {
|
|
207
|
+
size |= 0;
|
|
208
|
+
if (size < 0) throw new RangeError("Wrong ID size");
|
|
209
|
+
if (size === 0) return "";
|
|
210
|
+
if (poolOffset + size > pool.length) {
|
|
211
|
+
let target = Math.max(poolNext, size);
|
|
212
|
+
poolNext = Math.min(target * 16, POOL_MAX);
|
|
213
|
+
let buffer = Buffer.allocUnsafe(target);
|
|
214
|
+
if (mask === alphabetLen - 1) {
|
|
215
|
+
fillRandom(buffer);
|
|
216
|
+
for (let i = 0; i < target; i++) buffer[i] = charCodes[buffer[i] & mask];
|
|
217
|
+
} else {
|
|
218
|
+
let randomBytes = Buffer.allocUnsafe(Math.ceil(1.6 * (mask + 1) * target / alphabetLen));
|
|
219
|
+
let accepted = 0;
|
|
220
|
+
while (accepted < target) {
|
|
221
|
+
fillRandom(randomBytes);
|
|
222
|
+
for (let i = 0; i < randomBytes.length; i++) {
|
|
223
|
+
let index = randomBytes[i] & mask;
|
|
224
|
+
if (index < alphabetLen) {
|
|
225
|
+
buffer[accepted++] = charCodes[index];
|
|
226
|
+
if (accepted === target) break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
pool = buffer.toString("latin1");
|
|
232
|
+
poolOffset = 0;
|
|
233
|
+
}
|
|
234
|
+
poolOffset += size;
|
|
235
|
+
return pool.substring(poolOffset - size, poolOffset);
|
|
236
|
+
};
|
|
172
237
|
}
|
|
238
|
+
const nanoid = customAlphabet(urlAlphabet);
|
|
173
239
|
//#endregion
|
|
174
240
|
//#region src/utils.ts
|
|
175
241
|
function createDocId(prefix) {
|
|
@@ -199,6 +265,7 @@ function validateDocId(prefix, docId) {
|
|
|
199
265
|
//#region src/note.ts
|
|
200
266
|
const NOTE_DOCID_PREFIX = "note:";
|
|
201
267
|
const TRASH_BOOK_ID = "trash";
|
|
268
|
+
const TEMPLATE_BOOK_ID = "template";
|
|
202
269
|
const NOTE_STATUS = {
|
|
203
270
|
NONE: "none",
|
|
204
271
|
ACTIVE: "active",
|
|
@@ -558,6 +625,7 @@ Object.defineProperty(exports, "NoteSchema", {
|
|
|
558
625
|
exports.SUPPORTED_IMAGE_MIME_TYPES = SUPPORTED_IMAGE_MIME_TYPES;
|
|
559
626
|
exports.TAG_COLOR = TAG_COLOR;
|
|
560
627
|
exports.TAG_DOCID_PREFIX = TAG_DOCID_PREFIX;
|
|
628
|
+
exports.TEMPLATE_BOOK_ID = TEMPLATE_BOOK_ID;
|
|
561
629
|
exports.TRASH_BOOK_ID = TRASH_BOOK_ID;
|
|
562
630
|
Object.defineProperty(exports, "TagSchema", {
|
|
563
631
|
enumerable: true,
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["scopedUrlAlphabet","validator","validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@5.1.15/node_modules/nanoid/index.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { webcrypto as crypto } from 'node:crypto'\n\nimport { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet } from './url-alphabet/index.js'\n\nconst POOL_SIZE_MULTIPLIER = 128\nlet pool, poolOffset\n\nfunction fillPool(bytes) {\n if (bytes < 0) throw new RangeError('Wrong ID size')\n try {\n if (!pool || pool.length < bytes) {\n pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)\n crypto.getRandomValues(pool)\n poolOffset = 0\n } else if (poolOffset + bytes > pool.length) {\n crypto.getRandomValues(pool)\n poolOffset = 0\n }\n } catch (e) {\n pool = undefined\n throw e\n }\n poolOffset += bytes\n}\n\nexport function random(bytes) {\n fillPool((bytes |= 0))\n return pool.subarray(poolOffset - bytes, poolOffset)\n}\n\nexport function customRandom(alphabet, defaultSize, getRandom) {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let i = size\n while (i--) {\n id += alphabet[bytes[i] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let i = step\n while (i--) {\n if (bytes[i] < safeByteCutoff) {\n id += alphabet[bytes[i] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\nexport function customAlphabet(alphabet, size = 21) {\n return customRandom(alphabet, size, random)\n}\n\nexport function nanoid(size = 21) {\n fillPool((size |= 0))\n\n let id = ''\n for (let i = poolOffset - size; i < poolOffset; i++) {\n id += scopedUrlAlphabet[pool[i] & 63]\n }\n return id\n}\n","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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACKF,MAAM,uBAAuB;AAC7B,IAAI,MAAM;AAEV,SAAS,SAAS,OAAO;CACvB,IAAI,QAAQ,GAAG,MAAM,IAAI,WAAW,e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AO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC,gBAAAA;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["validator","validator","validator","validator"],"sources":["../json-schema/note.json","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/url-alphabet/index.js","../node_modules/.pnpm/nanoid@6.0.0/node_modules/nanoid/index.js","../src/utils.ts","../src/validator.ts","../src/note.ts","../json-schema/book.json","../src/book.ts","../json-schema/tag.json","../src/tag.ts","../json-schema/file.json","../src/file.ts"],"sourcesContent":["","export let urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n","import { urlAlphabet } from './url-alphabet/index.js'\n\nexport { urlAlphabet }\n\nconst GET_RANDOM_LIMIT = 65536\n\nfunction fillRandom(buffer) {\n let from = 0\n while (from < buffer.length) {\n let to = Math.min(from + GET_RANDOM_LIMIT, buffer.length)\n crypto.getRandomValues(buffer.subarray(from, to))\n from = to\n }\n}\n\nexport function random(bytes) {\n bytes |= 0\n if (bytes < 0) throw new RangeError('Wrong ID size')\n let buffer = Buffer.allocUnsafe(bytes)\n fillRandom(buffer)\n return buffer\n}\n\nexport function customRandom(alphabet, defaultSize, getRandom) {\n let safeByteCutoff = 256 - (256 % alphabet.length)\n\n if (safeByteCutoff === 256) {\n let mask = alphabet.length - 1\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(size)\n let i = size\n while (i--) {\n id += alphabet[bytes[i] & mask]\n if (id.length >= size) return id\n }\n }\n }\n }\n\n let step = Math.ceil((1.6 * 256 * defaultSize) / safeByteCutoff)\n\n return (size = defaultSize) => {\n if (!size) return ''\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let i = step\n while (i--) {\n if (bytes[i] < safeByteCutoff) {\n id += alphabet[bytes[i] % alphabet.length]\n if (id.length >= size) return id\n }\n }\n }\n }\n}\n\n\nconst POOL_MAX = GET_RANDOM_LIMIT / 2\n\nexport function customAlphabet(alphabet, defaultSize = 21) {\n if (\n typeof alphabet !== 'string' ||\n !alphabet.length ||\n alphabet.length > 256\n ) {\n return customRandom(alphabet, defaultSize, random)\n }\n for (let i = 0; i < alphabet.length; i++) {\n if (alphabet.charCodeAt(i) > 255) {\n return customRandom(alphabet, defaultSize, random)\n }\n }\n\n let charCodes = Uint8Array.from(alphabet, str => {\n return str.charCodeAt(0)\n })\n let alphabetLen = alphabet.length\n let mask = (2 << (31 - Math.clz32((alphabetLen - 1) | 1))) - 1\n\n let pool = ''\n let poolOffset = 0\n let poolNext = 0\n\n return (size = defaultSize) => {\n size |= 0\n if (size < 0) throw new RangeError('Wrong ID size')\n if (size === 0) return ''\n if (poolOffset + size > pool.length) {\n let target = Math.max(poolNext, size)\n poolNext = Math.min(target * 16, POOL_MAX)\n let buffer = Buffer.allocUnsafe(target)\n if (mask === alphabetLen - 1) {\n fillRandom(buffer)\n for (let i = 0; i < target; i++) {\n buffer[i] = charCodes[buffer[i] & mask]\n }\n } else {\n let randomBytes = Buffer.allocUnsafe(\n Math.ceil((1.6 * (mask + 1) * target) / alphabetLen)\n )\n let accepted = 0\n while (accepted < target) {\n fillRandom(randomBytes)\n for (let i = 0; i < randomBytes.length; i++) {\n let index = randomBytes[i] & mask\n if (index < alphabetLen) {\n buffer[accepted++] = charCodes[index]\n if (accepted === target) break\n }\n }\n }\n }\n pool = buffer.toString('latin1')\n poolOffset = 0\n }\n poolOffset += size\n return pool.substring(poolOffset - size, poolOffset)\n }\n}\n\nexport const nanoid = customAlphabet(urlAlphabet)\n","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 TemplateBookId = 'template'\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'\nexport const TEMPLATE_BOOK_ID = 'template'\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"],"x_google_ignoreList":[1,2],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IAAW,cACT;;;ACGF,MAAM,mBAAmB;AAEzB,SAAS,WAAW,QAAQ;CAC1B,IAAI,OAAO;CACX,OAAO,OAAO,OAAO,QAAQ;EAC3B,IAAI,KAAK,KAAK,IAAI,OAAO,kBAAkB,OAAO,MAAM;EACxD,OAAO,gBAAgB,OAAO,SAAS,MAAM,EAAE,CAAC;EAChD,OAAO;CACT;AACF;AAEA,SAAgB,OAAO,OAAO;CAC5B,SAAS;CACT,IAAI,QAAQ,GAAG,MAAM,IAAI,WAAW,eAAe;CACnD,IAAI,SAAS,OAAO,YAAY,KAAK;CACrC,WAAW,MAAM;CACjB,OAAO;AACT;AAEA,SAAgB,aAAa,UAAU,aAAa,WAAW;CAC7D,IAAI,iBAAiB,MAAO,MAAM,SAAS;CAE3C,IAAI,mBAAmB,KAAK;EAC1B,IAAI,OAAO,SAAS,SAAS;EAE7B,QAAQ,OAAO,gBAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;AEhEA,MAAa,0BAAwD;CACnE;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAa,6BAET;CACF,GAAG,wBAAwB,QACxB,MAAM,QAAQ;EAAE,GAAG;GAAO,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK;CAAG,IACjD,CAAC,CACH;CACA,KAAK;AACP;AACA,MAAa,wBAAgC,KAAK,OAAO;AAwBzD,MAAa,oBAAoB;AAEjC,MAAM,eAAuCC,gBAAAA;AAG7C,SAAgB,eAAuB;CACrC,OAAO,YAAY,iBAAiB;AACtC;AAEA,SAAgB,eAAe,OAAwB;CACrD,OAAO,cAAc,mBAAmB,KAAK;AAC/C"}
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("../validators/note"),require("node:crypto"),require("../validators/book"),require("../validators/tag"),require("../validators/file")):typeof define==`function`&&define.amd?define([`exports`,`../validators/note`,`node:crypto`,`../validators/book`,`../validators/tag`,`../validators/file`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.InkdropModel={},e.validators_note,e.node_crypto,e.validators_book,e.validators_tag,e.validators_file))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Object.create,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,f=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=l(t),a=0,o=i.length,u;a<o;a++)u=i[a],!d.call(e,u)&&u!==n&&s(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(r=c(t,u))||r.enumerable});return e},p=(e,t,n)=>(n=e==null?{}:o(u(e)),f(t||!e||!e.__esModule?s(n,`default`,{value:e,enumerable:!0}):n,e));t=p(t),r=p(r),i=p(i),a=p(a);var m={$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`]};let h,g;function _(e){if(e<0)throw RangeError(`Wrong ID size`);try{!h||h.length<e?(h=Buffer.allocUnsafe(e*128),n.webcrypto.getRandomValues(h),g=0):g+e>h.length&&(n.webcrypto.getRandomValues(h),g=0)}catch(e){throw h=void 0,e}g+=e}function v(e=21){_(e|=0);let t=``;for(let n=g-e;n<g;n++)t+=`useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict`[h[n]&63];return t}function y(e){return`${e}${v(8)}`}function b(e){return e instanceof Array?e.map(e=>typeof e==`object`?`"${e.instancePath}" ${e.message}`:e).join(`, `):e}var x=class extends Error{constructor(e,t){super(e+` `+b(t)),this.name=`InvalidDataError`,this.errors=t}};function S(e,t){if(!t.startsWith(e)||t.length<=5||t.length>128)throw Error(`Invalid document ID`);return!0}let C=`note:`,w={NONE:`none`,ACTIVE:`active`,ON_HOLD:`onHold`,COMPLETED:`completed`,DROPPED:`dropped`},T={PRIVATE:`private`,PUBLIC:`public`},E=t.default;function D(){return y(C)}function O(e){return S(C,e)}var k={$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`]};let A=`book:`,j=r.default;function M(){return y(A)}function N(e){return S(A,e)}var P={$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`]};let F={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`},I=`tag:`,L=i.default;function R(){return y(I)}function z(e){return S(I,e)}var B={$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`]};let V=[`image/png`,`image/jpeg`,`image/jpg`,`image/svg+xml`,`image/gif`,`image/heic`,`image/heif`],H={...V.reduce((e,t)=>({...e,[t.split(`/`)[1]]:t}),{}),jpg:`image/jpeg`},U=`file:`,W=a.default;function G(){return y(U)}function K(e){return S(U,e)}e.BOOK_DOCID_PREFIX=A,Object.defineProperty(e,"BookSchema",{enumerable:!0,get:function(){return k}}),e.FILE_DOCID_PREFIX=U,Object.defineProperty(e,"FileSchema",{enumerable:!0,get:function(){return B}}),e.InvalidDataError=x,e.NOTE_DOCID_PREFIX=C,e.NOTE_STATUS=w,e.NOTE_TITLE_MAX_LENGTH=256,e.NOTE_VISIBILITY=T,Object.defineProperty(e,"NoteSchema",{enumerable:!0,get:function(){return m}}),e.SUPPORTED_IMAGE_MIME_TYPES=H,e.TAG_COLOR=F,e.TAG_DOCID_PREFIX=I,e.TRASH_BOOK_ID=`trash`,Object.defineProperty(e,"TagSchema",{enumerable:!0,get:function(){return P}}),e.createBookId=M,e.createDocId=y,e.createFileId=G,e.createNoteId=D,e.createTagId=R,e.maxAttachmentFileSize=10485760,e.supportedImageFileTypes=V,e.validateBook=j,e.validateBookId=N,e.validateDocId=S,e.validateFile=W,e.validateFileId=K,e.validateNote=E,e.validateNoteId=O,e.validateTag=L,e.validateTagId=z,e.validationErrorsToMessage=b});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("../validators/note"),require("../validators/book"),require("../validators/tag"),require("../validators/file")):typeof define==`function`&&define.amd?define([`exports`,`../validators/note`,`../validators/book`,`../validators/tag`,`../validators/file`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.InkdropModel={},e.validators_note,e.validators_book,e.validators_tag,e.validators_file))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=Object.create,o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty,d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=c(t),a=0,l=i.length,d;a<l;a++)d=i[a],!u.call(e,d)&&d!==n&&o(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=s(t,d))||r.enumerable});return e},f=(e,t,n)=>(n=e==null?{}:a(l(e)),d(t||!e||!e.__esModule?o(n,`default`,{value:e,enumerable:!0}):n,e));t=f(t),n=f(n),r=f(r),i=f(i);var p={$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$|template$)`},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 m(e){let t=0;for(;t<e.length;){let n=Math.min(t+65536,e.length);crypto.getRandomValues(e.subarray(t,n)),t=n}}function h(e){if(e|=0,e<0)throw RangeError(`Wrong ID size`);let t=Buffer.allocUnsafe(e);return m(t),t}function g(e,t,n){let r=256-256%e.length;if(r===256){let r=e.length-1;return(i=t)=>{if(!i)return``;let a=``;for(;;){let t=n(i),o=i;for(;o--;)if(a+=e[t[o]&r],a.length>=i)return a}}}let i=Math.ceil(1.6*256*t/r);return(a=t)=>{if(!a)return``;let o=``;for(;;){let t=n(i),s=i;for(;s--;)if(t[s]<r&&(o+=e[t[s]%e.length],o.length>=a))return o}}}function _(e,t=21){if(typeof e!=`string`||!e.length||e.length>256)return g(e,t,h);for(let n=0;n<e.length;n++)if(e.charCodeAt(n)>255)return g(e,t,h);let n=Uint8Array.from(e,e=>e.charCodeAt(0)),r=e.length,i=(2<<31-Math.clz32(r-1|1))-1,a=``,o=0,s=0;return(e=t)=>{if(e|=0,e<0)throw RangeError(`Wrong ID size`);if(e===0)return``;if(o+e>a.length){let t=Math.max(s,e);s=Math.min(t*16,32768);let c=Buffer.allocUnsafe(t);if(i===r-1){m(c);for(let e=0;e<t;e++)c[e]=n[c[e]&i]}else{let e=Buffer.allocUnsafe(Math.ceil(1.6*(i+1)*t/r)),a=0;for(;a<t;){m(e);for(let o=0;o<e.length;o++){let s=e[o]&i;if(s<r&&(c[a++]=n[s],a===t))break}}}a=c.toString(`latin1`),o=0}return o+=e,a.substring(o-e,o)}}let v=_(`useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict`);function y(e){return`${e}${v(8)}`}function b(e){return e instanceof Array?e.map(e=>typeof e==`object`?`"${e.instancePath}" ${e.message}`:e).join(`, `):e}var x=class extends Error{constructor(e,t){super(e+` `+b(t)),this.name=`InvalidDataError`,this.errors=t}};function S(e,t){if(!t.startsWith(e)||t.length<=5||t.length>128)throw Error(`Invalid document ID`);return!0}let C=`note:`,w={NONE:`none`,ACTIVE:`active`,ON_HOLD:`onHold`,COMPLETED:`completed`,DROPPED:`dropped`},T={PRIVATE:`private`,PUBLIC:`public`},E=t.default;function D(){return y(C)}function O(e){return S(C,e)}var k={$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`]};let A=`book:`,j=n.default;function M(){return y(A)}function N(e){return S(A,e)}var P={$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`]};let F={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`},I=`tag:`,L=r.default;function R(){return y(I)}function z(e){return S(I,e)}var B={$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`]};let V=[`image/png`,`image/jpeg`,`image/jpg`,`image/svg+xml`,`image/gif`,`image/heic`,`image/heif`],H={...V.reduce((e,t)=>({...e,[t.split(`/`)[1]]:t}),{}),jpg:`image/jpeg`},U=`file:`,W=i.default;function G(){return y(U)}function K(e){return S(U,e)}e.BOOK_DOCID_PREFIX=A,Object.defineProperty(e,"BookSchema",{enumerable:!0,get:function(){return k}}),e.FILE_DOCID_PREFIX=U,Object.defineProperty(e,"FileSchema",{enumerable:!0,get:function(){return B}}),e.InvalidDataError=x,e.NOTE_DOCID_PREFIX=C,e.NOTE_STATUS=w,e.NOTE_TITLE_MAX_LENGTH=256,e.NOTE_VISIBILITY=T,Object.defineProperty(e,"NoteSchema",{enumerable:!0,get:function(){return p}}),e.SUPPORTED_IMAGE_MIME_TYPES=H,e.TAG_COLOR=F,e.TAG_DOCID_PREFIX=I,e.TEMPLATE_BOOK_ID=`template`,e.TRASH_BOOK_ID=`trash`,Object.defineProperty(e,"TagSchema",{enumerable:!0,get:function(){return P}}),e.createBookId=M,e.createDocId=y,e.createFileId=G,e.createNoteId=D,e.createTagId=R,e.maxAttachmentFileSize=10485760,e.supportedImageFileTypes=V,e.validateBook=j,e.validateBookId=N,e.validateDocId=S,e.validateFile=W,e.validateFileId=K,e.validateNote=E,e.validateNoteId=O,e.validateTag=L,e.validateTagId=z,e.validationErrorsToMessage=b});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inkdrop-model",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Data model for Inkdrop",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm-run-all build:schema build:lib doc",
|
|
@@ -8,32 +8,30 @@
|
|
|
8
8
|
"build:schema": "./compile_schema.sh",
|
|
9
9
|
"lint": "oxlint",
|
|
10
10
|
"format": "oxfmt",
|
|
11
|
-
"test": "
|
|
11
|
+
"test": "vitest --run",
|
|
12
12
|
"doc": "./generate_doc.sh",
|
|
13
13
|
"typecheck": "tsc --noEmit",
|
|
14
14
|
"prepublishOnly": "npm-run-all build:* typecheck lint test"
|
|
15
15
|
},
|
|
16
16
|
"author": "Takuya Matsuyama <t@inkdrop.app>",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"packageManager": "pnpm@11.
|
|
18
|
+
"packageManager": "pnpm@11.11.0",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
21
|
"url": "https://github.com/inkdropapp/inkdrop-model.git"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/
|
|
25
|
-
"@types/node": "^26.0.0",
|
|
24
|
+
"@types/node": "^26.1.1",
|
|
26
25
|
"ajv": "^8.20.0",
|
|
27
26
|
"ajv-cli": "^5.0.0",
|
|
28
27
|
"ajv-formats": "^3.0.1",
|
|
29
|
-
"
|
|
30
|
-
"nanoid": "^5.1.15",
|
|
28
|
+
"nanoid": "^6.0.0",
|
|
31
29
|
"npm-run-all2": "^9.0.2",
|
|
32
|
-
"oxfmt": "0.
|
|
33
|
-
"oxlint": "1.
|
|
34
|
-
"
|
|
35
|
-
"tsdown": "0.22.3",
|
|
30
|
+
"oxfmt": "0.58.0",
|
|
31
|
+
"oxlint": "1.73.0",
|
|
32
|
+
"tsdown": "0.22.5",
|
|
36
33
|
"typescript": "^6.0.3",
|
|
34
|
+
"vitest": "^4.1.10",
|
|
37
35
|
"yaml": "^2.9.0"
|
|
38
36
|
},
|
|
39
37
|
"types": "lib/index.d.ts",
|
package/validators/note.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";module.exports = validate20;module.exports.default = validate20;const schema22 = {"$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":true},"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":true}},"required":["_id","bookId","title","doctype","body","updatedAt","createdAt","timestamp"]};const func4 = require("ajv/dist/runtime/ucs2length").default;const pattern0 = new RegExp("^note:", "u");const pattern1 = new RegExp("^(book:|trash$)", "u");function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){/*# sourceURL="note" */;let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((((((((data._id === undefined) && (missing0 = "_id")) || ((data.bookId === undefined) && (missing0 = "bookId"))) || ((data.title === undefined) && (missing0 = "title"))) || ((data.doctype === undefined) && (missing0 = "doctype"))) || ((data.body === undefined) && (missing0 = "body"))) || ((data.updatedAt === undefined) && (missing0 = "updatedAt"))) || ((data.createdAt === undefined) && (missing0 = "createdAt"))) || ((data.timestamp === undefined) && (missing0 = "timestamp"))){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data._id !== undefined){let data0 = data._id;const _errs1 = errors;if(errors === _errs1){if(typeof data0 === "string"){if(func4(data0) > 128){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}else {if(func4(data0) < 6){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/minLength",keyword:"minLength",params:{limit: 6},message:"must NOT have fewer than 6 characters"}];return false;}else {if(!pattern0.test(data0)){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/pattern",keyword:"pattern",params:{pattern: "^note:"},message:"must match pattern \""+"^note:"+"\""}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data._rev !== undefined){const _errs3 = errors;if(typeof data._rev !== "string"){validate20.errors = [{instancePath:instancePath+"/_rev",schemaPath:"#/properties/_rev/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.bookId !== undefined){let data2 = data.bookId;const _errs5 = errors;if(errors === _errs5){if(typeof data2 === "string"){if(func4(data2) > 128){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}else {if(func4(data2) < 5){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/minLength",keyword:"minLength",params:{limit: 5},message:"must NOT have fewer than 5 characters"}];return false;}else {if(!pattern1.test(data2)){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/pattern",keyword:"pattern",params:{pattern: "^(book:|trash$)"},message:"must match pattern \""+"^(book:|trash$)"+"\""}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs5 === errors;}else {var valid0 = true;}if(valid0){if(data.title !== undefined){let data3 = data.title;const _errs7 = errors;if(errors === _errs7){if(typeof data3 === "string"){if(func4(data3) > 256){validate20.errors = [{instancePath:instancePath+"/title",schemaPath:"#/properties/title/maxLength",keyword:"maxLength",params:{limit: 256},message:"must NOT have more than 256 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/title",schemaPath:"#/properties/title/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs7 === errors;}else {var valid0 = true;}if(valid0){if(data.doctype !== undefined){let data4 = data.doctype;const _errs9 = errors;if(typeof data4 !== "string"){validate20.errors = [{instancePath:instancePath+"/doctype",schemaPath:"#/properties/doctype/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(data4 === "markdown")){validate20.errors = [{instancePath:instancePath+"/doctype",schemaPath:"#/properties/doctype/enum",keyword:"enum",params:{allowedValues: schema22.properties.doctype.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs9 === errors;}else {var valid0 = true;}if(valid0){if(data.body !== undefined){let data5 = data.body;const _errs11 = errors;if(errors === _errs11){if(typeof data5 === "string"){if(func4(data5) > 1048576){validate20.errors = [{instancePath:instancePath+"/body",schemaPath:"#/properties/body/maxLength",keyword:"maxLength",params:{limit: 1048576},message:"must NOT have more than 1048576 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/body",schemaPath:"#/properties/body/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs11 === errors;}else {var valid0 = true;}if(valid0){if(data.updatedAt !== undefined){let data6 = data.updatedAt;const _errs13 = errors;if(!((typeof data6 == "number") && (isFinite(data6)))){validate20.errors = [{instancePath:instancePath+"/updatedAt",schemaPath:"#/properties/updatedAt/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs13 === errors;}else {var valid0 = true;}if(valid0){if(data.createdAt !== undefined){let data7 = data.createdAt;const _errs15 = errors;if(!((typeof data7 == "number") && (isFinite(data7)))){validate20.errors = [{instancePath:instancePath+"/createdAt",schemaPath:"#/properties/createdAt/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs15 === errors;}else {var valid0 = true;}if(valid0){if(data.tags !== undefined){let data8 = data.tags;const _errs17 = errors;if(errors === _errs17){if(Array.isArray(data8)){var valid1 = true;const len0 = data8.length;for(let i0=0; i0<len0; i0++){const _errs19 = errors;if(typeof data8[i0] !== "string"){validate20.errors = [{instancePath:instancePath+"/tags/" + i0,schemaPath:"#/properties/tags/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs19 === errors;if(!valid1){break;}}if(valid1){let i1 = data8.length;let j0;if(i1 > 1){const indices0 = {};for(;i1--;){let item0 = data8[i1];if(typeof item0 !== "string"){continue;}if(typeof indices0[item0] == "number"){j0 = indices0[item0];validate20.errors = [{instancePath:instancePath+"/tags",schemaPath:"#/properties/tags/uniqueItems",keyword:"uniqueItems",params:{i: i1, j: j0},message:"must NOT have duplicate items (items ## "+j0+" and "+i1+" are identical)"}];return false;break;}indices0[item0] = i1;}}}}else {validate20.errors = [{instancePath:instancePath+"/tags",schemaPath:"#/properties/tags/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs17 === errors;}else {var valid0 = true;}if(valid0){if(data.numOfTasks !== undefined){let data10 = data.numOfTasks;const _errs21 = errors;if(!((typeof data10 == "number") && (isFinite(data10)))){validate20.errors = [{instancePath:instancePath+"/numOfTasks",schemaPath:"#/properties/numOfTasks/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs21 === errors;}else {var valid0 = true;}if(valid0){if(data.numOfCheckedTasks !== undefined){let data11 = data.numOfCheckedTasks;const _errs23 = errors;if(!((typeof data11 == "number") && (isFinite(data11)))){validate20.errors = [{instancePath:instancePath+"/numOfCheckedTasks",schemaPath:"#/properties/numOfCheckedTasks/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs23 === errors;}else {var valid0 = true;}if(valid0){if(data.migratedBy !== undefined){let data12 = data.migratedBy;const _errs25 = errors;if(errors === _errs25){if(typeof data12 === "string"){if(func4(data12) > 128){validate20.errors = [{instancePath:instancePath+"/migratedBy",schemaPath:"#/properties/migratedBy/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/migratedBy",schemaPath:"#/properties/migratedBy/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs25 === errors;}else {var valid0 = true;}if(valid0){if(data.status !== undefined){let data13 = data.status;const _errs27 = errors;if(typeof data13 !== "string"){validate20.errors = [{instancePath:instancePath+"/status",schemaPath:"#/properties/status/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(((((data13 === "none") || (data13 === "active")) || (data13 === "onHold")) || (data13 === "completed")) || (data13 === "dropped"))){validate20.errors = [{instancePath:instancePath+"/status",schemaPath:"#/properties/status/enum",keyword:"enum",params:{allowedValues: schema22.properties.status.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs27 === errors;}else {var valid0 = true;}if(valid0){if(data.share !== undefined){let data14 = data.share;const _errs29 = errors;if(typeof data14 !== "string"){validate20.errors = [{instancePath:instancePath+"/share",schemaPath:"#/properties/share/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!((data14 === "private") || (data14 === "public"))){validate20.errors = [{instancePath:instancePath+"/share",schemaPath:"#/properties/share/enum",keyword:"enum",params:{allowedValues: schema22.properties.share.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs29 === errors;}else {var valid0 = true;}if(valid0){if(data.pinned !== undefined){const _errs31 = errors;if(typeof data.pinned !== "boolean"){validate20.errors = [{instancePath:instancePath+"/pinned",schemaPath:"#/properties/pinned/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid0 = _errs31 === errors;}else {var valid0 = true;}if(valid0){if(data.timestamp !== undefined){let data16 = data.timestamp;const _errs33 = errors;if(!((typeof data16 == "number") && (isFinite(data16)))){validate20.errors = [{instancePath:instancePath+"/timestamp",schemaPath:"#/properties/timestamp/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs33 === errors;}else {var valid0 = true;}if(valid0){if(data._conflicts !== undefined){let data17 = data._conflicts;const _errs35 = errors;if(errors === _errs35){if(Array.isArray(data17)){var valid3 = true;const len1 = data17.length;for(let i2=0; i2<len1; i2++){const _errs37 = errors;if(typeof data17[i2] !== "string"){validate20.errors = [{instancePath:instancePath+"/_conflicts/" + i2,schemaPath:"#/properties/_conflicts/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs37 === errors;if(!valid3){break;}}if(valid3){let i3 = data17.length;let j1;if(i3 > 1){const indices1 = {};for(;i3--;){let item1 = data17[i3];if(typeof item1 !== "string"){continue;}if(typeof indices1[item1] == "number"){j1 = indices1[item1];validate20.errors = [{instancePath:instancePath+"/_conflicts",schemaPath:"#/properties/_conflicts/uniqueItems",keyword:"uniqueItems",params:{i: i3, j: j1},message:"must NOT have duplicate items (items ## "+j1+" and "+i3+" are identical)"}];return false;break;}indices1[item1] = i3;}}}}else {validate20.errors = [{instancePath:instancePath+"/_conflicts",schemaPath:"#/properties/_conflicts/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs35 === errors;}else {var valid0 = true;}}}}}}}}}}}}}}}}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}
|
|
1
|
+
"use strict";module.exports = validate20;module.exports.default = validate20;const schema22 = {"$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$|template$)"},"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":true},"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":true}},"required":["_id","bookId","title","doctype","body","updatedAt","createdAt","timestamp"]};const func4 = require("ajv/dist/runtime/ucs2length").default;const pattern0 = new RegExp("^note:", "u");const pattern1 = new RegExp("^(book:|trash$|template$)", "u");function validate20(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){/*# sourceURL="note" */;let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((((((((data._id === undefined) && (missing0 = "_id")) || ((data.bookId === undefined) && (missing0 = "bookId"))) || ((data.title === undefined) && (missing0 = "title"))) || ((data.doctype === undefined) && (missing0 = "doctype"))) || ((data.body === undefined) && (missing0 = "body"))) || ((data.updatedAt === undefined) && (missing0 = "updatedAt"))) || ((data.createdAt === undefined) && (missing0 = "createdAt"))) || ((data.timestamp === undefined) && (missing0 = "timestamp"))){validate20.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data._id !== undefined){let data0 = data._id;const _errs1 = errors;if(errors === _errs1){if(typeof data0 === "string"){if(func4(data0) > 128){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}else {if(func4(data0) < 6){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/minLength",keyword:"minLength",params:{limit: 6},message:"must NOT have fewer than 6 characters"}];return false;}else {if(!pattern0.test(data0)){validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/pattern",keyword:"pattern",params:{pattern: "^note:"},message:"must match pattern \""+"^note:"+"\""}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/_id",schemaPath:"#/properties/_id/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data._rev !== undefined){const _errs3 = errors;if(typeof data._rev !== "string"){validate20.errors = [{instancePath:instancePath+"/_rev",schemaPath:"#/properties/_rev/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.bookId !== undefined){let data2 = data.bookId;const _errs5 = errors;if(errors === _errs5){if(typeof data2 === "string"){if(func4(data2) > 128){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}else {if(func4(data2) < 5){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/minLength",keyword:"minLength",params:{limit: 5},message:"must NOT have fewer than 5 characters"}];return false;}else {if(!pattern1.test(data2)){validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/pattern",keyword:"pattern",params:{pattern: "^(book:|trash$|template$)"},message:"must match pattern \""+"^(book:|trash$|template$)"+"\""}];return false;}}}}else {validate20.errors = [{instancePath:instancePath+"/bookId",schemaPath:"#/properties/bookId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs5 === errors;}else {var valid0 = true;}if(valid0){if(data.title !== undefined){let data3 = data.title;const _errs7 = errors;if(errors === _errs7){if(typeof data3 === "string"){if(func4(data3) > 256){validate20.errors = [{instancePath:instancePath+"/title",schemaPath:"#/properties/title/maxLength",keyword:"maxLength",params:{limit: 256},message:"must NOT have more than 256 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/title",schemaPath:"#/properties/title/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs7 === errors;}else {var valid0 = true;}if(valid0){if(data.doctype !== undefined){let data4 = data.doctype;const _errs9 = errors;if(typeof data4 !== "string"){validate20.errors = [{instancePath:instancePath+"/doctype",schemaPath:"#/properties/doctype/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(data4 === "markdown")){validate20.errors = [{instancePath:instancePath+"/doctype",schemaPath:"#/properties/doctype/enum",keyword:"enum",params:{allowedValues: schema22.properties.doctype.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs9 === errors;}else {var valid0 = true;}if(valid0){if(data.body !== undefined){let data5 = data.body;const _errs11 = errors;if(errors === _errs11){if(typeof data5 === "string"){if(func4(data5) > 1048576){validate20.errors = [{instancePath:instancePath+"/body",schemaPath:"#/properties/body/maxLength",keyword:"maxLength",params:{limit: 1048576},message:"must NOT have more than 1048576 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/body",schemaPath:"#/properties/body/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs11 === errors;}else {var valid0 = true;}if(valid0){if(data.updatedAt !== undefined){let data6 = data.updatedAt;const _errs13 = errors;if(!((typeof data6 == "number") && (isFinite(data6)))){validate20.errors = [{instancePath:instancePath+"/updatedAt",schemaPath:"#/properties/updatedAt/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs13 === errors;}else {var valid0 = true;}if(valid0){if(data.createdAt !== undefined){let data7 = data.createdAt;const _errs15 = errors;if(!((typeof data7 == "number") && (isFinite(data7)))){validate20.errors = [{instancePath:instancePath+"/createdAt",schemaPath:"#/properties/createdAt/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs15 === errors;}else {var valid0 = true;}if(valid0){if(data.tags !== undefined){let data8 = data.tags;const _errs17 = errors;if(errors === _errs17){if(Array.isArray(data8)){var valid1 = true;const len0 = data8.length;for(let i0=0; i0<len0; i0++){const _errs19 = errors;if(typeof data8[i0] !== "string"){validate20.errors = [{instancePath:instancePath+"/tags/" + i0,schemaPath:"#/properties/tags/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs19 === errors;if(!valid1){break;}}if(valid1){let i1 = data8.length;let j0;if(i1 > 1){const indices0 = {};for(;i1--;){let item0 = data8[i1];if(typeof item0 !== "string"){continue;}if(typeof indices0[item0] == "number"){j0 = indices0[item0];validate20.errors = [{instancePath:instancePath+"/tags",schemaPath:"#/properties/tags/uniqueItems",keyword:"uniqueItems",params:{i: i1, j: j0},message:"must NOT have duplicate items (items ## "+j0+" and "+i1+" are identical)"}];return false;break;}indices0[item0] = i1;}}}}else {validate20.errors = [{instancePath:instancePath+"/tags",schemaPath:"#/properties/tags/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs17 === errors;}else {var valid0 = true;}if(valid0){if(data.numOfTasks !== undefined){let data10 = data.numOfTasks;const _errs21 = errors;if(!((typeof data10 == "number") && (isFinite(data10)))){validate20.errors = [{instancePath:instancePath+"/numOfTasks",schemaPath:"#/properties/numOfTasks/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs21 === errors;}else {var valid0 = true;}if(valid0){if(data.numOfCheckedTasks !== undefined){let data11 = data.numOfCheckedTasks;const _errs23 = errors;if(!((typeof data11 == "number") && (isFinite(data11)))){validate20.errors = [{instancePath:instancePath+"/numOfCheckedTasks",schemaPath:"#/properties/numOfCheckedTasks/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs23 === errors;}else {var valid0 = true;}if(valid0){if(data.migratedBy !== undefined){let data12 = data.migratedBy;const _errs25 = errors;if(errors === _errs25){if(typeof data12 === "string"){if(func4(data12) > 128){validate20.errors = [{instancePath:instancePath+"/migratedBy",schemaPath:"#/properties/migratedBy/maxLength",keyword:"maxLength",params:{limit: 128},message:"must NOT have more than 128 characters"}];return false;}}else {validate20.errors = [{instancePath:instancePath+"/migratedBy",schemaPath:"#/properties/migratedBy/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}}var valid0 = _errs25 === errors;}else {var valid0 = true;}if(valid0){if(data.status !== undefined){let data13 = data.status;const _errs27 = errors;if(typeof data13 !== "string"){validate20.errors = [{instancePath:instancePath+"/status",schemaPath:"#/properties/status/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(((((data13 === "none") || (data13 === "active")) || (data13 === "onHold")) || (data13 === "completed")) || (data13 === "dropped"))){validate20.errors = [{instancePath:instancePath+"/status",schemaPath:"#/properties/status/enum",keyword:"enum",params:{allowedValues: schema22.properties.status.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs27 === errors;}else {var valid0 = true;}if(valid0){if(data.share !== undefined){let data14 = data.share;const _errs29 = errors;if(typeof data14 !== "string"){validate20.errors = [{instancePath:instancePath+"/share",schemaPath:"#/properties/share/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!((data14 === "private") || (data14 === "public"))){validate20.errors = [{instancePath:instancePath+"/share",schemaPath:"#/properties/share/enum",keyword:"enum",params:{allowedValues: schema22.properties.share.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs29 === errors;}else {var valid0 = true;}if(valid0){if(data.pinned !== undefined){const _errs31 = errors;if(typeof data.pinned !== "boolean"){validate20.errors = [{instancePath:instancePath+"/pinned",schemaPath:"#/properties/pinned/type",keyword:"type",params:{type: "boolean"},message:"must be boolean"}];return false;}var valid0 = _errs31 === errors;}else {var valid0 = true;}if(valid0){if(data.timestamp !== undefined){let data16 = data.timestamp;const _errs33 = errors;if(!((typeof data16 == "number") && (isFinite(data16)))){validate20.errors = [{instancePath:instancePath+"/timestamp",schemaPath:"#/properties/timestamp/type",keyword:"type",params:{type: "number"},message:"must be number"}];return false;}var valid0 = _errs33 === errors;}else {var valid0 = true;}if(valid0){if(data._conflicts !== undefined){let data17 = data._conflicts;const _errs35 = errors;if(errors === _errs35){if(Array.isArray(data17)){var valid3 = true;const len1 = data17.length;for(let i2=0; i2<len1; i2++){const _errs37 = errors;if(typeof data17[i2] !== "string"){validate20.errors = [{instancePath:instancePath+"/_conflicts/" + i2,schemaPath:"#/properties/_conflicts/items/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs37 === errors;if(!valid3){break;}}if(valid3){let i3 = data17.length;let j1;if(i3 > 1){const indices1 = {};for(;i3--;){let item1 = data17[i3];if(typeof item1 !== "string"){continue;}if(typeof indices1[item1] == "number"){j1 = indices1[item1];validate20.errors = [{instancePath:instancePath+"/_conflicts",schemaPath:"#/properties/_conflicts/uniqueItems",keyword:"uniqueItems",params:{i: i3, j: j1},message:"must NOT have duplicate items (items ## "+j1+" and "+i3+" are identical)"}];return false;break;}indices1[item1] = i3;}}}}else {validate20.errors = [{instancePath:instancePath+"/_conflicts",schemaPath:"#/properties/_conflicts/type",keyword:"type",params:{type: "array"},message:"must be array"}];return false;}}var valid0 = _errs35 === errors;}else {var valid0 = true;}}}}}}}}}}}}}}}}}}}else {validate20.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate20.errors = vErrors;return errors === 0;}
|