@catafal/notion-cli 5.9.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +552 -0
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +14 -0
  6. package/bin/run.cmd +3 -0
  7. package/dist/base-command.d.ts +73 -0
  8. package/dist/base-command.js +179 -0
  9. package/dist/base-flags.d.ts +14 -0
  10. package/dist/base-flags.js +59 -0
  11. package/dist/cache.d.ts +84 -0
  12. package/dist/cache.js +351 -0
  13. package/dist/commands/append.d.ts +37 -0
  14. package/dist/commands/append.js +120 -0
  15. package/dist/commands/batch/delete.d.ts +42 -0
  16. package/dist/commands/batch/delete.js +199 -0
  17. package/dist/commands/batch/retrieve.d.ts +43 -0
  18. package/dist/commands/batch/retrieve.js +272 -0
  19. package/dist/commands/block/append.d.ts +42 -0
  20. package/dist/commands/block/append.js +219 -0
  21. package/dist/commands/block/delete.d.ts +30 -0
  22. package/dist/commands/block/delete.js +97 -0
  23. package/dist/commands/block/retrieve/children.d.ts +31 -0
  24. package/dist/commands/block/retrieve/children.js +177 -0
  25. package/dist/commands/block/retrieve.d.ts +30 -0
  26. package/dist/commands/block/retrieve.js +101 -0
  27. package/dist/commands/block/update.d.ts +45 -0
  28. package/dist/commands/block/update.js +242 -0
  29. package/dist/commands/bookmark/list.d.ts +30 -0
  30. package/dist/commands/bookmark/list.js +60 -0
  31. package/dist/commands/bookmark/remove.d.ts +26 -0
  32. package/dist/commands/bookmark/remove.js +47 -0
  33. package/dist/commands/bookmark/set.d.ts +29 -0
  34. package/dist/commands/bookmark/set.js +96 -0
  35. package/dist/commands/browse.d.ts +13 -0
  36. package/dist/commands/browse.js +44 -0
  37. package/dist/commands/cache/info.d.ts +19 -0
  38. package/dist/commands/cache/info.js +145 -0
  39. package/dist/commands/config/set-token.d.ts +22 -0
  40. package/dist/commands/config/set-token.js +137 -0
  41. package/dist/commands/daily/index.d.ts +32 -0
  42. package/dist/commands/daily/index.js +135 -0
  43. package/dist/commands/daily/setup.d.ts +42 -0
  44. package/dist/commands/daily/setup.js +149 -0
  45. package/dist/commands/db/create.d.ts +31 -0
  46. package/dist/commands/db/create.js +124 -0
  47. package/dist/commands/db/query.d.ts +41 -0
  48. package/dist/commands/db/query.js +360 -0
  49. package/dist/commands/db/retrieve.d.ts +33 -0
  50. package/dist/commands/db/retrieve.js +134 -0
  51. package/dist/commands/db/schema.d.ts +32 -0
  52. package/dist/commands/db/schema.js +308 -0
  53. package/dist/commands/db/update.d.ts +31 -0
  54. package/dist/commands/db/update.js +117 -0
  55. package/dist/commands/doctor.d.ts +50 -0
  56. package/dist/commands/doctor.js +420 -0
  57. package/dist/commands/init.d.ts +65 -0
  58. package/dist/commands/init.js +479 -0
  59. package/dist/commands/list.d.ts +29 -0
  60. package/dist/commands/list.js +219 -0
  61. package/dist/commands/open.d.ts +29 -0
  62. package/dist/commands/open.js +100 -0
  63. package/dist/commands/page/create.d.ts +33 -0
  64. package/dist/commands/page/create.js +261 -0
  65. package/dist/commands/page/delete.d.ts +36 -0
  66. package/dist/commands/page/delete.js +107 -0
  67. package/dist/commands/page/export.d.ts +38 -0
  68. package/dist/commands/page/export.js +120 -0
  69. package/dist/commands/page/retrieve/property_item.d.ts +24 -0
  70. package/dist/commands/page/retrieve/property_item.js +75 -0
  71. package/dist/commands/page/retrieve.d.ts +36 -0
  72. package/dist/commands/page/retrieve.js +244 -0
  73. package/dist/commands/page/update.d.ts +34 -0
  74. package/dist/commands/page/update.js +184 -0
  75. package/dist/commands/quick.d.ts +35 -0
  76. package/dist/commands/quick.js +168 -0
  77. package/dist/commands/search.d.ts +43 -0
  78. package/dist/commands/search.js +361 -0
  79. package/dist/commands/stats.d.ts +35 -0
  80. package/dist/commands/stats.js +274 -0
  81. package/dist/commands/sync.d.ts +24 -0
  82. package/dist/commands/sync.js +183 -0
  83. package/dist/commands/template/get.d.ts +28 -0
  84. package/dist/commands/template/get.js +59 -0
  85. package/dist/commands/template/list.d.ts +32 -0
  86. package/dist/commands/template/list.js +62 -0
  87. package/dist/commands/template/remove.d.ts +27 -0
  88. package/dist/commands/template/remove.js +48 -0
  89. package/dist/commands/template/save.d.ts +32 -0
  90. package/dist/commands/template/save.js +92 -0
  91. package/dist/commands/template/use.d.ts +34 -0
  92. package/dist/commands/template/use.js +142 -0
  93. package/dist/commands/user/list.d.ts +27 -0
  94. package/dist/commands/user/list.js +99 -0
  95. package/dist/commands/user/retrieve/bot.d.ts +28 -0
  96. package/dist/commands/user/retrieve/bot.js +96 -0
  97. package/dist/commands/user/retrieve.d.ts +30 -0
  98. package/dist/commands/user/retrieve.js +103 -0
  99. package/dist/commands/whoami.d.ts +19 -0
  100. package/dist/commands/whoami.js +175 -0
  101. package/dist/deduplication.d.ts +41 -0
  102. package/dist/deduplication.js +71 -0
  103. package/dist/envelope.d.ts +169 -0
  104. package/dist/envelope.js +257 -0
  105. package/dist/errors/enhanced-errors.d.ts +168 -0
  106. package/dist/errors/enhanced-errors.js +567 -0
  107. package/dist/errors/index.d.ts +18 -0
  108. package/dist/errors/index.js +33 -0
  109. package/dist/examples/cache-retry-examples.d.ts +64 -0
  110. package/dist/examples/cache-retry-examples.js +375 -0
  111. package/dist/helper.d.ts +102 -0
  112. package/dist/helper.js +885 -0
  113. package/dist/http-agent.d.ts +38 -0
  114. package/dist/http-agent.js +60 -0
  115. package/dist/index.d.ts +1 -0
  116. package/dist/index.js +4 -0
  117. package/dist/interface.d.ts +4 -0
  118. package/dist/interface.js +2 -0
  119. package/dist/notion.d.ts +144 -0
  120. package/dist/notion.js +547 -0
  121. package/dist/retry.d.ts +72 -0
  122. package/dist/retry.js +381 -0
  123. package/dist/utils/bookmarks.d.ts +32 -0
  124. package/dist/utils/bookmarks.js +98 -0
  125. package/dist/utils/daily-config.d.ts +22 -0
  126. package/dist/utils/daily-config.js +60 -0
  127. package/dist/utils/disk-cache.d.ts +80 -0
  128. package/dist/utils/disk-cache.js +291 -0
  129. package/dist/utils/fuzzy.d.ts +36 -0
  130. package/dist/utils/fuzzy.js +69 -0
  131. package/dist/utils/interactive-navigator.d.ts +63 -0
  132. package/dist/utils/interactive-navigator.js +123 -0
  133. package/dist/utils/markdown-to-blocks.d.ts +21 -0
  134. package/dist/utils/markdown-to-blocks.js +333 -0
  135. package/dist/utils/notion-resolver.d.ts +49 -0
  136. package/dist/utils/notion-resolver.js +278 -0
  137. package/dist/utils/notion-url-parser.d.ts +48 -0
  138. package/dist/utils/notion-url-parser.js +121 -0
  139. package/dist/utils/property-expander.d.ts +45 -0
  140. package/dist/utils/property-expander.js +323 -0
  141. package/dist/utils/schema-examples.d.ts +40 -0
  142. package/dist/utils/schema-examples.js +359 -0
  143. package/dist/utils/schema-extractor.d.ts +65 -0
  144. package/dist/utils/schema-extractor.js +235 -0
  145. package/dist/utils/shell-config.d.ts +30 -0
  146. package/dist/utils/shell-config.js +84 -0
  147. package/dist/utils/table-formatter.d.ts +36 -0
  148. package/dist/utils/table-formatter.js +125 -0
  149. package/dist/utils/templates.d.ts +30 -0
  150. package/dist/utils/templates.js +82 -0
  151. package/dist/utils/terminal-banner.d.ts +24 -0
  152. package/dist/utils/terminal-banner.js +34 -0
  153. package/dist/utils/token-validator.d.ts +42 -0
  154. package/dist/utils/token-validator.js +66 -0
  155. package/dist/utils/update-notifier.d.ts +26 -0
  156. package/dist/utils/update-notifier.js +54 -0
  157. package/dist/utils/workspace-cache.d.ts +58 -0
  158. package/dist/utils/workspace-cache.js +185 -0
  159. package/oclif.manifest.json +6471 -0
  160. package/package.json +118 -0
  161. package/scripts/banner.js +38 -0
  162. package/scripts/postinstall.js +44 -0
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Daily Command
3
+ *
4
+ * Zero-friction daily journal entries. After one-time setup:
5
+ * `notion-cli daily` → create (or find) today's entry
6
+ * `notion-cli daily "My note"` → create with body, or append if entry exists
7
+ *
8
+ * Queries the configured database by date to detect existing entries,
9
+ * so you never get duplicate pages for the same day.
10
+ */
11
+ import { Command } from '@oclif/core';
12
+ export default class Daily extends Command {
13
+ static description: string;
14
+ static aliases: string[];
15
+ static examples: {
16
+ description: string;
17
+ command: string;
18
+ }[];
19
+ static args: {
20
+ content: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
21
+ };
22
+ static flags: {
23
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
25
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
27
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
30
+ };
31
+ run(): Promise<void>;
32
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Daily Command
4
+ *
5
+ * Zero-friction daily journal entries. After one-time setup:
6
+ * `notion-cli daily` → create (or find) today's entry
7
+ * `notion-cli daily "My note"` → create with body, or append if entry exists
8
+ *
9
+ * Queries the configured database by date to detect existing entries,
10
+ * so you never get duplicate pages for the same day.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const core_1 = require("@oclif/core");
14
+ const dayjs = require("dayjs");
15
+ const notion = require("../../notion");
16
+ const daily_config_1 = require("../../utils/daily-config");
17
+ const markdown_to_blocks_1 = require("../../utils/markdown-to-blocks");
18
+ const base_flags_1 = require("../../base-flags");
19
+ const errors_1 = require("../../errors");
20
+ class Daily extends core_1.Command {
21
+ async run() {
22
+ const { args, flags } = await this.parse(Daily);
23
+ try {
24
+ // 1. Load config — fail fast if not set up
25
+ const config = await (0, daily_config_1.loadDailyConfig)();
26
+ if (!config) {
27
+ this.error('Daily journal not configured yet.\n' +
28
+ 'Run setup first:\n' +
29
+ ' notion-cli daily setup DB_ID (existing database)\n' +
30
+ ' notion-cli daily setup --auto PAGE_ID (auto-create database)');
31
+ process.exit(1);
32
+ return;
33
+ }
34
+ // 2. Today's date — used for both the entry title and the date filter
35
+ const today = dayjs();
36
+ const todayISO = today.format('YYYY-MM-DD');
37
+ const title = today.format(config.title_format);
38
+ // 3. Check if today's entry already exists (query by date property)
39
+ const existingPages = await notion.fetchAllPagesInDS(config.database_id, {
40
+ property: config.date_property,
41
+ date: { equals: todayISO },
42
+ });
43
+ // 4. Build content blocks from the positional arg (if provided)
44
+ const children = args.content
45
+ ? (0, markdown_to_blocks_1.markdownToBlocks)(args.content)
46
+ : undefined;
47
+ if (existingPages.length > 0) {
48
+ // Entry exists — append content or just show the link
49
+ const page = existingPages[0];
50
+ if (children && children.length > 0) {
51
+ await notion.appendBlockChildren({ block_id: page.id, children });
52
+ }
53
+ if (flags.json) {
54
+ this.log(JSON.stringify({
55
+ success: true,
56
+ action: children ? 'appended' : 'found',
57
+ data: page,
58
+ timestamp: new Date().toISOString()
59
+ }, null, 2));
60
+ }
61
+ else {
62
+ this.log(children ? `Appended to: ${title}` : `Today's entry: ${title}`);
63
+ this.log(page.url);
64
+ }
65
+ }
66
+ else {
67
+ // No entry for today — create one
68
+ const properties = {
69
+ [config.title_property]: {
70
+ title: [{ text: { content: title } }],
71
+ },
72
+ [config.date_property]: {
73
+ date: { start: todayISO },
74
+ },
75
+ };
76
+ const res = await notion.createPage({
77
+ parent: { data_source_id: config.database_id },
78
+ properties,
79
+ ...(children && { children }),
80
+ });
81
+ if (flags.json) {
82
+ this.log(JSON.stringify({
83
+ success: true,
84
+ action: 'created',
85
+ data: res,
86
+ timestamp: new Date().toISOString()
87
+ }, null, 2));
88
+ }
89
+ else {
90
+ this.log(`Created: ${title}`);
91
+ this.log(res.url);
92
+ }
93
+ }
94
+ process.exit(0);
95
+ }
96
+ catch (error) {
97
+ const cliError = error instanceof errors_1.NotionCLIError
98
+ ? error
99
+ : (0, errors_1.wrapNotionError)(error, { endpoint: 'daily', resourceType: 'page' });
100
+ if (flags.json) {
101
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
102
+ }
103
+ else {
104
+ this.error(cliError.toHumanString());
105
+ }
106
+ process.exit(1);
107
+ }
108
+ }
109
+ }
110
+ Daily.description = 'Create or open today\'s daily journal entry';
111
+ Daily.aliases = ['d'];
112
+ Daily.examples = [
113
+ {
114
+ description: 'Create today\'s entry',
115
+ command: '$ notion-cli daily',
116
+ },
117
+ {
118
+ description: 'Create entry with body content',
119
+ command: '$ notion-cli daily "Had a productive standup"',
120
+ },
121
+ {
122
+ description: 'First-time setup (see `daily setup --help`)',
123
+ command: '$ notion-cli daily setup DB_ID',
124
+ },
125
+ ];
126
+ Daily.args = {
127
+ content: core_1.Args.string({
128
+ required: false,
129
+ description: 'Text to add to today\'s entry (appended if entry already exists)',
130
+ }),
131
+ };
132
+ Daily.flags = {
133
+ ...base_flags_1.AutomationFlags,
134
+ };
135
+ exports.default = Daily;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Daily Setup Command
3
+ *
4
+ * One-time configuration for the `daily` command.
5
+ * Two modes:
6
+ * Manual — point to an existing database that has a Date property.
7
+ * Auto — create a new "Daily Journal" database under a parent page.
8
+ *
9
+ * After setup, `notion-cli daily` works with zero arguments.
10
+ */
11
+ import { Command } from '@oclif/core';
12
+ export default class DailySetup extends Command {
13
+ static description: string;
14
+ static examples: {
15
+ description: string;
16
+ command: string;
17
+ }[];
18
+ static args: {
19
+ target: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
20
+ };
21
+ static flags: {
22
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
23
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
24
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
26
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ auto: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
30
+ };
31
+ run(): Promise<void>;
32
+ /**
33
+ * Manual mode: resolve an existing database and detect its title + date properties.
34
+ * Fails if the database has no date-type property.
35
+ */
36
+ private manualSetup;
37
+ /**
38
+ * Auto mode: create a minimal "Daily Journal" database under a parent page.
39
+ * Schema: Name (title) + Date (date) — intentionally minimal.
40
+ */
41
+ private autoSetup;
42
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * Daily Setup Command
4
+ *
5
+ * One-time configuration for the `daily` command.
6
+ * Two modes:
7
+ * Manual — point to an existing database that has a Date property.
8
+ * Auto — create a new "Daily Journal" database under a parent page.
9
+ *
10
+ * After setup, `notion-cli daily` works with zero arguments.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const core_1 = require("@oclif/core");
14
+ const notion = require("../../notion");
15
+ const notion_resolver_1 = require("../../utils/notion-resolver");
16
+ const daily_config_1 = require("../../utils/daily-config");
17
+ const base_flags_1 = require("../../base-flags");
18
+ const errors_1 = require("../../errors");
19
+ class DailySetup extends core_1.Command {
20
+ async run() {
21
+ const { args, flags } = await this.parse(DailySetup);
22
+ try {
23
+ // Must provide exactly one mode: target (manual) or --auto
24
+ if (!args.target && !flags.auto) {
25
+ this.error('Provide a database ID (manual) or --auto PAGE_ID (auto-create).\n' +
26
+ ' Manual: notion-cli daily setup DB_ID\n' +
27
+ ' Auto: notion-cli daily setup --auto PAGE_ID');
28
+ process.exit(1);
29
+ return;
30
+ }
31
+ if (args.target && flags.auto) {
32
+ this.error('Cannot use both target database and --auto. Choose one mode.');
33
+ process.exit(1);
34
+ return;
35
+ }
36
+ let databaseId;
37
+ let titleProperty;
38
+ let dateProperty;
39
+ if (flags.auto) {
40
+ const result = await this.autoSetup(flags.auto);
41
+ databaseId = result.databaseId;
42
+ titleProperty = result.titleProperty;
43
+ dateProperty = result.dateProperty;
44
+ }
45
+ else {
46
+ const result = await this.manualSetup(args.target);
47
+ databaseId = result.databaseId;
48
+ titleProperty = result.titleProperty;
49
+ dateProperty = result.dateProperty;
50
+ }
51
+ // Persist config to ~/.notion-cli/daily.json
52
+ const config = (0, daily_config_1.createDailyConfig)(databaseId, titleProperty, dateProperty);
53
+ await (0, daily_config_1.saveDailyConfig)(config);
54
+ if (flags.json) {
55
+ this.log(JSON.stringify({
56
+ success: true,
57
+ data: config,
58
+ timestamp: new Date().toISOString()
59
+ }, null, 2));
60
+ }
61
+ else {
62
+ this.log('Daily journal configured!');
63
+ this.log(` Database: ${databaseId}`);
64
+ this.log(` Title property: ${titleProperty}`);
65
+ this.log(` Date property: ${dateProperty}`);
66
+ this.log('\nRun "notion-cli daily" to create today\'s entry.');
67
+ }
68
+ process.exit(0);
69
+ }
70
+ catch (error) {
71
+ const cliError = error instanceof errors_1.NotionCLIError
72
+ ? error
73
+ : (0, errors_1.wrapNotionError)(error, { endpoint: 'daily.setup', resourceType: 'database' });
74
+ if (flags.json) {
75
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
76
+ }
77
+ else {
78
+ this.error(cliError.toHumanString());
79
+ }
80
+ process.exit(1);
81
+ }
82
+ }
83
+ /**
84
+ * Manual mode: resolve an existing database and detect its title + date properties.
85
+ * Fails if the database has no date-type property.
86
+ */
87
+ async manualSetup(target) {
88
+ const dbId = await (0, notion_resolver_1.resolveNotionId)(target, 'database');
89
+ const schema = await notion.retrieveDataSource(dbId);
90
+ let titleProperty = 'Name';
91
+ let dateProperty = null;
92
+ if (schema.properties) {
93
+ for (const [name, prop] of Object.entries(schema.properties)) {
94
+ if (prop.type === 'title')
95
+ titleProperty = name;
96
+ // Take the first date property found
97
+ if (prop.type === 'date' && !dateProperty)
98
+ dateProperty = name;
99
+ }
100
+ }
101
+ if (!dateProperty) {
102
+ throw new errors_1.NotionCLIError(errors_1.NotionCLIErrorCode.VALIDATION_ERROR, 'This database has no Date property.', [{ description: 'Add a Date property to your database in Notion, then run setup again.' }], { resourceType: 'database', attemptedId: dbId });
103
+ }
104
+ return { databaseId: dbId, titleProperty, dateProperty };
105
+ }
106
+ /**
107
+ * Auto mode: create a minimal "Daily Journal" database under a parent page.
108
+ * Schema: Name (title) + Date (date) — intentionally minimal.
109
+ */
110
+ async autoSetup(parentTarget) {
111
+ const parentId = await (0, notion_resolver_1.resolveNotionId)(parentTarget, 'page');
112
+ const dbProps = {
113
+ parent: { type: 'page_id', page_id: parentId },
114
+ title: [{ type: 'text', text: { content: 'Daily Journal' } }],
115
+ initial_data_source: {
116
+ properties: {
117
+ Name: { title: {} },
118
+ Date: { date: {} },
119
+ },
120
+ },
121
+ };
122
+ const res = await notion.createDb(dbProps);
123
+ return { databaseId: res.id, titleProperty: 'Name', dateProperty: 'Date' };
124
+ }
125
+ }
126
+ DailySetup.description = 'Configure the daily journal command';
127
+ DailySetup.examples = [
128
+ {
129
+ description: 'Point to an existing database (manual)',
130
+ command: '$ notion-cli daily setup DB_ID_OR_URL',
131
+ },
132
+ {
133
+ description: 'Auto-create a daily journal database',
134
+ command: '$ notion-cli daily setup --auto PAGE_ID_OR_URL',
135
+ },
136
+ ];
137
+ DailySetup.args = {
138
+ target: core_1.Args.string({
139
+ required: false,
140
+ description: 'Existing database ID or URL (manual mode)',
141
+ }),
142
+ };
143
+ DailySetup.flags = {
144
+ auto: core_1.Flags.string({
145
+ description: 'Auto-create database under this parent page (pass page ID or URL)',
146
+ }),
147
+ ...base_flags_1.AutomationFlags,
148
+ };
149
+ exports.default = DailySetup;
@@ -0,0 +1,31 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class DbCreate extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ page_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
15
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
17
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
21
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
22
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
23
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
26
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ title: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
28
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ };
30
+ run(): Promise<void>;
31
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const table_formatter_1 = require("../../utils/table-formatter");
5
+ const notion = require("../../notion");
6
+ const helper_1 = require("../../helper");
7
+ const base_flags_1 = require("../../base-flags");
8
+ const errors_1 = require("../../errors");
9
+ const notion_resolver_1 = require("../../utils/notion-resolver");
10
+ class DbCreate extends core_1.Command {
11
+ async run() {
12
+ const { args, flags } = await this.parse(DbCreate);
13
+ try {
14
+ // Resolve ID from URL, direct ID, or name (future)
15
+ const pageId = await (0, notion_resolver_1.resolveNotionId)(args.page_id, 'page');
16
+ console.log(`Creating a database in page ${pageId}`);
17
+ const dbTitle = flags.title;
18
+ // TODO: support other properties
19
+ const dbProps = {
20
+ parent: {
21
+ type: 'page_id',
22
+ page_id: pageId,
23
+ },
24
+ title: [
25
+ {
26
+ type: 'text',
27
+ text: {
28
+ content: dbTitle,
29
+ },
30
+ },
31
+ ],
32
+ initial_data_source: {
33
+ properties: {
34
+ Name: {
35
+ title: {},
36
+ },
37
+ },
38
+ },
39
+ };
40
+ const res = await notion.createDb(dbProps);
41
+ // Handle JSON output for automation
42
+ if (flags.json) {
43
+ this.log(JSON.stringify({
44
+ success: true,
45
+ data: res,
46
+ timestamp: new Date().toISOString()
47
+ }, null, 2));
48
+ process.exit(0);
49
+ return;
50
+ }
51
+ // Handle raw JSON output (legacy)
52
+ if (flags.raw) {
53
+ (0, helper_1.outputRawJson)(res);
54
+ process.exit(0);
55
+ return;
56
+ }
57
+ // Handle table output
58
+ const columns = {
59
+ title: {
60
+ get: (row) => {
61
+ return (0, helper_1.getDbTitle)(row);
62
+ },
63
+ },
64
+ object: {},
65
+ id: {},
66
+ url: {},
67
+ };
68
+ const options = {
69
+ printLine: this.log.bind(this),
70
+ ...flags,
71
+ };
72
+ (0, table_formatter_1.formatTable)([res], columns, options);
73
+ process.exit(0);
74
+ }
75
+ catch (error) {
76
+ const cliError = error instanceof errors_1.NotionCLIError
77
+ ? error
78
+ : (0, errors_1.wrapNotionError)(error, {
79
+ resourceType: 'database',
80
+ endpoint: 'databases.create'
81
+ });
82
+ if (flags.json) {
83
+ this.log(JSON.stringify(cliError.toJSON(), null, 2));
84
+ }
85
+ else {
86
+ this.error(cliError.toHumanString());
87
+ }
88
+ process.exit(1);
89
+ }
90
+ }
91
+ }
92
+ DbCreate.description = 'Create a database with an initial data source (table)';
93
+ DbCreate.aliases = ['db:c'];
94
+ DbCreate.examples = [
95
+ {
96
+ description: 'Create a database with an initial data source',
97
+ command: `$ notion-cli db create PAGE_ID -t 'My Database'`,
98
+ },
99
+ {
100
+ description: 'Create a database using page URL',
101
+ command: `$ notion-cli db create https://notion.so/PAGE_ID -t 'My Database'`,
102
+ },
103
+ {
104
+ description: 'Create a database with an initial data source and output raw json',
105
+ command: `$ notion-cli db create PAGE_ID -t 'My Database' -r`,
106
+ },
107
+ ];
108
+ DbCreate.args = {
109
+ page_id: core_1.Args.string({ required: true, description: 'Parent page ID or URL where the database will be created' }),
110
+ };
111
+ DbCreate.flags = {
112
+ title: core_1.Flags.string({
113
+ char: 't',
114
+ description: 'Title for the database (and initial data source)',
115
+ required: true,
116
+ }),
117
+ raw: core_1.Flags.boolean({
118
+ char: 'r',
119
+ description: 'output raw json',
120
+ }),
121
+ ...table_formatter_1.tableFlags,
122
+ ...base_flags_1.AutomationFlags,
123
+ };
124
+ exports.default = DbCreate;
@@ -0,0 +1,41 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class DbQuery extends Command {
3
+ static description: string;
4
+ static aliases: string[];
5
+ static examples: {
6
+ description: string;
7
+ command: string;
8
+ }[];
9
+ static args: {
10
+ database_id: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
11
+ };
12
+ static flags: {
13
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
14
+ 'file-filter': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
15
+ search: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
16
+ select: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
17
+ rawFilter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ fileFilter: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
19
+ markdown: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ 'compact-json': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
21
+ pretty: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
22
+ json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
23
+ 'page-size': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
24
+ retry: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
25
+ timeout: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
26
+ 'no-cache': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
27
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
28
+ minimal: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
29
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
30
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
31
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
32
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
33
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
34
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
35
+ 'page-all': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
36
+ 'sort-property': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
37
+ 'sort-direction': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
38
+ raw: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
39
+ };
40
+ run(): Promise<void>;
41
+ }