@voilabs/oilang 0.0.6 → 0.0.7

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.
@@ -0,0 +1,55 @@
1
+ import { Client, type ClientConfig } from "pg";
2
+ import { LocaleData, TranslationData } from "../types";
3
+ type ActionResponse<T> = {
4
+ success: true;
5
+ data: T;
6
+ } | {
7
+ success: false;
8
+ error: any;
9
+ };
10
+ declare class Locales {
11
+ private schema;
12
+ private client;
13
+ constructor(schema: string, client: Client);
14
+ list(): Promise<ActionResponse<LocaleData[]>>;
15
+ create(locale: string, nativeName: string, englishName: string): Promise<ActionResponse<LocaleData>>;
16
+ delete(locale: string): Promise<ActionResponse<{
17
+ code: string;
18
+ }>>;
19
+ update(locale: string, nativeName: string, englishName: string): Promise<ActionResponse<LocaleData>>;
20
+ }
21
+ declare class Translations {
22
+ private schema;
23
+ private client;
24
+ private localesSchema;
25
+ constructor(schema: string, client: Client, localesSchema: string);
26
+ list(): Promise<ActionResponse<TranslationData[]>>;
27
+ create(key: string, value: string, locale: string): Promise<ActionResponse<TranslationData>>;
28
+ delete(key: string, locale: string): Promise<ActionResponse<{
29
+ locale_id: string;
30
+ key: string;
31
+ }>>;
32
+ update(key: string, value: string, locale: string): Promise<ActionResponse<TranslationData>>;
33
+ }
34
+ export declare class PostgreSQL {
35
+ private config;
36
+ client: Client;
37
+ schemaNames: {
38
+ keys: string;
39
+ locales: string;
40
+ };
41
+ locales: Locales;
42
+ translations: Translations;
43
+ constructor(config: string | ClientConfig | undefined, customizationConfig: {
44
+ schemaNames: {
45
+ keys: string;
46
+ locales: string;
47
+ };
48
+ });
49
+ connect(): Promise<void>;
50
+ getSchemaNames(): {
51
+ keys: string;
52
+ locales: string;
53
+ };
54
+ }
55
+ export {};
@@ -0,0 +1,5 @@
1
+ export { OILang } from "./oilang";
2
+ export { PostgreSQL } from "./adapters/PostgreSQL";
3
+ export { MemoryStore } from "./stores/MemoryStore";
4
+ export { RedisStore } from "./stores/RedisStore";
5
+ export * from "./types";
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export { OILang } from "./oilang";
2
2
  export { PostgreSQL } from "./adapters/PostgreSQL";
3
3
  export { MemoryStore } from "./stores/MemoryStore";
4
4
  export { RedisStore } from "./stores/RedisStore";
5
+ export * from "./types";
@@ -0,0 +1,72 @@
1
+ import type { MemoryStore } from "./stores/MemoryStore";
2
+ import type { PostgreSQL } from "./adapters/PostgreSQL";
3
+ import type { RedisStore } from "./stores/RedisStore";
4
+ import { LocaleData, TranslationData } from "./types";
5
+ type AdapterConfig = {
6
+ database: InstanceType<typeof PostgreSQL>;
7
+ store: InstanceType<typeof MemoryStore> | InstanceType<typeof RedisStore>;
8
+ fallbackLocale?: string;
9
+ };
10
+ type ActionResponse<T> = {
11
+ error: Error & {
12
+ code?: string;
13
+ };
14
+ data: null;
15
+ } | {
16
+ error: null;
17
+ data: T;
18
+ };
19
+ declare class Locale {
20
+ private database;
21
+ private store;
22
+ constructor(database: AdapterConfig["database"], store: AdapterConfig["store"]);
23
+ list(): Promise<{
24
+ error: null;
25
+ data: any[] | Record<string, string>;
26
+ }>;
27
+ create(locale: string, nativeName: string, englishName: string): Promise<ActionResponse<LocaleData>>;
28
+ delete(locale: string): Promise<{
29
+ error: null;
30
+ data: {
31
+ code: string;
32
+ };
33
+ } | {
34
+ error: any;
35
+ data: null;
36
+ }>;
37
+ update(locale: string, nativeName: string, englishName: string): Promise<ActionResponse<LocaleData>>;
38
+ }
39
+ declare class Translation {
40
+ private database;
41
+ private store;
42
+ private fallbackLocale?;
43
+ constructor(database: AdapterConfig["database"], store: AdapterConfig["store"], fallbackLocale?: string);
44
+ list(locale: string): Promise<any[] | Record<string, string>>;
45
+ create(locale: string, config: {
46
+ key: string;
47
+ value: string;
48
+ }): Promise<ActionResponse<TranslationData>>;
49
+ update(locale: string, key: string, newValue: string): Promise<ActionResponse<TranslationData>>;
50
+ delete(locale: string, key: string): Promise<{
51
+ error: null;
52
+ data: {
53
+ locale_id: string;
54
+ key: string;
55
+ };
56
+ } | {
57
+ error: any;
58
+ data: null;
59
+ }>;
60
+ translate(locale: string, key: string, variables?: Record<string, string | number>): Promise<string>;
61
+ }
62
+ export declare class OILang {
63
+ private config;
64
+ private database;
65
+ private store;
66
+ private fallbackLocale;
67
+ locales: Locale;
68
+ translations: Translation;
69
+ constructor(config: AdapterConfig);
70
+ init(): Promise<void>;
71
+ }
72
+ export {};
@@ -0,0 +1,65 @@
1
+ export declare class MemoryStore {
2
+ private translations;
3
+ private locales;
4
+ load(locales: Array<{
5
+ code: string;
6
+ native_name: string;
7
+ english_name: string;
8
+ }>, translations: Record<string, Record<string, string>>): Promise<void>;
9
+ set(config: {
10
+ seed: "translations";
11
+ locale: string;
12
+ key: string;
13
+ value: string;
14
+ } | {
15
+ seed: "locales";
16
+ locale: {
17
+ code: string;
18
+ native_name: string;
19
+ english_name: string;
20
+ };
21
+ }): Promise<void>;
22
+ get(config: {
23
+ seed: "locales";
24
+ code: string;
25
+ } | {
26
+ seed: "translations";
27
+ locale: string;
28
+ key: string;
29
+ }): Promise<string | {
30
+ code: string;
31
+ native_name: string;
32
+ english_name: string;
33
+ } | undefined>;
34
+ getAll(config: {
35
+ seed: "locales";
36
+ } | {
37
+ seed: "translations";
38
+ locale: string;
39
+ }): Promise<Record<string, string> | {
40
+ code: string;
41
+ native_name: string;
42
+ english_name: string;
43
+ }[]>;
44
+ remove(config: {
45
+ seed: "translations";
46
+ locale: string;
47
+ key: string;
48
+ } | {
49
+ seed: "locales";
50
+ locale: string;
51
+ }): Promise<void>;
52
+ update(config: {
53
+ seed: "translations";
54
+ locale: string;
55
+ key: string;
56
+ value: string;
57
+ } | {
58
+ seed: "locales";
59
+ code: string;
60
+ locale: {
61
+ native_name: string;
62
+ english_name: string;
63
+ };
64
+ }): Promise<true | void>;
65
+ }
@@ -0,0 +1,61 @@
1
+ export declare class RedisStore {
2
+ private options?;
3
+ private client;
4
+ constructor(connectionString?: string, options?: {
5
+ prefix?: string;
6
+ } | undefined);
7
+ private get prefix();
8
+ load(locales: Array<{
9
+ code: string;
10
+ native_name: string;
11
+ english_name: string;
12
+ }>, translations: Record<string, Record<string, string>>): Promise<void>;
13
+ set(config: {
14
+ seed: "translations";
15
+ locale: string;
16
+ key: string;
17
+ value: string;
18
+ } | {
19
+ seed: "locales";
20
+ locale: {
21
+ code: string;
22
+ native_name: string;
23
+ english_name: string;
24
+ };
25
+ }): Promise<void>;
26
+ get(config: {
27
+ seed: "locales";
28
+ code: string;
29
+ } | {
30
+ seed: "translations";
31
+ locale: string;
32
+ key: string;
33
+ }): Promise<any>;
34
+ getAll(config: {
35
+ seed: "locales";
36
+ } | {
37
+ seed: "translations";
38
+ locale: string;
39
+ }): Promise<any[] | Record<string, string>>;
40
+ remove(config: {
41
+ seed: "translations";
42
+ locale: string;
43
+ key: string;
44
+ } | {
45
+ seed: "locales";
46
+ locale: string;
47
+ }): Promise<void>;
48
+ update(config: {
49
+ seed: "translations";
50
+ locale: string;
51
+ key: string;
52
+ value: string;
53
+ } | {
54
+ seed: "locales";
55
+ code: string;
56
+ locale: {
57
+ native_name: string;
58
+ english_name: string;
59
+ };
60
+ }): Promise<true | void>;
61
+ }
@@ -0,0 +1,12 @@
1
+ export interface LocaleData {
2
+ code: string;
3
+ native_name: string;
4
+ english_name: string;
5
+ created_at?: string;
6
+ updated_at?: string;
7
+ }
8
+ export interface TranslationData {
9
+ locale_id: string;
10
+ key: string;
11
+ value: string;
12
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@voilabs/oilang",
3
3
  "description": "A robust internationalization (i18n) handling library designed for performance and flexibility.",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {