@mnemosyne_os/affine-reader 0.1.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.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +42 -0
  3. package/README.md +89 -0
  4. package/dist/cli.d.ts +14 -0
  5. package/dist/cli.js +79 -0
  6. package/dist/exportMarkdown.d.ts +46 -0
  7. package/dist/exportMarkdown.js +104 -0
  8. package/dist/index.d.ts +17 -0
  9. package/dist/index.js +34 -0
  10. package/dist/locate.d.ts +24 -0
  11. package/dist/locate.js +91 -0
  12. package/dist/nodeSqlite.d.ts +20 -0
  13. package/dist/nodeSqlite.js +50 -0
  14. package/dist/read.d.ts +45 -0
  15. package/dist/read.js +197 -0
  16. package/dist/stage.d.ts +27 -0
  17. package/dist/stage.js +54 -0
  18. package/dist/types.d.ts +72 -0
  19. package/dist/types.js +10 -0
  20. package/dist/vendor/affine/blocksuite-types.d.ts +25 -0
  21. package/dist/vendor/affine/blocksuite-types.js +14 -0
  22. package/dist/vendor/affine/delta-to-md/delta-converters.d.ts +39 -0
  23. package/dist/vendor/affine/delta-to-md/delta-converters.js +81 -0
  24. package/dist/vendor/affine/delta-to-md/delta-to-md.d.ts +1 -0
  25. package/dist/vendor/affine/delta-to-md/delta-to-md.js +132 -0
  26. package/dist/vendor/affine/delta-to-md/index.d.ts +2 -0
  27. package/dist/vendor/affine/delta-to-md/index.js +7 -0
  28. package/dist/vendor/affine/delta-to-md/utils/node.d.ts +13 -0
  29. package/dist/vendor/affine/delta-to-md/utils/node.js +59 -0
  30. package/dist/vendor/affine/delta-to-md/utils/url.d.ts +1 -0
  31. package/dist/vendor/affine/delta-to-md/utils/url.js +8 -0
  32. package/dist/vendor/affine/parser.d.ts +5 -0
  33. package/dist/vendor/affine/parser.js +386 -0
  34. package/dist/vendor/affine/types.d.ts +100 -0
  35. package/dist/vendor/affine/types.js +2 -0
  36. package/package.json +64 -0
@@ -0,0 +1,100 @@
1
+ import { type CellDataType } from './blocksuite-types';
2
+ import { type Doc as YDoc, type Map as YMap } from 'yjs';
3
+ export interface WorkspacePage {
4
+ id: string;
5
+ guid: string;
6
+ title: string;
7
+ createDate: number;
8
+ trash?: boolean;
9
+ favorite?: boolean;
10
+ properties?: Record<string, any>;
11
+ }
12
+ export type BaseFlavour<T extends string> = `affine:${T}`;
13
+ export type Flavour = BaseFlavour<'page' | 'frame' | 'paragraph' | 'code' | 'note' | 'list' | 'divider' | 'embed' | 'image' | 'surface' | 'database' | 'table' | 'attachment' | 'bookmark' | 'embed-youtube' | 'embed-linked-doc' | 'embed-synced-doc'>;
14
+ export interface BaseParsedBlock {
15
+ id: string;
16
+ flavour: Flavour;
17
+ content: string;
18
+ children: BaseParsedBlock[];
19
+ type?: string;
20
+ }
21
+ export interface ParsedDoc {
22
+ title: string;
23
+ md: string;
24
+ parsedBlock?: ParsedBlock;
25
+ }
26
+ export interface ParagraphBlock extends BaseParsedBlock {
27
+ flavour: 'affine:paragraph';
28
+ type: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'quote';
29
+ }
30
+ export interface DividerBlock extends BaseParsedBlock {
31
+ flavour: 'affine:divider';
32
+ }
33
+ export interface ListBlock extends BaseParsedBlock {
34
+ flavour: 'affine:list';
35
+ type: 'bulleted' | 'numbered';
36
+ }
37
+ export interface CodeBlock extends BaseParsedBlock {
38
+ flavour: 'affine:code';
39
+ language: string;
40
+ }
41
+ export interface ImageBlock extends BaseParsedBlock {
42
+ flavour: 'affine:image';
43
+ sourceId: string;
44
+ blobUrl: string;
45
+ width?: number;
46
+ height?: number;
47
+ caption?: string;
48
+ }
49
+ export interface AttachmentBlock extends BaseParsedBlock {
50
+ flavour: 'affine:attachment';
51
+ type: string;
52
+ sourceId: string;
53
+ }
54
+ export interface EmbedYoutubeBlock extends BaseParsedBlock {
55
+ flavour: 'affine:embed-youtube';
56
+ videoId: string;
57
+ }
58
+ export interface BookmarkBlock extends BaseParsedBlock {
59
+ flavour: 'affine:bookmark';
60
+ url: string;
61
+ }
62
+ export interface EmbedLinkedDocBlock extends BaseParsedBlock {
63
+ flavour: 'affine:embed-linked-doc';
64
+ pageId: string;
65
+ }
66
+ export interface EmbedSyncedDocBlock extends BaseParsedBlock {
67
+ flavour: 'affine:embed-synced-doc';
68
+ pageId: string;
69
+ }
70
+ export interface DatabaseBlock extends BaseParsedBlock {
71
+ title: string;
72
+ flavour: 'affine:database';
73
+ rows: Record<string, string>[];
74
+ }
75
+ export interface TableBlock extends BaseParsedBlock {
76
+ flavour: 'affine:table';
77
+ rows: string[][];
78
+ columns: string[];
79
+ }
80
+ export type ParsedBlock = ParagraphBlock | DividerBlock | ListBlock | CodeBlock | ImageBlock | AttachmentBlock | EmbedYoutubeBlock | BookmarkBlock | DatabaseBlock | TableBlock | BaseParsedBlock;
81
+ export interface ParsedDoc {
82
+ title: string;
83
+ md: string;
84
+ parsedBlock?: ParsedBlock;
85
+ }
86
+ export type SerializedCells = {
87
+ [key: string]: {
88
+ [key: string]: CellDataType;
89
+ };
90
+ };
91
+ export type YBlock = YMap<unknown>;
92
+ export type YBlocks = YMap<YBlock>;
93
+ export interface ParserContext {
94
+ workspaceId: string;
95
+ doc: YDoc;
96
+ buildBlobUrl: (blobId: string) => string;
97
+ buildDocUrl: (docId: string) => string;
98
+ renderDocTitle?: (docId: string) => string;
99
+ aiEditable?: boolean;
100
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@mnemosyne_os/affine-reader",
3
+ "version": "0.1.0",
4
+ "description": "Read a local AFFiNE workspace (SQLite + Yjs) and render its documents to Markdown. No BlockSuite at runtime, no native module, read-only.",
5
+ "license": "MIT",
6
+ "author": "Tony Trochet <tony@xpacegems.com> (https://xpacegems.com)",
7
+ "homepage": "https://mnemosyne-os.io",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS.git",
11
+ "directory": "packages/affine-reader"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS/issues"
15
+ },
16
+ "keywords": [
17
+ "affine",
18
+ "blocksuite",
19
+ "yjs",
20
+ "crdt",
21
+ "markdown",
22
+ "connector",
23
+ "local-first",
24
+ "mnemosyne"
25
+ ],
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "bin": {
29
+ "affine-export": "./dist/cli.js"
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "require": "./dist/index.js",
34
+ "import": "./dist/index.js",
35
+ "types": "./dist/index.d.ts"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "NOTICE.md",
42
+ "LICENSE"
43
+ ],
44
+ "sideEffects": false,
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.build.json",
50
+ "clean": "rimraf dist",
51
+ "typecheck": "tsc -p tsconfig.json --noEmit",
52
+ "test": "vitest run",
53
+ "prepublishOnly": "npm run clean && npm run build"
54
+ },
55
+ "dependencies": {
56
+ "yjs": "^13.6.27"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^20.0.0",
60
+ "rimraf": "^5.0.0",
61
+ "typescript": "^5.5.0",
62
+ "vitest": "^1.6.0"
63
+ }
64
+ }