@luzzle/core 0.0.65 → 0.0.67

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 (104) hide show
  1. package/dist/src/database/NodeSqliteDialect.d.ts +2 -1
  2. package/dist/src/database/NodeSqliteDialect.js.map +1 -1
  3. package/dist/src/database/client.d.ts +1 -1
  4. package/dist/src/database/client.js.map +1 -1
  5. package/dist/src/database/migrations/2023-05-26T15:04:19.094Z.d.ts +1 -1
  6. package/dist/src/database/migrations/2023-05-26T15:04:19.094Z.js.map +1 -1
  7. package/dist/src/database/migrations/2023-10-30T23:24:40Z.d.ts +1 -1
  8. package/dist/src/database/migrations/2023-10-30T23:24:40Z.js.map +1 -1
  9. package/dist/src/database/migrations/2023-11-22T14:55:18Z.d.ts +1 -1
  10. package/dist/src/database/migrations/2023-11-22T14:55:18Z.js.map +1 -1
  11. package/dist/src/database/migrations/2023-11-27T04:32:07Z.d.ts +1 -1
  12. package/dist/src/database/migrations/2023-11-27T04:32:07Z.js.map +1 -1
  13. package/dist/src/database/migrations/2024-01-01T23:30:29Z.d.ts +1 -1
  14. package/dist/src/database/migrations/2024-01-01T23:30:29Z.js.map +1 -1
  15. package/dist/src/database/migrations/2024-01-06T15:52:43Z.d.ts +1 -1
  16. package/dist/src/database/migrations/2024-01-06T15:52:43Z.js.map +1 -1
  17. package/dist/src/database/migrations/2024-02-09T16:33:10Z.d.ts +1 -1
  18. package/dist/src/database/migrations/2024-02-09T16:33:10Z.js.map +1 -1
  19. package/dist/src/database/migrations/2024-02-13T05:56:43Z.d.ts +1 -1
  20. package/dist/src/database/migrations/2024-02-13T05:56:43Z.js.map +1 -1
  21. package/dist/src/database/migrations/2024-02-24T03:05:47Z-add-texts-table.d.ts +1 -1
  22. package/dist/src/database/migrations/2024-02-24T03:05:47Z-add-texts-table.js.map +1 -1
  23. package/dist/src/database/migrations/2024-02-26T05:37:37Z-add-cache-table.d.ts +1 -1
  24. package/dist/src/database/migrations/2024-02-26T05:37:37Z-add-cache-table.js.map +1 -1
  25. package/dist/src/database/migrations/2024-03-01T01:01:47Z-fix-trigger-bugs.d.ts +1 -1
  26. package/dist/src/database/migrations/2024-03-01T01:01:47Z-fix-trigger-bugs.js.map +1 -1
  27. package/dist/src/database/migrations/2024-06-15T17:17:51Z-add-games-table.d.ts +1 -1
  28. package/dist/src/database/migrations/2024-06-15T17:17:51Z-add-games-table.js.map +1 -1
  29. package/dist/src/database/migrations/2024-06-24T20:16:48Z-remove-book-open-library-fields.d.ts +1 -1
  30. package/dist/src/database/migrations/2024-06-24T20:16:48Z-remove-book-open-library-fields.js.map +1 -1
  31. package/dist/src/database/migrations/2024-06-29T16:31:33Z-add-piece-manager-table.d.ts +1 -1
  32. package/dist/src/database/migrations/2024-06-29T16:31:33Z-add-piece-manager-table.js.map +1 -1
  33. package/dist/src/database/migrations/2024-07-14T06:59:07Z-remove-pieces.d.ts +1 -1
  34. package/dist/src/database/migrations/2024-07-14T06:59:07Z-remove-pieces.js.map +1 -1
  35. package/dist/src/database/migrations/2024-11-06T15:27:05Z-remove-tags.d.ts +1 -1
  36. package/dist/src/database/migrations/2024-11-06T15:27:05Z-remove-tags.js.map +1 -1
  37. package/dist/src/database/migrations/2024-11-08T05:59:37Z-remove-pieces-items-unique-tables.d.ts +1 -1
  38. package/dist/src/database/migrations/2024-11-08T05:59:37Z-remove-pieces-items-unique-tables.js.map +1 -1
  39. package/dist/src/database/migrations/2024-11-13T14:51:17Z-track-file-paths-on-piece.d.ts +1 -1
  40. package/dist/src/database/migrations/2024-11-13T14:51:17Z-track-file-paths-on-piece.js.map +1 -1
  41. package/dist/src/database/migrations/2024-12-15T06:35:24Z-track-assets-on-piece.d.ts +1 -1
  42. package/dist/src/database/migrations/2024-12-15T06:35:24Z-track-assets-on-piece.js.map +1 -1
  43. package/dist/src/database/migrations/2026-02-11T23:03:45Z-clear-pieces-cache.d.ts +1 -1
  44. package/dist/src/database/migrations/2026-02-11T23:03:45Z-clear-pieces-cache.js.map +1 -1
  45. package/dist/src/database/migrations.d.ts +2 -2
  46. package/dist/src/database/migrations.js.map +1 -1
  47. package/dist/src/database/tables/index.d.ts +5 -4
  48. package/dist/src/database/tables/index.js +1 -0
  49. package/dist/src/database/tables/index.js.map +1 -1
  50. package/dist/src/database/tables/pieces_cache.schema.d.ts +1 -1
  51. package/dist/src/database/tables/pieces_cache.schema.js.map +1 -1
  52. package/dist/src/database/tables/pieces_items.schema.d.ts +1 -1
  53. package/dist/src/database/tables/pieces_items.schema.js.map +1 -1
  54. package/dist/src/database/tables/pieces_manager.schema.d.ts +1 -1
  55. package/dist/src/database/tables/pieces_manager.schema.js.map +1 -1
  56. package/dist/src/database/utils.d.ts +1 -1
  57. package/dist/src/database/utils.js.map +1 -1
  58. package/dist/src/lib/ajv.d.ts +1 -1
  59. package/dist/src/lib/ajv.js.map +1 -1
  60. package/dist/src/lib/markdown.js.map +1 -1
  61. package/dist/src/llm/google.d.ts +1 -1
  62. package/dist/src/llm/google.js +2 -1
  63. package/dist/src/llm/google.js.map +1 -1
  64. package/dist/src/pieces/Piece.d.ts +29 -10
  65. package/dist/src/pieces/Piece.fixtures.d.ts +6 -6
  66. package/dist/src/pieces/Piece.fixtures.js.map +1 -1
  67. package/dist/src/pieces/Piece.js +62 -36
  68. package/dist/src/pieces/Piece.js.map +1 -1
  69. package/dist/src/pieces/Pieces.d.ts +25 -9
  70. package/dist/src/pieces/Pieces.js +72 -30
  71. package/dist/src/pieces/Pieces.js.map +1 -1
  72. package/dist/src/pieces/cache.d.ts +1 -1
  73. package/dist/src/pieces/cache.fixtures.d.ts +1 -1
  74. package/dist/src/pieces/cache.fixtures.js.map +1 -1
  75. package/dist/src/pieces/cache.js.map +1 -1
  76. package/dist/src/pieces/index.d.ts +2 -2
  77. package/dist/src/pieces/index.js +2 -2
  78. package/dist/src/pieces/index.js.map +1 -1
  79. package/dist/src/pieces/item.d.ts +4 -4
  80. package/dist/src/pieces/item.js.map +1 -1
  81. package/dist/src/pieces/items.d.ts +3 -3
  82. package/dist/src/pieces/items.js.map +1 -1
  83. package/dist/src/pieces/json.schema.d.ts +3 -3
  84. package/dist/src/pieces/json.schema.js.map +1 -1
  85. package/dist/src/pieces/manager.d.ts +4 -4
  86. package/dist/src/pieces/manager.js.map +1 -1
  87. package/dist/src/pieces/utils/frontmatter.d.ts +1 -1
  88. package/dist/src/pieces/utils/frontmatter.js.map +1 -1
  89. package/dist/src/pieces/utils/frontmatter.path.d.ts +1 -1
  90. package/dist/src/pieces/utils/frontmatter.path.js.map +1 -1
  91. package/dist/src/pieces/utils/markdown.d.ts +1 -1
  92. package/dist/src/pieces/utils/markdown.js.map +1 -1
  93. package/dist/src/pieces/utils/piece.d.ts +2 -2
  94. package/dist/src/pieces/utils/piece.js.map +1 -1
  95. package/dist/src/storage/abstract.d.ts +1 -1
  96. package/dist/src/storage/abstract.js.map +1 -1
  97. package/dist/src/storage/fs.d.ts +1 -1
  98. package/dist/src/storage/fs.js.map +1 -1
  99. package/dist/src/storage/index.js +1 -0
  100. package/dist/src/storage/index.js.map +1 -1
  101. package/dist/src/storage/storage.mock.d.ts +1 -1
  102. package/dist/src/storage/storage.mock.js.map +1 -1
  103. package/dist/tsconfig.build.tsbuildinfo +1 -1
  104. package/package.json +8 -1
@@ -1,3 +1,3 @@
1
- import { Kysely } from 'kysely';
1
+ import type { Kysely } from 'kysely';
2
2
  export declare function up(db: Kysely<any>): Promise<void>;
3
3
  export declare function down(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"2026-02-11T23:03:45Z-clear-pieces-cache.js","sourceRoot":"","sources":["../../../../src/database/migrations/2026-02-11T23:03:45Z-clear-pieces-cache.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,EAAe;IACvC,MAAM,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAA;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,gBAAgB;AACjB,CAAC","sourcesContent":["import { Kysely } from 'kysely'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function up(db: Kysely<any>): Promise<void> {\n\tawait db.deleteFrom('pieces_cache').execute()\n}\n\nexport async function down(): Promise<void> {\n\t// nothing to do\n}\n"]}
1
+ {"version":3,"file":"2026-02-11T23:03:45Z-clear-pieces-cache.js","sourceRoot":"","sources":["../../../../src/database/migrations/2026-02-11T23:03:45Z-clear-pieces-cache.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,EAAe;IACvC,MAAM,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAA;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI;IACzB,gBAAgB;AACjB,CAAC","sourcesContent":["import type { Kysely } from 'kysely'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function up(db: Kysely<any>): Promise<void> {\n\tawait db.deleteFrom('pieces_cache').execute()\n}\n\nexport async function down(): Promise<void> {\n\t// nothing to do\n}\n"]}
@@ -1,3 +1,3 @@
1
- import { MigrationResultSet } from 'kysely';
2
- import { LuzzleDatabase } from './tables/index.js';
1
+ import { type MigrationResultSet } from 'kysely';
2
+ import type { LuzzleDatabase } from './tables/index.js';
3
3
  export default function (db: LuzzleDatabase): Promise<MigrationResultSet>;
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../src/database/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAsB,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAE5E,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AACnC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtC,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,EAAkB;IAChD,MAAM,QAAQ,GAAG,IAAI,qBAAqB,CAAC;QAC1C,EAAE;QACF,IAAI;QACJ,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;KACnD,CAAC,CAAA;IACF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAE/C,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAA;AAClC,CAAC","sourcesContent":["import { FileMigrationProvider, MigrationResultSet, Migrator } from 'kysely'\nimport { LuzzleDatabase } from './tables/index.js'\nimport { promises as fs } from 'fs'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport default async function (db: LuzzleDatabase): Promise<MigrationResultSet> {\n\tconst provider = new FileMigrationProvider({\n\t\tfs,\n\t\tpath,\n\t\tmigrationFolder: path.join(dirname, './migrations'),\n\t})\n\tconst migrator = new Migrator({ db, provider })\n\n\treturn migrator.migrateToLatest()\n}\n"]}
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../../src/database/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA2B,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjF,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AACnC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtC,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,EAAkB;IAChD,MAAM,QAAQ,GAAG,IAAI,qBAAqB,CAAC;QAC1C,EAAE;QACF,IAAI;QACJ,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;KACnD,CAAC,CAAA;IACF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAE/C,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAA;AAClC,CAAC","sourcesContent":["import { FileMigrationProvider, type MigrationResultSet, Migrator } from 'kysely'\nimport type { LuzzleDatabase } from './tables/index.js'\nimport { promises as fs } from 'fs'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nexport default async function (db: LuzzleDatabase): Promise<MigrationResultSet> {\n\tconst provider = new FileMigrationProvider({\n\t\tfs,\n\t\tpath,\n\t\tmigrationFolder: path.join(dirname, './migrations'),\n\t})\n\tconst migrator = new Migrator({ db, provider })\n\n\treturn migrator.migrateToLatest()\n}\n"]}
@@ -1,7 +1,8 @@
1
- import { Kysely, Insertable, Updateable, Selectable } from 'kysely';
2
- import { CacheTable } from './pieces_cache.schema.js';
3
- import { PieceManagerTable } from './pieces_manager.schema.js';
4
- import { PiecesItemsTable } from './pieces_items.schema.js';
1
+ import type { Kysely } from 'kysely';
2
+ import { type Insertable, type Updateable, type Selectable } from 'kysely';
3
+ import type { CacheTable } from './pieces_cache.schema.js';
4
+ import type { PieceManagerTable } from './pieces_manager.schema.js';
5
+ import type { PiecesItemsTable } from './pieces_items.schema.js';
5
6
  declare const LuzzleTableName: {
6
7
  readonly Cache: "pieces_cache";
7
8
  readonly PieceManager: "pieces_manager";
@@ -1,3 +1,4 @@
1
+ import {} from 'kysely';
1
2
  const LuzzleTableName = {
2
3
  Cache: 'pieces_cache',
3
4
  PieceManager: 'pieces_manager',
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/database/tables/index.ts"],"names":[],"mappings":"AAKA,MAAM,eAAe,GAAG;IACvB,KAAK,EAAE,cAAc;IACrB,YAAY,EAAE,gBAAgB;IAC9B,UAAU,EAAE,cAAc;CACjB,CAAA;AAgBV,OAAO,EAON,eAAe,GACf,CAAA","sourcesContent":["import { Kysely, Insertable, Updateable, Selectable } from 'kysely'\nimport { CacheTable } from './pieces_cache.schema.js'\nimport { PieceManagerTable } from './pieces_manager.schema.js'\nimport { PiecesItemsTable } from './pieces_items.schema.js'\n\nconst LuzzleTableName = {\n\tCache: 'pieces_cache',\n\tPieceManager: 'pieces_manager',\n\tPieceItems: 'pieces_items',\n} as const\n\ntype LuzzleTables = {\n\t[LuzzleTableName.Cache]: CacheTable\n\t[LuzzleTableName.PieceManager]: PieceManagerTable\n\t[LuzzleTableName.PieceItems]: PiecesItemsTable\n}\n\ntype LuzzleDatabase = Kysely<LuzzleTables>\ntype LuzzleTableNames = (typeof LuzzleTableName)[keyof typeof LuzzleTableName]\ntype LuzzleTable<T extends LuzzleTableNames> = LuzzleTables[T]\n\ntype LuzzleInsertable<T extends LuzzleTableNames> = Insertable<LuzzleTable<T>>\ntype LuzzleUpdatable<T extends LuzzleTableNames> = Updateable<LuzzleTable<T>>\ntype LuzzleSelectable<T extends LuzzleTableNames> = Selectable<LuzzleTable<T>>\n\nexport {\n\ttype LuzzleTables,\n\ttype LuzzleDatabase,\n\ttype LuzzleInsertable,\n\ttype LuzzleUpdatable,\n\ttype LuzzleSelectable,\n\ttype LuzzleTableNames,\n\tLuzzleTableName,\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/database/tables/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqD,MAAM,QAAQ,CAAA;AAK1E,MAAM,eAAe,GAAG;IACvB,KAAK,EAAE,cAAc;IACrB,YAAY,EAAE,gBAAgB;IAC9B,UAAU,EAAE,cAAc;CACjB,CAAA;AAgBV,OAAO,EAON,eAAe,GACf,CAAA","sourcesContent":["import type { Kysely} from 'kysely';\nimport { type Insertable, type Updateable, type Selectable } from 'kysely'\nimport type { CacheTable } from './pieces_cache.schema.js'\nimport type { PieceManagerTable } from './pieces_manager.schema.js'\nimport type { PiecesItemsTable } from './pieces_items.schema.js'\n\nconst LuzzleTableName = {\n\tCache: 'pieces_cache',\n\tPieceManager: 'pieces_manager',\n\tPieceItems: 'pieces_items',\n} as const\n\ntype LuzzleTables = {\n\t[LuzzleTableName.Cache]: CacheTable\n\t[LuzzleTableName.PieceManager]: PieceManagerTable\n\t[LuzzleTableName.PieceItems]: PiecesItemsTable\n}\n\ntype LuzzleDatabase = Kysely<LuzzleTables>\ntype LuzzleTableNames = (typeof LuzzleTableName)[keyof typeof LuzzleTableName]\ntype LuzzleTable<T extends LuzzleTableNames> = LuzzleTables[T]\n\ntype LuzzleInsertable<T extends LuzzleTableNames> = Insertable<LuzzleTable<T>>\ntype LuzzleUpdatable<T extends LuzzleTableNames> = Updateable<LuzzleTable<T>>\ntype LuzzleSelectable<T extends LuzzleTableNames> = Selectable<LuzzleTable<T>>\n\nexport {\n\ttype LuzzleTables,\n\ttype LuzzleDatabase,\n\ttype LuzzleInsertable,\n\ttype LuzzleUpdatable,\n\ttype LuzzleSelectable,\n\ttype LuzzleTableNames,\n\tLuzzleTableName,\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Insertable, Updateable, Selectable } from 'kysely';
2
- import { cuid, date_added, date_updated } from '../utils.js';
2
+ import type { cuid, date_added, date_updated } from '../utils.js';
3
3
  interface CacheTable {
4
4
  id: cuid;
5
5
  file_path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"pieces_cache.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_cache.schema.ts"],"names":[],"mappings":"","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport { cuid, date_added, date_updated } from '../utils.js'\n\ninterface CacheTable {\n\tid: cuid\n\tfile_path: string\n\tcontent_hash: string\n\tdate_added: date_added\n\tdate_updated: date_updated\n}\n\ntype CacheSelectable = Selectable<CacheTable>\ntype CacheInsert = Insertable<CacheTable>\ntype CacheUpdate = Updateable<CacheTable>\n\nexport { type CacheTable, type CacheSelectable, type CacheInsert, type CacheUpdate }\n"]}
1
+ {"version":3,"file":"pieces_cache.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_cache.schema.ts"],"names":[],"mappings":"AAeA,OAAO,EAA6E,CAAA","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport type { cuid, date_added, date_updated } from '../utils.js'\n\ninterface CacheTable {\n\tid: cuid\n\tfile_path: string\n\tcontent_hash: string\n\tdate_added: date_added\n\tdate_updated: date_updated\n}\n\ntype CacheSelectable = Selectable<CacheTable>\ntype CacheInsert = Insertable<CacheTable>\ntype CacheUpdate = Updateable<CacheTable>\n\nexport { type CacheTable, type CacheSelectable, type CacheInsert, type CacheUpdate }\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Insertable, Updateable, Selectable } from 'kysely';
2
- import { cuid, date_added, date_updated } from '../utils.js';
2
+ import type { cuid, date_added, date_updated } from '../utils.js';
3
3
  interface PiecesItemsTable {
4
4
  id: cuid;
5
5
  file_path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"pieces_items.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_items.schema.ts"],"names":[],"mappings":"","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport { cuid, date_added, date_updated } from '../utils.js'\n\ninterface PiecesItemsTable {\n\tid: cuid\n\tfile_path: string\n\ttype: string\n\tdate_added: date_added\n\tdate_updated: date_updated\n\tnote_markdown: string\n\tfrontmatter_json: string\n\tassets_json_array?: string\n}\n\ntype PiecesItemsSelectable = Selectable<PiecesItemsTable>\ntype PiecesItemsInsertable = Insertable<PiecesItemsTable>\ntype PiecesItemsUpdateable = Updateable<PiecesItemsTable>\n\nexport {\n\ttype PiecesItemsTable,\n\ttype PiecesItemsSelectable,\n\ttype PiecesItemsInsertable,\n\ttype PiecesItemsUpdateable,\n}\n"]}
1
+ {"version":3,"file":"pieces_items.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_items.schema.ts"],"names":[],"mappings":"AAkBA,OAAO,EAKN,CAAA","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport type { cuid, date_added, date_updated } from '../utils.js'\n\ninterface PiecesItemsTable {\n\tid: cuid\n\tfile_path: string\n\ttype: string\n\tdate_added: date_added\n\tdate_updated: date_updated\n\tnote_markdown: string\n\tfrontmatter_json: string\n\tassets_json_array?: string\n}\n\ntype PiecesItemsSelectable = Selectable<PiecesItemsTable>\ntype PiecesItemsInsertable = Insertable<PiecesItemsTable>\ntype PiecesItemsUpdateable = Updateable<PiecesItemsTable>\n\nexport {\n\ttype PiecesItemsTable,\n\ttype PiecesItemsSelectable,\n\ttype PiecesItemsInsertable,\n\ttype PiecesItemsUpdateable,\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Insertable, Updateable, Selectable } from 'kysely';
2
- import { cuid, date_added, date_updated } from '../utils.js';
2
+ import type { cuid, date_added, date_updated } from '../utils.js';
3
3
  interface PieceManagerTable {
4
4
  id: cuid;
5
5
  date_added: date_added;
@@ -1 +1 @@
1
- {"version":3,"file":"pieces_manager.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_manager.schema.ts"],"names":[],"mappings":"","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport { cuid, date_added, date_updated } from '../utils.js'\n\ninterface PieceManagerTable {\n\tid: cuid\n\tdate_added: date_added\n\tdate_updated?: date_updated\n\tname: string\n\tschema: string\n}\n\ntype PieceManagerSelect = Selectable<PieceManagerTable>\ntype PieceManagerInsert = Insertable<PieceManagerTable>\ntype PieceManagerUpdate = Updateable<PieceManagerTable>\n\nexport {\n\ttype PieceManagerTable,\n\ttype PieceManagerSelect,\n\ttype PieceManagerInsert,\n\ttype PieceManagerUpdate,\n}\n"]}
1
+ {"version":3,"file":"pieces_manager.schema.js","sourceRoot":"","sources":["../../../../src/database/tables/pieces_manager.schema.ts"],"names":[],"mappings":"AAeA,OAAO,EAKN,CAAA","sourcesContent":["import type { Insertable, Updateable, Selectable } from 'kysely'\nimport type { cuid, date_added, date_updated } from '../utils.js'\n\ninterface PieceManagerTable {\n\tid: cuid\n\tdate_added: date_added\n\tdate_updated?: date_updated\n\tname: string\n\tschema: string\n}\n\ntype PieceManagerSelect = Selectable<PieceManagerTable>\ntype PieceManagerInsert = Insertable<PieceManagerTable>\ntype PieceManagerUpdate = Updateable<PieceManagerTable>\n\nexport {\n\ttype PieceManagerTable,\n\ttype PieceManagerSelect,\n\ttype PieceManagerInsert,\n\ttype PieceManagerUpdate,\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { ColumnType } from 'kysely';
1
+ import type { ColumnType } from 'kysely';
2
2
  type cuid = string;
3
3
  type date_added = ColumnType<number, undefined, never>;
4
4
  type date_updated = ColumnType<number | null, undefined, number>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/database/utils.ts"],"names":[],"mappings":"","sourcesContent":["import { ColumnType } from 'kysely'\n\ntype cuid = string\ntype date_added = ColumnType<number, undefined, never>\ntype date_updated = ColumnType<number | null, undefined, number>\n\ntype SchemaDateStringToDatabaseNumber<T> = {\n\t[K in keyof T]: K extends `date_${string}` ? number : T[K] extends number ? string : T[K]\n}\n\nexport { type cuid, type date_updated, type date_added, type SchemaDateStringToDatabaseNumber }\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/database/utils.ts"],"names":[],"mappings":"AAUA,OAAO,EAAwF,CAAA","sourcesContent":["import type { ColumnType } from 'kysely'\n\ntype cuid = string\ntype date_added = ColumnType<number, undefined, never>\ntype date_updated = ColumnType<number | null, undefined, number>\n\ntype SchemaDateStringToDatabaseNumber<T> = {\n\t[K in keyof T]: K extends `date_${string}` ? number : T[K] extends number ? string : T[K]\n}\n\nexport { type cuid, type date_updated, type date_added, type SchemaDateStringToDatabaseNumber }\n"]}
@@ -1,4 +1,4 @@
1
- import { ValidateFunction, JSONSchemaType } from 'ajv';
1
+ import type { ValidateFunction, JSONSchemaType } from 'ajv';
2
2
  export declare function commaSeparatedFormatValidator(data: string): boolean;
3
3
  export declare function markdownFormatValidator(data: string): boolean;
4
4
  export declare function dateFormatValidator(data: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ajv.js","sourceRoot":"","sources":["../../../src/lib/ajv.ts"],"names":[],"mappings":"AAAA,OAAO,GAAyC,MAAM,KAAK,CAAA;AAE3D,MAAM,UAAU,6BAA6B,CAAC,IAAY;IACzD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAY;IACnD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACpD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,MAAM,CAAC,OAAO,WAAc,MAAyB;IACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IAErB,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,mBAAmB,EAAE,CAAC,CAAA;IACxE,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC,CAAA;IAC1E,GAAG,CAAC,SAAS,CAAC,iBAAiB,EAAE;QAChC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,6BAA6B;KACvC,CAAC,CAAA;IACF,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,wBAAwB,EAAE,CAAC,CAAA;IAClF,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,uBAAuB,EAAE,CAAC,CAAA;IAEhF,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC","sourcesContent":["import Ajv, { ValidateFunction, JSONSchemaType } from 'ajv'\n\nexport function commaSeparatedFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport function markdownFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport function dateFormatValidator(data: string) {\n\treturn !isNaN(Date.parse(data))\n}\n\nexport function assetFormatValidator(data: string) {\n\treturn /^\\.assets\\/.+\\/.+/.test(data)\n}\n\nexport function paragraphFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport default function <T>(schema: JSONSchemaType<T>): ValidateFunction<T> {\n\tconst ajv = new Ajv()\n\n\tajv.addFormat('date', { type: 'string', validate: dateFormatValidator })\n\tajv.addFormat('asset', { type: 'string', validate: assetFormatValidator })\n\tajv.addFormat('comma-separated', {\n\t\ttype: 'string',\n\t\tvalidate: commaSeparatedFormatValidator,\n\t})\n\tajv.addFormat('paragraph', { type: 'string', validate: paragraphFormatValidator })\n\tajv.addFormat('markdown', { type: 'string', validate: markdownFormatValidator })\n\n\treturn ajv.compile(schema)\n}\n"]}
1
+ {"version":3,"file":"ajv.js","sourceRoot":"","sources":["../../../src/lib/ajv.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,MAAM,UAA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ValidateFunction, JSONSchemaType } from 'ajv';\nimport Ajv from 'ajv'\n\nexport function commaSeparatedFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport function markdownFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport function dateFormatValidator(data: string) {\n\treturn !isNaN(Date.parse(data))\n}\n\nexport function assetFormatValidator(data: string) {\n\treturn /^\\.assets\\/.+\\/.+/.test(data)\n}\n\nexport function paragraphFormatValidator(data: string) {\n\treturn typeof data === 'string'\n}\n\nexport default function <T>(schema: JSONSchemaType<T>): ValidateFunction<T> {\n\tconst ajv = new Ajv()\n\n\tajv.addFormat('date', { type: 'string', validate: dateFormatValidator })\n\tajv.addFormat('asset', { type: 'string', validate: assetFormatValidator })\n\tajv.addFormat('comma-separated', {\n\t\ttype: 'string',\n\t\tvalidate: commaSeparatedFormatValidator,\n\t})\n\tajv.addFormat('paragraph', { type: 'string', validate: paragraphFormatValidator })\n\tajv.addFormat('markdown', { type: 'string', validate: markdownFormatValidator })\n\n\treturn ajv.compile(schema)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/lib/markdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,KAAK,UAAU,mBAAmB,CACjC,QAAyB;IAEzB,IAAI,WAAW,GAAG,EAAE,CAAA;IACpB,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAA;IAElC,MAAM,MAAM,EAAE;SACZ,GAAG,CAAC,iBAAiB,CAAC;SACtB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,IAAU,EAAE,EAAE;QACzB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,IAAI;YACjC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACpC,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAA;YAC7C,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAA;QAC9C,CAAC,CAAC,CAAA;IACH,CAAC,CAAC;SACD,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEnB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA;AACjC,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA","sourcesContent":["import { Root } from 'mdast';\nimport { remark } from 'remark'\nimport remarkFrontMatter from 'remark-frontmatter'\nimport { visit } from 'unist-util-visit'\nimport YAML from 'yaml'\n\nasync function extractFullMarkdown(\n\tcontents: string | Buffer\n): Promise<{ frontmatter: { [key: string]: unknown }; markdown: string }> {\n\tlet frontmatter = {}\n\tlet markdown = contents.toString()\n\n\tawait remark()\n\t\t.use(remarkFrontMatter)\n\t\t.use(() => (tree: Root) => {\n\t\t\tvisit(tree, 'yaml', function (node) {\n\t\t\t\tfrontmatter = YAML.parse(node.value)\n\t\t\t\tconst endPosition = node.position?.end.offset\n\t\t\t\tmarkdown = markdown.slice(endPosition).trim()\n\t\t\t})\n\t\t})\n\t\t.process(contents)\n\n\treturn { frontmatter, markdown }\n}\n\nexport { extractFullMarkdown }\n"]}
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/lib/markdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,KAAK,UAAU,mBAAmB,CACjC,QAAyB;IAEzB,IAAI,WAAW,GAAG,EAAE,CAAA;IACpB,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAA;IAElC,MAAM,MAAM,EAAE;SACZ,GAAG,CAAC,iBAAiB,CAAC;SACtB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,IAAU,EAAE,EAAE;QACzB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,IAAI;YACjC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACpC,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAA;YAC7C,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAA;QAC9C,CAAC,CAAC,CAAA;IACH,CAAC,CAAC;SACD,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEnB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA;AACjC,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA","sourcesContent":["import type { Root } from 'mdast';\nimport { remark } from 'remark'\nimport remarkFrontMatter from 'remark-frontmatter'\nimport { visit } from 'unist-util-visit'\nimport YAML from 'yaml'\n\nasync function extractFullMarkdown(\n\tcontents: string | Buffer\n): Promise<{ frontmatter: { [key: string]: unknown }; markdown: string }> {\n\tlet frontmatter = {}\n\tlet markdown = contents.toString()\n\n\tawait remark()\n\t\t.use(remarkFrontMatter)\n\t\t.use(() => (tree: Root) => {\n\t\t\tvisit(tree, 'yaml', function (node) {\n\t\t\t\tfrontmatter = YAML.parse(node.value)\n\t\t\t\tconst endPosition = node.position?.end.offset\n\t\t\t\tmarkdown = markdown.slice(endPosition).trim()\n\t\t\t})\n\t\t})\n\t\t.process(contents)\n\n\treturn { frontmatter, markdown }\n}\n\nexport { extractFullMarkdown }\n"]}
@@ -1,4 +1,4 @@
1
- import { JSONSchemaType } from 'ajv';
1
+ import type { JSONSchemaType } from 'ajv';
2
2
  import { type PieceFrontmatter } from '../pieces/index.js';
3
3
  declare function pieceFrontMatterFromPrompt(apiKey: string, schema: JSONSchemaType<PieceFrontmatter>, prompt: string, files?: Array<string | Buffer>): Promise<{
4
4
  [k: string]: import("../index.js").PieceFrontMatterValue;
@@ -1,8 +1,9 @@
1
1
  import { fileTypeFromBuffer } from 'file-type';
2
2
  import { fileTypeFromFile } from 'file-type/node';
3
- import { createPartFromUri, GoogleGenAI, HarmCategory, HarmBlockThreshold, } from '@google/genai';
3
+ import { createPartFromUri, GoogleGenAI, HarmCategory, HarmBlockThreshold } from '@google/genai';
4
4
  import { readFile } from 'fs/promises';
5
5
  import path from 'path';
6
+ import {} from '../pieces/index.js';
6
7
  const MODEL_NAME = 'gemini-2.5-flash';
7
8
  const safetySettings = [
8
9
  {
@@ -1 +1 @@
1
- {"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/llm/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAEN,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,kBAAkB,GAElB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,IAAI,MAAM,MAAM,CAAA;AAIvB,MAAM,UAAU,GAAG,kBAAkB,CAAA;AAErC,MAAM,cAAc,GAAoB;IACvC;QACC,QAAQ,EAAE,YAAY,CAAC,+BAA+B;QACtD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;IACD;QACC,QAAQ,EAAE,YAAY,CAAC,+BAA+B;QACtD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;IACD;QACC,QAAQ,EAAE,YAAY,CAAC,6BAA6B;QACpD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;CACD,CAAA;AAED,SAAS,SAAS,CAAC,MAAc;IAChC,OAAO,IAAI,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P,gBAAgB,EAAE,kBAAkB;YACpC,cAAc,EAAE,cAAc;YAC9B,kBAAkB,EAAE,MAAM;YAC1B,iBAAiB,EAAE;;;;mMAI6K;SAChM;KACD,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,CAAA;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAqB,CAAA;IAE5D,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,CACjF,CAAA;AACF,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAA","sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { fileTypeFromFile } from 'file-type/node'\nimport {\n\tContentListUnion,\n\tcreatePartFromUri,\n\tGoogleGenAI,\n\tHarmCategory,\n\tHarmBlockThreshold,\n\tSafetySetting,\n} from '@google/genai'\nimport { readFile } from 'fs/promises'\nimport path from 'path'\nimport { JSONSchemaType } from 'ajv'\nimport { type PieceFrontmatter } from '../pieces/index.js'\n\nconst MODEL_NAME = 'gemini-2.5-flash'\n\nconst safetySettings: SafetySetting[] = [\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n]\n\nfunction getClient(apiKey: string) {\n\treturn new GoogleGenAI({ apiKey })\n}\n\nasync function extractPartFromFile(file: string | Buffer, genAI: GoogleGenAI) {\n\tconst isBuffer = Buffer.isBuffer(file)\n\tconst fileType = isBuffer ? await fileTypeFromBuffer(file) : await fileTypeFromFile(file)\n\tconst mimeType = fileType?.mime\n\n\t// assume it's non binary\n\tif (!mimeType) {\n\t\tconst fileContent = isBuffer ? file.toString() : await readFile(file, 'utf-8')\n\t\tconst fileName = isBuffer ? 'string buffer of downloaded file' : path.basename(file)\n\t\tconst data = [\n\t\t\t`---[start] embedding ${fileName}---`,\n\t\t\tfileContent,\n\t\t\t`---[end] embedding of ${fileName}---`,\n\t\t]\n\n\t\treturn data.join('\\n')\n\t} else {\n\t\tconst uploadedFile = await genAI.files.upload({\n\t\t\tfile: isBuffer ? new Blob([file]) : file,\n\t\t\tconfig: {\n\t\t\t\tmimeType,\n\t\t\t},\n\t\t})\n\n\t\t// Wait for the file to be processed.\n\t\tlet getFile = await genAI.files.get({ name: uploadedFile.name as string })\n\n\t\twhile (getFile.state === 'PROCESSING') {\n\t\t\tgetFile = await genAI.files.get({ name: uploadedFile.name as string })\n\n\t\t\tawait new Promise((resolve) => {\n\t\t\t\tsetTimeout(resolve, 5000)\n\t\t\t})\n\t\t}\n\n\t\tif (uploadedFile.state === 'FAILED') {\n\t\t\tthrow new Error('File processing failed.')\n\t\t}\n\n\t\tif (uploadedFile.uri && uploadedFile.mimeType) {\n\t\t\tconst fileContent = createPartFromUri(uploadedFile.uri, uploadedFile.mimeType)\n\t\t\treturn fileContent\n\t\t}\n\t}\n\n\tthrow new Error('File processing failed.')\n}\n\nasync function pieceFrontMatterFromPrompt(\n\tapiKey: string,\n\tschema: JSONSchemaType<PieceFrontmatter>,\n\tprompt: string,\n\tfiles?: Array<string | Buffer>\n) {\n\tconst genAI = getClient(apiKey)\n\n\tconst content: ContentListUnion = [prompt]\n\n\tif (files) {\n\t\tfor (const file of files) {\n\t\t\tconst part = await extractPartFromFile(file, genAI)\n\t\t\tcontent.push(part)\n\t\t}\n\t}\n\n\tconst result = await genAI.models.generateContent({\n\t\tmodel: MODEL_NAME,\n\t\tcontents: content,\n\t\tconfig: {\n\t\t\tresponseMimeType: 'application/json',\n\t\t\tsafetySettings: safetySettings,\n\t\t\tresponseJsonSchema: schema,\n\t\t\tsystemInstruction: `you are an assistant that helps generate JSON metadata for a record that will be added to a collection of similar records. \n\nif you are provided pdf attachments, images or other text based files, please prioritize them as inputs for generating metadata for the record. \n\nyou are also given a responseJsonSchema to guide your output. each field in the schema has a description and examples to help guide what the intention of each field is and what values to expect.`,\n\t\t},\n\t})\n\n\tconst metadata = result.text || '{}'\n\tconst frontmatter = JSON.parse(metadata) as PieceFrontmatter\n\n\treturn Object.fromEntries(\n\t\tObject.entries(frontmatter).filter(([, value]) => value !== null || value === '')\n\t)\n}\n\nexport { pieceFrontMatterFromPrompt }\n"]}
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../../src/llm/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAIjD,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAyB,MAAM,oBAAoB,CAAA;AAE1D,MAAM,UAAU,GAAG,kBAAkB,CAAA;AAErC,MAAM,cAAc,GAAoB;IACvC;QACC,QAAQ,EAAE,YAAY,CAAC,+BAA+B;QACtD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;IACD;QACC,QAAQ,EAAE,YAAY,CAAC,+BAA+B;QACtD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;IACD;QACC,QAAQ,EAAE,YAAY,CAAC,6BAA6B;QACpD,SAAS,EAAE,kBAAkB,CAAC,UAAU;KACxC;CACD,CAAA;AAED,SAAS,SAAS,CA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,OAAO;QACjB,MAAM,EAAE;YACP,gBAAgB,EAAE,kBAAkB;YACpC,cAAc,EAAE,cAAc;YAC9B,kBAAkB,EAAE,MAAM;YAC1B,iBAAiB,EAAE;;;;mMAI6K;SAChM;KACD,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,CAAA;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAqB,CAAA;IAE5D,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,CACjF,CAAA;AACF,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAA","sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { fileTypeFromFile } from 'file-type/node'\nimport type {\n\tContentListUnion,\n\tSafetySetting} from '@google/genai';\nimport {\n\tcreatePartFromUri,\n\tGoogleGenAI,\n\tHarmCategory,\n\tHarmBlockThreshold\n} from '@google/genai'\nimport { readFile } from 'fs/promises'\nimport path from 'path'\nimport type { JSONSchemaType } from 'ajv'\nimport { type PieceFrontmatter } from '../pieces/index.js'\n\nconst MODEL_NAME = 'gemini-2.5-flash'\n\nconst safetySettings: SafetySetting[] = [\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n\t{\n\t\tcategory: HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY,\n\t\tthreshold: HarmBlockThreshold.BLOCK_NONE,\n\t},\n]\n\nfunction getClient(apiKey: string) {\n\treturn new GoogleGenAI({ apiKey })\n}\n\nasync function extractPartFromFile(file: string | Buffer, genAI: GoogleGenAI) {\n\tconst isBuffer = Buffer.isBuffer(file)\n\tconst fileType = isBuffer ? await fileTypeFromBuffer(file) : await fileTypeFromFile(file)\n\tconst mimeType = fileType?.mime\n\n\t// assume it's non binary\n\tif (!mimeType) {\n\t\tconst fileContent = isBuffer ? file.toString() : await readFile(file, 'utf-8')\n\t\tconst fileName = isBuffer ? 'string buffer of downloaded file' : path.basename(file)\n\t\tconst data = [\n\t\t\t`---[start] embedding ${fileName}---`,\n\t\t\tfileContent,\n\t\t\t`---[end] embedding of ${fileName}---`,\n\t\t]\n\n\t\treturn data.join('\\n')\n\t} else {\n\t\tconst uploadedFile = await genAI.files.upload({\n\t\t\tfile: isBuffer ? new Blob([file]) : file,\n\t\t\tconfig: {\n\t\t\t\tmimeType,\n\t\t\t},\n\t\t})\n\n\t\t// Wait for the file to be processed.\n\t\tlet getFile = await genAI.files.get({ name: uploadedFile.name as string })\n\n\t\twhile (getFile.state === 'PROCESSING') {\n\t\t\tgetFile = await genAI.files.get({ name: uploadedFile.name as string })\n\n\t\t\tawait new Promise((resolve) => {\n\t\t\t\tsetTimeout(resolve, 5000)\n\t\t\t})\n\t\t}\n\n\t\tif (uploadedFile.state === 'FAILED') {\n\t\t\tthrow new Error('File processing failed.')\n\t\t}\n\n\t\tif (uploadedFile.uri && uploadedFile.mimeType) {\n\t\t\tconst fileContent = createPartFromUri(uploadedFile.uri, uploadedFile.mimeType)\n\t\t\treturn fileContent\n\t\t}\n\t}\n\n\tthrow new Error('File processing failed.')\n}\n\nasync function pieceFrontMatterFromPrompt(\n\tapiKey: string,\n\tschema: JSONSchemaType<PieceFrontmatter>,\n\tprompt: string,\n\tfiles?: Array<string | Buffer>\n) {\n\tconst genAI = getClient(apiKey)\n\n\tconst content: ContentListUnion = [prompt]\n\n\tif (files) {\n\t\tfor (const file of files) {\n\t\t\tconst part = await extractPartFromFile(file, genAI)\n\t\t\tcontent.push(part)\n\t\t}\n\t}\n\n\tconst result = await genAI.models.generateContent({\n\t\tmodel: MODEL_NAME,\n\t\tcontents: content,\n\t\tconfig: {\n\t\t\tresponseMimeType: 'application/json',\n\t\t\tsafetySettings: safetySettings,\n\t\t\tresponseJsonSchema: schema,\n\t\t\tsystemInstruction: `you are an assistant that helps generate JSON metadata for a record that will be added to a collection of similar records. \n\nif you are provided pdf attachments, images or other text based files, please prioritize them as inputs for generating metadata for the record. \n\nyou are also given a responseJsonSchema to guide your output. each field in the schema has a description and examples to help guide what the intention of each field is and what values to expect.`,\n\t\t},\n\t})\n\n\tconst metadata = result.text || '{}'\n\tconst frontmatter = JSON.parse(metadata) as PieceFrontmatter\n\n\treturn Object.fromEntries(\n\t\tObject.entries(frontmatter).filter(([, value]) => value !== null || value === '')\n\t)\n}\n\nexport { pieceFrontMatterFromPrompt }\n"]}
@@ -1,8 +1,8 @@
1
1
  import { Readable } from 'stream';
2
- import { PieceFrontmatter, PieceFrontmatterSchema, PieceFrontmatterSchemaField, PieceFrontMatterValue } from './utils/frontmatter.js';
3
- import LuzzleStorage from '../storage/abstract.js';
4
- import { PieceMarkdown } from './utils/markdown.js';
5
- import { LuzzleDatabase, LuzzleSelectable } from '../database/tables/index.js';
2
+ import type { PieceFrontmatter, PieceFrontmatterSchema, PieceFrontmatterSchemaField, PieceFrontMatterValue } from './utils/frontmatter.js';
3
+ import type LuzzleStorage from '../storage/abstract.js';
4
+ import type { PieceMarkdown } from './utils/markdown.js';
5
+ import type { LuzzleDatabase, LuzzleSelectable } from '../database/tables/index.js';
6
6
  import compile from '../lib/ajv.js';
7
7
  export interface InterfacePiece<F extends PieceFrontmatter> {
8
8
  new (directory: string, pieceName: string, schemaOverride?: PieceFrontmatterSchema<F>): Piece<F>;
@@ -25,6 +25,19 @@ export type PieceSyncResult = {
25
25
  error: true;
26
26
  message: string;
27
27
  };
28
+ export type PieceDiffResult<F extends PieceFrontmatter> = {
29
+ action: 'added';
30
+ file: string;
31
+ markdown: PieceMarkdown<F>;
32
+ } | {
33
+ action: 'updated';
34
+ file: string;
35
+ markdown: PieceMarkdown<F>;
36
+ dbPiece: LuzzleSelectable<'pieces_items'>;
37
+ } | {
38
+ action: 'skipped';
39
+ file: string;
40
+ };
28
41
  declare class Piece<F extends PieceFrontmatter> {
29
42
  private _validator?;
30
43
  private _schema;
@@ -47,16 +60,22 @@ declare class Piece<F extends PieceFrontmatter> {
47
60
  };
48
61
  get(file: string): Promise<PieceMarkdown<F>>;
49
62
  write(markdown: PieceMarkdown<F>): Promise<void>;
50
- prune(db: LuzzleDatabase, files: string[], options?: {
51
- dryRun: boolean;
52
- }): Promise<Readable & AsyncIterable<PiecePruneResult>>;
63
+ private findPrunable;
64
+ diffPrune(db: LuzzleDatabase, files: string[]): Promise<string[]>;
65
+ prune(db: LuzzleDatabase, files: string[]): Promise<Readable & AsyncIterable<PiecePruneResult>>;
66
+ private getChange;
67
+ diffFile(db: LuzzleDatabase, file: string, options?: {
68
+ force?: boolean;
69
+ }): Promise<PieceDiffResult<F>>;
70
+ diff(db: LuzzleDatabase, files: string[], options?: {
71
+ force?: boolean;
72
+ }): Promise<Readable & AsyncIterable<PieceDiffResult<F>>>;
53
73
  sync(db: LuzzleDatabase, files: string[], options?: {
54
- dryRun?: boolean;
55
74
  force?: boolean;
56
75
  }): Promise<Readable & AsyncIterable<PieceSyncResult>>;
57
- syncMarkdownAdd(db: LuzzleDatabase, markdown: PieceMarkdown<F>): Promise<void>;
76
+ syncMarkdownAdd(db: LuzzleDatabase, markdown: PieceMarkdown<F>, hash?: string): Promise<void>;
58
77
  syncMarkdown(db: LuzzleDatabase, markdown: PieceMarkdown<F>): Promise<void>;
59
- syncMarkdownUpdate(db: LuzzleDatabase, markdown: PieceMarkdown<F>, data: LuzzleSelectable<'pieces_items'>): Promise<void>;
78
+ syncMarkdownUpdate(db: LuzzleDatabase, markdown: PieceMarkdown<F>, data: LuzzleSelectable<'pieces_items'>, hash?: string): Promise<void>;
60
79
  toMarkdown(data: LuzzleSelectable<'pieces_items'>): PieceMarkdown<F>;
61
80
  getField(markdown: PieceMarkdown<F>, fieldPath: string): PieceFrontMatterValue | undefined;
62
81
  setFields(markdown: PieceMarkdown<F>, fields: Record<string, unknown>): Promise<PieceMarkdown<F>>;
@@ -1,10 +1,10 @@
1
- import { ValidateFunction } from 'ajv';
2
- import { LuzzleSelectable } from '../database/tables/index.js';
3
- import { PieceFrontmatter, PieceFrontmatterSchema } from './utils/frontmatter.js';
4
- import { PieceMarkdown } from './utils/markdown.js';
5
- import LuzzleStorage from '../storage/abstract.js';
1
+ import type { ValidateFunction } from 'ajv';
2
+ import type { LuzzleSelectable } from '../database/tables/index.js';
3
+ import type { PieceFrontmatter, PieceFrontmatterSchema } from './utils/frontmatter.js';
4
+ import type { PieceMarkdown } from './utils/markdown.js';
5
+ import type LuzzleStorage from '../storage/abstract.js';
6
6
  import Piece from './Piece.js';
7
- import { PieceManagerSelect } from '../database/tables/pieces_manager.schema.js';
7
+ import type { PieceManagerSelect } from '../database/tables/pieces_manager.schema.js';
8
8
  export type PieceValidator = ValidateFunction<PieceFrontmatter>;
9
9
  export declare function makeValidator(): PieceValidator;
10
10
  export type MockSchemaProperty = {
@@ -1 +1 @@
1
- {"version":3,"file":"Piece.fixtures.js","sourceRoot":"","sources":["../../../src/pieces/Piece.fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAG3B,MAAM,MAAM,GAAG;IACd,aAAa,EAAE,YAAY;IAC3B,SAAS,EAAE,eAAe;IAC1B,EAAE,EAAE,UAAU;IACd,IAAI,EAAE,OAAO;IACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;IAChC,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;IAClC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;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IAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,CAAA;IAC3C,OAAO;QACN,EAAE,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE;QACzB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;QAChC,YAAY,EAAE,IAAI;QAClB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,UAAU,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,GAAG,IAAI;KACP,CAAA;AACF,CAAC","sourcesContent":["import { ValidateFunction } from 'ajv'\nimport { LuzzleSelectable } from '../database/tables/index.js'\nimport { PieceFrontmatter, PieceFrontmatterSchema } from './utils/frontmatter.js'\nimport { PieceMarkdown } from './utils/markdown.js'\nimport LuzzleStorage from '../storage/abstract.js'\nimport Piece from './Piece.js'\nimport { vi } from 'vitest'\nimport { PieceManagerSelect } from '../database/tables/pieces_manager.schema.js'\n\nconst sample = {\n\tnote_markdown: 'sampleNote',\n\tfile_path: 'samplePath.md',\n\tid: 'sampleId',\n\ttype: 'table',\n\tdate_added: new Date().getTime(),\n\tdate_updated: new Date().getTime(),\n\tfrontmatter_json: JSON.stringify({ title: 'sampleTitle' }),\n} as LuzzleSelectable<'pieces_items'>\n\nexport type PieceValidator = ValidateFunction<PieceFrontmatter>\n\nexport function makeValidator(): PieceValidator {\n\tconst validate = () => true\n\treturn validate as unknown as PieceValidator\n}\n\nexport type MockSchemaProperty = {\n\ttype?: string\n\tnullable?: boolean\n\titems?: MockSchemaProperty\n\tformat?: string\n\tpattern?: string\n\tenum?: string[] | number[]\n\tproperties?: Record<string, MockSchemaProperty>\n\trequired?: string[]\n\texamples?: unknown[]\n\tdefault?: unknown\n}\n\nexport function makeSchema(\n\tpropertiesOrName?: string | Record<string, MockSchemaProperty>\n): PieceFrontmatterSchema<PieceFrontmatter> {\n\tconst name = typeof propertiesOrName === 'string' ? propertiesOrName : 'table'\n\tconst properties = typeof propertiesOrName === 'object' ? propertiesOrName : {}\n\n\treturn {\n\t\ttype: 'object',\n\t\ttitle: name,\n\t\tproperties: {\n\t\t\ttitle: { type: 'string', examples: ['title'] },\n\t\t\tkeywords: { type: 'string', nullable: true, examples: ['keyword1'] },\n\t\t\tsubtitle: { type: 'string', nullable: true, examples: ['subtitle'] },\n\t\t\t...properties,\n\t\t},\n\t\trequired: ['title'],\n\t\tadditionalProperties: true,\n\t} as unknown as PieceFrontmatterSchema<PieceFrontmatter>\n}\n\nexport function makeStorage(root = 'root'): LuzzleStorage {\n\treturn {\n\t\troot,\n\t\ttype: 'fs',\n\t\tparseArgPath: vi.fn((p) => p),\n\t\treadFile: vi.fn(),\n\t\twriteFile: vi.fn(),\n\t\tgetFilesIn: vi.fn(),\n\t\texists: vi.fn(),\n\t\tdelete: vi.fn(),\n\t\tstat: vi.fn(),\n\t\tcreateReadStream: vi.fn(),\n\t\tcreateWriteStream: vi.fn(),\n\t\tmakeDirectory: vi.fn(),\n\t} as unknown as LuzzleStorage\n}\n\nexport function makeFrontmatterSample(\n\toverrides: Record<string, unknown> = {}\n): PieceFrontmatter {\n\treturn {\n\t\ttitle: 'sampleTitle',\n\t\t...overrides,\n\t}\n}\n\nexport function makeMarkdownSample<F extends PieceFrontmatter>(\n\tfilePathOrOptions: string | Partial<PieceMarkdown<F>> = 'samplePath.md',\n\tpiece = 'table',\n\tnote = 'sampleNote',\n\tfrontmatter?: F\n): PieceMarkdown<F> {\n\tif (typeof filePathOrOptions === 'object') {\n\t\treturn {\n\t\t\tfilePath: 'samplePath.md',\n\t\t\tpiece: 'table',\n\t\t\tnote: 'sampleNote',\n\t\t\tfrontmatter: makeFrontmatterSample() as F,\n\t\t\t...filePathOrOptions,\n\t\t}\n\t}\n\n\treturn {\n\t\tfilePath: filePathOrOptions,\n\t\tpiece,\n\t\tnote,\n\t\tfrontmatter: (frontmatter || makeFrontmatterSample()) as F,\n\t}\n}\n\nexport function makePieceItemSelectable(\n\toverrides?: Partial<LuzzleSelectable<'pieces_items'>>\n): LuzzleSelectable<'pieces_items'> {\n\treturn {\n\t\t...sample,\n\t\t...overrides,\n\t}\n}\n\nexport class PieceMock extends Piece<PieceFrontmatter> {\n\tconstructor(\n\t\tname: string = 'table',\n\t\tstorage: LuzzleStorage = makeStorage(),\n\t\tschema: PieceFrontmatterSchema<PieceFrontmatter> = makeSchema(name)\n\t) {\n\t\tsuper(name, storage, schema)\n\t}\n}\n\nexport function makePieceMock() {\n\treturn PieceMock\n}\n\nexport function makeRegisteredPiece(overrides?: Partial<PieceManagerSelect>) {\n\tconst { schema, ...rest } = overrides || {}\n\treturn {\n\t\tid: `id-${Math.random()}`,\n\t\tdate_added: new Date().getTime(),\n\t\tdate_updated: null,\n\t\tname: 'table',\n\t\tschema: makeSchema(typeof schema === 'string' ? schema : 'table'),\n\t\t...rest,\n\t}\n}\n"]}
1
+ {"version":3,"file":"Piece.fixtures.js","sourceRoot":"","sources":["../../../src/pieces/Piece.fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAG3B,MAAM,MAAM,GAAG;IACd,aAAa,EAAE,YAAY;IAC3B,SAAS,EAAE,eAAe;IAC1B,EAAE,EAAE,UAAU;IACd,IAAI,EAAE,OAAO;IACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;IAChC,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;IAClC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;CACtB,CAAA;AAIrC,MAAM,UAAU,aAAa;IAC5B,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAA;IAC3B,OAAO,QAAqC,CAAA;AAC7C,CAAC;AAeD,MAAM,UAAU,UAAU,CACzB,gB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AI,IAAI,EAAE,CAAC,OAAO,EAAE;QAChC,YAAY,EAAE,IAAI;QAClB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,UAAU,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,GAAG,IAAI;KACP,CAAA;AACF,CAAC","sourcesContent":["import type { ValidateFunction } from 'ajv'\nimport type { LuzzleSelectable } from '../database/tables/index.js'\nimport type { PieceFrontmatter, PieceFrontmatterSchema } from './utils/frontmatter.js'\nimport type { PieceMarkdown } from './utils/markdown.js'\nimport type LuzzleStorage from '../storage/abstract.js'\nimport Piece from './Piece.js'\nimport { vi } from 'vitest'\nimport type { PieceManagerSelect } from '../database/tables/pieces_manager.schema.js'\n\nconst sample = {\n\tnote_markdown: 'sampleNote',\n\tfile_path: 'samplePath.md',\n\tid: 'sampleId',\n\ttype: 'table',\n\tdate_added: new Date().getTime(),\n\tdate_updated: new Date().getTime(),\n\tfrontmatter_json: JSON.stringify({ title: 'sampleTitle' }),\n} as LuzzleSelectable<'pieces_items'>\n\nexport type PieceValidator = ValidateFunction<PieceFrontmatter>\n\nexport function makeValidator(): PieceValidator {\n\tconst validate = () => true\n\treturn validate as unknown as PieceValidator\n}\n\nexport type MockSchemaProperty = {\n\ttype?: string\n\tnullable?: boolean\n\titems?: MockSchemaProperty\n\tformat?: string\n\tpattern?: string\n\tenum?: string[] | number[]\n\tproperties?: Record<string, MockSchemaProperty>\n\trequired?: string[]\n\texamples?: unknown[]\n\tdefault?: unknown\n}\n\nexport function makeSchema(\n\tpropertiesOrName?: string | Record<string, MockSchemaProperty>\n): PieceFrontmatterSchema<PieceFrontmatter> {\n\tconst name = typeof propertiesOrName === 'string' ? propertiesOrName : 'table'\n\tconst properties = typeof propertiesOrName === 'object' ? propertiesOrName : {}\n\n\treturn {\n\t\ttype: 'object',\n\t\ttitle: name,\n\t\tproperties: {\n\t\t\ttitle: { type: 'string', examples: ['title'] },\n\t\t\tkeywords: { type: 'string', nullable: true, examples: ['keyword1'] },\n\t\t\tsubtitle: { type: 'string', nullable: true, examples: ['subtitle'] },\n\t\t\t...properties,\n\t\t},\n\t\trequired: ['title'],\n\t\tadditionalProperties: true,\n\t} as unknown as PieceFrontmatterSchema<PieceFrontmatter>\n}\n\nexport function makeStorage(root = 'root'): LuzzleStorage {\n\treturn {\n\t\troot,\n\t\ttype: 'fs',\n\t\tparseArgPath: vi.fn((p) => p),\n\t\treadFile: vi.fn(),\n\t\twriteFile: vi.fn(),\n\t\tgetFilesIn: vi.fn(),\n\t\texists: vi.fn(),\n\t\tdelete: vi.fn(),\n\t\tstat: vi.fn(),\n\t\tcreateReadStream: vi.fn(),\n\t\tcreateWriteStream: vi.fn(),\n\t\tmakeDirectory: vi.fn(),\n\t} as unknown as LuzzleStorage\n}\n\nexport function makeFrontmatterSample(\n\toverrides: Record<string, unknown> = {}\n): PieceFrontmatter {\n\treturn {\n\t\ttitle: 'sampleTitle',\n\t\t...overrides,\n\t}\n}\n\nexport function makeMarkdownSample<F extends PieceFrontmatter>(\n\tfilePathOrOptions: string | Partial<PieceMarkdown<F>> = 'samplePath.md',\n\tpiece = 'table',\n\tnote = 'sampleNote',\n\tfrontmatter?: F\n): PieceMarkdown<F> {\n\tif (typeof filePathOrOptions === 'object') {\n\t\treturn {\n\t\t\tfilePath: 'samplePath.md',\n\t\t\tpiece: 'table',\n\t\t\tnote: 'sampleNote',\n\t\t\tfrontmatter: makeFrontmatterSample() as F,\n\t\t\t...filePathOrOptions,\n\t\t}\n\t}\n\n\treturn {\n\t\tfilePath: filePathOrOptions,\n\t\tpiece,\n\t\tnote,\n\t\tfrontmatter: (frontmatter || makeFrontmatterSample()) as F,\n\t}\n}\n\nexport function makePieceItemSelectable(\n\toverrides?: Partial<LuzzleSelectable<'pieces_items'>>\n): LuzzleSelectable<'pieces_items'> {\n\treturn {\n\t\t...sample,\n\t\t...overrides,\n\t}\n}\n\nexport class PieceMock extends Piece<PieceFrontmatter> {\n\tconstructor(\n\t\tname: string = 'table',\n\t\tstorage: LuzzleStorage = makeStorage(),\n\t\tschema: PieceFrontmatterSchema<PieceFrontmatter> = makeSchema(name)\n\t) {\n\t\tsuper(name, storage, schema)\n\t}\n}\n\nexport function makePieceMock() {\n\treturn PieceMock\n}\n\nexport function makeRegisteredPiece(overrides?: Partial<PieceManagerSelect>) {\n\tconst { schema, ...rest } = overrides || {}\n\treturn {\n\t\tid: `id-${Math.random()}`,\n\t\tdate_added: new Date().getTime(),\n\t\tdate_updated: null,\n\t\tname: 'table',\n\t\tschema: makeSchema(typeof schema === 'string' ? schema : 'table'),\n\t\t...rest,\n\t}\n}\n"]}
@@ -3,7 +3,7 @@ import { cpus } from 'os';
3
3
  import path from 'path';
4
4
  import slugify from '@sindresorhus/slugify';
5
5
  import { Readable } from 'stream';
6
- import { databaseValueToPieceFrontmatterValue, getPieceFrontmatterSchemaFields, initializePieceFrontMatter, } from './utils/frontmatter.js';
6
+ import { databaseValueToPieceFrontmatterValue, getPieceFrontmatterSchemaFields, initializePieceFrontMatter } from './utils/frontmatter.js';
7
7
  import { findFrontmatterField, setFrontmatterValue, unsetFrontmatterValue, getFrontmatterValue, } from './utils/frontmatter.path.js';
8
8
  import { makePieceMarkdown, makePieceMarkdownString } from './utils/markdown.js';
9
9
  import { isAttachableStream, calculateHashFromFile, savePieceFieldAsset, makePieceValue, } from './utils/piece.js';
@@ -99,17 +99,22 @@ class Piece {
99
99
  throw new Error(`Could not write ${markdown.filePath} due to\n\n: ${validated.errors.join('\n')}`);
100
100
  }
101
101
  }
102
- async prune(db, files, options) {
102
+ async findPrunable(db, files) {
103
103
  const dbPieces = await selectItems(db, { type: this._pieceName });
104
104
  const diskPiecesSet = new Set(files);
105
- const missingPieces = dbPieces.filter((piece) => !diskPiecesSet.has(piece.file_path));
106
- const missingFiles = missingPieces.map((piece) => piece.file_path);
105
+ return dbPieces
106
+ .filter((piece) => !diskPiecesSet.has(piece.file_path))
107
+ .map((piece) => piece.file_path);
108
+ }
109
+ async diffPrune(db, files) {
110
+ return this.findPrunable(db, files);
111
+ }
112
+ async prune(db, files) {
113
+ const missingFiles = await this.findPrunable(db, files);
107
114
  const stream = Readable.from(missingFiles);
108
115
  return stream.map(async (file) => {
109
116
  try {
110
- if (!options?.dryRun) {
111
- await deleteItem(db, file);
112
- }
117
+ await deleteItem(db, file);
113
118
  return { action: 'pruned', file };
114
119
  }
115
120
  catch (error) {
@@ -117,45 +122,63 @@ class Piece {
117
122
  }
118
123
  }, { concurrency: cpus().length });
119
124
  }
125
+ async getChange(db, file, options) {
126
+ const outdated = await this.isOutdated(file, db);
127
+ if (!options?.force && !outdated) {
128
+ return { result: { action: 'skipped', file } };
129
+ }
130
+ const markdown = await this.get(file);
131
+ const dbPiece = await selectItem(db, markdown.filePath);
132
+ const readStream = this._storage.createReadStream(markdown.filePath);
133
+ const hash = await calculateHashFromFile(readStream);
134
+ if (!dbPiece) {
135
+ return { result: { action: 'added', file, markdown }, hash };
136
+ }
137
+ const cache = await getCache(db, markdown.filePath);
138
+ if (options?.force || cache?.content_hash !== hash) {
139
+ return { result: { action: 'updated', file, markdown, dbPiece }, hash };
140
+ }
141
+ return { result: { action: 'skipped', file }, hash };
142
+ }
143
+ async diffFile(db, file, options) {
144
+ return (await this.getChange(db, file, options)).result;
145
+ }
146
+ async diff(db, files, options) {
147
+ const stream = Readable.from(files);
148
+ return stream.map((file) => this.diffFile(db, file, options), {
149
+ concurrency: cpus().length,
150
+ });
151
+ }
120
152
  async sync(db, files, options) {
121
153
  const stream = Readable.from(files);
122
154
  return stream.map(async (file) => {
123
155
  try {
124
- const markdown = await this.get(file);
125
- const dbPiece = await selectItem(db, markdown.filePath);
126
- if (dbPiece) {
127
- const readStream = this._storage.createReadStream(markdown.filePath);
128
- const newHash = await calculateHashFromFile(readStream);
129
- const cache = await getCache(db, markdown.filePath);
130
- if (options?.force || cache?.content_hash !== newHash) {
131
- if (!options?.dryRun) {
132
- await this.syncMarkdownUpdate(db, markdown, dbPiece);
133
- }
134
- return { action: 'updated', file };
135
- }
136
- if (!options?.dryRun) {
137
- await updateCache(db, markdown.filePath, newHash);
138
- }
139
- return { action: 'skipped', file };
156
+ const { result, hash } = await this.getChange(db, file, options);
157
+ if (result.action === 'added') {
158
+ await this.syncMarkdownAdd(db, result.markdown, hash);
140
159
  }
141
- else {
142
- if (!options?.dryRun) {
143
- await this.syncMarkdownAdd(db, markdown);
144
- }
145
- return { action: 'added', file };
160
+ else if (result.action === 'updated') {
161
+ await this.syncMarkdownUpdate(db, result.markdown, result.dbPiece, hash);
162
+ }
163
+ else if (hash) {
164
+ await updateCache(db, file, hash);
146
165
  }
166
+ return { action: result.action, file };
147
167
  }
148
168
  catch (error) {
149
169
  return { file, error: true, message: `error syncing piece: ${error}` };
150
170
  }
151
171
  }, { concurrency: cpus().length });
152
172
  }
153
- async syncMarkdownAdd(db, markdown) {
173
+ async syncMarkdownAdd(db, markdown, hash) {
154
174
  const createInput = makePieceItemInsertable(this._pieceName, markdown, this._schema);
155
- const readStream = this._storage.createReadStream(markdown.filePath);
156
- const hash = await calculateHashFromFile(readStream);
175
+ let contentHash = hash;
176
+ if (contentHash === undefined) {
177
+ const readStream = this._storage.createReadStream(markdown.filePath);
178
+ contentHash = await calculateHashFromFile(readStream);
179
+ }
157
180
  await insertItem(db, createInput);
158
- await addCache(db, markdown.filePath, hash);
181
+ await addCache(db, markdown.filePath, contentHash);
159
182
  }
160
183
  async syncMarkdown(db, markdown) {
161
184
  const dbPiece = await selectItem(db, markdown.filePath);
@@ -166,12 +189,15 @@ class Piece {
166
189
  await this.syncMarkdownAdd(db, markdown);
167
190
  }
168
191
  }
169
- async syncMarkdownUpdate(db, markdown, data) {
192
+ async syncMarkdownUpdate(db, markdown, data, hash) {
170
193
  const updateInput = makePieceItemUpdatable(markdown, this._schema, data, false);
171
194
  await updateItem(db, markdown.filePath, updateInput);
172
- const readStream = this._storage.createReadStream(markdown.filePath);
173
- const hash = await calculateHashFromFile(readStream);
174
- await updateCache(db, data.file_path, hash);
195
+ let contentHash = hash;
196
+ if (contentHash === undefined) {
197
+ const readStream = this._storage.createReadStream(markdown.filePath);
198
+ contentHash = await calculateHashFromFile(readStream);
199
+ }
200
+ await updateCache(db, data.file_path, contentHash);
175
201
  }
176
202
  toMarkdown(data) {
177
203
  const frontmatter = JSON.parse(data.frontmatter_json);