@fabriktor/fx 0.0.24 → 0.0.26
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/src/fx.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
1
|
+
import type { PreferencesOperator, TmpPhonesOperator, TmpUsernamesOperator, UsersOperator } from "@fabriktor/client";
|
|
2
2
|
import type { AuthOperator } from "./auth/auth.js";
|
|
3
|
+
import type { PreferencesFX, PreferencesFXOperator } from "./preferences/preferences.js";
|
|
3
4
|
import type { SessionFX, SessionFXOperator } from "./session/session.js";
|
|
4
5
|
import type { UsersFX, UsersFXOperator } from "./users/users.js";
|
|
5
6
|
export type FXOptions = {
|
|
@@ -7,6 +8,7 @@ export type FXOptions = {
|
|
|
7
8
|
users: UsersOperator;
|
|
8
9
|
tmp_usernames: TmpUsernamesOperator;
|
|
9
10
|
tmp_phones: TmpPhonesOperator;
|
|
11
|
+
preferences: PreferencesOperator;
|
|
10
12
|
};
|
|
11
13
|
export type DefaultFXOptions = {
|
|
12
14
|
base_url: string;
|
|
@@ -15,10 +17,12 @@ export type DefaultFXOptions = {
|
|
|
15
17
|
export interface FXOperator {
|
|
16
18
|
users: UsersFXOperator;
|
|
17
19
|
session: SessionFXOperator;
|
|
20
|
+
preferences: PreferencesFXOperator;
|
|
18
21
|
}
|
|
19
22
|
export declare class FX implements FXOperator {
|
|
20
23
|
users: UsersFX;
|
|
21
24
|
session: SessionFX;
|
|
25
|
+
preferences: PreferencesFX;
|
|
22
26
|
constructor(opts: FXOptions);
|
|
23
27
|
}
|
|
24
28
|
export declare function newFX(opts: FXOptions): FX;
|
package/dist/src/fx.js
CHANGED
|
@@ -3,18 +3,23 @@
|
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
4
|
// not use this file except in compliance with the License. You may obtain
|
|
5
5
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
import { newHTTPClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
6
|
+
import { newHTTPClient, newPreferencesClient, newTmpPhonesClient, newTmpUsernamesClient, newUsersClient, } from "@fabriktor/client";
|
|
7
|
+
import { newPreferencesFX } from "./preferences/preferences.js";
|
|
7
8
|
import { newSessionFX } from "./session/session.js";
|
|
8
9
|
import { newUsersFX } from "./users/users.js";
|
|
9
10
|
export class FX {
|
|
10
11
|
users;
|
|
11
12
|
session;
|
|
13
|
+
preferences;
|
|
12
14
|
constructor(opts) {
|
|
13
15
|
this.users = newUsersFX({
|
|
14
16
|
users: opts.users,
|
|
15
17
|
tmp_usernames: opts.tmp_usernames,
|
|
16
18
|
tmp_phones: opts.tmp_phones,
|
|
17
19
|
});
|
|
20
|
+
this.preferences = newPreferencesFX({
|
|
21
|
+
preferences: opts.preferences,
|
|
22
|
+
});
|
|
18
23
|
this.session = newSessionFX({
|
|
19
24
|
auth: opts.auth,
|
|
20
25
|
users: this.users,
|
|
@@ -26,22 +31,28 @@ export function newFX(opts) {
|
|
|
26
31
|
}
|
|
27
32
|
export function newDefaultFX(opts) {
|
|
28
33
|
const http = newHTTPClient();
|
|
34
|
+
const get_token = () => opts.auth.getToken();
|
|
29
35
|
return newFX({
|
|
30
36
|
auth: opts.auth,
|
|
31
37
|
users: newUsersClient({
|
|
32
38
|
http,
|
|
33
39
|
base_url: opts.base_url,
|
|
34
|
-
get_token
|
|
40
|
+
get_token,
|
|
35
41
|
}),
|
|
36
42
|
tmp_usernames: newTmpUsernamesClient({
|
|
37
43
|
http,
|
|
38
44
|
base_url: opts.base_url,
|
|
39
|
-
get_token
|
|
45
|
+
get_token,
|
|
40
46
|
}),
|
|
41
47
|
tmp_phones: newTmpPhonesClient({
|
|
42
48
|
http,
|
|
43
49
|
base_url: opts.base_url,
|
|
44
|
-
get_token
|
|
50
|
+
get_token,
|
|
51
|
+
}),
|
|
52
|
+
preferences: newPreferencesClient({
|
|
53
|
+
http,
|
|
54
|
+
base_url: opts.base_url,
|
|
55
|
+
get_token,
|
|
45
56
|
}),
|
|
46
57
|
});
|
|
47
58
|
}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type InPrefLanguage, type OperationResult, type PrefLanguage } from "@fabriktor/schema";
|
|
2
|
+
import type { InsertOneOptionsCRUD, OperationResultOf, PreferencesOperator, QueryOptionsCRUD, ReplaceOneOptionsCRUD } from "@fabriktor/client";
|
|
3
|
+
export type EnsurePrefLanguageOptions = {
|
|
4
|
+
owner_id: string;
|
|
5
|
+
language: string;
|
|
6
|
+
country: string;
|
|
7
|
+
speech_to_text_source_language?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface PreferencesFXOperator {
|
|
10
|
+
queryPrefLanguages(opts?: QueryOptionsCRUD): Promise<OperationResultOf<PrefLanguage[]>>;
|
|
11
|
+
insertOnePrefLanguage(opts: InsertOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
12
|
+
replaceOnePrefLanguage(opts: ReplaceOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
13
|
+
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
14
|
+
}
|
|
15
|
+
export type PreferencesFXOptions = {
|
|
16
|
+
preferences: PreferencesOperator;
|
|
17
|
+
};
|
|
18
|
+
export declare class PreferencesFX implements PreferencesFXOperator {
|
|
19
|
+
private preferences;
|
|
20
|
+
constructor(opts: PreferencesFXOptions);
|
|
21
|
+
queryPrefLanguages(opts?: QueryOptionsCRUD): Promise<OperationResultOf<PrefLanguage[]>>;
|
|
22
|
+
insertOnePrefLanguage(opts: InsertOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
23
|
+
replaceOnePrefLanguage(opts: ReplaceOneOptionsCRUD<InPrefLanguage>): Promise<OperationResult>;
|
|
24
|
+
ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
|
|
25
|
+
}
|
|
26
|
+
export declare function newPreferencesFX(opts: PreferencesFXOptions): PreferencesFX;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
import { OperationResultValueKey, } from "@fabriktor/schema";
|
|
7
|
+
export class PreferencesFX {
|
|
8
|
+
preferences;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.preferences = opts.preferences;
|
|
11
|
+
}
|
|
12
|
+
async queryPrefLanguages(opts) {
|
|
13
|
+
return await this.preferences.queryPrefLanguages(opts);
|
|
14
|
+
}
|
|
15
|
+
async insertOnePrefLanguage(opts) {
|
|
16
|
+
return await this.preferences.insertOnePrefLanguage(opts);
|
|
17
|
+
}
|
|
18
|
+
async replaceOnePrefLanguage(opts) {
|
|
19
|
+
return await this.preferences.replaceOnePrefLanguage(opts);
|
|
20
|
+
}
|
|
21
|
+
async ensurePrefLanguage(opts) {
|
|
22
|
+
const out = await this.preferences.queryPrefLanguages({
|
|
23
|
+
query: {
|
|
24
|
+
owner_id: opts.owner_id,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const prefs = out[OperationResultValueKey] ?? [];
|
|
28
|
+
const pref = prefs[0];
|
|
29
|
+
const input = {
|
|
30
|
+
is_default: false,
|
|
31
|
+
language: opts.language,
|
|
32
|
+
country: opts.country,
|
|
33
|
+
speech_to_text_source_language: opts.speech_to_text_source_language ?? opts.language,
|
|
34
|
+
};
|
|
35
|
+
if (!pref || pref.is_default) {
|
|
36
|
+
return await this.preferences.insertOnePrefLanguage({
|
|
37
|
+
in: input,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (pref.language === input.language &&
|
|
41
|
+
pref.country === input.country &&
|
|
42
|
+
pref.speech_to_text_source_language ===
|
|
43
|
+
input.speech_to_text_source_language) {
|
|
44
|
+
return {
|
|
45
|
+
id: pref.id,
|
|
46
|
+
value: pref,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return await this.preferences.replaceOnePrefLanguage({
|
|
50
|
+
id: pref.id,
|
|
51
|
+
in: input,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function newPreferencesFX(opts) {
|
|
56
|
+
return new PreferencesFX(opts);
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/client": "^0.0.
|
|
21
|
-
"@fabriktor/schema": "^0.0.
|
|
20
|
+
"@fabriktor/client": "^0.0.21",
|
|
21
|
+
"@fabriktor/schema": "^0.0.15"
|
|
22
22
|
}
|
|
23
23
|
}
|