@real1ty-obsidian-plugins/utils 1.2.0 → 1.2.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/dist/async-utils.d.ts +69 -0
- package/dist/async-utils.d.ts.map +1 -0
- package/dist/async-utils.js +108 -0
- package/dist/async-utils.js.map +1 -0
- package/dist/batch-operations.d.ts +11 -0
- package/dist/batch-operations.d.ts.map +1 -0
- package/dist/batch-operations.js +31 -0
- package/dist/batch-operations.js.map +1 -0
- package/dist/child-reference-utils.d.ts +9 -0
- package/dist/child-reference-utils.d.ts.map +1 -0
- package/dist/child-reference-utils.js +57 -0
- package/dist/child-reference-utils.js.map +1 -0
- package/dist/date-recurrence-utils.d.ts +30 -0
- package/dist/date-recurrence-utils.d.ts.map +1 -0
- package/dist/date-recurrence-utils.js +167 -0
- package/dist/date-recurrence-utils.js.map +1 -0
- package/dist/date-utils.d.ts +21 -0
- package/dist/date-utils.d.ts.map +1 -0
- package/dist/date-utils.js +105 -0
- package/dist/date-utils.js.map +1 -0
- package/dist/evaluator-base.d.ts +52 -0
- package/dist/evaluator-base.d.ts.map +1 -0
- package/dist/evaluator-base.js +84 -0
- package/dist/evaluator-base.js.map +1 -0
- package/dist/file-operations.d.ts +31 -0
- package/dist/file-operations.d.ts.map +1 -0
- package/dist/file-operations.js +160 -0
- package/dist/file-operations.js.map +1 -0
- package/dist/file-utils.d.ts +6 -0
- package/dist/file-utils.d.ts.map +1 -0
- package/dist/file-utils.js +25 -0
- package/dist/file-utils.js.map +1 -0
- package/dist/generate.d.ts +7 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +13 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/link-parser.d.ts +9 -0
- package/dist/link-parser.d.ts.map +1 -0
- package/dist/link-parser.js +19 -0
- package/dist/link-parser.js.map +1 -0
- package/dist/settings-store.d.ts +19 -0
- package/dist/settings-store.d.ts.map +1 -0
- package/dist/settings-store.js +79 -0
- package/dist/settings-store.js.map +1 -0
- package/dist/string-utils.d.ts +5 -0
- package/dist/string-utils.d.ts.map +1 -0
- package/dist/string-utils.js +25 -0
- package/dist/string-utils.js.map +1 -0
- package/dist/templater-utils.d.ts +4 -0
- package/dist/templater-utils.d.ts.map +1 -0
- package/dist/templater-utils.js +51 -0
- package/dist/templater-utils.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mocks/obsidian.d.ts +149 -0
- package/dist/testing/mocks/obsidian.d.ts.map +1 -0
- package/dist/testing/mocks/obsidian.js +220 -0
- package/dist/testing/mocks/obsidian.js.map +1 -0
- package/dist/testing/mocks/utils.d.ts +14 -0
- package/dist/testing/mocks/utils.d.ts.map +1 -0
- package/dist/testing/mocks/utils.js +85 -0
- package/dist/testing/mocks/utils.js.map +1 -0
- package/dist/testing/setup.d.ts +2 -0
- package/dist/testing/setup.d.ts.map +1 -0
- package/dist/testing/setup.js +18 -0
- package/dist/testing/setup.js.map +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that ensures an async operation runs only once,
|
|
3
|
+
* returning the same promise for concurrent calls.
|
|
4
|
+
*
|
|
5
|
+
* Useful for initialization patterns where you want to ensure
|
|
6
|
+
* expensive async operations (like indexing, API calls, etc.)
|
|
7
|
+
* only happen once even if called multiple times.
|
|
8
|
+
*
|
|
9
|
+
* @param fn The async function to memoize
|
|
10
|
+
* @returns A function that returns the same promise on subsequent calls
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const initializeOnce = onceAsync(async () => {
|
|
15
|
+
* await heavyInitialization();
|
|
16
|
+
* console.log("Initialized!");
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // All these calls will share the same promise
|
|
20
|
+
* await initializeOnce();
|
|
21
|
+
* await initializeOnce(); // Won't run again
|
|
22
|
+
* await initializeOnce(); // Won't run again
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function onceAsync<T>(fn: () => Promise<T>): () => Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a function that ensures an async operation runs only once per key,
|
|
28
|
+
* useful for caching expensive operations with different parameters.
|
|
29
|
+
*
|
|
30
|
+
* @param fn The async function to memoize
|
|
31
|
+
* @returns A function that memoizes results by key
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const fetchUserOnce = onceAsyncKeyed(async (userId: string) => {
|
|
36
|
+
* return await api.getUser(userId);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Each unique userId will only be fetched once
|
|
40
|
+
* await fetchUserOnce("user1");
|
|
41
|
+
* await fetchUserOnce("user1"); // Returns cached promise
|
|
42
|
+
* await fetchUserOnce("user2"); // New fetch for different key
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function onceAsyncKeyed<TArgs extends readonly unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>): (...args: TArgs) => Promise<TReturn>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a resettable version of onceAsync that can be cleared and re-run.
|
|
48
|
+
*
|
|
49
|
+
* @param fn The async function to memoize
|
|
50
|
+
* @returns Object with execute and reset methods
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const { execute: initialize, reset } = onceAsyncResettable(async () => {
|
|
55
|
+
* await heavyInitialization();
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* await initialize(); // Runs
|
|
59
|
+
* await initialize(); // Cached
|
|
60
|
+
*
|
|
61
|
+
* reset(); // Clear cache
|
|
62
|
+
* await initialize(); // Runs again
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function onceAsyncResettable<T>(fn: () => Promise<T>): {
|
|
66
|
+
execute: () => Promise<T>;
|
|
67
|
+
reset: () => void;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=async-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-utils.d.ts","sourceRoot":"","sources":["../src/async-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,CAcnE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EAAE,OAAO,EACvE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,GACtC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAYtC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG;IAC7D,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CAClB,CAmBA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that ensures an async operation runs only once,
|
|
3
|
+
* returning the same promise for concurrent calls.
|
|
4
|
+
*
|
|
5
|
+
* Useful for initialization patterns where you want to ensure
|
|
6
|
+
* expensive async operations (like indexing, API calls, etc.)
|
|
7
|
+
* only happen once even if called multiple times.
|
|
8
|
+
*
|
|
9
|
+
* @param fn The async function to memoize
|
|
10
|
+
* @returns A function that returns the same promise on subsequent calls
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const initializeOnce = onceAsync(async () => {
|
|
15
|
+
* await heavyInitialization();
|
|
16
|
+
* console.log("Initialized!");
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // All these calls will share the same promise
|
|
20
|
+
* await initializeOnce();
|
|
21
|
+
* await initializeOnce(); // Won't run again
|
|
22
|
+
* await initializeOnce(); // Won't run again
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function onceAsync(fn) {
|
|
26
|
+
let promise = null;
|
|
27
|
+
return () => {
|
|
28
|
+
if (!promise) {
|
|
29
|
+
try {
|
|
30
|
+
promise = fn();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// Convert synchronous errors to rejected promises
|
|
34
|
+
promise = Promise.reject(error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return promise;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a function that ensures an async operation runs only once per key,
|
|
42
|
+
* useful for caching expensive operations with different parameters.
|
|
43
|
+
*
|
|
44
|
+
* @param fn The async function to memoize
|
|
45
|
+
* @returns A function that memoizes results by key
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const fetchUserOnce = onceAsyncKeyed(async (userId: string) => {
|
|
50
|
+
* return await api.getUser(userId);
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Each unique userId will only be fetched once
|
|
54
|
+
* await fetchUserOnce("user1");
|
|
55
|
+
* await fetchUserOnce("user1"); // Returns cached promise
|
|
56
|
+
* await fetchUserOnce("user2"); // New fetch for different key
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function onceAsyncKeyed(fn) {
|
|
60
|
+
const cache = new Map();
|
|
61
|
+
return (...args) => {
|
|
62
|
+
const key = JSON.stringify(args);
|
|
63
|
+
if (!cache.has(key)) {
|
|
64
|
+
cache.set(key, fn(...args));
|
|
65
|
+
}
|
|
66
|
+
return cache.get(key);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a resettable version of onceAsync that can be cleared and re-run.
|
|
71
|
+
*
|
|
72
|
+
* @param fn The async function to memoize
|
|
73
|
+
* @returns Object with execute and reset methods
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const { execute: initialize, reset } = onceAsyncResettable(async () => {
|
|
78
|
+
* await heavyInitialization();
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* await initialize(); // Runs
|
|
82
|
+
* await initialize(); // Cached
|
|
83
|
+
*
|
|
84
|
+
* reset(); // Clear cache
|
|
85
|
+
* await initialize(); // Runs again
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export function onceAsyncResettable(fn) {
|
|
89
|
+
let promise = null;
|
|
90
|
+
return {
|
|
91
|
+
execute: () => {
|
|
92
|
+
if (!promise) {
|
|
93
|
+
try {
|
|
94
|
+
promise = fn();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// Convert synchronous errors to rejected promises
|
|
98
|
+
promise = Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return promise;
|
|
102
|
+
},
|
|
103
|
+
reset: () => {
|
|
104
|
+
promise = null;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=async-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-utils.js","sourceRoot":"","sources":["../src/async-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,SAAS,CAAI,EAAoB;IAChD,IAAI,OAAO,GAAsB,IAAI,CAAC;IAEtC,OAAO,GAAG,EAAE;QACX,IAAI,CAAC,OAA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,CAAC;AACH,CAAC","sourcesContent":["/**\n * Creates a function that ensures an async operation runs only once,\n * returning the same promise for concurrent calls.\n *\n * Useful for initialization patterns where you want to ensure\n * expensive async operations (like indexing, API calls, etc.)\n * only happen once even if called multiple times.\n *\n * @param fn The async function to memoize\n * @returns A function that returns the same promise on subsequent calls\n *\n * @example\n * ```typescript\n * const initializeOnce = onceAsync(async () => {\n * await heavyInitialization();\n * console.log(\"Initialized!\");\n * });\n *\n * // All these calls will share the same promise\n * await initializeOnce();\n * await initializeOnce(); // Won't run again\n * await initializeOnce(); // Won't run again\n * ```\n */\nexport function onceAsync<T>(fn: () => Promise<T>): () => Promise<T> {\n\tlet promise: Promise<T> | null = null;\n\n\treturn () => {\n\t\tif (!promise) {\n\t\t\ttry {\n\t\t\t\tpromise = fn();\n\t\t\t} catch (error) {\n\t\t\t\t// Convert synchronous errors to rejected promises\n\t\t\t\tpromise = Promise.reject(error);\n\t\t\t}\n\t\t}\n\t\treturn promise;\n\t};\n}\n\n/**\n * Creates a function that ensures an async operation runs only once per key,\n * useful for caching expensive operations with different parameters.\n *\n * @param fn The async function to memoize\n * @returns A function that memoizes results by key\n *\n * @example\n * ```typescript\n * const fetchUserOnce = onceAsyncKeyed(async (userId: string) => {\n * return await api.getUser(userId);\n * });\n *\n * // Each unique userId will only be fetched once\n * await fetchUserOnce(\"user1\");\n * await fetchUserOnce(\"user1\"); // Returns cached promise\n * await fetchUserOnce(\"user2\"); // New fetch for different key\n * ```\n */\nexport function onceAsyncKeyed<TArgs extends readonly unknown[], TReturn>(\n\tfn: (...args: TArgs) => Promise<TReturn>\n): (...args: TArgs) => Promise<TReturn> {\n\tconst cache = new Map<string, Promise<TReturn>>();\n\n\treturn (...args: TArgs) => {\n\t\tconst key = JSON.stringify(args);\n\n\t\tif (!cache.has(key)) {\n\t\t\tcache.set(key, fn(...args));\n\t\t}\n\n\t\treturn cache.get(key)!;\n\t};\n}\n\n/**\n * Creates a resettable version of onceAsync that can be cleared and re-run.\n *\n * @param fn The async function to memoize\n * @returns Object with execute and reset methods\n *\n * @example\n * ```typescript\n * const { execute: initialize, reset } = onceAsyncResettable(async () => {\n * await heavyInitialization();\n * });\n *\n * await initialize(); // Runs\n * await initialize(); // Cached\n *\n * reset(); // Clear cache\n * await initialize(); // Runs again\n * ```\n */\nexport function onceAsyncResettable<T>(fn: () => Promise<T>): {\n\texecute: () => Promise<T>;\n\treset: () => void;\n} {\n\tlet promise: Promise<T> | null = null;\n\n\treturn {\n\t\texecute: () => {\n\t\t\tif (!promise) {\n\t\t\t\ttry {\n\t\t\t\t\tpromise = fn();\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Convert synchronous errors to rejected promises\n\t\t\t\t\tpromise = Promise.reject(error);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn promise;\n\t\t},\n\t\treset: () => {\n\t\t\tpromise = null;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface BatchOperationOptions {
|
|
2
|
+
closeAfter?: boolean;
|
|
3
|
+
callOnComplete?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface BatchOperationResult {
|
|
6
|
+
successCount: number;
|
|
7
|
+
errorCount: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function runBatchOperation<T>(items: T[], operationLabel: string, handler: (item: T) => Promise<void>, showResult?: boolean): Promise<BatchOperationResult>;
|
|
10
|
+
export declare function showBatchOperationResult(operation: string, successCount: number, errorCount: number): void;
|
|
11
|
+
//# sourceMappingURL=batch-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-operations.d.ts","sourceRoot":"","sources":["../src/batch-operations.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACrC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EACxC,KAAK,EAAE,CAAC,EAAE,EACV,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,EACnC,UAAU,GAAE,OAAc,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAmB/B;AAED,wBAAgB,wBAAwB,CACvC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GAChB,IAAI,CAUN"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { Notice } from "obsidian";
|
|
3
|
+
export function runBatchOperation(items_1, operationLabel_1, handler_1) {
|
|
4
|
+
return __awaiter(this, arguments, void 0, function* (items, operationLabel, handler, showResult = true) {
|
|
5
|
+
let successCount = 0;
|
|
6
|
+
let errorCount = 0;
|
|
7
|
+
for (const item of items) {
|
|
8
|
+
try {
|
|
9
|
+
yield handler(item);
|
|
10
|
+
successCount++;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error(`${operationLabel}: error processing item:`, error);
|
|
14
|
+
errorCount++;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (showResult) {
|
|
18
|
+
showBatchOperationResult(operationLabel, successCount, errorCount);
|
|
19
|
+
}
|
|
20
|
+
return { successCount, errorCount };
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function showBatchOperationResult(operation, successCount, errorCount) {
|
|
24
|
+
if (errorCount === 0) {
|
|
25
|
+
new Notice(`${operation}: ${successCount} item${successCount === 1 ? "" : "s"} processed successfully`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
new Notice(`${operation}: ${successCount} succeeded, ${errorCount} failed. Check console for details.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=batch-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-operations.js","sourceRoot":"","sources":["../src/batch-operations.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAYlC,MAAM,UAAgB,iBAAiB;yDACtC,KAAU,EACV,cAAsB,EACtB,OAAmC,EACnC,aAAsB,IAAI;QAE1B,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACJ,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBACpB,YAAY,EAAE,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,GAAG,cAAc,0BAA0B,EAAE,KAAK,CAAC,CAAC;gBAClE,UAAU,EAAE,CAAC;YACd,CAAC;QACF,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YAChB,wBAAwB,CAAC,cAAc,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;IACrC,CAAC;CAAA;AAED,MAAM,UAAU,wBAAwB,CACvC,SAAiB,EACjB,YAAoB,EACpB,UAAkB;IAElB,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACtB,IAAI,MAAM,CACT,GAAG,SAAS,KAAK,YAAY,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,yBAAyB,CAC3F,CAAC;IACH,CAAC;SAAM,CAAC;QACP,IAAI,MAAM,CACT,GAAG,SAAS,KAAK,YAAY,eAAe,UAAU,qCAAqC,CAC3F,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["import { Notice } from \"obsidian\";\n\nexport interface BatchOperationOptions {\n\tcloseAfter?: boolean;\n\tcallOnComplete?: boolean;\n}\n\nexport interface BatchOperationResult {\n\tsuccessCount: number;\n\terrorCount: number;\n}\n\nexport async function runBatchOperation<T>(\n\titems: T[],\n\toperationLabel: string,\n\thandler: (item: T) => Promise<void>,\n\tshowResult: boolean = true\n): Promise<BatchOperationResult> {\n\tlet successCount = 0;\n\tlet errorCount = 0;\n\n\tfor (const item of items) {\n\t\ttry {\n\t\t\tawait handler(item);\n\t\t\tsuccessCount++;\n\t\t} catch (error) {\n\t\t\tconsole.error(`${operationLabel}: error processing item:`, error);\n\t\t\terrorCount++;\n\t\t}\n\t}\n\n\tif (showResult) {\n\t\tshowBatchOperationResult(operationLabel, successCount, errorCount);\n\t}\n\n\treturn { successCount, errorCount };\n}\n\nexport function showBatchOperationResult(\n\toperation: string,\n\tsuccessCount: number,\n\terrorCount: number\n): void {\n\tif (errorCount === 0) {\n\t\tnew Notice(\n\t\t\t`${operation}: ${successCount} item${successCount === 1 ? \"\" : \"s\"} processed successfully`\n\t\t);\n\t} else {\n\t\tnew Notice(\n\t\t\t`${operation}: ${successCount} succeeded, ${errorCount} failed. Check console for details.`\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TFile } from "obsidian";
|
|
2
|
+
export interface VaultAdapter {
|
|
3
|
+
getAbstractFileByPath(path: string): TFile | null;
|
|
4
|
+
}
|
|
5
|
+
export declare function extractDirectoryPath(filePath: string): string;
|
|
6
|
+
export declare function isRelativeChildReference(childRef: string): boolean;
|
|
7
|
+
export declare function normalizeChildReference(childRef: string, vault: VaultAdapter, currentFileDirectory?: string): string;
|
|
8
|
+
export declare function normalizeChildReferences(childRefs: string[], vault: VaultAdapter, currentFileDirectory?: string): string[];
|
|
9
|
+
//# sourceMappingURL=child-reference-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-reference-utils.d.ts","sourceRoot":"","sources":["../src/child-reference-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,MAAM,WAAW,YAAY;IAC5B,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;CAClD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMlE;AAED,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,YAAY,EACnB,oBAAoB,CAAC,EAAE,MAAM,GAC3B,MAAM,CAqCR;AAED,wBAAgB,wBAAwB,CACvC,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,EAAE,YAAY,EACnB,oBAAoB,CAAC,EAAE,MAAM,GAC3B,MAAM,EAAE,CAIV"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TFile } from "obsidian";
|
|
2
|
+
import { createFileLink } from "./file-operations";
|
|
3
|
+
import { extractFilePathFromLink } from "./link-parser";
|
|
4
|
+
export function extractDirectoryPath(filePath) {
|
|
5
|
+
const lastSlashIndex = filePath.lastIndexOf("/");
|
|
6
|
+
if (lastSlashIndex === -1) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
return filePath.substring(0, lastSlashIndex);
|
|
10
|
+
}
|
|
11
|
+
export function isRelativeChildReference(childRef) {
|
|
12
|
+
const filePath = extractFilePathFromLink(childRef);
|
|
13
|
+
if (!filePath) {
|
|
14
|
+
return !childRef.includes("/");
|
|
15
|
+
}
|
|
16
|
+
return !filePath.includes("/");
|
|
17
|
+
}
|
|
18
|
+
export function normalizeChildReference(childRef, vault, currentFileDirectory) {
|
|
19
|
+
const filePath = extractFilePathFromLink(childRef);
|
|
20
|
+
// Handle plain text references (not wrapped in [[]])
|
|
21
|
+
if (!filePath) {
|
|
22
|
+
// If it's not a link format, check if it should be converted to a link
|
|
23
|
+
if (!childRef.includes("/") && currentFileDirectory !== undefined) {
|
|
24
|
+
// This is a plain text reference that might need to be converted to a link
|
|
25
|
+
const potentialPath = currentFileDirectory
|
|
26
|
+
? `${currentFileDirectory}/${childRef.endsWith(".md") ? childRef : `${childRef}.md`}`
|
|
27
|
+
: childRef.endsWith(".md")
|
|
28
|
+
? childRef
|
|
29
|
+
: `${childRef}.md`;
|
|
30
|
+
const file = vault.getAbstractFileByPath(potentialPath);
|
|
31
|
+
if (file instanceof TFile) {
|
|
32
|
+
return createFileLink(file);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return childRef;
|
|
36
|
+
}
|
|
37
|
+
// Handle relative references by making them absolute
|
|
38
|
+
if (isRelativeChildReference(childRef) && currentFileDirectory) {
|
|
39
|
+
const absolutePath = `${currentFileDirectory}/${filePath}`;
|
|
40
|
+
const file = vault.getAbstractFileByPath(absolutePath);
|
|
41
|
+
if (file instanceof TFile) {
|
|
42
|
+
return createFileLink(file);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// For absolute references or when no directory context, try to find the file as-is
|
|
46
|
+
const file = vault.getAbstractFileByPath(filePath);
|
|
47
|
+
if (file instanceof TFile) {
|
|
48
|
+
return createFileLink(file);
|
|
49
|
+
}
|
|
50
|
+
return childRef;
|
|
51
|
+
}
|
|
52
|
+
export function normalizeChildReferences(childRefs, vault, currentFileDirectory) {
|
|
53
|
+
return childRefs.map((childRef) => {
|
|
54
|
+
return normalizeChildReference(childRef, vault, currentFileDirectory);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=child-reference-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-reference-utils.js","sourceRoot":"","sources":["../src/child-reference-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CA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AC;YACxD,IAAI,IAAI,YAAY,KAAK,EAAE,CAAC;gBAC3B,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,qDAAqD;IACrD,IAAI,wBAAwB,CAAC,QAAQ,CAAC,IAAI,oBAAoB,EAAE,CAAC;QAChE,MAAM,YAAY,GAAG,GAAG,oBAAoB,IAAI,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,IAAI,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;IACF,CAAC;IAED,mFAAmF;IACnF,MAAM,IAAI,GAAG,KAAK,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACnD,IAAI,IAAI,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,SAAmB,EACnB,KAAmB,EACnB,oBAA6B;IAE7B,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QACjC,OAAO,uBAAuB,CAAC,QAAQ,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { TFile } from \"obsidian\";\nimport { createFileLink } from \"./file-operations\";\nimport { extractFilePathFromLink } from \"./link-parser\";\n\nexport interface VaultAdapter {\n\tgetAbstractFileByPath(path: string): TFile | null;\n}\n\nexport function extractDirectoryPath(filePath: string): string {\n\tconst lastSlashIndex = filePath.lastIndexOf(\"/\");\n\tif (lastSlashIndex === -1) {\n\t\treturn \"\";\n\t}\n\treturn filePath.substring(0, lastSlashIndex);\n}\n\nexport function isRelativeChildReference(childRef: string): boolean {\n\tconst filePath = extractFilePathFromLink(childRef);\n\tif (!filePath) {\n\t\treturn !childRef.includes(\"/\");\n\t}\n\treturn !filePath.includes(\"/\");\n}\n\nexport function normalizeChildReference(\n\tchildRef: string,\n\tvault: VaultAdapter,\n\tcurrentFileDirectory?: string\n): string {\n\tconst filePath = extractFilePathFromLink(childRef);\n\n\t// Handle plain text references (not wrapped in [[]])\n\tif (!filePath) {\n\t\t// If it's not a link format, check if it should be converted to a link\n\t\tif (!childRef.includes(\"/\") && currentFileDirectory !== undefined) {\n\t\t\t// This is a plain text reference that might need to be converted to a link\n\t\t\tconst potentialPath = currentFileDirectory\n\t\t\t\t? `${currentFileDirectory}/${childRef.endsWith(\".md\") ? childRef : `${childRef}.md`}`\n\t\t\t\t: childRef.endsWith(\".md\")\n\t\t\t\t\t? childRef\n\t\t\t\t\t: `${childRef}.md`;\n\t\t\tconst file = vault.getAbstractFileByPath(potentialPath);\n\t\t\tif (file instanceof TFile) {\n\t\t\t\treturn createFileLink(file);\n\t\t\t}\n\t\t}\n\t\treturn childRef;\n\t}\n\n\t// Handle relative references by making them absolute\n\tif (isRelativeChildReference(childRef) && currentFileDirectory) {\n\t\tconst absolutePath = `${currentFileDirectory}/${filePath}`;\n\t\tconst file = vault.getAbstractFileByPath(absolutePath);\n\t\tif (file instanceof TFile) {\n\t\t\treturn createFileLink(file);\n\t\t}\n\t}\n\n\t// For absolute references or when no directory context, try to find the file as-is\n\tconst file = vault.getAbstractFileByPath(filePath);\n\tif (file instanceof TFile) {\n\t\treturn createFileLink(file);\n\t}\n\n\treturn childRef;\n}\n\nexport function normalizeChildReferences(\n\tchildRefs: string[],\n\tvault: VaultAdapter,\n\tcurrentFileDirectory?: string\n): string[] {\n\treturn childRefs.map((childRef) => {\n\t\treturn normalizeChildReference(childRef, vault, currentFileDirectory);\n\t});\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DateTime } from "luxon";
|
|
2
|
+
export type RecurrenceType = "daily" | "weekly" | "bi-weekly" | "monthly" | "bi-monthly" | "yearly";
|
|
3
|
+
export type Weekday = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
|
|
4
|
+
export declare const WEEKDAY_TO_NUMBER: Record<Weekday, number>;
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the next occurrence date based on recurrence type and optional weekdays
|
|
7
|
+
*/
|
|
8
|
+
export declare function getNextOccurrence(currentDate: DateTime, recurrenceType: RecurrenceType, weekdays?: Weekday[]): DateTime;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a given date matches any of the specified weekdays
|
|
11
|
+
*/
|
|
12
|
+
export declare function isDateOnWeekdays(date: DateTime, weekdays: Weekday[]): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Finds the next occurrence on specified weekdays
|
|
15
|
+
*/
|
|
16
|
+
export declare function getNextWeekdayOccurrence(currentDate: DateTime, weekdays: Weekday[]): DateTime;
|
|
17
|
+
/**
|
|
18
|
+
* Finds the next bi-weekly occurrence on specified weekdays
|
|
19
|
+
*/
|
|
20
|
+
export declare function getNextBiWeeklyOccurrence(currentDate: DateTime, weekdays: Weekday[]): DateTime;
|
|
21
|
+
export declare function iterateOccurrencesInRange(startDate: DateTime, rrules: {
|
|
22
|
+
type: RecurrenceType;
|
|
23
|
+
weekdays?: Weekday[];
|
|
24
|
+
}, rangeStart: DateTime, rangeEnd: DateTime): Generator<DateTime, void, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Calculates a DateTime for a specific date with optional time
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculateInstanceDateTime(instanceDate: DateTime, timeString?: string): DateTime;
|
|
29
|
+
export declare function calculateRecurringInstanceDateTime(nextInstanceDateTime: DateTime, nodeRecuringEventDateTime: DateTime, recurrenceType: RecurrenceType, allDay?: boolean): DateTime;
|
|
30
|
+
//# sourceMappingURL=date-recurrence-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AE,MAAM,GAAG,QAAQ,CAO/F;AAED,wBAAgB,kCAAkC,CACjD,oBAAoB,EAAE,QAAQ,EAC9B,yBAAyB,EAAE,QAAQ,EACnC,cAAc,EAAE,cAAc,EAC9B,MAAM,CAAC,EAAE,OAAO,GACd,QAAQ,CA0DV"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export const WEEKDAY_TO_NUMBER = {
|
|
2
|
+
sunday: 0,
|
|
3
|
+
monday: 1,
|
|
4
|
+
tuesday: 2,
|
|
5
|
+
wednesday: 3,
|
|
6
|
+
thursday: 4,
|
|
7
|
+
friday: 5,
|
|
8
|
+
saturday: 6,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the next occurrence date based on recurrence type and optional weekdays
|
|
12
|
+
*/
|
|
13
|
+
export function getNextOccurrence(currentDate, recurrenceType, weekdays) {
|
|
14
|
+
switch (recurrenceType) {
|
|
15
|
+
case "daily":
|
|
16
|
+
return currentDate.plus({ days: 1 });
|
|
17
|
+
case "weekly":
|
|
18
|
+
if (weekdays && weekdays.length > 0) {
|
|
19
|
+
return getNextWeekdayOccurrence(currentDate, weekdays);
|
|
20
|
+
}
|
|
21
|
+
return currentDate.plus({ weeks: 1 });
|
|
22
|
+
case "bi-weekly":
|
|
23
|
+
if (weekdays && weekdays.length > 0) {
|
|
24
|
+
return getNextBiWeeklyOccurrence(currentDate, weekdays);
|
|
25
|
+
}
|
|
26
|
+
return currentDate.plus({ weeks: 2 });
|
|
27
|
+
case "monthly":
|
|
28
|
+
return currentDate.plus({ months: 1 });
|
|
29
|
+
case "bi-monthly":
|
|
30
|
+
return currentDate.plus({ months: 2 });
|
|
31
|
+
case "yearly":
|
|
32
|
+
return currentDate.plus({ years: 1 });
|
|
33
|
+
default:
|
|
34
|
+
return currentDate.plus({ days: 1 });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a given date matches any of the specified weekdays
|
|
39
|
+
*/
|
|
40
|
+
export function isDateOnWeekdays(date, weekdays) {
|
|
41
|
+
const dateWeekday = date.weekday;
|
|
42
|
+
const luxonWeekdays = weekdays.map((day) => {
|
|
43
|
+
const dayNumber = WEEKDAY_TO_NUMBER[day];
|
|
44
|
+
return dayNumber === 0 ? 7 : dayNumber; // Convert Sunday from 0 to 7 for Luxon
|
|
45
|
+
});
|
|
46
|
+
return luxonWeekdays.includes(dateWeekday);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Finds the next occurrence on specified weekdays
|
|
50
|
+
*/
|
|
51
|
+
export function getNextWeekdayOccurrence(currentDate, weekdays) {
|
|
52
|
+
const currentWeekday = currentDate.weekday;
|
|
53
|
+
const luxonWeekdays = weekdays.map((day) => {
|
|
54
|
+
const dayNumber = WEEKDAY_TO_NUMBER[day];
|
|
55
|
+
return dayNumber === 0 ? 7 : dayNumber; // Convert Sunday from 0 to 7 for Luxon
|
|
56
|
+
});
|
|
57
|
+
// Find next weekday in the current week (after today)
|
|
58
|
+
const nextWeekday = luxonWeekdays.find((day) => day > currentWeekday);
|
|
59
|
+
if (nextWeekday) {
|
|
60
|
+
return currentDate.set({ weekday: nextWeekday });
|
|
61
|
+
}
|
|
62
|
+
// No more weekdays this week, go to first weekday of next week
|
|
63
|
+
const firstWeekday = Math.min(...luxonWeekdays);
|
|
64
|
+
return currentDate.plus({ weeks: 1 }).set({ weekday: firstWeekday });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Finds the next bi-weekly occurrence on specified weekdays
|
|
68
|
+
*/
|
|
69
|
+
export function getNextBiWeeklyOccurrence(currentDate, weekdays) {
|
|
70
|
+
const nextWeekly = getNextWeekdayOccurrence(currentDate, weekdays);
|
|
71
|
+
// Add one more week to make it bi-weekly
|
|
72
|
+
return nextWeekly.plus({ weeks: 1 });
|
|
73
|
+
}
|
|
74
|
+
export function* iterateOccurrencesInRange(startDate, rrules, rangeStart, rangeEnd) {
|
|
75
|
+
let currentDate = startDate >= rangeStart ? startDate : rangeStart;
|
|
76
|
+
while (currentDate <= rangeEnd) {
|
|
77
|
+
// Check if current date should have an event
|
|
78
|
+
let shouldAddEvent = false;
|
|
79
|
+
if (rrules.type === "daily") {
|
|
80
|
+
shouldAddEvent = true;
|
|
81
|
+
}
|
|
82
|
+
else if (rrules.type === "weekly" || rrules.type === "bi-weekly") {
|
|
83
|
+
if (rrules.weekdays && rrules.weekdays.length > 0) {
|
|
84
|
+
shouldAddEvent = isDateOnWeekdays(currentDate, rrules.weekdays);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
shouldAddEvent = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
shouldAddEvent = true;
|
|
92
|
+
}
|
|
93
|
+
if (shouldAddEvent) {
|
|
94
|
+
yield currentDate;
|
|
95
|
+
}
|
|
96
|
+
const nextDate = getNextOccurrence(currentDate, rrules.type, rrules.weekdays);
|
|
97
|
+
if (nextDate <= rangeEnd) {
|
|
98
|
+
currentDate = nextDate;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Calculates a DateTime for a specific date with optional time
|
|
107
|
+
*/
|
|
108
|
+
export function calculateInstanceDateTime(instanceDate, timeString) {
|
|
109
|
+
if (!timeString) {
|
|
110
|
+
return instanceDate.startOf("day");
|
|
111
|
+
}
|
|
112
|
+
const [hours, minutes] = timeString.split(":").map(Number);
|
|
113
|
+
return instanceDate.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 });
|
|
114
|
+
}
|
|
115
|
+
export function calculateRecurringInstanceDateTime(nextInstanceDateTime, nodeRecuringEventDateTime, recurrenceType, allDay) {
|
|
116
|
+
// Convert the original event time to the target timezone once to preserve local time
|
|
117
|
+
const originalInTargetZone = nodeRecuringEventDateTime.setZone(nextInstanceDateTime.zone);
|
|
118
|
+
switch (recurrenceType) {
|
|
119
|
+
case "daily":
|
|
120
|
+
case "weekly":
|
|
121
|
+
case "bi-weekly": {
|
|
122
|
+
if (allDay) {
|
|
123
|
+
return nextInstanceDateTime.startOf("day");
|
|
124
|
+
}
|
|
125
|
+
return nextInstanceDateTime.set({
|
|
126
|
+
hour: originalInTargetZone.hour,
|
|
127
|
+
minute: originalInTargetZone.minute,
|
|
128
|
+
second: 0,
|
|
129
|
+
millisecond: 0,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
case "monthly":
|
|
133
|
+
case "bi-monthly": {
|
|
134
|
+
if (allDay) {
|
|
135
|
+
return nextInstanceDateTime.set({ day: originalInTargetZone.day }).startOf("day");
|
|
136
|
+
}
|
|
137
|
+
return nextInstanceDateTime.set({
|
|
138
|
+
day: originalInTargetZone.day,
|
|
139
|
+
hour: originalInTargetZone.hour,
|
|
140
|
+
minute: originalInTargetZone.minute,
|
|
141
|
+
second: 0,
|
|
142
|
+
millisecond: 0,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
case "yearly": {
|
|
146
|
+
if (allDay) {
|
|
147
|
+
return nextInstanceDateTime
|
|
148
|
+
.set({
|
|
149
|
+
month: originalInTargetZone.month,
|
|
150
|
+
day: originalInTargetZone.day,
|
|
151
|
+
})
|
|
152
|
+
.startOf("day");
|
|
153
|
+
}
|
|
154
|
+
return nextInstanceDateTime.set({
|
|
155
|
+
month: originalInTargetZone.month,
|
|
156
|
+
day: originalInTargetZone.day,
|
|
157
|
+
hour: originalInTargetZone.hour,
|
|
158
|
+
minute: originalInTargetZone.minute,
|
|
159
|
+
second: 0,
|
|
160
|
+
millisecond: 0,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
default:
|
|
164
|
+
return nextInstanceDateTime.startOf("day");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=date-recurrence-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-recurrence-utils.js","sourceRoot":"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ACT,WAAW,EAAE,CAAC;aACd,CAAC,CAAC;QACJ,CAAC;QAED,KAAK,SAAS,CAAC;QACf,KAAK,YAAY,CAAC,CAAC,CAAC;YACnB,IAAI,MAAM,EAAE,CAAC;gBACZ,OAAO,oBAAoB,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnF,CAAC;YAED,OAAO,oBAAoB,CAAC,GAAG,CAAC;gBAC/B,GAAG,EAAE,oBAAoB,CAAC,GAAG;gBAC7B,IAAI,EAAE,oBAAoB,CAAC,IAAI;gBAC/B,MAAM,EAAE,oBAAoB,CAAC,MAAM;gBACnC,MAAM,EAAE,CAAC;gBACT,WAAW,EAAE,CAAC;aACd,CAAC,CAAC;QACJ,CAAC;QAED,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,IAAI,MAAM,EAAE,CAAC;gBACZ,OAAO,oBAAoB;qBACzB,GAAG,CAAC;oBACJ,KAAK,EAAE,oBAAoB,CAAC,KAAK;oBACjC,GAAG,EAAE,oBAAoB,CAAC,GAAG;iBAC7B,CAAC;qBACD,OAAO,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAED,OAAO,oBAAoB,CAAC,GAAG,CAAC;gBAC/B,KAAK,EAAE,oBAAoB,CAAC,KAAK;gBACjC,GAAG,EAAE,oBAAoB,CAAC,GAAG;gBAC7B,IAAI,EAAE,oBAAoB,CAAC,IAAI;gBAC/B,MAAM,EAAE,oBAAoB,CAAC,MAAM;gBACnC,MAAM,EAAE,CAAC;gBACT,WAAW,EAAE,CAAC;aACd,CAAC,CAAC;QACJ,CAAC;QAED;YACC,OAAO,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;AACF,CAAC","sourcesContent":["import type { DateTime } from \"luxon\";\n\nexport type RecurrenceType = \"daily\" | \"weekly\" | \"bi-weekly\" | \"monthly\" | \"bi-monthly\" | \"yearly\";\n\nexport type Weekday =\n\t| \"sunday\"\n\t| \"monday\"\n\t| \"tuesday\"\n\t| \"wednesday\"\n\t| \"thursday\"\n\t| \"friday\"\n\t| \"saturday\";\n\nexport const WEEKDAY_TO_NUMBER: Record<Weekday, number> = {\n\tsunday: 0,\n\tmonday: 1,\n\ttuesday: 2,\n\twednesday: 3,\n\tthursday: 4,\n\tfriday: 5,\n\tsaturday: 6,\n};\n\n/**\n * Calculates the next occurrence date based on recurrence type and optional weekdays\n */\nexport function getNextOccurrence(\n\tcurrentDate: DateTime,\n\trecurrenceType: RecurrenceType,\n\tweekdays?: Weekday[]\n): DateTime {\n\tswitch (recurrenceType) {\n\t\tcase \"daily\":\n\t\t\treturn currentDate.plus({ days: 1 });\n\t\tcase \"weekly\":\n\t\t\tif (weekdays && weekdays.length > 0) {\n\t\t\t\treturn getNextWeekdayOccurrence(currentDate, weekdays);\n\t\t\t}\n\t\t\treturn currentDate.plus({ weeks: 1 });\n\t\tcase \"bi-weekly\":\n\t\t\tif (weekdays && weekdays.length > 0) {\n\t\t\t\treturn getNextBiWeeklyOccurrence(currentDate, weekdays);\n\t\t\t}\n\t\t\treturn currentDate.plus({ weeks: 2 });\n\t\tcase \"monthly\":\n\t\t\treturn currentDate.plus({ months: 1 });\n\t\tcase \"bi-monthly\":\n\t\t\treturn currentDate.plus({ months: 2 });\n\t\tcase \"yearly\":\n\t\t\treturn currentDate.plus({ years: 1 });\n\t\tdefault:\n\t\t\treturn currentDate.plus({ days: 1 });\n\t}\n}\n\n/**\n * Checks if a given date matches any of the specified weekdays\n */\nexport function isDateOnWeekdays(date: DateTime, weekdays: Weekday[]): boolean {\n\tconst dateWeekday = date.weekday;\n\tconst luxonWeekdays = weekdays.map((day) => {\n\t\tconst dayNumber = WEEKDAY_TO_NUMBER[day];\n\t\treturn dayNumber === 0 ? 7 : dayNumber; // Convert Sunday from 0 to 7 for Luxon\n\t});\n\n\treturn luxonWeekdays.includes(dateWeekday);\n}\n\n/**\n * Finds the next occurrence on specified weekdays\n */\nexport function getNextWeekdayOccurrence(currentDate: DateTime, weekdays: Weekday[]): DateTime {\n\tconst currentWeekday = currentDate.weekday;\n\tconst luxonWeekdays = weekdays.map((day) => {\n\t\tconst dayNumber = WEEKDAY_TO_NUMBER[day];\n\t\treturn dayNumber === 0 ? 7 : dayNumber; // Convert Sunday from 0 to 7 for Luxon\n\t});\n\n\t// Find next weekday in the current week (after today)\n\tconst nextWeekday = luxonWeekdays.find((day) => day > currentWeekday);\n\tif (nextWeekday) {\n\t\treturn currentDate.set({ weekday: nextWeekday as 1 | 2 | 3 | 4 | 5 | 6 | 7 });\n\t}\n\n\t// No more weekdays this week, go to first weekday of next week\n\tconst firstWeekday = Math.min(...luxonWeekdays);\n\treturn currentDate.plus({ weeks: 1 }).set({ weekday: firstWeekday as 1 | 2 | 3 | 4 | 5 | 6 | 7 });\n}\n\n/**\n * Finds the next bi-weekly occurrence on specified weekdays\n */\nexport function getNextBiWeeklyOccurrence(currentDate: DateTime, weekdays: Weekday[]): DateTime {\n\tconst nextWeekly = getNextWeekdayOccurrence(currentDate, weekdays);\n\t// Add one more week to make it bi-weekly\n\treturn nextWeekly.plus({ weeks: 1 });\n}\n\nexport function* iterateOccurrencesInRange(\n\tstartDate: DateTime,\n\trrules: { type: RecurrenceType; weekdays?: Weekday[] },\n\trangeStart: DateTime,\n\trangeEnd: DateTime\n): Generator<DateTime, void, unknown> {\n\tlet currentDate = startDate >= rangeStart ? startDate : rangeStart;\n\n\twhile (currentDate <= rangeEnd) {\n\t\t// Check if current date should have an event\n\t\tlet shouldAddEvent = false;\n\n\t\tif (rrules.type === \"daily\") {\n\t\t\tshouldAddEvent = true;\n\t\t} else if (rrules.type === \"weekly\" || rrules.type === \"bi-weekly\") {\n\t\t\tif (rrules.weekdays && rrules.weekdays.length > 0) {\n\t\t\t\tshouldAddEvent = isDateOnWeekdays(currentDate, rrules.weekdays);\n\t\t\t} else {\n\t\t\t\tshouldAddEvent = true;\n\t\t\t}\n\t\t} else {\n\t\t\tshouldAddEvent = true;\n\t\t}\n\n\t\tif (shouldAddEvent) {\n\t\t\tyield currentDate;\n\t\t}\n\n\t\tconst nextDate = getNextOccurrence(currentDate, rrules.type, rrules.weekdays);\n\n\t\tif (nextDate <= rangeEnd) {\n\t\t\tcurrentDate = nextDate;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Calculates a DateTime for a specific date with optional time\n */\nexport function calculateInstanceDateTime(instanceDate: DateTime, timeString?: string): DateTime {\n\tif (!timeString) {\n\t\treturn instanceDate.startOf(\"day\");\n\t}\n\n\tconst [hours, minutes] = timeString.split(\":\").map(Number);\n\treturn instanceDate.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 });\n}\n\nexport function calculateRecurringInstanceDateTime(\n\tnextInstanceDateTime: DateTime,\n\tnodeRecuringEventDateTime: DateTime,\n\trecurrenceType: RecurrenceType,\n\tallDay?: boolean\n): DateTime {\n\t// Convert the original event time to the target timezone once to preserve local time\n\tconst originalInTargetZone = nodeRecuringEventDateTime.setZone(nextInstanceDateTime.zone);\n\n\tswitch (recurrenceType) {\n\t\tcase \"daily\":\n\t\tcase \"weekly\":\n\t\tcase \"bi-weekly\": {\n\t\t\tif (allDay) {\n\t\t\t\treturn nextInstanceDateTime.startOf(\"day\");\n\t\t\t}\n\n\t\t\treturn nextInstanceDateTime.set({\n\t\t\t\thour: originalInTargetZone.hour,\n\t\t\t\tminute: originalInTargetZone.minute,\n\t\t\t\tsecond: 0,\n\t\t\t\tmillisecond: 0,\n\t\t\t});\n\t\t}\n\n\t\tcase \"monthly\":\n\t\tcase \"bi-monthly\": {\n\t\t\tif (allDay) {\n\t\t\t\treturn nextInstanceDateTime.set({ day: originalInTargetZone.day }).startOf(\"day\");\n\t\t\t}\n\n\t\t\treturn nextInstanceDateTime.set({\n\t\t\t\tday: originalInTargetZone.day,\n\t\t\t\thour: originalInTargetZone.hour,\n\t\t\t\tminute: originalInTargetZone.minute,\n\t\t\t\tsecond: 0,\n\t\t\t\tmillisecond: 0,\n\t\t\t});\n\t\t}\n\n\t\tcase \"yearly\": {\n\t\t\tif (allDay) {\n\t\t\t\treturn nextInstanceDateTime\n\t\t\t\t\t.set({\n\t\t\t\t\t\tmonth: originalInTargetZone.month,\n\t\t\t\t\t\tday: originalInTargetZone.day,\n\t\t\t\t\t})\n\t\t\t\t\t.startOf(\"day\");\n\t\t\t}\n\n\t\t\treturn nextInstanceDateTime.set({\n\t\t\t\tmonth: originalInTargetZone.month,\n\t\t\t\tday: originalInTargetZone.day,\n\t\t\t\thour: originalInTargetZone.hour,\n\t\t\t\tminute: originalInTargetZone.minute,\n\t\t\t\tsecond: 0,\n\t\t\t\tmillisecond: 0,\n\t\t\t});\n\t\t}\n\n\t\tdefault:\n\t\t\treturn nextInstanceDateTime.startOf(\"day\");\n\t}\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
export declare const formatDateTimeForInput: (dateString: string) => string;
|
|
3
|
+
export declare const formatDateForInput: (dateString: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Converts input value to ISO string, handling edge cases where
|
|
6
|
+
* browser datetime-local inputs behave differently across platforms.
|
|
7
|
+
* Returns null for invalid dates to prevent silent failures.
|
|
8
|
+
*/
|
|
9
|
+
export declare const inputValueToISOString: (inputValue: string) => string | null;
|
|
10
|
+
export declare const formatDuration: (minutes: number) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Parse time string from datetime value - returns DateTime object
|
|
13
|
+
* Rejects plain HH:mm format, requires full datetime
|
|
14
|
+
*/
|
|
15
|
+
export declare const parseTimeString: (value: string | null) => DateTime | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Parse and validate datetime strings for event parsing
|
|
18
|
+
* Supports multiple formats including date-only and datetime formats
|
|
19
|
+
*/
|
|
20
|
+
export declare const parseDateTimeString: (value: string | null) => DateTime | undefined;
|
|
21
|
+
//# sourceMappingURL=date-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-utils.d.ts","sourceRoot":"","sources":["../src/date-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,eAAO,MAAM,sBAAsB,GAAI,YAAY,MAAM,KAAG,MAgB3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,KAAG,MAavD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,YAAY,MAAM,KAAG,MAAM,GAAG,IAMnE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAIhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,GAAG,IAAI,KAAG,QAAQ,GAAG,SAgBjE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,GAAG,IAAI,KAAG,QAAQ,GAAG,SA8BrE,CAAC"}
|