@plyaz/types 1.3.2 → 1.3.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.
Files changed (49) hide show
  1. package/dist/api/index.d.ts +1 -0
  2. package/dist/api/types.d.ts +84 -0
  3. package/dist/auth/enums.d.ts +32 -0
  4. package/dist/auth/index.d.ts +3 -0
  5. package/dist/auth/schemas.d.ts +27 -0
  6. package/dist/auth/types.d.ts +34 -0
  7. package/dist/common/index.d.ts +2 -0
  8. package/dist/common/types.d.ts +22 -0
  9. package/dist/entities/index.d.ts +1 -0
  10. package/dist/errors/enums.d.ts +33 -0
  11. package/dist/errors/index.d.ts +2 -0
  12. package/dist/errors/types.d.ts +79 -0
  13. package/dist/events/enums.d.ts +25 -0
  14. package/dist/events/index.d.ts +3 -0
  15. package/dist/events/payload.d.ts +6 -0
  16. package/dist/events/types.d.ts +136 -0
  17. package/dist/features/cache/index.d.ts +1 -0
  18. package/dist/features/cache/types.d.ts +142 -0
  19. package/dist/features/feature-flag/index.d.ts +1 -0
  20. package/dist/features/feature-flag/types.d.ts +491 -0
  21. package/dist/features/index.d.ts +2 -0
  22. package/dist/index.d.ts +12 -0
  23. package/dist/store/index.d.ts +1 -0
  24. package/dist/testing/common/assertions/index.d.ts +1 -0
  25. package/dist/testing/common/assertions/types.d.ts +137 -0
  26. package/dist/testing/common/factories/index.d.ts +1 -0
  27. package/dist/testing/common/factories/types.d.ts +701 -0
  28. package/dist/testing/common/index.d.ts +6 -0
  29. package/dist/testing/common/mocks/index.d.ts +1 -0
  30. package/dist/testing/common/mocks/types.d.ts +1662 -0
  31. package/dist/testing/common/patterns/index.d.ts +1 -0
  32. package/dist/testing/common/patterns/types.d.ts +397 -0
  33. package/dist/testing/common/utils/index.d.ts +1 -0
  34. package/dist/testing/common/utils/types.d.ts +1970 -0
  35. package/dist/testing/common/wrappers/index.d.ts +1 -0
  36. package/dist/testing/common/wrappers/types.d.ts +373 -0
  37. package/dist/testing/features/cache/index.d.ts +1 -0
  38. package/dist/testing/features/cache/types.d.ts +43 -0
  39. package/dist/testing/features/feature-flags/index.d.ts +1 -0
  40. package/dist/testing/features/feature-flags/types.d.ts +1133 -0
  41. package/dist/testing/features/index.d.ts +2 -0
  42. package/dist/testing/index.d.ts +2 -0
  43. package/dist/translations/index.d.ts +1 -0
  44. package/dist/translations/types.d.ts +390 -0
  45. package/dist/ui/index.d.ts +1 -0
  46. package/dist/web3/enums.d.ts +17 -0
  47. package/dist/web3/index.d.ts +2 -0
  48. package/dist/web3/types.d.ts +63 -0
  49. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ export type * from './cache';
2
+ export type * from './feature-flags';
@@ -0,0 +1,2 @@
1
+ export type * from './common';
2
+ export type * from './features';
@@ -0,0 +1 @@
1
+ export type * from './types';
@@ -0,0 +1,390 @@
1
+ /**
2
+ * Translation leaf type.
3
+ * @description This type represents the structure of a translation leaf.
4
+ * @example
5
+ * const leaf: TranslationLeaf = 'Hello';
6
+ */
7
+ export type TranslationLeaf = string | TranslationResourcesNested;
8
+ /**
9
+ * Translation resources nested type.
10
+ * @description This type represents the structure of a translation resources nested.
11
+ * @example
12
+ * const nested: TranslationResourcesNested = {
13
+ * hello: 'Hello',
14
+ * };
15
+ */
16
+ export interface TranslationResourcesNested {
17
+ [key: string]: TranslationLeaf;
18
+ }
19
+ /**
20
+ * Translation resources type.
21
+ * @description This type represents the structure of translation resources.
22
+ * @example
23
+ * const resources: TranslationResources = {
24
+ * en: {
25
+ * common: {
26
+ * hello: 'Hello',
27
+ * },
28
+ * },
29
+ * };
30
+ */
31
+ export type TranslationResources = Record<string, // language code
32
+ Record<string, // namespace
33
+ TranslationResourcesNested>>;
34
+ /**
35
+ * All translation namespaces available in the 'en' language resources.
36
+ * @example 'common', 'errors', etc.
37
+ */
38
+ export type Namespace<Resources extends TranslationResources> = keyof Resources['en'];
39
+ /**
40
+ * Helper type to remove the first element from a tuple type.
41
+ * Used internally by LeafPaths to track recursion depth.
42
+ */
43
+ type PrevTuple<T extends readonly unknown[]> = T extends [unknown, ...infer R] ? R : [];
44
+ /**
45
+ * Recursively extracts all nested keys from an object, creating dot-notation paths.
46
+ * @description This utility type traverses nested objects and creates dot-separated key paths.
47
+ * It uses a depth counter to prevent infinite recursion (max 25 levels, which should be sufficient
48
+ * for most translation structures while avoiding TypeScript compiler limits).
49
+ * @example
50
+ * type Paths = LeafPaths<{ a: { b: string, c: { d: string } } }>;
51
+ * // Result: 'a.b' | 'a.c.d'
52
+ * @template T - The object type to extract paths from
53
+ * @template Prev - The accumulated path string (used internally)
54
+ * @template Depth - Tuple type used to track recursion depth and prevent infinite loops
55
+ */
56
+ export type LeafPaths<T, Prev extends string = '', Depth extends readonly unknown[] = [
57
+ 1,
58
+ 1,
59
+ 1,
60
+ 1,
61
+ 1,
62
+ 1,
63
+ 1,
64
+ 1,
65
+ 1,
66
+ 1,
67
+ 1,
68
+ 1,
69
+ 1,
70
+ 1,
71
+ 1,
72
+ 1,
73
+ 1,
74
+ 1,
75
+ 1,
76
+ 1,
77
+ 1,
78
+ 1,
79
+ 1,
80
+ 1,
81
+ 1
82
+ ]> = Depth['length'] extends 0 ? never : T extends string ? Prev : T extends object ? {
83
+ [K in keyof T]: LeafPaths<T[K], Prev extends '' ? Extract<K, string> : `${Prev}.${Extract<K, string>}`, PrevTuple<Depth>>;
84
+ }[keyof T] : never;
85
+ /**
86
+ * Type-safe union of all translation keys in the form 'namespace.key' or 'namespace.nested.key'.
87
+ * @description This type generates a union of all possible translation keys by combining
88
+ * namespace names with their nested key paths. It ensures type safety when accessing translations.
89
+ * @example 'common.hello', 'common.greeting', 'common.followers.zero', etc.
90
+ * @example use: TranslationKeys<TranslationResources, 'en'>
91
+ */
92
+ export type TranslationKeys<Resources extends TranslationResources, Lang extends keyof Resources = 'en'> = {
93
+ [N in keyof Resources[Lang]]: `${Extract<N, string>}.${LeafPaths<Resources[Lang][N]>}`;
94
+ }[keyof Resources[Lang]];
95
+ /**
96
+ * All supported language codes, as defined in the resources object.
97
+ * @example 'en', 'es', 'fr', etc.
98
+ */
99
+ export type SupportedLanguage = 'en' | 'es' | 'fr' | 'it' | 'pt-PT' | 'pt-BR';
100
+ /**
101
+ * Configuration options for the translation system.
102
+ */
103
+ export interface TranslationConfig {
104
+ /**
105
+ * The default locale to fall back to when translations are missing
106
+ */
107
+ readonly defaultLocale: SupportedLanguage;
108
+ /**
109
+ * Array of locales supported by the application
110
+ */
111
+ readonly supportedLocales: readonly SupportedLanguage[];
112
+ /**
113
+ * Optional locale to use if translation is missing in the current locale
114
+ */
115
+ readonly fallbackLocale?: SupportedLanguage;
116
+ /**
117
+ * Settings for extracting translation keys from source code
118
+ */
119
+ readonly extraction?: {
120
+ /**
121
+ * File patterns to search for translation keys
122
+ */
123
+ readonly patterns: readonly string[];
124
+ /**
125
+ * Function names that should be treated as translation functions
126
+ */
127
+ readonly functions: readonly string[];
128
+ /**
129
+ * Component names that should be treated as translation components
130
+ */
131
+ readonly components: readonly string[];
132
+ /**
133
+ * Directory where extracted translation files should be saved
134
+ */
135
+ readonly outputDir: string;
136
+ /**
137
+ * Whether to split extracted translations by namespace into separate files
138
+ */
139
+ readonly shouldSplitByNamespace: boolean;
140
+ };
141
+ /**
142
+ * Optional list of translation namespaces to load
143
+ */
144
+ readonly namespaces?: readonly string[];
145
+ /**
146
+ * Interpolation settings for variable replacement in translations
147
+ */
148
+ readonly interpolation?: {
149
+ /**
150
+ * Whether to escape interpolation values to prevent XSS attacks
151
+ */
152
+ readonly shouldEscapeValue?: boolean;
153
+ /**
154
+ * Prefix for interpolation variables (default: '{{')
155
+ */
156
+ readonly prefix?: string;
157
+ /**
158
+ * Suffix for interpolation variables (default: '}}')
159
+ */
160
+ readonly suffix?: string;
161
+ };
162
+ /**
163
+ * Loading strategy for translations
164
+ */
165
+ readonly loading?: {
166
+ /**
167
+ * Whether to load all translations at once ('eager') or on-demand ('lazy')
168
+ */
169
+ readonly strategy: 'lazy' | 'eager';
170
+ /**
171
+ * Whether to use fallback locale when translation is missing
172
+ */
173
+ readonly shouldUseFallback?: boolean;
174
+ };
175
+ /**
176
+ * Validation settings for translation keys
177
+ */
178
+ readonly validation?: {
179
+ /**
180
+ * Whether to throw errors for missing translation keys (strict mode)
181
+ */
182
+ readonly isStrict?: boolean;
183
+ /**
184
+ * Whether to show warnings for missing translation keys
185
+ */
186
+ readonly shouldWarnOnMissingKeys?: boolean;
187
+ };
188
+ }
189
+ /**
190
+ * Represents a translation key, including namespace, key, defaultValue, and interpolation options.
191
+ */
192
+ export interface TranslationKey {
193
+ /**
194
+ * The namespace this translation key belongs to (e.g., 'common', 'errors')
195
+ */
196
+ readonly namespace: string;
197
+ /**
198
+ * The specific translation key within the namespace (e.g., 'hello', 'notFound')
199
+ */
200
+ readonly key: string;
201
+ /**
202
+ * Default value to use if translation is missing
203
+ */
204
+ readonly defaultValue?: string;
205
+ /**
206
+ * Interpolation variables to replace in the translation
207
+ */
208
+ readonly interpolation?: Record<string, string>;
209
+ }
210
+ /**
211
+ * Options for translation functions, including default value, interpolation args, locale override, and fallback flag.
212
+ */
213
+ export interface TranslationOptions {
214
+ /**
215
+ * Default value to use if translation is missing
216
+ */
217
+ readonly defaultValue?: string;
218
+ /**
219
+ * Arguments to interpolate into the translation string
220
+ */
221
+ readonly args?: Record<string, string>;
222
+ /**
223
+ * Interpolation variables to replace in the translation
224
+ */
225
+ readonly interpolation?: Record<string, string>;
226
+ /**
227
+ * Override the current locale for this translation
228
+ */
229
+ readonly lang?: string;
230
+ /**
231
+ * Whether to use fallback locale if translation is missing
232
+ */
233
+ readonly shouldUseFallback?: boolean;
234
+ }
235
+ /**
236
+ * Defines methods available on translation service implementations.
237
+ */
238
+ export interface Translator {
239
+ /**
240
+ * Translate a key to the current locale
241
+ */
242
+ readonly t: (key: TranslationKeys<TranslationResources>, options?: TranslationOptions) => string;
243
+ /**
244
+ * Translate a key within a specific namespace
245
+ */
246
+ readonly tNamespace: (namespace: string, key: TranslationKeys<TranslationResources>, options?: TranslationOptions) => string;
247
+ /**
248
+ * Change the current locale
249
+ */
250
+ readonly changeLocale: (locale: SupportedLanguage) => void;
251
+ /**
252
+ * Get the current locale
253
+ */
254
+ readonly getCurrentLocale: () => string;
255
+ /**
256
+ * Check if a translation key exists for the given locale
257
+ */
258
+ readonly hasTranslation: (key: string, locale?: string) => boolean;
259
+ /**
260
+ * Add a new namespace with translations
261
+ */
262
+ readonly addNamespace: (namespace: string, translations: Record<string, string>) => void;
263
+ }
264
+ /**
265
+ * Command-line interface options for extracting translation keys from source code.
266
+ * @description These types define the configuration options for the CLI tool that
267
+ * automatically extracts translation keys from source files and generates translation files.
268
+ */
269
+ export interface ExtractOptions {
270
+ /**
271
+ * File pattern to search for translation keys
272
+ */
273
+ readonly pattern: string;
274
+ /**
275
+ * Output directory for extracted translation files
276
+ */
277
+ readonly output: string;
278
+ /**
279
+ * Whether to split extracted translations by namespace
280
+ */
281
+ readonly shouldSplitByNamespace: boolean;
282
+ /**
283
+ * Whether to update existing translation files
284
+ */
285
+ readonly shouldUpdate: boolean;
286
+ /**
287
+ * Whether to perform a dry run without writing files
288
+ */
289
+ readonly shouldDryRun: boolean;
290
+ }
291
+ /**
292
+ * Pluralization test cases for validating translation pluralization rules.
293
+ * @description These types define the structure for testing pluralization functionality
294
+ * across different languages, ensuring correct plural forms are used based on numeric values.
295
+ */
296
+ /**
297
+ * Represents a single test case for pluralization validation.
298
+ * @description Defines a numeric value and its expected translation string
299
+ * to test pluralization rules in different languages.
300
+ */
301
+ export interface PluralizationValueCase {
302
+ /**
303
+ * The numeric value to test pluralization against
304
+ */
305
+ readonly value: number;
306
+ /**
307
+ * The expected translation string for this value
308
+ */
309
+ readonly expected: string;
310
+ }
311
+ /**
312
+ * Represents a complete set of pluralization test cases for a specific language.
313
+ * @description Groups multiple pluralization value cases together for a single language,
314
+ * allowing comprehensive testing of pluralization rules across different numeric values.
315
+ */
316
+ export interface PluralizationCase {
317
+ /**
318
+ * The language code for this pluralization case
319
+ */
320
+ readonly lang: SupportedLanguage;
321
+ /**
322
+ * Array of value cases to test pluralization rules
323
+ */
324
+ readonly values: readonly PluralizationValueCase[];
325
+ }
326
+ /**
327
+ * Date formatting test cases for validating locale-specific date formatting.
328
+ * @description These types define the structure for testing date formatting functionality
329
+ * across different languages and locales.
330
+ */
331
+ /**
332
+ * Represents a test case for date formatting validation.
333
+ * @description Defines a language and its expected formatted date string
334
+ * to test date formatting rules in different locales.
335
+ */
336
+ export interface DateCase {
337
+ /**
338
+ * The language code for this date formatting case
339
+ */
340
+ readonly lang: SupportedLanguage;
341
+ /**
342
+ * The expected formatted date string
343
+ */
344
+ readonly expected: string;
345
+ }
346
+ /**
347
+ * Number formatting test cases for validating locale-specific number formatting.
348
+ * @description These types define the structure for testing number formatting functionality
349
+ * across different languages and locales.
350
+ */
351
+ /**
352
+ * Represents a test case for number formatting validation.
353
+ * @description Defines a language and its expected formatted number string
354
+ * to test number formatting rules in different locales.
355
+ */
356
+ export interface NumberCase {
357
+ /**
358
+ * The language code for this number formatting case
359
+ */
360
+ readonly lang: SupportedLanguage;
361
+ /**
362
+ * The expected formatted number string
363
+ */
364
+ readonly expected: string;
365
+ }
366
+ /**
367
+ * Currency formatting test cases for validating locale-specific currency formatting.
368
+ * @description These types define the structure for testing currency formatting functionality
369
+ * across different languages and locales, including currency symbols and formatting options.
370
+ */
371
+ /**
372
+ * Represents a test case for currency formatting validation.
373
+ * @description Defines a language, expected formatted currency string, and formatting options
374
+ * to test currency formatting rules in different locales.
375
+ */
376
+ export interface CurrencyCase {
377
+ /**
378
+ * The language code for this currency formatting case
379
+ */
380
+ readonly lang: SupportedLanguage;
381
+ /**
382
+ * The expected formatted currency string
383
+ */
384
+ readonly expected: string;
385
+ /**
386
+ * NumberFormat options for currency formatting
387
+ */
388
+ readonly options: Intl.NumberFormatOptions;
389
+ }
390
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Enum representing supported EVM-compatible blockchain networks by their numeric chain IDs.
3
+ * @description These IDs are used to identify the specific network when interacting with wallets or smart contracts.
4
+ * @see https://chainlist.org for reference chain IDs
5
+ */
6
+ export declare const CHAIN_ID: {
7
+ readonly EthereumMainnet: 1;
8
+ readonly EthereumSepolia: 11155111;
9
+ readonly Optimism: 10;
10
+ readonly OptimismSepolia: 11155420;
11
+ readonly Arbitrum: 42161;
12
+ readonly ArbitrumSepolia: 421614;
13
+ readonly Polygon: 137;
14
+ readonly PolygonAmoy: 80002;
15
+ readonly Base: 8453;
16
+ readonly BaseSepolia: 84532;
17
+ };
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export type * from './types';
@@ -0,0 +1,63 @@
1
+ import type { CHAIN_ID } from './enums';
2
+ /**
3
+ * Defines the configuration structure for an EVM-compatible blockchain network.
4
+ * @description This is commonly used for wallet integration, chain switching, and displaying metadata such as currency and explorer links.
5
+ */
6
+ export interface NetworkConfig {
7
+ /**
8
+ * Numeric chain ID of the blockchain network.
9
+ * @description Should match the value from {@link typeof CHAIN_ID}.
10
+ * @example 137 // Polygon Mainnet
11
+ */
12
+ readonly chainId: typeof CHAIN_ID;
13
+ /**
14
+ * @description Full name of the network.
15
+ * @example "Polygon"
16
+ */
17
+ readonly name: string;
18
+ /**
19
+ * @description Short, user-friendly name for display purposes.
20
+ * @example "MATIC"
21
+ */
22
+ readonly shortName: string;
23
+ /**
24
+ * Native currency used on the network for fees and balances.
25
+ */
26
+ readonly nativeCurrency: {
27
+ /**
28
+ * @description Full name of the native currency.
29
+ * @example "Matic"
30
+ */
31
+ readonly name: string;
32
+ /**
33
+ * @description Symbol of the currency used in wallet UIs.
34
+ * @example "MATIC"
35
+ */
36
+ readonly symbol: string;
37
+ /**
38
+ * @description Number of decimal places used by the currency.
39
+ * @example 18
40
+ */
41
+ readonly decimals: number;
42
+ };
43
+ /**
44
+ * @description List of public RPC endpoints used to communicate with the blockchain.
45
+ * @example ["https://polygon-rpc.com"]
46
+ */
47
+ readonly rpcUrls: readonly string[];
48
+ /**
49
+ * @description List of block explorer base URLs for viewing transactions and contracts.
50
+ * @example ["https://polygonscan.com"]
51
+ */
52
+ readonly blockExplorerUrls: readonly string[];
53
+ /**
54
+ * @description Optional icon URL for the network, used in UIs.
55
+ * @example "https://example.com/icons/polygon.svg"
56
+ */
57
+ readonly iconUrl?: string;
58
+ /**
59
+ * @description Flag indicating if the network is a testnet.
60
+ * @example true
61
+ */
62
+ readonly isTestnet: boolean;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",
@@ -105,7 +105,7 @@
105
105
  "scripts": {
106
106
  "build": "pnpm clean && pnpm build:js && pnpm build:types",
107
107
  "build:js": "tsup",
108
- "build:types": "tsc -p tsconfig.build.json",
108
+ "build:types": "tsc src/index.ts --emitDeclarationOnly --esModuleInterop --outDir dist --declaration --skipLibCheck",
109
109
  "build:watch": "tsup --watch",
110
110
  "dev": "tsup --watch",
111
111
  "lint": "eslint ./src",