@ic-reactor/candid 3.0.13-beta.0 → 3.0.14-beta.1

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.
@@ -30,27 +30,36 @@ const CYCLE_KEYS_REGEX = new RegExp(
30
30
  "i"
31
31
  )
32
32
 
33
- const EMAIL_KEYS_REGEX = /email|mail/i
34
- const PHONE_KEYS_REGEX = /phone|tel|mobile/i
35
- const URL_KEYS_REGEX = /url|link|website/i
36
- const UUID_KEYS_REGEX = /uuid|guid/i
37
- const BITCOIN_KEYS_REGEX = /bitcoin|btc/i
38
- const ETHEREUM_KEYS_REGEX = /ethereum|eth/i
39
33
  const ACCOUNT_ID_KEYS_REGEX =
40
- /account_id|account_identifier|ledger_account|block_hash|transaction_hash|tx_hash/i
41
- const PRINCIPAL_KEYS_REGEX = /canister|principal/i
34
+ /account_identifier|ledger_account|block_hash|transaction_hash|tx_hash/i
35
+
36
+ const tokenize = (label: string): Set<string> => {
37
+ const parts = label
38
+ .replace(/_/g, " ")
39
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
40
+ .toLowerCase()
41
+ .split(/[\s-]+/)
42
+ return new Set(parts)
43
+ }
42
44
 
43
45
  export const checkTextFormat = (label?: string): TextFormat => {
44
46
  if (!label) return "plain"
47
+
45
48
  if (TAMESTAMP_KEYS_REGEX.test(label)) return "timestamp"
46
- if (EMAIL_KEYS_REGEX.test(label)) return "email"
47
- if (PHONE_KEYS_REGEX.test(label)) return "phone"
48
- if (URL_KEYS_REGEX.test(label)) return "url"
49
- if (UUID_KEYS_REGEX.test(label)) return "uuid"
50
- if (BITCOIN_KEYS_REGEX.test(label)) return "btc"
51
- if (ETHEREUM_KEYS_REGEX.test(label)) return "eth"
52
49
  if (ACCOUNT_ID_KEYS_REGEX.test(label)) return "account-id"
53
- if (PRINCIPAL_KEYS_REGEX.test(label)) return "principal"
50
+
51
+ const tokens = tokenize(label)
52
+
53
+ if (tokens.has("email") || tokens.has("mail")) return "email"
54
+ if (tokens.has("phone") || tokens.has("tel") || tokens.has("mobile"))
55
+ return "phone"
56
+ if (tokens.has("url") || tokens.has("link") || tokens.has("website"))
57
+ return "url"
58
+ if (tokens.has("uuid") || tokens.has("guid")) return "uuid"
59
+ if (tokens.has("btc") || tokens.has("bitcoin")) return "btc"
60
+ if (tokens.has("eth") || tokens.has("ethereum")) return "eth"
61
+ if (tokens.has("principal") || tokens.has("canister")) return "principal"
62
+
54
63
  return "plain"
55
64
  }
56
65
 
@@ -58,7 +58,7 @@ describe("ResultFieldVisitor", () => {
58
58
  const ethField = visitor.visitText(IDL.Text, "ethereum_address")
59
59
  expect(ethField.format).toBe("eth")
60
60
 
61
- const accountIdField = visitor.visitText(IDL.Text, "account_id")
61
+ const accountIdField = visitor.visitText(IDL.Text, "account_identifier")
62
62
  expect(accountIdField.format).toBe("account-id")
63
63
 
64
64
  const principalField = visitor.visitText(IDL.Text, "canister_id")
@@ -4,25 +4,15 @@ import type {
4
4
  FunctionType,
5
5
  ActorMethodReturnType,
6
6
  } from "@ic-reactor/core"
7
+ import type { VisitorDataType, TextFormat, NumberFormat } from "../types"
8
+
9
+ export type { TextFormat, NumberFormat }
7
10
 
8
11
  // ════════════════════════════════════════════════════════════════════════════
9
12
  // Core Types & Formats
10
13
  // ════════════════════════════════════════════════════════════════════════════
11
14
 
12
- export type NodeType =
13
- | "record"
14
- | "variant"
15
- | "tuple"
16
- | "optional"
17
- | "vector"
18
- | "blob"
19
- | "recursive"
20
- | "principal"
21
- | "number"
22
- | "text"
23
- | "boolean"
24
- | "null"
25
- | "unknown"
15
+ export type NodeType = VisitorDataType
26
16
 
27
17
  export type DisplayType =
28
18
  | "string"
@@ -38,19 +28,6 @@ export type DisplayType =
38
28
  | "blob"
39
29
  | "unknown"
40
30
 
41
- export type NumberFormat = "timestamp" | "cycle" | "value" | "token" | "normal"
42
- export type TextFormat =
43
- | "plain"
44
- | "timestamp"
45
- | "uuid"
46
- | "url"
47
- | "email"
48
- | "phone"
49
- | "btc"
50
- | "eth"
51
- | "account-id"
52
- | "principal"
53
-
54
31
  // ════════════════════════════════════════════════════════════════════════════
55
32
  // Unified Result Node - Single Structure for Schema & Resolved Data
56
33
  // ════════════════════════════════════════════════════════════════════════════
@@ -26,3 +26,48 @@ export type AllNumberTypes =
26
26
  | IDL.FixedNatClass
27
27
  | IDL.FixedIntClass
28
28
  | IDL.FloatClass
29
+
30
+ // ════════════════════════════════════════════════════════════════════════════
31
+ // Shared Types for Visitors (Arguments & Returns)
32
+ // ════════════════════════════════════════════════════════════════════════════
33
+
34
+ /**
35
+ * The core Candid type category used across visitors.
36
+ */
37
+ export type VisitorDataType =
38
+ | "record"
39
+ | "variant"
40
+ | "tuple"
41
+ | "optional"
42
+ | "vector"
43
+ | "blob"
44
+ | "recursive"
45
+ | "principal"
46
+ | "number"
47
+ | "text"
48
+ | "boolean"
49
+ | "null"
50
+ | "unknown"
51
+
52
+ /**
53
+ * Detected format for text fields based on label heuristics.
54
+ * Used to provide format-specific validation and display.
55
+ */
56
+ export type TextFormat =
57
+ | "plain"
58
+ | "timestamp"
59
+ | "uuid"
60
+ | "url"
61
+ | "email"
62
+ | "phone"
63
+ | "btc"
64
+ | "eth"
65
+ | "account-id"
66
+ | "principal"
67
+ | "cycle"
68
+
69
+ /**
70
+ * Detected format for number fields based on label heuristics.
71
+ * Used to provide format-specific validation and display.
72
+ */
73
+ export type NumberFormat = "timestamp" | "cycle" | "value" | "token" | "normal"