Skip to content

Commit 54204bc

Browse files
committed
Enum -> singleton.
1 parent 9973a77 commit 54204bc

File tree

28 files changed

+2002
-3519
lines changed

28 files changed

+2002
-3519
lines changed

index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "react-native-get-random-values";
2-
export { AbsentSyncableStateEnum } from "./react-native/types/AbsentSyncableStateEnum";
2+
export { AbsentSyncableStateSingleton } from "./react-native/types/AbsentSyncableStateSingleton";
33
export { Aligned } from "./react-native/components/Aligned";
44
export { AwaitingPullSyncableStateCollectionItem } from "./react-native/types/AwaitingPullSyncableStateCollectionItem";
55
export { AwaitingPushSyncableStateCollectionItem } from "./react-native/types/AwaitingPushSyncableStateCollectionItem";
@@ -92,7 +92,7 @@ export { PictureHelperInterface } from "./react-native/types/PictureHelperInterf
9292
export { PreflightResponse } from "./react-native/types/PreflightResponse";
9393
export { PreflightResponseCollection } from "./react-native/types/PreflightResponseCollection";
9494
export { PreflightResponseCollectionItem } from "./react-native/types/PreflightResponseCollectionItem";
95-
export { PreflightResponseEnum } from "./react-native/types/PreflightResponseEnum";
95+
export { PreflightResponseSingleton } from "./react-native/types/PreflightResponseSingleton";
9696
export { PushingSyncableStateCollectionItem } from "./react-native/types/PushingSyncableStateCollectionItem";
9797
export { QueryParameter } from "./react-native/types/QueryParameter";
9898
export { QueryParameters } from "./react-native/types/QueryParameters";
@@ -124,7 +124,7 @@ export { SyncableSchema } from "./react-native/types/SyncableSchema";
124124
export { SyncableState } from "./react-native/types/SyncableState";
125125
export { SyncableStateCollection } from "./react-native/types/SyncableStateCollection";
126126
export { SyncableStateCollectionItem } from "./react-native/types/SyncableStateCollectionItem";
127-
export { SyncableStateEnum } from "./react-native/types/SyncableStateEnum";
127+
export { SyncableStateSingleton } from "./react-native/types/SyncableStateSingleton";
128128
export { SyncableStateHelper } from "./react-native/services/SyncableStateHelper";
129129
export { SyncConfiguration } from "./react-native/types/SyncConfiguration";
130130
export { SyncConfigurationCollection } from "./react-native/types/SyncConfigurationCollection";
@@ -143,7 +143,7 @@ export { UnderlinedTopTabBarStyle } from "./react-native/types/UnderlinedTopTabB
143143
export { UnderlinedTopTabBarStyleState } from "./react-native/types/UnderlinedTopTabBarStyleState";
144144
export { unwrapRenderedFunctionComponent } from "./react-native/utilities/unwrapRenderedFunctionComponent";
145145
export { UpToDateSyncableStateCollectionItem } from "./react-native/types/UpToDateSyncableStateCollectionItem";
146-
export { UpToDateSyncableStateEnum } from "./react-native/types/UpToDateSyncableStateEnum";
146+
export { UpToDateSyncableStateSingleton } from "./react-native/types/UpToDateSyncableStateSingleton";
147147
export { useBackButton } from "./react-native/hooks/useBackButton";
148148
export { useEventRefresh } from "./react-native/hooks/useEventRefresh";
149149
export { useMeasure } from "./react-native/hooks/useMeasure";

react-native/services/Sync/index.tsx

+42-37
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import type { SyncConfigurationCollection } from "../../types/SyncConfigurationC
1616
import type { FileStoreInterface } from "../../types/FileStoreInterface";
1717
import type { SyncState } from "../../types/SyncState";
1818
import type { SyncInterface } from "../../types/SyncInterface";
19-
import type { PreflightResponseEnum, SyncableStateEnum } from "../../..";
19+
import type { SyncableStateSingleton } from "../../types/SyncableStateSingleton";
20+
import type { PreflightResponseSingleton } from "../../types/PreflightResponseSingleton";
2021

2122
const camelCaseToKebabCase = (camelCase: string): string =>
2223
camelCase.replace(/([A-Z])/g, `-$1`).toLowerCase();
@@ -510,7 +511,7 @@ export class Sync<
510511
execute(): Promise<boolean>;
511512
}
512513
| {
513-
readonly type: `enum`;
514+
readonly type: `singleton`;
514515
readonly beforeLogMessage: string;
515516
execute(): Promise<boolean>;
516517
}
@@ -522,68 +523,70 @@ export class Sync<
522523

523524
for (const step of this.syncConfiguration.order) {
524525
switch (step.type) {
525-
case `enum`: {
526-
const stateEnum = state.enums[
526+
case `singleton`: {
527+
const stateSingleton = state.singletons[
527528
step.key
528-
] as SyncableStateEnum<Json>;
529+
] as SyncableStateSingleton<Json>;
529530

530-
const preflightEnum = preflightResponse.value.enums[
531+
const preflightSingleton = preflightResponse.value.singletons[
531532
step.key
532-
] as PreflightResponseEnum;
533+
] as PreflightResponseSingleton;
533534

534-
const kebabCasedEnumKey = camelCaseToKebabCase(step.key);
535+
const kebabCasedSingletonKey = camelCaseToKebabCase(step.key);
535536

536-
switch (stateEnum.type) {
537+
switch (stateSingleton.type) {
537538
case `absent`:
538539
this.logger.information(
539-
`New enum "${step.key}" will be pulled.`
540+
`New singleton "${step.key}" will be pulled.`
540541
);
541542

542543
pulls.push({
543-
type: `enum`,
544-
beforeLogMessage: `Pulling enum "${step.key}"...`,
544+
type: `singleton`,
545+
beforeLogMessage: `Pulling singleton "${step.key}"...`,
545546
execute: async () => {
546547
const response = await this.request.returningJson<{
547548
"200": SyncPullResponse<Json>;
548549
}>(
549550
`GET`,
550-
`sync/${kebabCasedEnumKey}`,
551+
`sync/${kebabCasedSingletonKey}`,
551552
{ type: `empty` },
552553
{},
553554
abortSignal,
554555
[`200`]
555556
);
556-
if (response.value.version === preflightEnum.version) {
557+
if (
558+
response.value.version === preflightSingleton.version
559+
) {
557560
if (this.stateStore.get() === state) {
558561
state = {
559562
...state,
560-
enums: {
561-
...state.enums,
563+
singletons: {
564+
...state.singletons,
562565
[step.key]: {
563566
type: `upToDate`,
564-
version: preflightEnum.version,
565-
values: response.value.data,
567+
version: preflightSingleton.version,
568+
value: response.value.data,
566569
},
567570
},
568571
};
569572

570573
this.stateStore.set(state);
571574

572575
this.logger.information(
573-
`Successfully pulled new enum "${step.key}".`
576+
`Successfully pulled new singleton "${step.key}".`
574577
);
575578

576579
return true;
577580
} else {
578581
this.logger.warning(
579-
`The state store changed during pull of enum "${step.key}"; sync has been interrupted and will need to run again.`
582+
`The state store changed during pull of singleton "${step.key}"; sync has been interrupted and will need to run again.`
580583
);
581584

582585
return false;
583586
}
584587
} else {
585588
this.logger.warning(
586-
`The version of enum "${step.key}" changed from "${preflightEnum.version}" at the time of preflight to "${response.value.version}" at the time of pull; sync has been interrupted and will need to run again.`
589+
`The version of singleton "${step.key}" changed from "${preflightSingleton.version}" at the time of preflight to "${response.value.version}" at the time of pull; sync has been interrupted and will need to run again.`
587590
);
588591

589592
return false;
@@ -593,60 +596,62 @@ export class Sync<
593596
break;
594597

595598
case `upToDate`:
596-
if (preflightEnum.version === stateEnum.version) {
599+
if (preflightSingleton.version === stateSingleton.version) {
597600
this.logger.debug(
598-
`No pull required of enum "${step.key}" as preflight and state store versions match ("${preflightEnum.version}").`
601+
`No pull required of singleton "${step.key}" as preflight and state store versions match ("${preflightSingleton.version}").`
599602
);
600603
} else {
601604
this.logger.information(
602-
`Previously pulled enum "${step.key}" will be pulled again as versions do not match between preflight ("${preflightEnum.version}") and state store ("${stateEnum.version}").`
605+
`Previously pulled singleton "${step.key}" will be pulled again as versions do not match between preflight ("${preflightSingleton.version}") and state store ("${stateSingleton.version}").`
603606
);
604607

605608
pulls.push({
606-
type: `enum`,
607-
beforeLogMessage: `Pulling enum "${step.key}"...`,
609+
type: `singleton`,
610+
beforeLogMessage: `Pulling singleton "${step.key}"...`,
608611
execute: async () => {
609612
const response = await this.request.returningJson<{
610613
"200": SyncPullResponse<Json>;
611614
}>(
612615
`GET`,
613-
`sync/${kebabCasedEnumKey}`,
616+
`sync/${kebabCasedSingletonKey}`,
614617
{ type: `empty` },
615618
{},
616619
abortSignal,
617620
[`200`]
618621
);
619-
if (response.value.version === preflightEnum.version) {
622+
if (
623+
response.value.version === preflightSingleton.version
624+
) {
620625
if (this.stateStore.get() === state) {
621626
state = {
622627
...state,
623-
enums: {
624-
...state.enums,
628+
singletons: {
629+
...state.singletons,
625630
[step.key]: {
626631
type: `upToDate`,
627-
version: preflightEnum.version,
628-
values: response.value.data,
632+
version: preflightSingleton.version,
633+
value: response.value.data,
629634
},
630635
},
631636
};
632637

633638
this.stateStore.set(state);
634639

635640
this.logger.information(
636-
`Successfully pulled update of enum "${step.key}".`
641+
`Successfully pulled update of singleton "${step.key}".`
637642
);
638643

639644
return true;
640645
} else {
641646
this.logger.warning(
642-
`The state store changed during pull of enum "${step.key}"; sync has been interrupted and will need to run again.`
647+
`The state store changed during pull of singleton "${step.key}"; sync has been interrupted and will need to run again.`
643648
);
644649

645650
return false;
646651
}
647652
} else {
648653
this.logger.warning(
649-
`The version of enum "${step.key}" changed from "${preflightEnum.version}" at the time of preflight to "${response.value.version}" at the time of pull; sync has been interrupted and will need to run again.`
654+
`The version of singleton "${step.key}" changed from "${preflightSingleton.version}" at the time of preflight to "${response.value.version}" at the time of pull; sync has been interrupted and will need to run again.`
650655
);
651656

652657
return false;
@@ -983,9 +988,9 @@ export class Sync<
983988
this.logger.information(pull.beforeLogMessage);
984989

985990
switch (pull.type) {
986-
case `enum`:
991+
case `singleton`:
987992
this.setState({
988-
type: `pullingEnum`,
993+
type: `pullingSingleton`,
989994
completedSteps: completedPulls,
990995
totalSteps: pulls.length,
991996
});

0 commit comments

Comments
 (0)