@narrative.io/data-collaboration-sdk-ts 2.68.0 → 2.84.0
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.
|
@@ -12,36 +12,70 @@ function buildAttributeIndexes(attributes) {
|
|
|
12
12
|
}
|
|
13
13
|
return { byId, byName };
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts an ISO 8601 duration string to milliseconds for comparison.
|
|
17
|
+
* This is an approximation for human-readable durations (months/years vary in length).
|
|
18
|
+
*
|
|
19
|
+
* @param duration - ISO 8601 duration string (e.g., "PT1H", "P1D", "P1M")
|
|
20
|
+
* @returns Duration in milliseconds
|
|
21
|
+
*/
|
|
22
|
+
function parseDurationToMilliseconds(duration) {
|
|
23
|
+
const regex = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
|
|
24
|
+
const matches = duration.match(regex);
|
|
25
|
+
if (!matches) {
|
|
26
|
+
throw new Error(`Invalid ISO 8601 duration format: ${duration}`);
|
|
27
|
+
}
|
|
28
|
+
const [, years, months, weeks, days, hours, minutes, seconds] = matches.map((m) => Number.parseInt(m || "0", 10));
|
|
29
|
+
// Approximate conversions (months = 30 days, years = 365 days)
|
|
30
|
+
const milliseconds = years * 365 * 24 * 60 * 60 * 1000 +
|
|
31
|
+
months * 30 * 24 * 60 * 60 * 1000 +
|
|
32
|
+
weeks * 7 * 24 * 60 * 60 * 1000 +
|
|
33
|
+
days * 24 * 60 * 60 * 1000 +
|
|
34
|
+
hours * 60 * 60 * 1000 +
|
|
35
|
+
minutes * 60 * 1000 +
|
|
36
|
+
seconds * 1000;
|
|
37
|
+
return milliseconds;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Finds the smallest (most frequent) refresh schedule from a list of ISO 8601 duration strings.
|
|
41
|
+
* The smallest duration means the most frequent refresh rate.
|
|
42
|
+
*
|
|
43
|
+
* @param schedules - Array of ISO 8601 duration strings
|
|
44
|
+
* @returns The smallest duration in milliseconds, or 2592000000 (30 days/1 month) if no schedules provided
|
|
45
|
+
*/
|
|
15
46
|
function getSmallestRefreshSchedule(schedules) {
|
|
47
|
+
// Default to monthly (30 days in milliseconds)
|
|
48
|
+
const defaultMonthlyMs = 30 * 24 * 60 * 60 * 1000;
|
|
16
49
|
if (schedules.length === 0) {
|
|
17
|
-
return
|
|
50
|
+
return defaultMonthlyMs;
|
|
18
51
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let smallestValue =
|
|
52
|
+
if (schedules.length === 1) {
|
|
53
|
+
try {
|
|
54
|
+
return parseDurationToMilliseconds(schedules[0]);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.warn(`Invalid refresh schedule: ${schedules[0]}, using default`, error);
|
|
58
|
+
return defaultMonthlyMs;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Find the schedule with the smallest duration (most frequent refresh)
|
|
62
|
+
let smallestValue = Number.MAX_SAFE_INTEGER;
|
|
30
63
|
for (const schedule of schedules) {
|
|
31
|
-
|
|
32
|
-
const value =
|
|
64
|
+
try {
|
|
65
|
+
const value = parseDurationToMilliseconds(schedule);
|
|
33
66
|
if (value < smallestValue) {
|
|
34
67
|
smallestValue = value;
|
|
35
|
-
smallestSchedule = schedule;
|
|
36
68
|
}
|
|
37
69
|
}
|
|
38
|
-
|
|
39
|
-
// If
|
|
40
|
-
|
|
41
|
-
return schedule;
|
|
70
|
+
catch (error) {
|
|
71
|
+
// If parsing fails, skip this schedule
|
|
72
|
+
console.warn(`Skipping invalid refresh schedule: ${schedule}`, error);
|
|
42
73
|
}
|
|
43
74
|
}
|
|
44
|
-
return
|
|
75
|
+
// If all schedules failed to parse, return default
|
|
76
|
+
return smallestValue === Number.MAX_SAFE_INTEGER
|
|
77
|
+
? defaultMonthlyMs
|
|
78
|
+
: smallestValue;
|
|
45
79
|
}
|
|
46
80
|
/**
|
|
47
81
|
* Builds structured WHERE clauses for a single branch node
|
|
@@ -23,6 +23,7 @@ export interface PolicyMatchResult extends PolicySqlFragments {
|
|
|
23
23
|
details: string[];
|
|
24
24
|
}>;
|
|
25
25
|
warnings: string[];
|
|
26
|
-
|
|
26
|
+
/** The minimum refresh schedule in milliseconds across all evaluated policies */
|
|
27
|
+
refresh_schedule: number;
|
|
27
28
|
}
|
|
28
29
|
export {};
|
|
@@ -12,13 +12,7 @@ declare const CollaborationPolicy: z.ZodObject<{
|
|
|
12
12
|
metadata: z.ZodObject<{
|
|
13
13
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
14
14
|
refresh_schedule: z.ZodOptional<z.ZodObject<{
|
|
15
|
-
max: z.
|
|
16
|
-
"@hourly": "@hourly";
|
|
17
|
-
"@daily": "@daily";
|
|
18
|
-
"@weekly": "@weekly";
|
|
19
|
-
"@monthly": "@monthly";
|
|
20
|
-
"@once": "@once";
|
|
21
|
-
}>, z.ZodString]>;
|
|
15
|
+
max: z.ZodString;
|
|
22
16
|
}, z.core.$strict>>;
|
|
23
17
|
}, z.core.$strip>;
|
|
24
18
|
definition: z.ZodObject<{
|
|
@@ -7,15 +7,27 @@ const CollaborationPolicyIdentifier = z
|
|
|
7
7
|
.meta({
|
|
8
8
|
id: "collaboration_policy_identifier",
|
|
9
9
|
});
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Refresh Schedule Schema
|
|
12
|
+
*
|
|
13
|
+
* Specifies how often the destination should be refreshed to ensure data doesn't expire.
|
|
14
|
+
* This is the maximum time interval allowed between destination updates. Waiting longer
|
|
15
|
+
* than this duration may result in the destination expiring data that should be retained.
|
|
16
|
+
*
|
|
17
|
+
* Uses ISO 8601 duration format (e.g., "PT1H" for 1 hour, "P1D" for 1 day).
|
|
18
|
+
* Supported values:
|
|
19
|
+
* - PT1H: Hourly (1 hour)
|
|
20
|
+
* - P1D: Daily (1 day)
|
|
21
|
+
* - P7D: Weekly (7 days)
|
|
22
|
+
* - P1M: Monthly (1 month)
|
|
23
|
+
* - P0D: Once (no recurring refresh)
|
|
24
|
+
* - Custom ISO 8601 duration strings (e.g., "PT30M" for 30 minutes, "P2W" for 2 weeks)
|
|
25
|
+
*/
|
|
11
26
|
const RefreshScheduleSchema = z
|
|
12
27
|
.object({
|
|
13
|
-
max: z
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.string()
|
|
17
|
-
.regex(/^([0-5]?[0-9]|\*) ([01]?[0-9]|2[0-3]|\*) ([0-2]?[0-9]|3[01]|\*) ([0]?[1-9]|1[0-2]|\*) ([0-6]|\*)$/, "Invalid cron expression"),
|
|
18
|
-
]),
|
|
28
|
+
max: z
|
|
29
|
+
.string()
|
|
30
|
+
.regex(/^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$/, "Invalid ISO 8601 duration format. Expected format like 'PT1H' (1 hour), 'P1D' (1 day), 'P7D' (7 days), 'P1M' (1 month), or 'P0D' (once)"),
|
|
19
31
|
})
|
|
20
32
|
.strict()
|
|
21
33
|
.meta({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narrative.io/data-collaboration-sdk-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.84.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"repository": "github:narrative-io/data-collaboration-sdk-ts",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -27,18 +27,18 @@
|
|
|
27
27
|
"@babel/core": "7.28.4",
|
|
28
28
|
"@babel/preset-env": "7.28.3",
|
|
29
29
|
"@babel/preset-typescript": "7.27.1",
|
|
30
|
-
"@biomejs/biome": "2.2.
|
|
30
|
+
"@biomejs/biome": "2.2.7",
|
|
31
31
|
"@commitlint/cli": "20.1.0",
|
|
32
32
|
"@commitlint/config-conventional": "20.0.0",
|
|
33
33
|
"@types/jest": "30.0.0",
|
|
34
34
|
"babel-jest": "30.2.0",
|
|
35
35
|
"jest": "30.2.0",
|
|
36
|
-
"lefthook": "
|
|
37
|
-
"ts-jest": "29.4.
|
|
36
|
+
"lefthook": "2.0.0",
|
|
37
|
+
"ts-jest": "29.4.5"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"mande": "2.0.9",
|
|
41
|
-
"zod": "4.1.
|
|
41
|
+
"zod": "4.1.12",
|
|
42
42
|
"bignumber.js": "9.3.1"
|
|
43
43
|
},
|
|
44
44
|
"overrides": {
|