Skip to content

Commit 74783d9

Browse files
committed
[types] Local enums minify correctly
1 parent 3c76486 commit 74783d9

File tree

16 files changed

+82
-69
lines changed

16 files changed

+82
-69
lines changed

src/persisters/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
Persister,
1212
PersisterListener,
1313
PersisterStats,
14-
Persists as PersistsType,
14+
Persists as PersistsEnum,
1515
} from '../@types/persisters/index.d.ts';
1616
import {arrayClear, arrayPush, arrayShift} from '../common/array.ts';
1717
import {
@@ -24,10 +24,16 @@ import {mapEnsure, mapGet, mapNew, mapSet} from '../common/map.ts';
2424
import {objFreeze, objIsEmpty} from '../common/obj.ts';
2525
import type {Id} from '../@types/common/index.d.ts';
2626

27+
const enum PersistsValues {
28+
StoreOnly = 1,
29+
MergeableStoreOnly = 2,
30+
StoreOrMergeableStore = 3,
31+
}
32+
2733
export const Persists = {
28-
StoreOnly: 1,
29-
MergeableStoreOnly: 2,
30-
StoreOrMergeableStore: 3,
34+
StoreOnly: PersistsValues.StoreOnly,
35+
MergeableStoreOnly: PersistsValues.MergeableStoreOnly,
36+
StoreOrMergeableStore: PersistsValues.StoreOrMergeableStore,
3137
};
3238

3339
type Action = () => Promise<any>;
@@ -36,7 +42,7 @@ const scheduleRunning: Map<any, 0 | 1> = mapNew();
3642
const scheduleActions: Map<any, Action[]> = mapNew();
3743

3844
const getStoreFunctions = (
39-
persist: PersistsType = Persists.StoreOnly,
45+
persist: PersistsEnum | any = PersistsValues.StoreOnly,
4046
store: PersistedStore<typeof persist>,
4147
):
4248
| [
@@ -53,7 +59,7 @@ const getStoreFunctions = (
5359
hasChanges: (changes: MergeableChanges) => boolean,
5460
setDefaultContent: (content: Content) => MergeableStore,
5561
] =>
56-
persist != Persists.StoreOnly && store.isMergeable()
62+
persist != PersistsValues.StoreOnly && store.isMergeable()
5763
? [
5864
1,
5965
(store as MergeableStore).getMergeableContent,
@@ -62,7 +68,7 @@ const getStoreFunctions = (
6268
!objIsEmpty(changedTables) || !objIsEmpty(changedValues),
6369
(store as MergeableStore).setDefaultContent,
6470
]
65-
: persist != Persists.MergeableStoreOnly
71+
: persist != PersistsValues.MergeableStoreOnly
6672
? [
6773
0,
6874
store.getContent,
@@ -75,7 +81,7 @@ const getStoreFunctions = (
7581

7682
export const createCustomPersister = <
7783
ListeningHandle,
78-
Persist extends PersistsType = PersistsType.StoreOnly,
84+
Persist extends PersistsEnum = PersistsEnum.StoreOnly,
7985
>(
8086
store: PersistedStore<Persist>,
8187
getPersisted: () => Promise<PersistedContent<Persist> | undefined>,

src/persisters/persister-automerge/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
objSize,
1414
objToArray,
1515
} from '../../common/obj.ts';
16-
import {Persists, createCustomPersister} from '../index.ts';
1716
import {ifNotUndefined, isUndefined} from '../../common/other.ts';
1817
import {DocHandle} from '@automerge/automerge-repo';
1918
import type {Id} from '../../@types/common/index.d.ts';
2019
import type {PersisterListener} from '../../@types/persisters/index.d.ts';
2120
import {TINYBASE} from '../../common/strings.ts';
21+
import {createCustomPersister} from '../index.ts';
2222

2323
type Observer = ({doc}: {doc: any}) => void;
2424

@@ -170,7 +170,7 @@ export const createAutomergePersister = ((
170170
addPersisterListener,
171171
delPersisterListener,
172172
onIgnoredError,
173-
Persists.StoreOnly,
173+
1, // StoreOnly,
174174
{getDocHandle: () => docHandle},
175175
) as AutomergePersister;
176176
}) as typeof createAutomergePersisterDecl;

src/persisters/persister-browser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
PersisterListener,
1111
Persists as PersistsType,
1212
} from '../../@types/persisters/index.d.ts';
13-
import {Persists, createCustomPersister} from '../index.ts';
1413
import {
1514
jsonParse,
1615
jsonParseWithUndefined,
@@ -19,6 +18,7 @@ import {
1918
import type {MergeableStore} from '../../@types/mergeable-store/index.d.ts';
2019
import type {Store} from '../../@types/store/index.d.ts';
2120
import {WINDOW} from '../../common/other.ts';
21+
import {createCustomPersister} from '../index.ts';
2222

2323
type StorageListener = (event: StorageEvent) => void;
2424
const STORAGE = 'storage';
@@ -64,7 +64,7 @@ const createStoragePersister = (
6464
addPersisterListener,
6565
delPersisterListener,
6666
onIgnoredError,
67-
Persists.StoreOrMergeableStore,
67+
3, // StoreOrMergeableStore,
6868
{getStorageName: () => storageName},
6969
);
7070
};

src/persisters/persister-cr-sqlite-wasm/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import {DB} from '@vlcn.io/crsqlite-wasm';
1010
import type {DatabasePersisterConfig} from '../../@types/persisters/index.d.ts';
1111
import {IdObj} from '../../common/obj.ts';
12-
import {Persists} from '../index.ts';
1312
import type {Store} from '../../@types/store/index.d.ts';
1413

1514
export const createCrSqliteWasmPersister = ((
@@ -29,6 +28,6 @@ export const createCrSqliteWasmPersister = ((
2928
(removeListener: () => void): void => removeListener(),
3029
onSqlCommand,
3130
onIgnoredError,
32-
Persists.StoreOnly,
31+
1, // StoreOnly,
3332
db,
3433
) as CrSqliteWasmPersister) as typeof createCrSqliteWasmPersisterDecl;

src/persisters/persister-electric-sql/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import type {DatabasePersisterConfig} from '../../@types/persisters/index.d.ts';
1010
import type {ElectricClient} from 'electric-sql/client/model';
1111
import {IdObj} from '../../common/obj.ts';
12-
import {Persists} from '../index.ts';
1312
import type {Store} from '../../@types/store/index.d.ts';
1413
import type {UnsubscribeFunction} from 'electric-sql/notifiers';
1514
import {arrayForEach} from '../../common/array.ts';
@@ -36,7 +35,7 @@ export const createElectricSqlPersister = ((
3635
(unsubscribeFunction: UnsubscribeFunction): any => unsubscribeFunction(),
3736
onSqlCommand,
3837
onIgnoredError,
39-
Persists.StoreOnly,
38+
1, // StoreOnly,
4039
electricClient,
4140
'getElectricClient',
4241
) as ElectricSqlPersister) as typeof createElectricSqlPersisterDecl;

src/persisters/persister-expo-sqlite/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import type {DatabasePersisterConfig} from '../../@types/persisters/index.d.ts';
1010
import {IdObj} from '../../common/obj.ts';
1111
import type {MergeableStore} from '../../@types/mergeable-store/index.d.ts';
12-
import {Persists} from '../index.ts';
1312
import type {SQLiteDatabase} from 'expo-sqlite';
1413
import type {Store} from '../../@types/store/index.d.ts';
1514
import {addDatabaseChangeListener} from 'expo-sqlite';
@@ -33,6 +32,6 @@ export const createExpoSqlitePersister = ((
3332
(subscription: Subscription) => subscription.remove(),
3433
onSqlCommand,
3534
onIgnoredError,
36-
Persists.StoreOrMergeableStore,
35+
3, // StoreOrMergeableStore,
3736
db,
3837
) as ExpoSqlitePersister) as typeof createExpoSqlitePersisterDecl;

src/persisters/persister-file/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import type {
99
PersisterListener,
1010
Persists as PersistsType,
1111
} from '../../@types/persisters/index.d.ts';
12-
import {Persists, createCustomPersister} from '../index.ts';
1312
import {
1413
jsonParseWithUndefined,
1514
jsonStringWithUndefined,
1615
} from '../../common/json.ts';
1716
import {readFile, writeFile} from 'fs/promises';
1817
import type {MergeableStore} from '../../@types/mergeable-store/index.d.ts';
1918
import type {Store} from '../../@types/store/index.d.ts';
19+
import {createCustomPersister} from '../index.ts';
2020

2121
export const createFilePersister = ((
2222
store: Store | MergeableStore,
@@ -50,7 +50,7 @@ export const createFilePersister = ((
5050
addPersisterListener,
5151
delPersisterListener,
5252
onIgnoredError,
53-
Persists.StoreOrMergeableStore,
53+
3, // StoreOrMergeableStore,
5454
{getFilePath: () => filePath},
5555
) as FilePersister;
5656
}) as typeof createFilePersisterDecl;

src/persisters/persister-indexed-db/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
IndexedDbPersister,
55
createIndexedDbPersister as createIndexedDbPersisterDecl,
66
} from '../../@types/persisters/persister-indexed-db/index.d.ts';
7-
import {Persists, createCustomPersister} from '../index.ts';
87
import {T, V} from '../../common/strings.ts';
98
import {
109
WINDOW,
@@ -16,6 +15,7 @@ import {
1615
import {arrayMap, arrayPush} from '../../common/array.ts';
1716
import type {Id} from '../../@types/common/index.d.ts';
1817
import type {PersisterListener} from '../../@types/persisters/index.d.ts';
18+
import {createCustomPersister} from '../index.ts';
1919

2020
const OBJECT_STORE_NAMES = [T, V];
2121
const KEY_PATH = {keyPath: 'k'};
@@ -126,7 +126,7 @@ export const createIndexedDbPersister = ((
126126
addPersisterListener,
127127
delPersisterListener,
128128
onIgnoredError,
129-
Persists.StoreOnly,
129+
1, // StoreOnly,
130130
{getDbName: () => dbName},
131131
) as IndexedDbPersister;
132132
}) as typeof createIndexedDbPersisterDecl;

src/persisters/persister-libsql/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
import {Client} from '@libsql/client';
66
import type {DatabasePersisterConfig} from '../../@types/persisters/index.d.ts';
77
import {IdObj} from '../../common/obj.ts';
8-
import {Persists} from '../index.ts';
98
import type {Store} from '../../@types/store/index.d.ts';
109
import type {UnsubscribeFunction} from 'electric-sql/notifiers';
1110
import {createSqlitePersister} from '../common/sqlite/create.ts';
@@ -26,7 +25,7 @@ export const createLibSqlPersister = ((
2625
(unsubscribeFunction: UnsubscribeFunction): any => unsubscribeFunction(),
2726
onSqlCommand,
2827
onIgnoredError,
29-
Persists.StoreOnly,
28+
1, // StoreOnly,
3029
client,
3130
'getClient',
3231
) as LibSqlPersister) as typeof createLibSqlPersisterDecl;

src/persisters/persister-partykit-client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import type {
1111
PartyKitPersisterConfig,
1212
createPartyKitPersister as createPartyKitPersisterDecl,
1313
} from '../../@types/persisters/persister-partykit-client/index.d.ts';
14-
import {Persists, createCustomPersister} from '../index.ts';
1514
import {ifNotUndefined, isString} from '../../common/other.ts';
1615
import {EMPTY_STRING} from '../../common/strings.ts';
1716
import type {PartySocket} from 'partysocket';
1817
import type {PersisterListener} from '../../@types/persisters/index.d.ts';
18+
import {createCustomPersister} from '../index.ts';
1919
import {jsonStringWithMap} from '../../common/json.ts';
2020

2121
type MessageListener = (event: MessageEvent) => void;
@@ -97,7 +97,7 @@ export const createPartyKitPersister = ((
9797
addPersisterListener,
9898
delPersisterListener,
9999
onIgnoredError,
100-
Persists.StoreOnly,
100+
1, // StoreOnly,
101101
{getConnection: () => connection},
102102
) as PartyKitPersister;
103103
}) as typeof createPartyKitPersisterDecl;

0 commit comments

Comments
 (0)