@luxonis/ui-utils 0.0.1 → 1.0.3

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { stringify } from 'safe-stable-stringify';
1
2
  import React from 'react';
2
3
  import { ErrorObject } from 'serialize-error';
3
4
  export { serializeError } from 'serialize-error';
@@ -38,6 +39,18 @@ declare function oldestFirstByCreatedAt<T extends {
38
39
  createdAt: Date | string;
39
40
  }>(a: T, b: T): number;
40
41
 
42
+ declare const serializeToJson: typeof stringify;
43
+ type JsonPrimitive = string | number | boolean | null;
44
+ type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
45
+ type JsonObject = {
46
+ [key: string]: JsonValue;
47
+ };
48
+ declare const serializeToJsonOrThrow: (data: unknown) => string;
49
+ declare const parseJson: <T = unknown>(value: string) => T;
50
+ declare const resolveReference: (jsonSchema: JsonObject, ref: string) => JsonValue | undefined;
51
+ declare const replaceRefs: (schema: JsonValue, jsonSchema: JsonObject) => string | number | boolean | JsonObject | JsonValue[] | null;
52
+ declare const replaceRefsInJsonSchema: (jsonSchema: JsonObject) => string | number | boolean | JsonObject | JsonValue[] | null;
53
+
41
54
  type UseDebounceProps = {
42
55
  effect: () => void;
43
56
  dependencies: React.DependencyList;
@@ -119,4 +132,4 @@ declare const errorAsContext: (e: unknown) => MessageContext;
119
132
  declare function prettifyMessage(data: string): string;
120
133
  declare const log: Logger;
121
134
 
122
- export { DAY, HOUR, type LogFnParams, type LogFnParamsBase, type LogFnParamsCtx, LogLevel, type Logger, type LoggerConfig, MINUTE, MONTH, type Message, type MessageContext, SECOND, WEEK, YEAR, buildLogger, buildSerializeMessage, defaultLogger, errorAsContext, formatAgentVersion, formatBps, formatBytes, formatCapitalizeFirstLetter, formatCapitalizeWords, formatDate, formatDateISOInTimezone, formatFirmwareVersion, formatIntTemperature, formatLastSeen, formatMaxLength, formatPlatform, formatPrettyDate, formatRobotName, formatSlug, formatTemperature, formatUptime, formatUsbPort, getDateWithTimezone, getDistance, getShortDate, getShortDateOrDistance, getShortDateTime, getShortTime, getShortTimeElapsed, getTime, isLogFnParamsCtx, log, newestFirstByCreatedAt, oldestFirstByCreatedAt, prettifyMessage, secondsToTime, toTwoDigits, unixTimestamp, unixTimestampAtUtc, unixTimestampWithMillis, unixTimestampWithMillisAtUtc, useDebounce };
135
+ export { DAY, HOUR, type JsonObject, type JsonPrimitive, type JsonValue, type LogFnParams, type LogFnParamsBase, type LogFnParamsCtx, LogLevel, type Logger, type LoggerConfig, MINUTE, MONTH, type Message, type MessageContext, SECOND, WEEK, YEAR, buildLogger, buildSerializeMessage, defaultLogger, errorAsContext, formatAgentVersion, formatBps, formatBytes, formatCapitalizeFirstLetter, formatCapitalizeWords, formatDate, formatDateISOInTimezone, formatFirmwareVersion, formatIntTemperature, formatLastSeen, formatMaxLength, formatPlatform, formatPrettyDate, formatRobotName, formatSlug, formatTemperature, formatUptime, formatUsbPort, getDateWithTimezone, getDistance, getShortDate, getShortDateOrDistance, getShortDateTime, getShortTime, getShortTimeElapsed, getTime, isLogFnParamsCtx, log, newestFirstByCreatedAt, oldestFirstByCreatedAt, parseJson, prettifyMessage, replaceRefs, replaceRefsInJsonSchema, resolveReference, secondsToTime, serializeToJson, serializeToJsonOrThrow, toTwoDigits, unixTimestamp, unixTimestampAtUtc, unixTimestampWithMillis, unixTimestampWithMillisAtUtc, useDebounce };
package/dist/index.js CHANGED
@@ -1584,6 +1584,54 @@ function oldestFirstByCreatedAt(a, b) {
1584
1584
  return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
1585
1585
  }
1586
1586
 
1587
+ // src/utils/json.ts
1588
+ import { stringify } from "safe-stable-stringify";
1589
+ var serializeToJson = stringify;
1590
+ var serializeToJsonOrThrow = (data) => {
1591
+ const serialized = serializeToJson(data);
1592
+ if (serialized !== void 0) {
1593
+ return serialized;
1594
+ }
1595
+ throw new Error("Failed to serialize!");
1596
+ };
1597
+ var parseJson = (value) => JSON.parse(value);
1598
+ var resolveReference = (jsonSchema, ref) => {
1599
+ const path = ref.substring(2).split("/");
1600
+ return path.reduce((schema, key) => {
1601
+ if (schema && typeof schema === "object" && !Array.isArray(schema)) {
1602
+ return schema[key];
1603
+ }
1604
+ return void 0;
1605
+ }, jsonSchema);
1606
+ };
1607
+ var replaceRefs = (schema, jsonSchema) => {
1608
+ if (typeof schema === "object" && schema !== null) {
1609
+ if (Array.isArray(schema)) {
1610
+ for (let index = 0; index < schema.length; index += 1) {
1611
+ const item = schema[index];
1612
+ if (item && typeof item === "object") {
1613
+ schema[index] = replaceRefs(item, jsonSchema);
1614
+ }
1615
+ }
1616
+ return schema;
1617
+ }
1618
+ for (const key in schema) {
1619
+ const value = schema[key];
1620
+ if (value && typeof value === "object") {
1621
+ if ("$ref" in value) {
1622
+ schema[key] = resolveReference(jsonSchema, String(value.$ref)) ?? value;
1623
+ } else {
1624
+ schema[key] = replaceRefs(value, jsonSchema);
1625
+ }
1626
+ }
1627
+ }
1628
+ }
1629
+ return schema;
1630
+ };
1631
+ var replaceRefsInJsonSchema = (jsonSchema) => {
1632
+ return replaceRefs(jsonSchema, jsonSchema);
1633
+ };
1634
+
1587
1635
  // src/hooks/use-debounce.ts
1588
1636
  var import_react = __toESM(require_react(), 1);
1589
1637
  var useDebounce = (props) => {
@@ -1828,7 +1876,7 @@ function formatSlug(value) {
1828
1876
 
1829
1877
  // src/logger.ts
1830
1878
  import chalk from "chalk";
1831
- import { stringify } from "safe-stable-stringify";
1879
+ import { stringify as stringify2 } from "safe-stable-stringify";
1832
1880
  import { serializeError } from "serialize-error";
1833
1881
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1834
1882
  LogLevel2[LogLevel2["trace"] = 10] = "trace";
@@ -1887,7 +1935,7 @@ function colorize(level) {
1887
1935
  return { color: chalk.gray, bgcolor: chalk.bgGray.black };
1888
1936
  }
1889
1937
  function customStringify(data, useSpaces = true) {
1890
- return stringify(
1938
+ return stringify2(
1891
1939
  data,
1892
1940
  (_key, value) => {
1893
1941
  if (typeof Buffer !== "undefined" && value instanceof Buffer) {
@@ -2114,9 +2162,15 @@ export {
2114
2162
  log,
2115
2163
  newestFirstByCreatedAt,
2116
2164
  oldestFirstByCreatedAt,
2165
+ parseJson,
2117
2166
  prettifyMessage,
2167
+ replaceRefs,
2168
+ replaceRefsInJsonSchema,
2169
+ resolveReference,
2118
2170
  secondsToTime,
2119
2171
  serializeError,
2172
+ serializeToJson,
2173
+ serializeToJsonOrThrow,
2120
2174
  toTwoDigits,
2121
2175
  unixTimestamp,
2122
2176
  unixTimestampAtUtc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/ui-utils",
3
- "version": "0.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "UI utilities library for Luxonis projects",
5
5
  "author": "Luxonis Corp",
6
6
  "license": "UNLICENSED",