Consider using --force-message for ts/protobuf.bzl (#1694)
* Use --force-message in ts/protobuf * Remove some now unnecessary type assertions in deck-options/lib * Satisfy formatter
This commit is contained in:
parent
3564ece6b5
commit
5963791d85
@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import Container from "../components/Container.svelte";
|
import Container from "../components/Container.svelte";
|
||||||
import Row from "../components/Row.svelte";
|
import Row from "../components/Row.svelte";
|
||||||
import type { Stats } from "../lib/proto";
|
import type { Stats } from "../lib/proto";
|
||||||
import { stats as statsService } from "../lib/proto";
|
import { Cards, stats as statsService } from "../lib/proto";
|
||||||
import CardInfoPlaceholder from "./CardInfoPlaceholder.svelte";
|
import CardInfoPlaceholder from "./CardInfoPlaceholder.svelte";
|
||||||
import CardStats from "./CardStats.svelte";
|
import CardStats from "./CardStats.svelte";
|
||||||
import Revlog from "./Revlog.svelte";
|
import Revlog from "./Revlog.svelte";
|
||||||
@ -19,7 +19,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
async function updateStats(cardId: number): Promise<void> {
|
async function updateStats(cardId: number): Promise<void> {
|
||||||
const requestedCardId = cardId;
|
const requestedCardId = cardId;
|
||||||
const cardStats = await statsService.cardStats({ cid: requestedCardId });
|
const cardStats = await statsService.cardStats(
|
||||||
|
Cards.CardId.create({ cid: requestedCardId }),
|
||||||
|
);
|
||||||
|
|
||||||
/* Skip if another update has been triggered in the meantime. */
|
/* Skip if another update has been triggered in the meantime. */
|
||||||
if (requestedCardId === cardId) {
|
if (requestedCardId === cardId) {
|
||||||
|
@ -5,7 +5,7 @@ import "./change-notetype-base.css";
|
|||||||
|
|
||||||
import { ModuleName, setupI18n } from "../lib/i18n";
|
import { ModuleName, setupI18n } from "../lib/i18n";
|
||||||
import { checkNightMode } from "../lib/nightmode";
|
import { checkNightMode } from "../lib/nightmode";
|
||||||
import { empty, notetypes } from "../lib/proto";
|
import { empty, Notetypes, notetypes } from "../lib/proto";
|
||||||
import ChangeNotetypePage from "./ChangeNotetypePage.svelte";
|
import ChangeNotetypePage from "./ChangeNotetypePage.svelte";
|
||||||
import { ChangeNotetypeState } from "./lib";
|
import { ChangeNotetypeState } from "./lib";
|
||||||
|
|
||||||
@ -18,10 +18,12 @@ export async function setupChangeNotetypePage(
|
|||||||
oldNotetypeId: number,
|
oldNotetypeId: number,
|
||||||
newNotetypeId: number,
|
newNotetypeId: number,
|
||||||
): Promise<ChangeNotetypePage> {
|
): Promise<ChangeNotetypePage> {
|
||||||
const changeNotetypeInfo = notetypes.getChangeNotetypeInfo({
|
const changeNotetypeInfo = notetypes.getChangeNotetypeInfo(
|
||||||
oldNotetypeId,
|
Notetypes.GetChangeNotetypeInfoRequest.create({
|
||||||
newNotetypeId,
|
oldNotetypeId,
|
||||||
});
|
newNotetypeId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
const [names, info] = await Promise.all([notetypeNames, changeNotetypeInfo, i18n]);
|
const [names, info] = await Promise.all([notetypeNames, changeNotetypeInfo, i18n]);
|
||||||
|
|
||||||
checkNightMode();
|
checkNightMode();
|
||||||
|
@ -144,10 +144,12 @@ export class ChangeNotetypeState {
|
|||||||
this.info_.input().newNotetypeId = this.notetypeNames.entries[idx].id!;
|
this.info_.input().newNotetypeId = this.notetypeNames.entries[idx].id!;
|
||||||
this.notetypesSetter(this.buildNotetypeList());
|
this.notetypesSetter(this.buildNotetypeList());
|
||||||
const { oldNotetypeId, newNotetypeId } = this.info_.input();
|
const { oldNotetypeId, newNotetypeId } = this.info_.input();
|
||||||
const newInfo = await notetypes.getChangeNotetypeInfo({
|
const newInfo = await notetypes.getChangeNotetypeInfo(
|
||||||
oldNotetypeId,
|
Notetypes.GetChangeNotetypeInfoRequest.create({
|
||||||
newNotetypeId,
|
oldNotetypeId,
|
||||||
});
|
newNotetypeId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
this.info_ = new ChangeNotetypeInfoWrapper(newInfo);
|
this.info_ = new ChangeNotetypeInfoWrapper(newInfo);
|
||||||
this.info_.unusedItems(MapContext.Field);
|
this.info_.unusedItems(MapContext.Field);
|
||||||
|
@ -11,7 +11,7 @@ import "./deck-options-base.css";
|
|||||||
import { modalsKey, touchDeviceKey } from "../components/context-keys";
|
import { modalsKey, touchDeviceKey } from "../components/context-keys";
|
||||||
import { ModuleName, setupI18n } from "../lib/i18n";
|
import { ModuleName, setupI18n } from "../lib/i18n";
|
||||||
import { checkNightMode } from "../lib/nightmode";
|
import { checkNightMode } from "../lib/nightmode";
|
||||||
import { deckConfig } from "../lib/proto";
|
import { deckConfig, Decks } from "../lib/proto";
|
||||||
import DeckOptionsPage from "./DeckOptionsPage.svelte";
|
import DeckOptionsPage from "./DeckOptionsPage.svelte";
|
||||||
import { DeckOptionsState } from "./lib";
|
import { DeckOptionsState } from "./lib";
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ const i18n = setupI18n({
|
|||||||
|
|
||||||
export async function setupDeckOptions(did: number): Promise<DeckOptionsPage> {
|
export async function setupDeckOptions(did: number): Promise<DeckOptionsPage> {
|
||||||
const [info] = await Promise.all([
|
const [info] = await Promise.all([
|
||||||
deckConfig.getDeckConfigsForUpdate({ did }),
|
deckConfig.getDeckConfigsForUpdate(Decks.DeckId.create({ did })),
|
||||||
i18n,
|
i18n,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -304,12 +304,8 @@ test("aux data", () => {
|
|||||||
// ensure changes serialize
|
// ensure changes serialize
|
||||||
const out = state.dataForSaving(true);
|
const out = state.dataForSaving(true);
|
||||||
expect(out.configs!.length).toBe(2);
|
expect(out.configs!.length).toBe(2);
|
||||||
const json = out.configs!.map(
|
const json = out.configs!.map((c) =>
|
||||||
(c) =>
|
JSON.parse(new TextDecoder().decode(c.config!.other)),
|
||||||
JSON.parse(new TextDecoder().decode((c.config as any).other)) as Record<
|
|
||||||
string,
|
|
||||||
unknown
|
|
||||||
>,
|
|
||||||
);
|
);
|
||||||
expect(json).toStrictEqual([
|
expect(json).toStrictEqual([
|
||||||
// other deck comes first
|
// other deck comes first
|
||||||
|
@ -28,15 +28,14 @@ export interface ConfigListEntry {
|
|||||||
current: boolean;
|
current: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigInner = DeckConfig.DeckConfig.Config;
|
|
||||||
export class DeckOptionsState {
|
export class DeckOptionsState {
|
||||||
readonly currentConfig: Writable<ConfigInner>;
|
readonly currentConfig: Writable<DeckConfig.DeckConfig.Config>;
|
||||||
readonly currentAuxData: Writable<Record<string, unknown>>;
|
readonly currentAuxData: Writable<Record<string, unknown>>;
|
||||||
readonly configList: Readable<ConfigListEntry[]>;
|
readonly configList: Readable<ConfigListEntry[]>;
|
||||||
readonly parentLimits: Readable<ParentLimits>;
|
readonly parentLimits: Readable<ParentLimits>;
|
||||||
readonly cardStateCustomizer: Writable<string>;
|
readonly cardStateCustomizer: Writable<string>;
|
||||||
readonly currentDeck: DeckConfig.DeckConfigsForUpdate.CurrentDeck;
|
readonly currentDeck: DeckConfig.DeckConfigsForUpdate.CurrentDeck;
|
||||||
readonly defaults: ConfigInner;
|
readonly defaults: DeckConfig.DeckConfig.Config;
|
||||||
readonly addonComponents: Writable<DynamicSvelteComponent[]>;
|
readonly addonComponents: Writable<DynamicSvelteComponent[]>;
|
||||||
readonly v3Scheduler: boolean;
|
readonly v3Scheduler: boolean;
|
||||||
readonly haveAddons: boolean;
|
readonly haveAddons: boolean;
|
||||||
@ -52,11 +51,11 @@ export class DeckOptionsState {
|
|||||||
|
|
||||||
constructor(targetDeckId: number, data: DeckConfig.DeckConfigsForUpdate) {
|
constructor(targetDeckId: number, data: DeckConfig.DeckConfigsForUpdate) {
|
||||||
this.targetDeckId = targetDeckId;
|
this.targetDeckId = targetDeckId;
|
||||||
this.currentDeck =
|
this.currentDeck = data.currentDeck!;
|
||||||
data.currentDeck as DeckConfig.DeckConfigsForUpdate.CurrentDeck;
|
this.defaults = data.defaults!.config!;
|
||||||
this.defaults = data.defaults!.config! as ConfigInner;
|
|
||||||
this.configs = data.allConfig.map((config) => {
|
this.configs = data.allConfig.map((config) => {
|
||||||
const configInner = config.config as DeckConfig.DeckConfig;
|
const configInner = config.config!;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
config: configInner,
|
config: configInner,
|
||||||
useCount: config.useCount!,
|
useCount: config.useCount!,
|
||||||
@ -136,7 +135,7 @@ export class DeckOptionsState {
|
|||||||
const config = DeckConfig.DeckConfig.create({
|
const config = DeckConfig.DeckConfig.create({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: uniqueName,
|
name: uniqueName,
|
||||||
config: cloneDeep(source),
|
config: DeckConfig.DeckConfig.Config.create(cloneDeep(source)),
|
||||||
});
|
});
|
||||||
const configWithCount = { config, useCount: 0 };
|
const configWithCount = { config, useCount: 0 };
|
||||||
this.configs.push(configWithCount);
|
this.configs.push(configWithCount);
|
||||||
@ -195,10 +194,14 @@ export class DeckOptionsState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async save(applyToChildren: boolean): Promise<void> {
|
async save(applyToChildren: boolean): Promise<void> {
|
||||||
await deckConfig.updateDeckConfigs(this.dataForSaving(applyToChildren));
|
await deckConfig.updateDeckConfigs(
|
||||||
|
DeckConfig.UpdateDeckConfigsRequest.create(
|
||||||
|
this.dataForSaving(applyToChildren),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onCurrentConfigChanged(config: ConfigInner): void {
|
private onCurrentConfigChanged(config: DeckConfig.DeckConfig.Config): void {
|
||||||
const configOuter = this.configs[this.selectedIdx].config;
|
const configOuter = this.configs[this.selectedIdx].config;
|
||||||
if (!isEqual(config, configOuter.config)) {
|
if (!isEqual(config, configOuter.config)) {
|
||||||
configOuter.config = config;
|
configOuter.config = config;
|
||||||
@ -240,13 +243,13 @@ export class DeckOptionsState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a copy of the currently selected config.
|
/// Returns a copy of the currently selected config.
|
||||||
private getCurrentConfig(): ConfigInner {
|
private getCurrentConfig(): DeckConfig.DeckConfig.Config {
|
||||||
return cloneDeep(this.configs[this.selectedIdx].config.config as ConfigInner);
|
return cloneDeep(this.configs[this.selectedIdx].config.config!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extra data associated with current config (for add-ons)
|
/// Extra data associated with current config (for add-ons)
|
||||||
private getCurrentAuxData(): Record<string, unknown> {
|
private getCurrentAuxData(): Record<string, unknown> {
|
||||||
const conf = this.configs[this.selectedIdx].config.config as ConfigInner;
|
const conf = this.configs[this.selectedIdx].config.config!;
|
||||||
return bytesToObject(conf.other);
|
return bytesToObject(conf.other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,20 +290,21 @@ export class DeckOptionsState {
|
|||||||
|
|
||||||
function bytesToObject(bytes: Uint8Array): Record<string, unknown> {
|
function bytesToObject(bytes: Uint8Array): Record<string, unknown> {
|
||||||
if (!bytes.length) {
|
if (!bytes.length) {
|
||||||
return {} as Record<string, unknown>;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
let obj: Record<string, unknown>;
|
let obj: Record<string, unknown>;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(new TextDecoder().decode(bytes)) as Record<string, unknown>;
|
obj = JSON.parse(new TextDecoder().decode(bytes));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`invalid json in deck config`);
|
console.log(`invalid json in deck config`);
|
||||||
return {} as Record<string, unknown>;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.constructor !== Object) {
|
if (obj.constructor !== Object) {
|
||||||
console.log(`invalid object in deck config`);
|
console.log(`invalid object in deck config`);
|
||||||
return {} as Record<string, unknown>;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -8,7 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
import ButtonToolbar from "../../components/ButtonToolbar.svelte";
|
import ButtonToolbar from "../../components/ButtonToolbar.svelte";
|
||||||
import StickyContainer from "../../components/StickyContainer.svelte";
|
import StickyContainer from "../../components/StickyContainer.svelte";
|
||||||
import { tags as tagsService } from "../../lib/proto";
|
import { Tags, tags as tagsService } from "../../lib/proto";
|
||||||
import { execCommand } from "../helpers";
|
import { execCommand } from "../helpers";
|
||||||
import Tag from "./Tag.svelte";
|
import Tag from "./Tag.svelte";
|
||||||
import TagEditMode from "./TagEditMode.svelte";
|
import TagEditMode from "./TagEditMode.svelte";
|
||||||
@ -56,7 +56,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
let autocompleteDisabled: boolean = false;
|
let autocompleteDisabled: boolean = false;
|
||||||
|
|
||||||
async function fetchSuggestions(input: string): Promise<string[]> {
|
async function fetchSuggestions(input: string): Promise<string[]> {
|
||||||
const { tags } = await tagsService.completeTag({ input, matchLimit: 500 });
|
const { tags } = await tagsService.completeTag(
|
||||||
|
Tags.CompleteTagRequest.create({ input, matchLimit: 500 }),
|
||||||
|
);
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Writable } from "svelte/store";
|
import type { Writable } from "svelte/store";
|
||||||
|
|
||||||
import { Stats } from "../lib/proto";
|
import { empty, Stats, stats } from "../lib/proto";
|
||||||
import { empty, stats } from "../lib/proto";
|
|
||||||
import useAsync from "../sveltelib/async";
|
import useAsync from "../sveltelib/async";
|
||||||
import useAsyncReactive from "../sveltelib/asyncReactive";
|
import useAsyncReactive from "../sveltelib/asyncReactive";
|
||||||
import type { PreferenceRaw } from "../sveltelib/preferences";
|
import type { PreferenceRaw } from "../sveltelib/preferences";
|
||||||
@ -21,7 +20,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
error: graphError,
|
error: graphError,
|
||||||
value: graphValue,
|
value: graphValue,
|
||||||
} = useAsyncReactive(
|
} = useAsyncReactive(
|
||||||
() => stats.graphs({ search: $search, days: $days }),
|
() =>
|
||||||
|
stats.graphs(Stats.GraphsRequest.create({ search: $search, days: $days })),
|
||||||
[search, days],
|
[search, days],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
getPreferences(
|
getPreferences(
|
||||||
() => stats.getGraphPreferences(empty),
|
() => stats.getGraphPreferences(empty),
|
||||||
async (input: Stats.IGraphPreferences): Promise<void> => {
|
async (input: Stats.IGraphPreferences): Promise<void> => {
|
||||||
stats.setGraphPreferences(input);
|
stats.setGraphPreferences(Stats.GraphPreferences.create(input));
|
||||||
},
|
},
|
||||||
Stats.GraphPreferences.toObject.bind(Stats.GraphPreferences) as (
|
Stats.GraphPreferences.toObject.bind(Stats.GraphPreferences) as (
|
||||||
preferences: Stats.GraphPreferences,
|
preferences: Stats.GraphPreferences,
|
||||||
|
@ -5,7 +5,7 @@ import "intl-pluralrules";
|
|||||||
|
|
||||||
import { FluentBundle, FluentResource } from "@fluent/bundle";
|
import { FluentBundle, FluentResource } from "@fluent/bundle";
|
||||||
|
|
||||||
import { i18n } from "../proto";
|
import { I18n, i18n } from "../proto";
|
||||||
import { firstLanguage, setBundles } from "./bundles";
|
import { firstLanguage, setBundles } from "./bundles";
|
||||||
import type { ModuleName } from "./modules";
|
import type { ModuleName } from "./modules";
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ export function withoutUnicodeIsolation(s: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
||||||
const resources = await i18n.i18nResources(args);
|
const resources = await i18n.i18nResources(I18n.I18nResourcesRequest.create(args));
|
||||||
const json = JSON.parse(new TextDecoder().decode(resources.json));
|
const json = JSON.parse(new TextDecoder().decode(resources.json));
|
||||||
|
|
||||||
const newBundles: FluentBundle[] = [];
|
const newBundles: FluentBundle[] = [];
|
||||||
|
@ -23,7 +23,7 @@ import Tags = anki.tags;
|
|||||||
|
|
||||||
export { Cards, Collection, Decks, Generic, Notes };
|
export { Cards, Collection, Decks, Generic, Notes };
|
||||||
|
|
||||||
export const empty = Generic.Empty.encode(Generic.Empty.create()).finish();
|
export const empty = Generic.Empty.create();
|
||||||
|
|
||||||
async function serviceCallback(
|
async function serviceCallback(
|
||||||
method: rpc.ServiceMethod<Message<any>, Message<any>>,
|
method: rpc.ServiceMethod<Message<any>, Message<any>>,
|
||||||
|
@ -79,6 +79,7 @@ def protobufjs_library(name, proto, **kwargs):
|
|||||||
"--wrap=default",
|
"--wrap=default",
|
||||||
#"--strict-long", # Force usage of Long type with int64 fields
|
#"--strict-long", # Force usage of Long type with int64 fields
|
||||||
"--force-number",
|
"--force-number",
|
||||||
|
"--force-message",
|
||||||
"--out=$@",
|
"--out=$@",
|
||||||
"$(execpaths %s)" % proto_target,
|
"$(execpaths %s)" % proto_target,
|
||||||
],
|
],
|
||||||
@ -96,6 +97,7 @@ def protobufjs_library(name, proto, **kwargs):
|
|||||||
"--wrap=default",
|
"--wrap=default",
|
||||||
#"--strict-long", # Force usage of Long type with int64 fields
|
#"--strict-long", # Force usage of Long type with int64 fields
|
||||||
"--force-number",
|
"--force-number",
|
||||||
|
"--force-message",
|
||||||
"--out=$@",
|
"--out=$@",
|
||||||
"$(execpaths %s)" % proto_target,
|
"$(execpaths %s)" % proto_target,
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user