@luzzle/core 0.0.243 → 0.0.245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -43
- package/dist/src/database/client.d.ts +3 -2
- package/dist/src/database/client.js +4 -1
- package/dist/src/database/client.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/pieces/item.js +1 -1
- package/dist/src/pieces/item.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/vite.config.js +1 -0
- package/dist/vite.config.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
# @luzzle/core
|
|
1
|
+
# @luzzle/core
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Luzzle is a specification designed to solve the challenges of managing digital
|
|
6
|
-
records using plain text files instead of proprietary databases or spreadsheets.
|
|
7
|
-
`@luzzle/core` provides the tooling to define, parse, and validate these text
|
|
8
|
-
records ("pieces") and attachments so they can be easily queried, indexed, and
|
|
9
|
-
synced to a database.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Core Concepts 🏗️
|
|
14
|
-
|
|
15
|
-
### 1. Pieces & Schemas
|
|
16
|
-
|
|
17
|
-
The core of the Luzzle spec is the **Piece**: a standard Markdown file with
|
|
18
|
-
structured YAML frontmatter. `@luzzle/core` validates these pieces using
|
|
19
|
-
standard JSON schemas (typically defined in your archive under
|
|
20
|
-
`.luzzle/schemas/`). This gives you uniform, type-safe records without holding
|
|
21
|
-
your data hostage.
|
|
22
|
-
|
|
23
|
-
### 2. Assets & Attachments
|
|
24
|
-
|
|
25
|
-
A digital garden is not just text. `@luzzle/core` defines conventions for how
|
|
26
|
-
non-text media (like images or PDF attachments) are stored within the
|
|
27
|
-
`.assets/` directory and referenced in a piece's metadata.
|
|
28
|
-
|
|
29
|
-
### 3. File Naming Convention
|
|
30
|
-
|
|
31
|
-
To associate a piece with its schema, Luzzle relies on a specific file naming
|
|
32
|
-
convention: `name.[piece-type].md` (e.g., `dune.books.md`). This naming
|
|
33
|
-
convention solves the problem of quickly identifying a piece's type to map it
|
|
34
|
-
to the correct validator. _Note: This convention might be evolved or removed
|
|
35
|
-
in the future, but remains the current way piece types are discovered._
|
|
36
|
-
|
|
37
|
-
### 4. Simple Filesystem Backend
|
|
38
|
-
|
|
39
|
-
To adhere to the Unix philosophy, `@luzzle/core` **only** implements a simple
|
|
40
|
-
local filesystem backend. It reads Markdown files, validates frontmatter, and
|
|
41
|
-
updates a derivative SQLite index for query performance.
|
|
42
|
-
|
|
43
|
-
Upstream apps (such as `@luzzle/web` or custom deploy scripts) are responsible
|
|
44
|
-
for handling remote storage backends (like WebDAV or cloud storage syncing).
|
|
3
|
+
Archive parsing, validation and indexing. [Archive guide](../../docs/archive.md).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Kysely } from 'kysely';
|
|
2
|
-
import type { LuzzleTables } from './tables/index.js';
|
|
2
|
+
import type { LuzzleDatabase, LuzzleTables } from './tables/index.js';
|
|
3
3
|
declare function getDatabaseClient(pathToDb: string, debug?: boolean): Kysely<LuzzleTables>;
|
|
4
|
-
|
|
4
|
+
declare function asCoreDatabase<DB extends LuzzleTables>(db: Kysely<DB>): LuzzleDatabase;
|
|
5
|
+
export { getDatabaseClient, asCoreDatabase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/database/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,SAAS,iBAAiB,CAAC,QAAgB,EAAE,KAAK,GAAG,KAAK;IACzD,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAA;IACrC,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IACrC,EAAE,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IACvC,EAAE,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IAEtC,OAAO,IAAI,MAAM,CAAe;QAC/B,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QACpC,OAAO,EAAE,IAAI,iBAAiB,CAAC;YAC9B,QAAQ,EAAE,EAAE;SACZ,CAAC;KACF,CAAC,CAAA;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA","sourcesContent":["import { Kysely } from 'kysely'\nimport { NodeSqliteDialect } from './NodeSqliteDialect.js'\nimport { DatabaseSync } from 'node:sqlite'\nimport type { LuzzleTables } from './tables/index.js'\n\nfunction getDatabaseClient(pathToDb: string, debug = false) {\n\tconst db = new DatabaseSync(pathToDb)\n\tdb.exec('PRAGMA journal_mode = WAL;')\n\tdb.exec('PRAGMA synchronous = NORMAL;')\n\tdb.exec('PRAGMA busy_timeout = 5000;')\n\n\treturn new Kysely<LuzzleTables>({\n\t\tlog: debug ? ['query', 'error'] : [],\n\t\tdialect: new NodeSqliteDialect({\n\t\t\tdatabase: db,\n\t\t}),\n\t})\n}\n\nexport { getDatabaseClient }\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/database/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,SAAS,iBAAiB,CAAC,QAAgB,EAAE,KAAK,GAAG,KAAK;IACzD,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAA;IACrC,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IACrC,EAAE,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IACvC,EAAE,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IAEtC,OAAO,IAAI,MAAM,CAAe;QAC/B,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QACpC,OAAO,EAAE,IAAI,iBAAiB,CAAC;YAC9B,QAAQ,EAAE,EAAE;SACZ,CAAC;KACF,CAAC,CAAA;AACH,CAAC;AAED,SAAS,cAAc,CAA0B,EAAc;IAC9D,OAAO,EAA+B,CAAA;AACvC,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAA","sourcesContent":["import { Kysely } from 'kysely'\nimport { NodeSqliteDialect } from './NodeSqliteDialect.js'\nimport { DatabaseSync } from 'node:sqlite'\nimport type { LuzzleDatabase, LuzzleTables } from './tables/index.js'\n\nfunction getDatabaseClient(pathToDb: string, debug = false) {\n\tconst db = new DatabaseSync(pathToDb)\n\tdb.exec('PRAGMA journal_mode = WAL;')\n\tdb.exec('PRAGMA synchronous = NORMAL;')\n\tdb.exec('PRAGMA busy_timeout = 5000;')\n\n\treturn new Kysely<LuzzleTables>({\n\t\tlog: debug ? ['query', 'error'] : [],\n\t\tdialect: new NodeSqliteDialect({\n\t\t\tdatabase: db,\n\t\t}),\n\t})\n}\n\nfunction asCoreDatabase<DB extends LuzzleTables>(db: Kysely<DB>): LuzzleDatabase {\n\treturn db as unknown as LuzzleDatabase\n}\n\nexport { getDatabaseClient, asCoreDatabase }\n"]}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import compile from './lib/ajv.js';
|
|
|
3
3
|
import { sql } from 'kysely';
|
|
4
4
|
import { extractFullMarkdown } from './lib/markdown.js';
|
|
5
5
|
import { addFrontMatter } from './lib/frontmatter.js';
|
|
6
|
-
import { getDatabaseClient } from './database/client.js';
|
|
6
|
+
import { getDatabaseClient, asCoreDatabase } from './database/client.js';
|
|
7
7
|
import { filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset } from './pieces/index.js';
|
|
8
8
|
export * from './database/tables/index.js';
|
|
9
9
|
export * from './pieces/index.js';
|
|
10
10
|
export * from './llm/google/index.js';
|
|
11
11
|
export * from './storage/index.js';
|
|
12
12
|
export { mergeGeneratedFields, appendGeneratedBody } from './pieces/utils/generation.js';
|
|
13
|
-
export { getDatabaseClient, migrate, sql, compile, extractFullMarkdown, addFrontMatter, filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset, };
|
|
13
|
+
export { getDatabaseClient, asCoreDatabase, migrate, sql, compile, extractFullMarkdown, addFrontMatter, filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset, };
|
package/dist/src/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import compile from './lib/ajv.js';
|
|
|
3
3
|
import { sql } from 'kysely';
|
|
4
4
|
import { extractFullMarkdown } from './lib/markdown.js';
|
|
5
5
|
import { addFrontMatter } from './lib/frontmatter.js';
|
|
6
|
-
import { getDatabaseClient } from './database/client.js';
|
|
6
|
+
import { getDatabaseClient, asCoreDatabase } from './database/client.js';
|
|
7
7
|
import { filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset, } from './pieces/index.js';
|
|
8
8
|
export * from './database/tables/index.js';
|
|
9
9
|
export * from './pieces/index.js';
|
|
10
10
|
export * from './llm/google/index.js';
|
|
11
11
|
export * from './storage/index.js';
|
|
12
12
|
export { mergeGeneratedFields, appendGeneratedBody } from './pieces/utils/generation.js';
|
|
13
|
-
export { getDatabaseClient, migrate, sql, compile, extractFullMarkdown, addFrontMatter, filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset, };
|
|
13
|
+
export { getDatabaseClient, asCoreDatabase, migrate, sql, compile, extractFullMarkdown, addFrontMatter, filterFrontmatterFields, findFrontmatterField, getFrontmatterValue, getFrontmatterValues, resolveFieldPaths, setFrontmatterValue, unsetFrontmatterValue, savePieceAsset, };
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAA;AAC9C,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAA;AAC9C,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACN,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,GACd,MAAM,mBAAmB,CAAA;AAE1B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAExF,OAAO,EACN,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,GAAG,EACH,OAAO,EACP,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,GACd,CAAA","sourcesContent":["import migrate from './database/migrations.js'\nimport compile from './lib/ajv.js'\nimport { sql } from 'kysely'\nimport { extractFullMarkdown } from './lib/markdown.js'\nimport { addFrontMatter } from './lib/frontmatter.js'\nimport { getDatabaseClient, asCoreDatabase } from './database/client.js'\nimport {\n\tfilterFrontmatterFields,\n\tfindFrontmatterField,\n\tgetFrontmatterValue,\n\tgetFrontmatterValues,\n\tresolveFieldPaths,\n\tsetFrontmatterValue,\n\tunsetFrontmatterValue,\n\tsavePieceAsset,\n} from './pieces/index.js'\n\nexport * from './database/tables/index.js'\nexport * from './pieces/index.js'\nexport * from './llm/google/index.js'\nexport * from './storage/index.js'\nexport { mergeGeneratedFields, appendGeneratedBody } from './pieces/utils/generation.js'\n\nexport {\n\tgetDatabaseClient,\n\tasCoreDatabase,\n\tmigrate,\n\tsql,\n\tcompile,\n\textractFullMarkdown,\n\taddFrontMatter,\n\tfilterFrontmatterFields,\n\tfindFrontmatterField,\n\tgetFrontmatterValue,\n\tgetFrontmatterValues,\n\tresolveFieldPaths,\n\tsetFrontmatterValue,\n\tunsetFrontmatterValue,\n\tsavePieceAsset,\n}\n"]}
|
package/dist/src/pieces/item.js
CHANGED
|
@@ -73,7 +73,7 @@ function makePieceItemUpdatable(markdown, schema, data, force = false) {
|
|
|
73
73
|
update.file_path = markdown.filePath;
|
|
74
74
|
}
|
|
75
75
|
if (force || data.assets_json_array !== assetString) {
|
|
76
|
-
update.assets_json_array = assetString
|
|
76
|
+
update.assets_json_array = assetString;
|
|
77
77
|
}
|
|
78
78
|
return update;
|
|
79
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item.js","sourceRoot":"","sources":["../../../src/pieces/item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAO/C,OAAO,EAEN,oCAAoC,EACpC,+BAA+B,GAG/B,MAAM,wBAAwB,CAAA;AAG/B;;GAEG;AACH,SAAS,aAAa,CAAC,KAAc,EAAE,QAAkC,EAAE,MAAgB;IAC1F,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC3C,OAAM;IACP,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,KAAkB,CAAA;QACjC,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YACvC,MAAM,CAAC,IAAI,CAAC,GAAI,MAAmB,CAAC,CAAA;QACrC,CAAC;aAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAChF,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CACpB,aAAa,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CACxC,CAAA;QACF,CAAC;IACF,CAAC;SAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,KAAgC,CAAA;QAC5C,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;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;AACd,CAAC;AAED,SAAS,iBAAiB,CACzB,QAA0B,EAC1B,SAA8B;IAE9B,IAAI,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACrC,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC;AAED,SAAS,0BAA0B,CAA6B,SAA8B;IAC7F,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAA;IACrC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;AAC7D,CAAC;AAED,OAAO,EACN,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,GAC1B,CAAA","sourcesContent":["import { createId } from '@paralleldrive/cuid2'\nimport type {\n\tPiecesItemsSelectable,\n\tPiecesItemsInsertable,\n\tPiecesItemsUpdateable,\n} from '../database/tables/pieces_items.schema.js'\nimport type { PieceMarkdown } from './utils/markdown.js'\nimport {\n\ttype PieceFrontmatter,\n\tpieceFrontmatterValueToDatabaseValue,\n\tgetPieceFrontmatterSchemaFields,\n\ttype PieceFrontmatterSchema,\n\ttype PieceFrontmatterProperty,\n} from './utils/frontmatter.js'\nimport type { ValidateFunction } from 'ajv'\n\n/**\n * Recursively collects asset paths from frontmatter values based on schema property definitions.\n */\nfunction collectAssets(value: unknown, property: PieceFrontmatterProperty, assets: string[]) {\n\tif (value === undefined || value === null) {\n\t\treturn\n\t}\n\n\tif (property.type === 'array') {\n\t\tconst values = value as unknown[]\n\t\tif (property.items.format === 'asset') {\n\t\t\tassets.push(...(values as string[]))\n\t\t} else if (property.items.type === 'array' || property.items.type === 'object') {\n\t\t\tvalues.forEach((v) =>\n\t\t\t\tcollectAssets(v, property.items, assets)\n\t\t\t)\n\t\t}\n\t} else if (property.type === 'object') {\n\t\tconst obj = value as Record<string, unknown>\n\t\tfor (const key in property.properties) {\n\t\t\tcollectAssets(\n\t\t\t\tobj[key],\n\t\t\t\tproperty.properties[key],\n\t\t\t\tassets\n\t\t\t)\n\t\t}\n\t} else if (property.format === 'asset') {\n\t\tassets.push(value as string)\n\t}\n}\n\nfunction makePieceItemInsertable<F extends PieceFrontmatter>(\n\tpiece: string,\n\tmarkdown: PieceMarkdown<F>,\n\tschema: PieceFrontmatterSchema<F>\n): PiecesItemsInsertable {\n\tconst frontmatterJson = {} as Record<string, unknown>\n\tconst fields = getPieceFrontmatterSchemaFields(schema)\n\tconst assets: string[] = []\n\n\tfields.forEach((field) => {\n\t\tconst name = field.name\n\t\tconst value = markdown.frontmatter[name]\n\t\tconst jsonValue = pieceFrontmatterValueToDatabaseValue(value, field)\n\n\t\tcollectAssets(value, field, assets)\n\n\t\tfrontmatterJson[name] = jsonValue\n\t})\n\n\tconst insertable: PiecesItemsInsertable = {\n\t\tid: createId(),\n\t\tfile_path: markdown.filePath,\n\t\tnote_markdown: markdown.note as string,\n\t\tfrontmatter_json: JSON.stringify(frontmatterJson),\n\t\ttype: piece,\n\t}\n\n\tif (assets.length) {\n\t\tinsertable.assets_json_array = JSON.stringify(assets)\n\t}\n\n\treturn insertable\n}\n\nfunction makePieceItemUpdatable<F extends PieceFrontmatter>(\n\tmarkdown: PieceMarkdown<F>,\n\tschema: PieceFrontmatterSchema<F>,\n\tdata: PiecesItemsSelectable,\n\tforce = false\n): PiecesItemsUpdateable {\n\tconst frontmatter = {} as Record<string, unknown>\n\tconst fields = getPieceFrontmatterSchemaFields(schema)\n\tconst update: PiecesItemsUpdateable = { date_updated: new Date().getTime() }\n\tconst assets: string[] = []\n\n\tfields.forEach((field) => {\n\t\tconst name = field.name\n\t\tconst value = (markdown.frontmatter as Record<string, unknown>)[name]\n\t\tconst updateValue = pieceFrontmatterValueToDatabaseValue(value, field)\n\n\t\tcollectAssets(value, field, assets)\n\n\t\tfrontmatter[name] = updateValue\n\t})\n\n\tconst frontmatterJson = JSON.stringify(frontmatter)\n\tconst assetString = JSON.stringify(assets)\n\n\tif (force || frontmatterJson !== data.frontmatter_json) {\n\t\tupdate.frontmatter_json = frontmatterJson\n\t}\n\n\tif (force || markdown.note !== data.note_markdown) {\n\t\tupdate.note_markdown = markdown.note as string\n\t}\n\n\tif (force || markdown.filePath !== data.file_path) {\n\t\tupdate.file_path = markdown.filePath\n\t}\n\n\tif (force || data.assets_json_array !== assetString) {\n\t\tupdate.assets_json_array = assetString\n\t}\n\n\treturn update\n}\n\nfunction validatePieceItem<F extends PieceFrontmatter>(\n\tmarkdown: PieceMarkdown<F>,\n\tvalidator: ValidateFunction<F>\n) {\n\tif (validator(markdown.frontmatter)) {\n\t\treturn true\n\t}\n\n\treturn false\n}\n\nfunction getValidatePieceItemErrors<F extends PieceFrontmatter>(validator: ValidateFunction<F>) {\n\tconst errors = validator.errors || []\n\treturn errors.map((e) => `\\t${e.instancePath} ${e.message}`)\n}\n\nexport {\n\tmakePieceItemInsertable,\n\tmakePieceItemUpdatable,\n\tvalidatePieceItem,\n\tgetValidatePieceItemErrors,\n}\n"]}
|