@perses-dev/core 0.10.0 → 0.11.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.
@@ -26,8 +26,7 @@ _export(exports, {
26
26
  toAbsoluteTimeRange: ()=>toAbsoluteTimeRange,
27
27
  parseDurationString: ()=>parseDurationString,
28
28
  isDurationString: ()=>isDurationString,
29
- getSuggestedStepMs: ()=>getSuggestedStepMs,
30
- getDefaultTimeRange: ()=>getDefaultTimeRange
29
+ getSuggestedStepMs: ()=>getSuggestedStepMs
31
30
  });
32
31
  const _dateFns = require("date-fns");
33
32
  function isRelativeTimeRange(timeRange) {
@@ -71,20 +70,3 @@ function getSuggestedStepMs(timeRange, width) {
71
70
  const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
72
71
  return Math.floor(queryRangeMs / width);
73
72
  }
74
- function getDefaultTimeRange(dashboardDuration, queryString) {
75
- const startParam = queryString.get('start');
76
- const endParam = queryString.get('end');
77
- if (startParam === null) {
78
- // use relative time range from dashboard definition if start param is empty
79
- return {
80
- pastDuration: dashboardDuration
81
- };
82
- }
83
- // convert query param format to RelativeTimeRange or AbsoluteTimeRange
84
- return isDurationString(startParam) ? {
85
- pastDuration: startParam
86
- } : {
87
- start: new Date(Number(startParam)),
88
- end: new Date(Number(endParam))
89
- };
90
- }
@@ -43,9 +43,5 @@ export declare function isDurationString(maybeDuration: string): maybeDuration i
43
43
  * Gets a suggested step/interval size for a time range based on the width of a visual component.
44
44
  */
45
45
  export declare function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number): number;
46
- /**
47
- * Gets the default time range taking into account URL params
48
- */
49
- export declare function getDefaultTimeRange(dashboardDuration: DurationString, queryString: URLSearchParams): TimeRangeValue;
50
46
  export {};
51
47
  //# sourceMappingURL=time.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ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C;AAC1C,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AACxC,aAAK,kBAAkB,GAAG,GAAG,MAAM,GAAG,CAAC;AACvC,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AACxC,aAAK,mBAAmB,GAAG,GAAG,MAAM,GAAG,CAAC;AAExC,oBAAY,cAAc,GAAG,OAAO,CAClC,GAAG,mBAAmB,GAAG,EAAE,GAAG,mBAAmB,GAAG,EAAE,GAAG,kBAAkB,GAAG,EAAE,GAAG,mBAAmB,GAAG,EAAE,GACvG,qBAAqB,GACrB,EAAE,GAAG,qBAAqB,GAAG,EAAE,GAAG,0BAA0B,GAAG,EAAE,EAAE,EACvE,EAAE,CACH,CAAC;AAIF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAepE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,IAAI,cAAc,CAGvF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,UAK7E"}
@@ -65,24 +65,5 @@ const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?
65
65
  const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
66
66
  return Math.floor(queryRangeMs / width);
67
67
  }
68
- /**
69
- * Gets the default time range taking into account URL params
70
- */ export function getDefaultTimeRange(dashboardDuration, queryString) {
71
- const startParam = queryString.get('start');
72
- const endParam = queryString.get('end');
73
- if (startParam === null) {
74
- // use relative time range from dashboard definition if start param is empty
75
- return {
76
- pastDuration: dashboardDuration
77
- };
78
- }
79
- // convert query param format to RelativeTimeRange or AbsoluteTimeRange
80
- return isDurationString(startParam) ? {
81
- pastDuration: startParam
82
- } : {
83
- start: new Date(Number(startParam)),
84
- end: new Date(Number(endParam))
85
- };
86
- }
87
68
 
88
69
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nconst DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n // TODO: Should we try to suggest more \"rounded\" step values based around\n // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n return Math.floor(queryRangeMs / width);\n}\n\n/**\n * Gets the default time range taking into account URL params\n */\nexport function getDefaultTimeRange(dashboardDuration: DurationString, queryString: URLSearchParams): TimeRangeValue {\n const startParam = queryString.get('start');\n const endParam = queryString.get('end');\n\n if (startParam === null) {\n // use relative time range from dashboard definition if start param is empty\n return { pastDuration: dashboardDuration };\n }\n\n // convert query param format to RelativeTimeRange or AbsoluteTimeRange\n return isDurationString(startParam)\n ? { pastDuration: startParam }\n : { start: new Date(Number(startParam)), end: new Date(Number(endParam)) };\n}\n"],"names":["sub","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","getSuggestedStepMs","width","queryRangeMs","valueOf","Math","floor","getDefaultTimeRange","dashboardDuration","queryString","startParam","get","endParam","Number"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAmBA,GAAG,QAAQ,UAAU,CAAC;AAmBzC;;CAEC,GACD,OAAO,SAASC,mBAAmB,CAACC,SAAyB,EAAkC;IAC7F,OAAO,AAACA,SAAS,CAAuBC,YAAY,KAAKC,SAAS,CAAC;AACrE,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,mBAAmB,CAACH,SAAyB,EAAkC;IAC7F,OAAO,AAACA,SAAS,CAAuBI,KAAK,KAAKF,SAAS,IAAI,AAACF,SAAS,CAAuBK,GAAG,KAAKH,SAAS,CAAC;AACpH,CAAC;AAED;;CAEC,GACD,OAAO,SAASI,mBAAmB,CAACN,SAA4B,EAAqB;QACvEA,IAAa;IAAzB,MAAMK,GAAG,GAAGL,CAAAA,IAAa,GAAbA,SAAS,CAACK,GAAG,cAAbL,IAAa,cAAbA,IAAa,GAAI,IAAIO,IAAI,EAAE,AAAC;IAExC,OAAO;QACLH,KAAK,EAAEN,GAAG,CAACO,GAAG,EAAEG,mBAAmB,CAACR,SAAS,CAACC,YAAY,CAAC,CAAC;QAC5DI,GAAG;KACJ,CAAC;AACJ,CAAC;AAiBD,MAAMI,cAAc,qFAAqF,AAAC;AAE1G;;;C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,CAAC,GAAG,IAAI;KAC1E,CAAC;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,SAASW,gBAAgB,CAACC,aAAqB,EAAmC;IACvF,IAAIA,aAAa,KAAK,EAAE,EAAE,OAAO,KAAK,CAAC;IACvC,OAAOd,cAAc,CAACe,IAAI,CAACD,aAAa,CAAC,CAAC;AAC5C,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,kBAAkB,CAACzB,SAA4B,EAAE0B,KAAa,EAAE;IAC9E,yEAAyE;IACzE,gEAAgE;IAChE,MAAMC,YAAY,GAAG3B,SAAS,CAACK,GAAG,CAACuB,OAAO,EAAE,GAAG5B,SAAS,CAACI,KAAK,CAACwB,OAAO,EAAE,AAAC;IACzE,OAAOC,IAAI,CAACC,KAAK,CAACH,YAAY,GAAGD,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED;;CAEC,GACD,OAAO,SAASK,mBAAmB,CAACC,iBAAiC,EAAEC,WAA4B,EAAkB;IACnH,MAAMC,UAAU,GAAGD,WAAW,CAACE,GAAG,CAAC,OAAO,CAAC,AAAC;IAC5C,MAAMC,QAAQ,GAAGH,WAAW,CAACE,GAAG,CAAC,KAAK,CAAC,AAAC;IAExC,IAAID,UAAU,KAAK,IAAI,EAAE;QACvB,4EAA4E;QAC5E,OAAO;YAAEjC,YAAY,EAAE+B,iBAAiB;SAAE,CAAC;IAC7C,CAAC;IAED,uEAAuE;IACvE,OAAOV,gBAAgB,CAACY,UAAU,CAAC,GAC/B;QAAEjC,YAAY,EAAEiC,UAAU;KAAE,GAC5B;QAAE9B,KAAK,EAAE,IAAIG,IAAI,CAAC8B,MAAM,CAACH,UAAU,CAAC,CAAC;QAAE7B,GAAG,EAAE,IAAIE,IAAI,CAAC8B,MAAM,CAACD,QAAQ,CAAC,CAAC;KAAE,CAAC;AAC/E,CAAC"}
1
+ {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nconst DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n // TODO: Should we try to suggest more \"rounded\" step values based around\n // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n return Math.floor(queryRangeMs / width);\n}\n"],"names":["sub","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","getSuggestedStepMs","width","queryRangeMs","valueOf","Math","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAA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,CAAC,CAAC;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/core",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Core functionality consumed by both the Perses UI and plugins",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",