@haustle/notion-orm 0.0.43 → 0.0.45

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 (412) hide show
  1. package/README.md +449 -109
  2. package/build/src/agents-sdk-resolver.d.ts +8 -0
  3. package/build/src/agents-sdk-resolver.d.ts.map +1 -0
  4. package/build/src/agents-sdk-resolver.js +23 -0
  5. package/build/src/agents-sdk-resolver.js.map +1 -0
  6. package/build/src/ast/agents/agent-file-writer.d.ts +21 -0
  7. package/build/src/ast/agents/agent-file-writer.d.ts.map +1 -0
  8. package/build/src/ast/agents/agent-file-writer.js +99 -0
  9. package/build/src/ast/agents/agent-file-writer.js.map +1 -0
  10. package/build/src/ast/agents/generate-agents-cli.d.ts +24 -0
  11. package/build/src/ast/agents/generate-agents-cli.d.ts.map +1 -0
  12. package/build/src/ast/agents/generate-agents-cli.js +193 -0
  13. package/build/src/ast/agents/generate-agents-cli.js.map +1 -0
  14. package/build/src/ast/database/database-file-writer.d.ts +37 -0
  15. package/build/src/ast/database/database-file-writer.d.ts.map +1 -0
  16. package/build/src/ast/database/database-file-writer.js +240 -0
  17. package/build/src/ast/database/database-file-writer.js.map +1 -0
  18. package/build/src/ast/database/generate-databases-cli.d.ts +27 -0
  19. package/build/src/ast/database/generate-databases-cli.d.ts.map +1 -0
  20. package/build/src/ast/database/generate-databases-cli.js +141 -0
  21. package/build/src/ast/database/generate-databases-cli.js.map +1 -0
  22. package/build/src/ast/database/notion-column-generators.d.ts +180 -0
  23. package/build/src/ast/database/notion-column-generators.d.ts.map +1 -0
  24. package/build/src/ast/database/notion-column-generators.js +269 -0
  25. package/build/src/ast/database/notion-column-generators.js.map +1 -0
  26. package/build/src/ast/database/zod-schema.d.ts +17 -0
  27. package/build/src/ast/database/zod-schema.d.ts.map +1 -0
  28. package/build/src/ast/database/zod-schema.js +5 -0
  29. package/build/src/ast/database/zod-schema.js.map +1 -0
  30. package/build/src/ast/demo/datasource-fixture-builder.d.ts +38 -0
  31. package/build/src/ast/demo/datasource-fixture-builder.d.ts.map +1 -0
  32. package/build/src/ast/demo/datasource-fixture-builder.js +274 -0
  33. package/build/src/ast/demo/datasource-fixture-builder.js.map +1 -0
  34. package/build/src/ast/demo/demo-entry-builders.d.ts +28 -0
  35. package/build/src/ast/demo/demo-entry-builders.d.ts.map +1 -0
  36. package/build/src/ast/demo/demo-entry-builders.js +133 -0
  37. package/build/src/ast/demo/demo-entry-builders.js.map +1 -0
  38. package/build/src/ast/demo/demo-playground-spec.d.ts +51 -0
  39. package/build/src/ast/demo/demo-playground-spec.d.ts.map +1 -0
  40. package/build/src/ast/demo/demo-playground-spec.js +91 -0
  41. package/build/src/ast/demo/demo-playground-spec.js.map +1 -0
  42. package/build/src/ast/demo/demo-workspace-builder.d.ts +24 -0
  43. package/build/src/ast/demo/demo-workspace-builder.d.ts.map +1 -0
  44. package/build/src/ast/demo/demo-workspace-builder.js +90 -0
  45. package/build/src/ast/demo/demo-workspace-builder.js.map +1 -0
  46. package/build/src/ast/shared/ast-builders.d.ts +112 -0
  47. package/build/src/ast/shared/ast-builders.d.ts.map +1 -0
  48. package/build/src/ast/shared/ast-builders.js +181 -0
  49. package/build/src/ast/shared/ast-builders.js.map +1 -0
  50. package/build/src/ast/shared/cached-metadata.d.ts +26 -0
  51. package/build/src/ast/shared/cached-metadata.d.ts.map +1 -0
  52. package/build/src/ast/shared/cached-metadata.js +76 -0
  53. package/build/src/ast/shared/cached-metadata.js.map +1 -0
  54. package/build/src/ast/shared/codegen-diagnostics.d.ts +23 -0
  55. package/build/src/ast/shared/codegen-diagnostics.d.ts.map +1 -0
  56. package/build/src/ast/shared/codegen-diagnostics.js +13 -0
  57. package/build/src/ast/shared/codegen-diagnostics.js.map +1 -0
  58. package/build/src/ast/shared/codegen-environment.d.ts +37 -0
  59. package/build/src/ast/shared/codegen-environment.d.ts.map +1 -0
  60. package/build/src/ast/shared/codegen-environment.js +53 -0
  61. package/build/src/ast/shared/codegen-environment.js.map +1 -0
  62. package/build/src/ast/shared/constants.d.ts +98 -0
  63. package/build/src/ast/shared/constants.d.ts.map +1 -0
  64. package/build/src/ast/shared/constants.js +145 -0
  65. package/build/src/ast/shared/constants.js.map +1 -0
  66. package/build/src/ast/shared/emit/config-emitter.d.ts +56 -0
  67. package/build/src/ast/shared/emit/config-emitter.d.ts.map +1 -0
  68. package/build/src/ast/shared/emit/config-emitter.js +454 -0
  69. package/build/src/ast/shared/emit/config-emitter.js.map +1 -0
  70. package/build/src/ast/shared/emit/emit-value-as-expression.d.ts +10 -0
  71. package/build/src/ast/shared/emit/emit-value-as-expression.d.ts.map +1 -0
  72. package/build/src/ast/shared/emit/emit-value-as-expression.js +37 -0
  73. package/build/src/ast/shared/emit/emit-value-as-expression.js.map +1 -0
  74. package/build/src/ast/shared/emit/orm-index-emitter.d.ts +61 -0
  75. package/build/src/ast/shared/emit/orm-index-emitter.d.ts.map +1 -0
  76. package/build/src/ast/shared/emit/orm-index-emitter.js +376 -0
  77. package/build/src/ast/shared/emit/orm-index-emitter.js.map +1 -0
  78. package/build/src/ast/shared/emit/registry-emitter.d.ts +35 -0
  79. package/build/src/ast/shared/emit/registry-emitter.d.ts.map +1 -0
  80. package/build/src/ast/shared/emit/registry-emitter.js +39 -0
  81. package/build/src/ast/shared/emit/registry-emitter.js.map +1 -0
  82. package/build/src/ast/shared/emit/ts-emit-core.d.ts +79 -0
  83. package/build/src/ast/shared/emit/ts-emit-core.d.ts.map +1 -0
  84. package/build/src/ast/shared/emit/ts-emit-core.js +135 -0
  85. package/build/src/ast/shared/emit/ts-emit-core.js.map +1 -0
  86. package/build/src/ast/shared/emit/ts-emit-options.d.ts +29 -0
  87. package/build/src/ast/shared/emit/ts-emit-options.d.ts.map +1 -0
  88. package/build/src/ast/shared/emit/ts-emit-options.js +29 -0
  89. package/build/src/ast/shared/emit/ts-emit-options.js.map +1 -0
  90. package/build/src/base.d.ts +21 -0
  91. package/build/src/base.d.ts.map +1 -0
  92. package/build/src/base.js +19 -0
  93. package/build/src/base.js.map +1 -0
  94. package/build/src/cli/agents-sdk-setup.d.ts +2 -0
  95. package/build/src/cli/agents-sdk-setup.d.ts.map +1 -0
  96. package/build/src/cli/agents-sdk-setup.js +107 -0
  97. package/build/src/cli/agents-sdk-setup.js.map +1 -0
  98. package/build/src/cli/helpers.d.ts +14 -0
  99. package/build/src/cli/helpers.d.ts.map +1 -0
  100. package/build/src/cli/helpers.js +125 -0
  101. package/build/src/cli/helpers.js.map +1 -0
  102. package/build/src/cli/index.d.ts +3 -0
  103. package/build/src/cli/index.d.ts.map +1 -0
  104. package/build/src/cli/index.js +244 -0
  105. package/build/src/cli/index.js.map +1 -0
  106. package/build/src/cli/sync-progress-renderer.d.ts +20 -0
  107. package/build/src/cli/sync-progress-renderer.d.ts.map +1 -0
  108. package/build/src/cli/sync-progress-renderer.js +79 -0
  109. package/build/src/cli/sync-progress-renderer.js.map +1 -0
  110. package/build/src/cli/sync-progress.d.ts +55 -0
  111. package/build/src/cli/sync-progress.d.ts.map +1 -0
  112. package/build/src/cli/sync-progress.js +120 -0
  113. package/build/src/cli/sync-progress.js.map +1 -0
  114. package/build/src/cli/sync-report.d.ts +17 -0
  115. package/build/src/cli/sync-report.d.ts.map +1 -0
  116. package/build/src/cli/sync-report.js +86 -0
  117. package/build/src/cli/sync-report.js.map +1 -0
  118. package/build/src/client/agent/AgentClient.d.ts +84 -0
  119. package/build/src/client/agent/AgentClient.d.ts.map +1 -0
  120. package/build/src/client/agent/AgentClient.js +118 -0
  121. package/build/src/client/agent/AgentClient.js.map +1 -0
  122. package/build/src/client/database/DatabaseClient.d.ts +37 -0
  123. package/build/src/client/database/DatabaseClient.d.ts.map +1 -0
  124. package/build/src/client/database/DatabaseClient.js +328 -0
  125. package/build/src/client/database/DatabaseClient.js.map +1 -0
  126. package/build/src/client/database/create/build-create-page-parameters.d.ts +9 -0
  127. package/build/src/client/database/create/build-create-page-parameters.d.ts.map +1 -0
  128. package/build/src/client/database/create/build-create-page-parameters.js +13 -0
  129. package/build/src/client/database/create/build-create-page-parameters.js.map +1 -0
  130. package/build/src/client/database/create/index.d.ts +4 -0
  131. package/build/src/client/database/create/index.d.ts.map +1 -0
  132. package/build/src/client/database/create/index.js +4 -0
  133. package/build/src/client/database/create/index.js.map +1 -0
  134. package/build/src/client/database/create/map-to-notion-properties.d.ts +14 -0
  135. package/build/src/client/database/create/map-to-notion-properties.d.ts.map +1 -0
  136. package/build/src/client/database/create/map-to-notion-properties.js +31 -0
  137. package/build/src/client/database/create/map-to-notion-properties.js.map +1 -0
  138. package/build/src/client/database/create/property-value.d.ts +16 -0
  139. package/build/src/client/database/create/property-value.d.ts.map +1 -0
  140. package/build/src/client/database/create/property-value.js +213 -0
  141. package/build/src/client/database/create/property-value.js.map +1 -0
  142. package/build/src/client/database/query/build-query-params.d.ts +11 -0
  143. package/build/src/client/database/query/build-query-params.d.ts.map +1 -0
  144. package/build/src/client/database/query/build-query-params.js +24 -0
  145. package/build/src/client/database/query/build-query-params.js.map +1 -0
  146. package/build/src/client/database/query/build-query-response.d.ts +23 -0
  147. package/build/src/client/database/query/build-query-response.d.ts.map +1 -0
  148. package/build/src/client/database/query/build-query-response.js +41 -0
  149. package/build/src/client/database/query/build-query-response.js.map +1 -0
  150. package/build/src/client/database/query/filter/builders.d.ts +4 -0
  151. package/build/src/client/database/query/filter/builders.d.ts.map +1 -0
  152. package/build/src/client/database/query/filter/builders.js +141 -0
  153. package/build/src/client/database/query/filter/builders.js.map +1 -0
  154. package/build/src/client/database/query/filter/compound.d.ts +3 -0
  155. package/build/src/client/database/query/filter/compound.d.ts.map +1 -0
  156. package/build/src/client/database/query/filter/compound.js +13 -0
  157. package/build/src/client/database/query/filter/compound.js.map +1 -0
  158. package/build/src/client/database/query/filter/index.d.ts +3 -0
  159. package/build/src/client/database/query/filter/index.d.ts.map +1 -0
  160. package/build/src/client/database/query/filter/index.js +89 -0
  161. package/build/src/client/database/query/filter/index.js.map +1 -0
  162. package/build/src/client/database/query/http-guards.d.ts +2 -0
  163. package/build/src/client/database/query/http-guards.d.ts.map +1 -0
  164. package/build/src/client/database/query/http-guards.js +10 -0
  165. package/build/src/client/database/query/http-guards.js.map +1 -0
  166. package/build/src/client/database/query/index.d.ts +5 -0
  167. package/build/src/client/database/query/index.d.ts.map +1 -0
  168. package/build/src/client/database/query/index.js +5 -0
  169. package/build/src/client/database/query/index.js.map +1 -0
  170. package/build/src/client/database/query/normalize-page-result.d.ts +15 -0
  171. package/build/src/client/database/query/normalize-page-result.d.ts.map +1 -0
  172. package/build/src/client/database/query/normalize-page-result.js +35 -0
  173. package/build/src/client/database/query/normalize-page-result.js.map +1 -0
  174. package/build/src/client/database/query/page-collection.d.ts +42 -0
  175. package/build/src/client/database/query/page-collection.d.ts.map +1 -0
  176. package/build/src/client/database/query/page-collection.js +71 -0
  177. package/build/src/client/database/query/page-collection.js.map +1 -0
  178. package/build/src/client/database/query/projection.d.ts +9 -0
  179. package/build/src/client/database/query/projection.d.ts.map +1 -0
  180. package/build/src/client/database/query/projection.js +43 -0
  181. package/build/src/client/database/query/projection.js.map +1 -0
  182. package/build/src/client/database/query/response/checkbox.d.ts +3 -0
  183. package/build/src/client/database/query/response/checkbox.d.ts.map +1 -0
  184. package/build/src/client/database/query/response/checkbox.js +7 -0
  185. package/build/src/client/database/query/response/checkbox.js.map +1 -0
  186. package/build/src/client/database/query/response/created_by.d.ts +3 -0
  187. package/build/src/client/database/query/response/created_by.d.ts.map +1 -0
  188. package/build/src/client/database/query/response/created_by.js +8 -0
  189. package/build/src/client/database/query/response/created_by.js.map +1 -0
  190. package/build/src/client/database/query/response/created_time.d.ts +3 -0
  191. package/build/src/client/database/query/response/created_time.d.ts.map +1 -0
  192. package/build/src/client/database/query/response/created_time.js +7 -0
  193. package/build/src/client/database/query/response/created_time.js.map +1 -0
  194. package/build/src/client/database/query/response/date.d.ts +6 -0
  195. package/build/src/client/database/query/response/date.d.ts.map +1 -0
  196. package/build/src/client/database/query/response/date.js +13 -0
  197. package/build/src/client/database/query/response/date.js.map +1 -0
  198. package/build/src/client/database/query/response/email.d.ts +3 -0
  199. package/build/src/client/database/query/response/email.d.ts.map +1 -0
  200. package/build/src/client/database/query/response/email.js +7 -0
  201. package/build/src/client/database/query/response/email.js.map +1 -0
  202. package/build/src/client/database/query/response/files.d.ts +6 -0
  203. package/build/src/client/database/query/response/files.d.ts.map +1 -0
  204. package/build/src/client/database/query/response/files.js +8 -0
  205. package/build/src/client/database/query/response/files.js.map +1 -0
  206. package/build/src/client/database/query/response/index.d.ts +53 -0
  207. package/build/src/client/database/query/response/index.d.ts.map +1 -0
  208. package/build/src/client/database/query/response/index.js +44 -0
  209. package/build/src/client/database/query/response/index.js.map +1 -0
  210. package/build/src/client/database/query/response/last_edited_by.d.ts +3 -0
  211. package/build/src/client/database/query/response/last_edited_by.d.ts.map +1 -0
  212. package/build/src/client/database/query/response/last_edited_by.js +8 -0
  213. package/build/src/client/database/query/response/last_edited_by.js.map +1 -0
  214. package/build/src/client/database/query/response/last_edited_time.d.ts +3 -0
  215. package/build/src/client/database/query/response/last_edited_time.d.ts.map +1 -0
  216. package/build/src/client/database/query/response/last_edited_time.js +7 -0
  217. package/build/src/client/database/query/response/last_edited_time.js.map +1 -0
  218. package/build/src/client/database/query/response/multi_select.d.ts +3 -0
  219. package/build/src/client/database/query/response/multi_select.d.ts.map +1 -0
  220. package/build/src/client/database/query/response/multi_select.js +10 -0
  221. package/build/src/client/database/query/response/multi_select.js.map +1 -0
  222. package/build/src/client/database/query/response/number.d.ts +3 -0
  223. package/build/src/client/database/query/response/number.d.ts.map +1 -0
  224. package/build/src/client/database/query/response/number.js +7 -0
  225. package/build/src/client/database/query/response/number.js.map +1 -0
  226. package/build/src/client/database/query/response/people.d.ts +3 -0
  227. package/build/src/client/database/query/response/people.d.ts.map +1 -0
  228. package/build/src/client/database/query/response/people.js +13 -0
  229. package/build/src/client/database/query/response/people.js.map +1 -0
  230. package/build/src/client/database/query/response/phone_number.d.ts +3 -0
  231. package/build/src/client/database/query/response/phone_number.d.ts.map +1 -0
  232. package/build/src/client/database/query/response/phone_number.js +7 -0
  233. package/build/src/client/database/query/response/phone_number.js.map +1 -0
  234. package/build/src/client/database/query/response/relation.d.ts +4 -0
  235. package/build/src/client/database/query/response/relation.d.ts.map +1 -0
  236. package/build/src/client/database/query/response/relation.js +14 -0
  237. package/build/src/client/database/query/response/relation.js.map +1 -0
  238. package/build/src/client/database/query/response/rich_text.d.ts +3 -0
  239. package/build/src/client/database/query/response/rich_text.d.ts.map +1 -0
  240. package/build/src/client/database/query/response/rich_text.js +12 -0
  241. package/build/src/client/database/query/response/rich_text.js.map +1 -0
  242. package/build/src/client/database/query/response/select.d.ts +3 -0
  243. package/build/src/client/database/query/response/select.d.ts.map +1 -0
  244. package/build/src/client/database/query/response/select.js +7 -0
  245. package/build/src/client/database/query/response/select.js.map +1 -0
  246. package/build/src/client/database/query/response/shared.d.ts +6 -0
  247. package/build/src/client/database/query/response/shared.d.ts.map +1 -0
  248. package/build/src/client/database/query/response/shared.js +41 -0
  249. package/build/src/client/database/query/response/shared.js.map +1 -0
  250. package/build/src/client/database/query/response/status.d.ts +3 -0
  251. package/build/src/client/database/query/response/status.d.ts.map +1 -0
  252. package/build/src/client/database/query/response/status.js +7 -0
  253. package/build/src/client/database/query/response/status.js.map +1 -0
  254. package/build/src/client/database/query/response/title.d.ts +3 -0
  255. package/build/src/client/database/query/response/title.d.ts.map +1 -0
  256. package/build/src/client/database/query/response/title.js +12 -0
  257. package/build/src/client/database/query/response/title.js.map +1 -0
  258. package/build/src/client/database/query/response/unique_id.d.ts +3 -0
  259. package/build/src/client/database/query/response/unique_id.d.ts.map +1 -0
  260. package/build/src/client/database/query/response/unique_id.js +14 -0
  261. package/build/src/client/database/query/response/unique_id.js.map +1 -0
  262. package/build/src/client/database/query/response/url.d.ts +3 -0
  263. package/build/src/client/database/query/response/url.d.ts.map +1 -0
  264. package/build/src/client/database/query/response/url.js +7 -0
  265. package/build/src/client/database/query/response/url.js.map +1 -0
  266. package/build/src/client/database/query/schema-drift-validation.d.ts +31 -0
  267. package/build/src/client/database/query/schema-drift-validation.d.ts.map +1 -0
  268. package/build/src/client/database/query/schema-drift-validation.js +68 -0
  269. package/build/src/client/database/query/schema-drift-validation.js.map +1 -0
  270. package/build/src/client/database/query/sort-transform.d.ts +6 -0
  271. package/build/src/client/database/query/sort-transform.d.ts.map +1 -0
  272. package/build/src/client/database/query/sort-transform.js +13 -0
  273. package/build/src/client/database/query/sort-transform.js.map +1 -0
  274. package/build/src/client/database/query/types.d.ts +42 -0
  275. package/build/src/client/database/query/types.d.ts.map +1 -0
  276. package/build/src/client/database/query/types.js +2 -0
  277. package/build/src/client/database/query/types.js.map +1 -0
  278. package/build/src/client/database/schema-builder.d.ts +8 -0
  279. package/build/src/client/database/schema-builder.d.ts.map +1 -0
  280. package/build/src/client/database/schema-builder.js +78 -0
  281. package/build/src/client/database/schema-builder.js.map +1 -0
  282. package/build/src/client/database/types/crud.d.ts +40 -0
  283. package/build/src/client/database/types/crud.d.ts.map +1 -0
  284. package/build/src/client/database/types/crud.js +5 -0
  285. package/build/src/client/database/types/crud.js.map +1 -0
  286. package/build/src/client/database/types/filter-capability.d.ts +30 -0
  287. package/build/src/client/database/types/filter-capability.d.ts.map +1 -0
  288. package/build/src/client/database/types/filter-capability.js +28 -0
  289. package/build/src/client/database/types/filter-capability.js.map +1 -0
  290. package/build/src/client/database/types/index.d.ts +16 -0
  291. package/build/src/client/database/types/index.d.ts.map +1 -0
  292. package/build/src/client/database/types/index.js +16 -0
  293. package/build/src/client/database/types/index.js.map +1 -0
  294. package/build/src/client/database/types/notion-database-id.d.ts +14 -0
  295. package/build/src/client/database/types/notion-database-id.d.ts.map +1 -0
  296. package/build/src/client/database/types/notion-database-id.js +9 -0
  297. package/build/src/client/database/types/notion-database-id.js.map +1 -0
  298. package/build/src/client/database/types/notion-filter-model.d.ts +98 -0
  299. package/build/src/client/database/types/notion-filter-model.d.ts.map +1 -0
  300. package/build/src/client/database/types/notion-filter-model.js +5 -0
  301. package/build/src/client/database/types/notion-filter-model.js.map +1 -0
  302. package/build/src/client/database/types/notion-id-brand.d.ts +27 -0
  303. package/build/src/client/database/types/notion-id-brand.d.ts.map +1 -0
  304. package/build/src/client/database/types/notion-id-brand.js +8 -0
  305. package/build/src/client/database/types/notion-id-brand.js.map +1 -0
  306. package/build/src/client/database/types/notion-page-id.d.ts +10 -0
  307. package/build/src/client/database/types/notion-page-id.d.ts.map +1 -0
  308. package/build/src/client/database/types/notion-page-id.js +6 -0
  309. package/build/src/client/database/types/notion-page-id.js.map +1 -0
  310. package/build/src/client/database/types/notion-user-id.d.ts +10 -0
  311. package/build/src/client/database/types/notion-user-id.d.ts.map +1 -0
  312. package/build/src/client/database/types/notion-user-id.js +6 -0
  313. package/build/src/client/database/types/notion-user-id.js.map +1 -0
  314. package/build/src/client/database/types/projection.d.ts +78 -0
  315. package/build/src/client/database/types/projection.d.ts.map +1 -0
  316. package/build/src/client/database/types/projection.js +6 -0
  317. package/build/src/client/database/types/projection.js.map +1 -0
  318. package/build/src/client/database/types/query-filter.d.ts +19 -0
  319. package/build/src/client/database/types/query-filter.d.ts.map +1 -0
  320. package/build/src/client/database/types/query-filter.js +5 -0
  321. package/build/src/client/database/types/query-filter.js.map +1 -0
  322. package/build/src/client/database/types/query-object.d.ts +42 -0
  323. package/build/src/client/database/types/query-object.d.ts.map +1 -0
  324. package/build/src/client/database/types/query-object.js +5 -0
  325. package/build/src/client/database/types/query-object.js.map +1 -0
  326. package/build/src/client/database/types/schema.d.ts +190 -0
  327. package/build/src/client/database/types/schema.d.ts.map +1 -0
  328. package/build/src/client/database/types/schema.js +41 -0
  329. package/build/src/client/database/types/schema.js.map +1 -0
  330. package/build/src/client/database/types/sort.d.ts +22 -0
  331. package/build/src/client/database/types/sort.d.ts.map +1 -0
  332. package/build/src/client/database/types/sort.js +5 -0
  333. package/build/src/client/database/types/sort.js.map +1 -0
  334. package/build/src/config/findConfigFile.d.ts +8 -0
  335. package/build/src/config/findConfigFile.d.ts.map +1 -0
  336. package/build/src/config/findConfigFile.js +18 -0
  337. package/build/src/config/findConfigFile.js.map +1 -0
  338. package/build/src/config/helpers.d.ts +7 -0
  339. package/build/src/config/helpers.d.ts.map +1 -0
  340. package/build/src/config/helpers.js +57 -0
  341. package/build/src/config/helpers.js.map +1 -0
  342. package/build/src/config/init.d.ts +7 -0
  343. package/build/src/config/init.d.ts.map +1 -0
  344. package/build/src/config/init.js +28 -0
  345. package/build/src/config/init.js.map +1 -0
  346. package/build/src/config/loadConfig.d.ts +11 -0
  347. package/build/src/config/loadConfig.d.ts.map +1 -0
  348. package/build/src/config/loadConfig.js +91 -0
  349. package/build/src/config/loadConfig.js.map +1 -0
  350. package/build/src/config/loadDotEnvFromCwd.d.ts +12 -0
  351. package/build/src/config/loadDotEnvFromCwd.d.ts.map +1 -0
  352. package/build/src/config/loadDotEnvFromCwd.js +47 -0
  353. package/build/src/config/loadDotEnvFromCwd.js.map +1 -0
  354. package/build/src/config/notion-config-filenames.d.ts +20 -0
  355. package/build/src/config/notion-config-filenames.d.ts.map +1 -0
  356. package/build/src/config/notion-config-filenames.js +24 -0
  357. package/build/src/config/notion-config-filenames.js.map +1 -0
  358. package/build/src/config/resolveNotionAuth.d.ts +18 -0
  359. package/build/src/config/resolveNotionAuth.d.ts.map +1 -0
  360. package/build/src/config/resolveNotionAuth.js +24 -0
  361. package/build/src/config/resolveNotionAuth.js.map +1 -0
  362. package/build/src/config/types.d.ts +16 -0
  363. package/build/src/config/types.d.ts.map +1 -0
  364. package/build/src/config/types.js +7 -0
  365. package/build/src/config/types.js.map +1 -0
  366. package/build/src/helpers.d.ts +22 -0
  367. package/build/src/helpers.d.ts.map +1 -0
  368. package/build/src/helpers.js +67 -0
  369. package/build/src/helpers.js.map +1 -0
  370. package/build/src/index.d.ts +15 -11
  371. package/build/src/index.d.ts.map +1 -1
  372. package/build/src/index.js +11 -116
  373. package/build/src/index.js.map +1 -1
  374. package/build/src/notion-id-patterns.d.ts +9 -0
  375. package/build/src/notion-id-patterns.d.ts.map +1 -0
  376. package/build/src/notion-id-patterns.js +9 -0
  377. package/build/src/notion-id-patterns.js.map +1 -0
  378. package/build/src/runtime-constants.d.ts +13 -0
  379. package/build/src/runtime-constants.d.ts.map +1 -0
  380. package/build/src/runtime-constants.js +13 -0
  381. package/build/src/runtime-constants.js.map +1 -0
  382. package/build/src/typeUtils.d.ts +77 -0
  383. package/build/src/typeUtils.d.ts.map +1 -0
  384. package/build/src/typeUtils.js +52 -0
  385. package/build/src/typeUtils.js.map +1 -0
  386. package/package.json +85 -30
  387. package/build/src/BuildCall.d.ts +0 -45
  388. package/build/src/BuildCall.d.ts.map +0 -1
  389. package/build/src/BuildCall.js +0 -114
  390. package/build/src/BuildCall.js.map +0 -1
  391. package/build/src/DatabaseActions.d.ts +0 -19
  392. package/build/src/DatabaseActions.d.ts.map +0 -1
  393. package/build/src/DatabaseActions.js +0 -158
  394. package/build/src/DatabaseActions.js.map +0 -1
  395. package/build/src/GenerateTypes.d.ts +0 -8
  396. package/build/src/GenerateTypes.d.ts.map +0 -1
  397. package/build/src/GenerateTypes.js +0 -257
  398. package/build/src/GenerateTypes.js.map +0 -1
  399. package/build/src/cli.d.ts +0 -3
  400. package/build/src/cli.d.ts.map +0 -1
  401. package/build/src/cli.js +0 -48
  402. package/build/src/cli.js.map +0 -1
  403. package/build/src/queryTypes.d.ts +0 -117
  404. package/build/src/queryTypes.d.ts.map +0 -1
  405. package/build/src/queryTypes.js +0 -7
  406. package/build/src/queryTypes.js.map +0 -1
  407. package/src/BuildCall.ts +0 -118
  408. package/src/DatabaseActions.ts +0 -227
  409. package/src/GenerateTypes.ts +0 -448
  410. package/src/cli.ts +0 -40
  411. package/src/index.ts +0 -136
  412. package/src/queryTypes.ts +0 -177
@@ -1,227 +0,0 @@
1
- import {
2
- CreatePageParameters,
3
- CreatePageResponse,
4
- PageObjectResponse,
5
- QueryDatabaseParameters,
6
- QueryDatabaseResponse,
7
- } from "@notionhq/client/build/src/api-endpoints";
8
- import { Client } from "@notionhq/client";
9
- import { getCall } from "./BuildCall";
10
- import path from "path";
11
- import { NotionConfigType } from "./index";
12
- import {
13
- apiFilterType,
14
- apiSingleFilter,
15
- CompoundFilters,
16
- Query,
17
- QueryFilter,
18
- SimpleQueryResponse,
19
- SingleFilter,
20
- SupportedNotionColumnTypes,
21
- } from "./queryTypes";
22
-
23
- import { camelize } from "./GenerateTypes";
24
- export type propNameToColumnNameType = Record<
25
- string,
26
- { columnName: string; type: SupportedNotionColumnTypes }
27
- >;
28
-
29
- // Import auth key from config file
30
- const { auth }: NotionConfigType = require(path.join(
31
- process.cwd(),
32
- "notion.config"
33
- ));
34
-
35
- export class DatabaseActions<
36
- DatabaseSchemaType extends Record<string, any>,
37
- ColumnNameToColumnType extends Record<
38
- keyof DatabaseSchemaType,
39
- SupportedNotionColumnTypes
40
- >
41
- > {
42
- private NotionClient: Client = new Client({
43
- auth,
44
- });
45
- private databaseId: string;
46
- private propNameToColumnName: propNameToColumnNameType;
47
- private columnNames: string[];
48
-
49
- constructor(
50
- datbaseId: string,
51
- propNameToColumnName: propNameToColumnNameType
52
- ) {
53
- this.databaseId = datbaseId;
54
- this.propNameToColumnName = propNameToColumnName;
55
- this.columnNames = Object.keys(propNameToColumnName);
56
- }
57
-
58
- // Add page to a database
59
- async add(
60
- pageObject: DatabaseSchemaType,
61
- getCallBody?: boolean
62
- ): Promise<CreatePageParameters | CreatePageResponse> {
63
- const callBody: CreatePageParameters = {
64
- parent: {
65
- database_id: this.databaseId,
66
- },
67
- properties: {},
68
- };
69
-
70
- const columnTypePropNames = Object.keys(pageObject);
71
- columnTypePropNames.forEach((propName) => {
72
- const { type, columnName } = this.propNameToColumnName[propName];
73
- const columnObject = getCall({
74
- type,
75
- value: pageObject[propName],
76
- });
77
-
78
- callBody.properties[columnName] = columnObject!;
79
- });
80
-
81
- // CORS: If user wants the body of the call. Can then send to API
82
- if (getCallBody) {
83
- return callBody;
84
- }
85
-
86
- return await this.NotionClient.pages.create(callBody);
87
- }
88
-
89
- // Look for page inside the database
90
- async query(
91
- query: Query<DatabaseSchemaType, ColumnNameToColumnType>
92
- ): Promise<SimpleQueryResponse<DatabaseSchemaType>> {
93
- const queryCall: QueryDatabaseParameters = {
94
- database_id: this.databaseId,
95
- };
96
-
97
- const filters = query.filter
98
- ? this.recursivelyBuildFilter(query.filter)
99
- : undefined;
100
- if (filters) {
101
- // @ts-ignore errors vs notion api types
102
- queryCall["filter"] = filters;
103
- }
104
-
105
- const sort = query.sort;
106
-
107
- const response = await this.NotionClient.databases.query(queryCall);
108
-
109
- return this.simplifyQueryResponse(response);
110
- }
111
-
112
- private simplifyQueryResponse(
113
- res: QueryDatabaseResponse
114
- ): SimpleQueryResponse<DatabaseSchemaType> {
115
- // Is this smart too do...idk
116
- const rawResults = res.results as PageObjectResponse[];
117
- const rawResponse = res;
118
-
119
- const results: Partial<DatabaseSchemaType>[] = rawResults.map((result) => {
120
- const simpleResult: Partial<DatabaseSchemaType> = {};
121
- const properties = Object.entries(result.properties);
122
-
123
- for (const [columnName, result] of properties) {
124
- const camelizeColumnName = camelize(columnName);
125
-
126
- const columnType = this.propNameToColumnName[camelizeColumnName].type;
127
-
128
- // @ts-ignore
129
- simpleResult[camelizeColumnName] = this.getResponseValue(
130
- columnType,
131
- result
132
- );
133
- }
134
- return simpleResult;
135
- });
136
-
137
- return {
138
- results,
139
- rawResponse,
140
- };
141
- }
142
-
143
- private getResponseValue(
144
- prop: SupportedNotionColumnTypes,
145
- x: Record<string, any>
146
- ) {
147
- switch (prop) {
148
- case "select": {
149
- const { select } = x;
150
- if (select) {
151
- return select["name"];
152
- }
153
- return undefined;
154
- }
155
- case "title": {
156
- const { title } = x;
157
- if (title) {
158
- const combinedText = title.map(
159
- ({ plain_text }: { plain_text: string }) => plain_text
160
- );
161
- return combinedText.join("");
162
- }
163
- return undefined;
164
- }
165
- case "url": {
166
- const { url } = x;
167
- return url;
168
- }
169
-
170
- case "multi_select": {
171
- const { multi_select } = x;
172
- if (multi_select) {
173
- const multi_selectArr: string[] = multi_select.map(
174
- ({ name }: { name: string }) => name
175
- );
176
- return multi_selectArr;
177
- }
178
- return undefined;
179
- }
180
- default: {
181
- return "lol";
182
- }
183
- }
184
- }
185
-
186
- private recursivelyBuildFilter(
187
- queryFilter: QueryFilter<DatabaseSchemaType, ColumnNameToColumnType>
188
- ): apiFilterType {
189
- // Need to loop because we don't kno
190
- for (const prop in queryFilter) {
191
- // if the filter is "and" || "or" we need to recursively
192
- if (prop === "and" || prop === "or") {
193
- const compoundFilters: QueryFilter<
194
- DatabaseSchemaType,
195
- ColumnNameToColumnType
196
- >[] =
197
- // @ts-ignore
198
- queryFilter[prop];
199
-
200
- const compoundApiFilters = compoundFilters.map(
201
- (i: QueryFilter<DatabaseSchemaType, ColumnNameToColumnType>) => {
202
- return this.recursivelyBuildFilter(i);
203
- }
204
- );
205
-
206
- // Either have an `and` or an `or` compound filter
207
- let temp: apiFilterType = {
208
- ...(prop === "and"
209
- ? { and: compoundApiFilters }
210
- : { or: compoundApiFilters }),
211
- };
212
- return temp;
213
- } else {
214
- const propType = this.propNameToColumnName[prop].type;
215
- const temp: apiSingleFilter = {
216
- property: this.propNameToColumnName[prop].columnName,
217
- };
218
-
219
- //@ts-ignore
220
- temp[propType] = (queryFilter as SingleFilter<ColumnNameToColumnType>)[
221
- prop
222
- ];
223
- return temp;
224
- }
225
- }
226
- }
227
- }
@@ -1,448 +0,0 @@
1
- import {
2
- DatabaseObjectResponse,
3
- GetDatabaseResponse,
4
- } from "@notionhq/client/build/src/api-endpoints";
5
- import * as ts from "typescript";
6
- import fs from "fs";
7
- import path from "path";
8
- import { DATABASES_DIR } from "./index";
9
- import { NotionColumnTypes } from "queryTypes";
10
-
11
- type propNameToColumnNameType = Record<
12
- string,
13
- { columnName: string; type: NotionColumnTypes }
14
- >;
15
-
16
- /*
17
- Responsible for generating `.ts` files
18
- */
19
- export async function createTypescriptFileForDatabase(
20
- dbResponse: GetDatabaseResponse
21
- ) {
22
- const {
23
- id: databaseId,
24
- properties,
25
- title,
26
- } = dbResponse as DatabaseObjectResponse;
27
- const propNameToColumnName: propNameToColumnNameType = {};
28
- const databaseName = title[0].plain_text;
29
- const databaseClassName = camelize(databaseName).replace(/[^a-zA-Z0-9]/g, "");
30
-
31
- const databaseColumnTypeProps: ts.TypeElement[] = [];
32
-
33
- // Looping through each column of database
34
- Object.values(properties).forEach((value) => {
35
- const { type: columnType, name: columnName } = value;
36
-
37
- // Taking the column name and camelizing it for typescript use
38
- const camelizedColumnName = camelize(columnName);
39
-
40
- // Creating map of column name to the column's name in the database's typescript type
41
- propNameToColumnName[camelizedColumnName] = {
42
- columnName,
43
- type: columnType,
44
- };
45
-
46
- if (
47
- columnType === "title" ||
48
- columnType === "rich_text" ||
49
- columnType === "email" ||
50
- columnType === "phone_number"
51
- ) {
52
- // add text column to collection type
53
- databaseColumnTypeProps.push(
54
- createTextProperty({
55
- name: camelizedColumnName,
56
- isTitle: columnType === "title",
57
- })
58
- );
59
- } else if (columnType === "number") {
60
- // add number column to collection type
61
- databaseColumnTypeProps.push(createNumberProperty(camelizedColumnName));
62
- } else if (columnType === "url") {
63
- // add url column to collection type
64
- databaseColumnTypeProps.push(
65
- createTextProperty({ name: camelizedColumnName, isTitle: false })
66
- );
67
- } else if (columnType === "date") {
68
- // add Date column to collection type
69
- databaseColumnTypeProps.push(createDateProperty(camelizedColumnName));
70
- } else if (
71
- columnType === "select" ||
72
- columnType === "status" ||
73
- columnType === "multi_select"
74
- ) {
75
- // @ts-ignore
76
- const options = value[columnType].options.map((x) => x.name);
77
- databaseColumnTypeProps.push(
78
- createMultiOptionProp({
79
- name: camelizedColumnName,
80
- options,
81
- isArray: columnType === "multi_select", // Union or Union Array
82
- })
83
- );
84
- }
85
- });
86
-
87
- // Object type that represents the database schema
88
- const DatabaseSchemaType = ts.factory.createTypeAliasDeclaration(
89
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
90
- ts.factory.createIdentifier("DatabaseSchemaType"),
91
- undefined,
92
- ts.factory.createTypeLiteralNode(databaseColumnTypeProps)
93
- );
94
-
95
- // Top level non-nested variable, functions, types for database files
96
- const TsNodesForDatabaseFile = ts.factory.createNodeArray([
97
- createNameImport({
98
- namedImport: "DatabaseActions",
99
- path: "../src/DatabaseActions",
100
- }),
101
- createNameImport({
102
- namedImport: "Query",
103
- path: "../src/queryTypes",
104
- }),
105
- createDatabaseIdVariable(databaseId),
106
- DatabaseSchemaType,
107
- createColumnNameToColumnProperties(propNameToColumnName),
108
- createColumnNameToColumnType(),
109
- createQueryTypeExport(),
110
- createDatabaseClassExport({ databaseName: databaseClassName }),
111
- ]);
112
-
113
- const sourceFile = ts.createSourceFile(
114
- "",
115
- "",
116
- ts.ScriptTarget.ESNext,
117
- true,
118
- ts.ScriptKind.TS
119
- );
120
- const printer = ts.createPrinter();
121
-
122
- const typescriptCodeToString = printer.printList(
123
- ts.ListFormat.MultiLine,
124
- TsNodesForDatabaseFile,
125
- sourceFile
126
- );
127
- const transpileToJavaScript = ts.transpile(typescriptCodeToString, {
128
- module: ts.ModuleKind.None,
129
- target: ts.ScriptTarget.ESNext,
130
- });
131
-
132
- // Create databases output folder
133
- if (!fs.existsSync(DATABASES_DIR)) {
134
- fs.mkdirSync(DATABASES_DIR);
135
- }
136
-
137
- // Create TypeScript and JavaScript files
138
- fs.writeFileSync(
139
- path.resolve(DATABASES_DIR, `${databaseClassName}.ts`),
140
- typescriptCodeToString
141
- );
142
- fs.writeFileSync(
143
- path.resolve(DATABASES_DIR, `${databaseClassName}.js`),
144
- transpileToJavaScript
145
- );
146
-
147
- return { databaseName, databaseClassName, databaseId };
148
- }
149
-
150
- // generate text property
151
- function createTextProperty(args: { name: string; isTitle: boolean }) {
152
- const { name, isTitle } = args;
153
- const text = ts.factory.createPropertySignature(
154
- undefined,
155
- ts.factory.createIdentifier(name),
156
- !isTitle ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,
157
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
158
- );
159
- return text;
160
- }
161
-
162
- /**
163
- * Generate number property to go inside a type
164
- * name: number
165
- */
166
- function createNumberProperty(name: string) {
167
- const number = ts.factory.createPropertySignature(
168
- undefined,
169
- ts.factory.createIdentifier(name),
170
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
171
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)
172
- );
173
- return number;
174
- }
175
-
176
- /**
177
- * For selects and multi-select collection properties
178
- * array = true for multi-select
179
- */
180
- function createMultiOptionProp(args: {
181
- name: string;
182
- options: string[];
183
- isArray: boolean;
184
- }) {
185
- const { isArray, name, options } = args;
186
- return ts.factory.createPropertySignature(
187
- undefined,
188
- ts.factory.createIdentifier(name),
189
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
190
- isArray
191
- ? ts.factory.createArrayTypeNode(
192
- ts.factory.createParenthesizedType(
193
- ts.factory.createUnionTypeNode([
194
- ...options.map((option) =>
195
- ts.factory.createLiteralTypeNode(
196
- ts.factory.createStringLiteral(option)
197
- )
198
- ),
199
- createOtherStringProp(),
200
- ])
201
- )
202
- )
203
- : ts.factory.createUnionTypeNode([
204
- ...options.map((option) =>
205
- ts.factory.createLiteralTypeNode(
206
- ts.factory.createStringLiteral(option)
207
- )
208
- ),
209
- createOtherStringProp(),
210
- ])
211
- );
212
- }
213
-
214
- // string & {}. Allows users to pass in values
215
- function createOtherStringProp() {
216
- return ts.factory.createIntersectionTypeNode([
217
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
218
- ts.factory.createTypeLiteralNode([]),
219
- ]);
220
- }
221
-
222
- function createDateProperty(name: string) {
223
- return ts.factory.createPropertySignature(
224
- undefined,
225
- ts.factory.createIdentifier(name),
226
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
227
- ts.factory.createTypeLiteralNode([
228
- ts.factory.createPropertySignature(
229
- undefined,
230
- ts.factory.createIdentifier("start"),
231
- undefined,
232
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
233
- ),
234
- ts.factory.createPropertySignature(
235
- undefined,
236
- ts.factory.createIdentifier("end"),
237
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
238
- ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
239
- ),
240
- ])
241
- );
242
- }
243
-
244
- // Generate database Id variable
245
- // const databaseId = <database-id>
246
- function createDatabaseIdVariable(databaseId: string) {
247
- return ts.factory.createVariableStatement(
248
- undefined,
249
- ts.factory.createVariableDeclarationList(
250
- [
251
- ts.factory.createVariableDeclaration(
252
- ts.factory.createIdentifier("databaseId"),
253
- undefined,
254
- undefined,
255
- ts.factory.createStringLiteral(databaseId)
256
- ),
257
- ],
258
- ts.NodeFlags.Const
259
- )
260
- );
261
- }
262
-
263
- /**
264
- * Instead of refering to the column names 1:1 such as "Book Rating", we transform them to
265
- * camelcase (eg. bookRating). So we need to keep track of the original name and the type
266
- * for when we construct request for API
267
- *
268
- * Example
269
- *
270
- * const columnNameToColumnProperties = {
271
- *
272
- * "bookRating": {
273
- * columnName: "Book Rating",
274
- * type: "select"
275
- * },
276
- * "genre": {
277
- * columnName: "Genre",
278
- * type: "multi_select"
279
- * }
280
- *
281
- * }
282
- */
283
- function createColumnNameToColumnProperties(colMap: propNameToColumnNameType) {
284
- return ts.factory.createVariableDeclarationList(
285
- [
286
- ts.factory.createVariableDeclaration(
287
- ts.factory.createIdentifier("columnNameToColumnProperties"),
288
- undefined,
289
- undefined,
290
- ts.factory.createAsExpression(
291
- ts.factory.createObjectLiteralExpression(
292
- [
293
- ...Object.entries(colMap).map(([propName, value]) =>
294
- ts.factory.createPropertyAssignment(
295
- ts.factory.createStringLiteral(propName),
296
- ts.factory.createObjectLiteralExpression(
297
- [
298
- ts.factory.createPropertyAssignment(
299
- ts.factory.createIdentifier("columnName"),
300
- ts.factory.createStringLiteral(value.columnName)
301
- ),
302
- ts.factory.createPropertyAssignment(
303
- ts.factory.createIdentifier("type"),
304
- ts.factory.createStringLiteral(value.type)
305
- ),
306
- ],
307
- true
308
- )
309
- )
310
- ),
311
- ],
312
- true
313
- ),
314
- ts.factory.createTypeReferenceNode(
315
- ts.factory.createIdentifier("const"),
316
- undefined
317
- )
318
- )
319
- ),
320
- ],
321
- ts.NodeFlags.Const
322
- );
323
- }
324
-
325
- function createColumnNameToColumnType() {
326
- return ts.factory.createTypeAliasDeclaration(
327
- undefined,
328
- ts.factory.createIdentifier("ColumnNameToColumnType"),
329
- undefined,
330
- ts.factory.createMappedTypeNode(
331
- undefined,
332
- ts.factory.createTypeParameterDeclaration(
333
- undefined,
334
- ts.factory.createIdentifier("Property"),
335
- ts.factory.createTypeOperatorNode(
336
- ts.SyntaxKind.KeyOfKeyword,
337
- ts.factory.createTypeQueryNode(
338
- ts.factory.createIdentifier("columnNameToColumnProperties"),
339
- undefined
340
- )
341
- ),
342
- undefined
343
- ),
344
- undefined,
345
- undefined,
346
- ts.factory.createIndexedAccessTypeNode(
347
- ts.factory.createIndexedAccessTypeNode(
348
- ts.factory.createTypeQueryNode(
349
- ts.factory.createIdentifier("columnNameToColumnProperties"),
350
- undefined
351
- ),
352
- ts.factory.createTypeReferenceNode(
353
- ts.factory.createIdentifier("Property"),
354
- undefined
355
- )
356
- ),
357
- ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("type"))
358
- ),
359
- undefined
360
- /* unknown */
361
- )
362
- );
363
- }
364
-
365
- // Need to import the database class used to execute database actions (adding + querying)
366
- function createNameImport(args: { namedImport: string; path: string }) {
367
- const { namedImport, path } = args;
368
- return ts.factory.createImportDeclaration(
369
- undefined,
370
- ts.factory.createImportClause(
371
- false,
372
- undefined,
373
- ts.factory.createNamedImports([
374
- ts.factory.createImportSpecifier(
375
- false,
376
- undefined,
377
- ts.factory.createIdentifier(namedImport)
378
- ),
379
- ])
380
- ),
381
- ts.factory.createStringLiteral(path),
382
- undefined
383
- );
384
- }
385
-
386
- function createQueryTypeExport() {
387
- return ts.factory.createTypeAliasDeclaration(
388
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
389
- ts.factory.createIdentifier("QuerySchemaType"),
390
- undefined,
391
- ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Query"), [
392
- ts.factory.createTypeReferenceNode(
393
- ts.factory.createIdentifier("DatabaseSchemaType"),
394
- undefined
395
- ),
396
- ts.factory.createTypeReferenceNode(
397
- ts.factory.createIdentifier("ColumnNameToColumnType"),
398
- undefined
399
- ),
400
- ])
401
- );
402
- }
403
-
404
- /**
405
- * Create export statement for the database class
406
- * export const <databaseName> = new DatabaseActions<DatabaseSchemaType>(datbaseId, columnNameToColumnProperties)
407
- */
408
- function createDatabaseClassExport(args: { databaseName: string }) {
409
- const { databaseName } = args;
410
- return ts.factory.createVariableStatement(
411
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
412
- ts.factory.createVariableDeclarationList(
413
- [
414
- ts.factory.createVariableDeclaration(
415
- ts.factory.createIdentifier(databaseName),
416
- undefined,
417
- undefined,
418
- ts.factory.createNewExpression(
419
- ts.factory.createIdentifier("DatabaseActions"),
420
- [
421
- ts.factory.createTypeReferenceNode(
422
- ts.factory.createIdentifier("DatabaseSchemaType"),
423
- undefined
424
- ),
425
- ts.factory.createTypeReferenceNode(
426
- ts.factory.createIdentifier("ColumnNameToColumnType"),
427
- undefined
428
- ),
429
- ],
430
- [
431
- ts.factory.createIdentifier("databaseId"),
432
- ts.factory.createIdentifier("columnNameToColumnProperties"),
433
- ]
434
- )
435
- ),
436
- ],
437
- ts.NodeFlags.Const
438
- )
439
- );
440
- }
441
-
442
- // for a type's property name
443
- export function camelize(str: string) {
444
- return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
445
- if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
446
- return index === 0 ? match.toLowerCase() : match.toUpperCase();
447
- });
448
- }
package/src/cli.ts DELETED
@@ -1,40 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import fs from "fs";
4
- import { createDatabaseTypes } from "./index";
5
- import path from "path";
6
-
7
- async function main() {
8
- const args = process.argv.slice(2);
9
-
10
- if (args.length === 1 && args[0] === "generate") {
11
- const projDir = process.cwd();
12
-
13
- const notionConfigDirJS = fs.existsSync(
14
- path.join(projDir, "notion.config.js")
15
- );
16
- const notionConfigDirTS = fs.existsSync(
17
- path.join(projDir, "notion.config.ts")
18
- );
19
-
20
- console.log(path.join(projDir, "notion.config"));
21
- if (notionConfigDirJS || notionConfigDirTS) {
22
- const config = require(path.join(projDir, "notion.config"));
23
-
24
- const { databaseNames } = await createDatabaseTypes(config);
25
- if (databaseNames.length < 0) {
26
- console.log("generated no types");
27
- } else {
28
- console.log("Generated types for the following Database's: ");
29
- for (let x = 0; x < databaseNames.length; x++) {
30
- console.log(`${x}. ${databaseNames[x]}`);
31
- }
32
- }
33
- } else {
34
- console.error("Could not find file `notion.config.ts` in root");
35
- process.exit(1);
36
- }
37
- }
38
- }
39
-
40
- main();