yarlo-core 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,133 @@
1
+ PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to [Distribution
18
+ License](#distribution-license) and make changes or new works
19
+ based on the software according to [Changes and New Works
20
+ License](#changes-and-new-works-license).
21
+
22
+ ## Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by [Changes and New Works
28
+ License](#changes-and-new-works-license).
29
+
30
+ ## Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright Jordy Fontoura (https://github.com/jordyfontoura)
39
+
40
+ ## Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ ## Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ ## Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ ## Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ ## Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization, or
69
+ government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ ## Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ ## No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ ## Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ ## Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ ## No Liability
104
+
105
+ ***As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to anyone for any damages related to this software or this
108
+ license, under any kind of legal claim.***
109
+
110
+ ## Definitions
111
+
112
+ The **licensor** is the individual or entity offering these
113
+ terms, and the **software** is the software the licensor makes
114
+ available under these terms.
115
+
116
+ **You** refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ **Your company** is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. **Control**
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ **Your licenses** are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ **Use** means anything you do with the software requiring one
131
+ of your licenses.
132
+
133
+ Required Notice: Copyright (c) 2026 Jordy Fontoura (https://github.com/jordyfontoura)
@@ -0,0 +1,29 @@
1
+ import type { YarloConfig } from "yarlo-types";
2
+ /**
3
+ * Returns the published version of `yarlo-core` (used for config compatibility checks).
4
+ *
5
+ * @returns Semver string from this package's package.json
6
+ */
7
+ export declare function getYarloVersion(): string;
8
+ export interface CompatibilityResult {
9
+ compatible: boolean;
10
+ warning?: string;
11
+ }
12
+ /**
13
+ * Check if the current yarlo version is compatible with a config.
14
+ * - Same major = compatible
15
+ * - Current major > config major = compatible with migration warning
16
+ * - Current major < config major = incompatible (config was created by a newer yarlo)
17
+ */
18
+ export declare function checkCompatibility(configVersion: string, currentVersion: string): CompatibilityResult;
19
+ export declare function findConfigDir(from?: string): Promise<string | null>;
20
+ export declare function loadConfig(configDir?: string): Promise<{
21
+ config: YarloConfig;
22
+ configDir: string;
23
+ projectDir: string;
24
+ }>;
25
+ export declare function saveConfig(config: YarloConfig, configDir: string): Promise<void>;
26
+ export declare function getTasksDir(config: YarloConfig, configDir: string): string;
27
+ export declare function getAttachmentsDir(config: YarloConfig, configDir: string): string;
28
+ export declare function initProject(projectDir: string, config: YarloConfig): Promise<string>;
29
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../source/config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAKxC;AAcD,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB,mBAAmB,CAmBrB;AAED,wBAAsB,aAAa,CACjC,IAAI,GAAE,MAAsB,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBxB;AAED,wBAAsB,UAAU,CAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA4BzE;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,GAChB,MAAM,CAER;AAED,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CASjB"}
package/dist/config.js ADDED
@@ -0,0 +1,117 @@
1
+ import fs from "node:fs/promises";
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { parse, stringify } from "yaml";
6
+ const CONFIG_DIR = ".yarlo";
7
+ const CONFIG_FILE = "config.yml";
8
+ /**
9
+ * Returns the published version of `yarlo-core` (used for config compatibility checks).
10
+ *
11
+ * @returns Semver string from this package's package.json
12
+ */
13
+ export function getYarloVersion() {
14
+ const here = path.dirname(fileURLToPath(import.meta.url));
15
+ const pkgPath = path.join(here, "..", "package.json");
16
+ const raw = readFileSync(pkgPath, "utf-8");
17
+ return JSON.parse(raw).version;
18
+ }
19
+ /**
20
+ * Parse a semver string into [major, minor, patch].
21
+ */
22
+ function parseSemver(version) {
23
+ const parts = version.replace(/^v/, "").split(".");
24
+ return [
25
+ parseInt(parts[0] ?? "0", 10),
26
+ parseInt(parts[1] ?? "0", 10),
27
+ parseInt(parts[2] ?? "0", 10),
28
+ ];
29
+ }
30
+ /**
31
+ * Check if the current yarlo version is compatible with a config.
32
+ * - Same major = compatible
33
+ * - Current major > config major = compatible with migration warning
34
+ * - Current major < config major = incompatible (config was created by a newer yarlo)
35
+ */
36
+ export function checkCompatibility(configVersion, currentVersion) {
37
+ const [configMajor] = parseSemver(configVersion);
38
+ const [currentMajor] = parseSemver(currentVersion);
39
+ if (configMajor === currentMajor) {
40
+ return { compatible: true };
41
+ }
42
+ if (currentMajor > configMajor) {
43
+ return {
44
+ compatible: true,
45
+ warning: `This project was created with yarlo ${configVersion}. You are running ${currentVersion}. Run \`yarlo init\` to update the config if needed.`,
46
+ };
47
+ }
48
+ return {
49
+ compatible: false,
50
+ warning: `This project requires yarlo ${configVersion} or compatible. You are running ${currentVersion}. Please upgrade (e.g. \`npm i -g yarlo-cli\`).`,
51
+ };
52
+ }
53
+ export async function findConfigDir(from = process.cwd()) {
54
+ let current = from;
55
+ while (true) {
56
+ const candidate = path.join(current, CONFIG_DIR);
57
+ try {
58
+ const stat = await fs.stat(candidate);
59
+ if (stat.isDirectory()) {
60
+ return candidate;
61
+ }
62
+ }
63
+ catch {
64
+ // not found, go up
65
+ }
66
+ const parent = path.dirname(current);
67
+ if (parent === current)
68
+ return null;
69
+ current = parent;
70
+ }
71
+ }
72
+ export async function loadConfig(configDir) {
73
+ const dir = configDir ?? (await findConfigDir());
74
+ if (!dir) {
75
+ throw new Error("No .yarlo directory found. Run `yarlo init` to initialize.");
76
+ }
77
+ const configPath = path.join(dir, CONFIG_FILE);
78
+ const content = await fs.readFile(configPath, "utf-8");
79
+ const config = parse(content);
80
+ // Compatibility check
81
+ if (config.yarlo_version) {
82
+ const currentVersion = getYarloVersion();
83
+ const compat = checkCompatibility(config.yarlo_version, currentVersion);
84
+ if (!compat.compatible) {
85
+ throw new Error(compat.warning);
86
+ }
87
+ if (compat.warning) {
88
+ console.error(`Warning: ${compat.warning}`);
89
+ }
90
+ }
91
+ return {
92
+ config,
93
+ configDir: dir,
94
+ projectDir: path.dirname(dir),
95
+ };
96
+ }
97
+ export async function saveConfig(config, configDir) {
98
+ const configPath = path.join(configDir, CONFIG_FILE);
99
+ await fs.writeFile(configPath, stringify(config), "utf-8");
100
+ }
101
+ export function getTasksDir(config, configDir) {
102
+ return path.join(configDir, config.tasks_dir);
103
+ }
104
+ export function getAttachmentsDir(config, configDir) {
105
+ return path.join(configDir, config.attachments_dir);
106
+ }
107
+ export async function initProject(projectDir, config) {
108
+ const configDir = path.join(projectDir, CONFIG_DIR);
109
+ await fs.mkdir(configDir, { recursive: true });
110
+ await fs.mkdir(path.join(configDir, config.tasks_dir), { recursive: true });
111
+ await fs.mkdir(path.join(configDir, config.attachments_dir), {
112
+ recursive: true,
113
+ });
114
+ await saveConfig(config, configDir);
115
+ return configDir;
116
+ }
117
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../source/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGxC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3C,OAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC,OAAO,C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,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { FieldDefinition } from "yarlo-types";
2
+ export declare function validateFieldValue(field: FieldDefinition, value: unknown): {
3
+ valid: boolean;
4
+ error?: string;
5
+ };
6
+ export declare function applyDefaults(fields: Record<string, unknown>, definitions: FieldDefinition[]): Record<string, unknown>;
7
+ export declare function getFieldDefinition(name: string, definitions: FieldDefinition[]): FieldDefinition | undefined;
8
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../source/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,OAAO,GACb;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAwEpC;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,WAAW,EAAE,eAAe,EAAE,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,eAAe,EAAE,GAC7B,eAAe,GAAG,SAAS,CAE7B"}
package/dist/fields.js ADDED
@@ -0,0 +1,82 @@
1
+ export function validateFieldValue(field, value) {
2
+ if (value === undefined || value === null) {
3
+ if (field.required && field.default === undefined) {
4
+ return { valid: false, error: `Field "${field.name}" is required` };
5
+ }
6
+ return { valid: true };
7
+ }
8
+ switch (field.type) {
9
+ case "text":
10
+ case "url":
11
+ if (typeof value !== "string") {
12
+ return {
13
+ valid: false,
14
+ error: `Field "${field.name}" must be a string`,
15
+ };
16
+ }
17
+ break;
18
+ case "number":
19
+ if (typeof value !== "number") {
20
+ return {
21
+ valid: false,
22
+ error: `Field "${field.name}" must be a number`,
23
+ };
24
+ }
25
+ break;
26
+ case "boolean":
27
+ if (typeof value !== "boolean") {
28
+ return {
29
+ valid: false,
30
+ error: `Field "${field.name}" must be a boolean`,
31
+ };
32
+ }
33
+ break;
34
+ case "date":
35
+ if (typeof value !== "string" || isNaN(Date.parse(value))) {
36
+ return {
37
+ valid: false,
38
+ error: `Field "${field.name}" must be a valid date`,
39
+ };
40
+ }
41
+ break;
42
+ case "single_select":
43
+ if (field.options && !field.options.includes(String(value))) {
44
+ return {
45
+ valid: false,
46
+ error: `Field "${field.name}" must be one of: ${field.options.join(", ")}`,
47
+ };
48
+ }
49
+ break;
50
+ case "multi_select":
51
+ if (!Array.isArray(value)) {
52
+ return {
53
+ valid: false,
54
+ error: `Field "${field.name}" must be an array`,
55
+ };
56
+ }
57
+ if (field.options) {
58
+ const invalid = value.filter((v) => !field.options.includes(String(v)));
59
+ if (invalid.length > 0) {
60
+ return {
61
+ valid: false,
62
+ error: `Field "${field.name}" contains invalid values: ${invalid.join(", ")}. Valid: ${field.options.join(", ")}`,
63
+ };
64
+ }
65
+ }
66
+ break;
67
+ }
68
+ return { valid: true };
69
+ }
70
+ export function applyDefaults(fields, definitions) {
71
+ const result = { ...fields };
72
+ for (const def of definitions) {
73
+ if (result[def.name] === undefined && def.default !== undefined) {
74
+ result[def.name] = def.default;
75
+ }
76
+ }
77
+ return result;
78
+ }
79
+ export function getFieldDefinition(name, definitions) {
80
+ return definitions.find((d) => d.name === name);
81
+ }
82
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../source/fields.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAChC,KAAsB,EACtB,KAAc;IAEd,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1C,IAAI,KAAK,CAAC,QAAQ,IAAI,K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CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,WAA8B;IAE9B,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Programmatic API for yarlo: config, task CRUD, field validation, and ID naming.
3
+ */
4
+ export { findConfigDir, loadConfig, saveConfig, getTasksDir, getAttachmentsDir, initProject, getYarloVersion, checkCompatibility, } from "./config.js";
5
+ export type { CompatibilityResult } from "./config.js";
6
+ export { listTasks, getTask, createTask, updateTask, deleteTask, } from "./task.js";
7
+ export { validateFieldValue, applyDefaults, getFieldDefinition, } from "./fields.js";
8
+ export { generateSlug, generateUuid, generateIncremental, generateOrderedSlug, applyCustomPattern, generateTaskId, } from "./naming.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EACL,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Programmatic API for yarlo: config, task CRUD, field validation, and ID naming.
3
+ */
4
+ export { findConfigDir, loadConfig, saveConfig, getTasksDir, getAttachmentsDir, initProject, getYarloVersion, checkCompatibility, } from "./config.js";
5
+ export { listTasks, getTask, createTask, updateTask, deleteTask, } from "./task.js";
6
+ export { validateFieldValue, applyDefaults, getFieldDefinition, } from "./fields.js";
7
+ export { generateSlug, generateUuid, generateIncremental, generateOrderedSlug, applyCustomPattern, generateTaskId, } from "./naming.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EACV,UAAU,GACX,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NamingStrategy } from "yarlo-types";
2
+ export declare function generateSlug(title: string): string;
3
+ export declare function generateUuid(): string;
4
+ export declare function generateIncremental(tasksDir: string): Promise<string>;
5
+ export declare function generateOrderedSlug(title: string, tasksDir: string): Promise<string>;
6
+ export declare function applyCustomPattern(pattern: string, values: {
7
+ order: string;
8
+ slug: string;
9
+ uuid: string;
10
+ }): string;
11
+ export declare function generateTaskId(strategy: NamingStrategy, title: string, tasksDir: string, customPattern?: string): Promise<string>;
12
+ //# sourceMappingURL=naming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../source/naming.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAe3E;AAED,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpD,MAAM,CAKR;AAED,wBAAsB,cAAc,CAClC,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
package/dist/naming.js ADDED
@@ -0,0 +1,61 @@
1
+ import fs from "node:fs/promises";
2
+ import slugify from "slugify";
3
+ import { nanoid } from "nanoid";
4
+ export function generateSlug(title) {
5
+ return slugify(title, { lower: true, strict: true });
6
+ }
7
+ export function generateUuid() {
8
+ return nanoid(8);
9
+ }
10
+ export async function generateIncremental(tasksDir) {
11
+ let max = 0;
12
+ try {
13
+ const files = await fs.readdir(tasksDir);
14
+ for (const file of files) {
15
+ const match = file.match(/^(\d+)/);
16
+ if (match) {
17
+ const num = parseInt(match[1], 10);
18
+ if (num > max)
19
+ max = num;
20
+ }
21
+ }
22
+ }
23
+ catch {
24
+ // directory might not exist yet
25
+ }
26
+ return String(max + 1).padStart(3, "0");
27
+ }
28
+ export async function generateOrderedSlug(title, tasksDir) {
29
+ const id = await generateIncremental(tasksDir);
30
+ const slug = generateSlug(title);
31
+ return `${id}-${slug}`;
32
+ }
33
+ export function applyCustomPattern(pattern, values) {
34
+ return pattern
35
+ .replace("{order}", values.order)
36
+ .replace("{slug}", values.slug)
37
+ .replace("{uuid}", values.uuid);
38
+ }
39
+ export async function generateTaskId(strategy, title, tasksDir, customPattern) {
40
+ switch (strategy) {
41
+ case "slug":
42
+ return generateSlug(title);
43
+ case "uuid":
44
+ return generateUuid();
45
+ case "incremental":
46
+ return generateIncremental(tasksDir);
47
+ case "ordered-slug":
48
+ return generateOrderedSlug(title, tasksDir);
49
+ case "custom": {
50
+ const order = await generateIncremental(tasksDir);
51
+ const slug = generateSlug(title);
52
+ const uuid = generateUuid();
53
+ return applyCustomPattern(customPattern ?? "{order}-{slug}", {
54
+ order,
55
+ slug,
56
+ uuid,
57
+ });
58
+ }
59
+ }
60
+ }
61
+ //# sourceMappingURL=naming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming.js","sourceRoot":"","sources":["../source/naming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAgB;IACxD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACz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B,CAAC,QAAQ,CAAC,CAAC;QACvC,KAAK,cAAc;YACjB,OAAO,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC9C,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAC;YAClD,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YACjC,MAAM,IAAI,GAAG,YAAY,EAAE,CAAC;YAC5B,OAAO,kBAAkB,CAAC,aAAa,IAAI,gBAAgB,EAAE;gBAC3D,KAAK;gBACL,IAAI;gBACJ,IAAI;aACL,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/task.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { Task, CreateTaskInput, UpdateTaskInput, TaskFilter, YarloConfig } from "yarlo-types";
2
+ export declare function listTasks(config: YarloConfig, configDir: string, filter?: TaskFilter): Promise<Task[]>;
3
+ export declare function getTask(config: YarloConfig, configDir: string, id: string): Promise<Task>;
4
+ export declare function createTask(config: YarloConfig, configDir: string, input: CreateTaskInput): Promise<Task>;
5
+ export declare function updateTask(config: YarloConfig, configDir: string, id: string, input: UpdateTaskInput): Promise<Task>;
6
+ export declare function deleteTask(config: YarloConfig, configDir: string, id: string): Promise<Task>;
7
+ //# sourceMappingURL=task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../source/task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,eAAe,EACf,UAAU,EACV,WAAW,EACZ,MAAM,aAAa,CAAC;AAqCrB,wBAAsB,SAAS,CAC7B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,EAAE,CAAC,CAyCjB;AAED,wBAAsB,OAAO,CAC3B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC,CAIf"}
package/dist/task.js ADDED
@@ -0,0 +1,160 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import matter from "gray-matter";
4
+ import { getTasksDir } from "./config.js";
5
+ import { generateTaskId } from "./naming.js";
6
+ import { applyDefaults, validateFieldValue } from "./fields.js";
7
+ const META_KEYS = new Set(["id", "title", "created_at", "updated_at"]);
8
+ function parseTaskFile(filePath, raw) {
9
+ const { data, content } = matter(raw);
10
+ const fields = {};
11
+ for (const [key, value] of Object.entries(data)) {
12
+ if (!META_KEYS.has(key)) {
13
+ fields[key] = value;
14
+ }
15
+ }
16
+ return {
17
+ id: data.id,
18
+ title: data.title,
19
+ content: content.trim(),
20
+ fields,
21
+ created_at: data.created_at,
22
+ updated_at: data.updated_at,
23
+ file_path: filePath,
24
+ };
25
+ }
26
+ function serializeTask(task) {
27
+ const frontmatter = {
28
+ id: task.id,
29
+ title: task.title,
30
+ ...task.fields,
31
+ created_at: task.created_at,
32
+ updated_at: task.updated_at,
33
+ };
34
+ return matter.stringify(task.content ? `\n${task.content}\n` : "\n", frontmatter);
35
+ }
36
+ export async function listTasks(config, configDir, filter) {
37
+ const tasksDir = getTasksDir(config, configDir);
38
+ let files;
39
+ try {
40
+ files = await fs.readdir(tasksDir);
41
+ }
42
+ catch {
43
+ return [];
44
+ }
45
+ const tasks = [];
46
+ for (const file of files) {
47
+ if (!file.endsWith(".md"))
48
+ continue;
49
+ const filePath = path.join(tasksDir, file);
50
+ const raw = await fs.readFile(filePath, "utf-8");
51
+ tasks.push(parseTaskFile(filePath, raw));
52
+ }
53
+ if (!filter)
54
+ return tasks;
55
+ return tasks.filter((task) => {
56
+ if (filter.status && task.fields.status !== filter.status)
57
+ return false;
58
+ if (filter.priority && task.fields.priority !== filter.priority)
59
+ return false;
60
+ if (filter.assignee && task.fields.assignee !== filter.assignee)
61
+ return false;
62
+ if (filter.label) {
63
+ const labels = task.fields.labels;
64
+ if (!Array.isArray(labels) ||
65
+ !labels.includes(filter.label))
66
+ return false;
67
+ }
68
+ if (filter.search) {
69
+ const q = filter.search.toLowerCase();
70
+ const inTitle = task.title.toLowerCase().includes(q);
71
+ const inContent = task.content.toLowerCase().includes(q);
72
+ if (!inTitle && !inContent)
73
+ return false;
74
+ }
75
+ return true;
76
+ });
77
+ }
78
+ export async function getTask(config, configDir, id) {
79
+ const tasksDir = getTasksDir(config, configDir);
80
+ // Try exact match first
81
+ const exactPath = path.join(tasksDir, `${id}.md`);
82
+ try {
83
+ const raw = await fs.readFile(exactPath, "utf-8");
84
+ return parseTaskFile(exactPath, raw);
85
+ }
86
+ catch {
87
+ // Try prefix match
88
+ }
89
+ const files = await fs.readdir(tasksDir);
90
+ const matches = files.filter((f) => f.endsWith(".md") && f.startsWith(id));
91
+ if (matches.length === 0) {
92
+ throw new Error(`Task "${id}" not found`);
93
+ }
94
+ if (matches.length > 1) {
95
+ throw new Error(`Ambiguous ID "${id}". Matches: ${matches.map((f) => f.replace(".md", "")).join(", ")}`);
96
+ }
97
+ const filePath = path.join(tasksDir, matches[0]);
98
+ const raw = await fs.readFile(filePath, "utf-8");
99
+ return parseTaskFile(filePath, raw);
100
+ }
101
+ export async function createTask(config, configDir, input) {
102
+ const tasksDir = getTasksDir(config, configDir);
103
+ await fs.mkdir(tasksDir, { recursive: true });
104
+ const id = await generateTaskId(config.naming, input.title, tasksDir, config.naming_pattern);
105
+ const now = new Date().toISOString();
106
+ const fields = applyDefaults(input.fields ?? {}, config.fields);
107
+ // Validate fields
108
+ for (const def of config.fields) {
109
+ const result = validateFieldValue(def, fields[def.name]);
110
+ if (!result.valid) {
111
+ throw new Error(result.error);
112
+ }
113
+ }
114
+ const task = {
115
+ id,
116
+ title: input.title,
117
+ content: input.content ?? "",
118
+ fields,
119
+ created_at: now,
120
+ updated_at: now,
121
+ file_path: path.join(tasksDir, `${id}.md`),
122
+ };
123
+ await fs.writeFile(task.file_path, serializeTask(task), "utf-8");
124
+ return task;
125
+ }
126
+ export async function updateTask(config, configDir, id, input) {
127
+ const existing = await getTask(config, configDir, id);
128
+ const now = new Date().toISOString();
129
+ const updatedFields = {
130
+ ...existing.fields,
131
+ ...(input.fields ?? {}),
132
+ };
133
+ // Validate changed fields
134
+ if (input.fields) {
135
+ for (const [name, value] of Object.entries(input.fields)) {
136
+ const def = config.fields.find((f) => f.name === name);
137
+ if (def) {
138
+ const result = validateFieldValue(def, value);
139
+ if (!result.valid) {
140
+ throw new Error(result.error);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ const task = {
146
+ ...existing,
147
+ title: input.title ?? existing.title,
148
+ content: input.content ?? existing.content,
149
+ fields: updatedFields,
150
+ updated_at: now,
151
+ };
152
+ await fs.writeFile(task.file_path, serializeTask(task), "utf-8");
153
+ return task;
154
+ }
155
+ export async function deleteTask(config, configDir, id) {
156
+ const task = await getTask(config, configDir, id);
157
+ await fs.unlink(task.file_path);
158
+ return task;
159
+ }
160
+ //# sourceMappingURL=task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.js","sourceRoot":"","sources":["../source/task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,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d,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "yarlo-core",
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "description": "Yarlo task storage, config, and field validation (programmatic API)",
6
+ "license": "PolyForm-Noncommercial-1.0.0",
7
+ "author": "Jordy Fontoura <jordyfontoura@outlook.com> (https://github.com/jordyfontoura)",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/jordyfontoura/yarlo.git",
11
+ "directory": "packages/yarlo-core"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "gray-matter": "^4.0.3",
27
+ "nanoid": "^5.1.0",
28
+ "slugify": "^1.6.6",
29
+ "yaml": "^2.7.0",
30
+ "yarlo-types": "0.1.2"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.0.0",
34
+ "typescript": "^5.7.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "dev": "tsc --watch"
39
+ }
40
+ }