Skip to content

Commit 440b073

Browse files
committed
[hygiene] Remove more wrapped promises
1 parent d7a1ef1 commit 440b073

11 files changed

Lines changed: 69 additions & 86 deletions

File tree

gulpfile.mjs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ const lintCheckDocs = async (dir) => {
402402
});
403403
};
404404

405-
const spellCheck = async (dir, deep = false) =>
406-
await execute(`cspell "${dir}/*${deep ? '*' : ''}"`);
405+
const spellCheck = (dir, deep = false) =>
406+
execute(`cspell "${dir}/*${deep ? '*' : ''}"`);
407407

408408
const getTsOptions = async (dir) => {
409409
const {default: tsc} = await import('typescript');
@@ -701,8 +701,8 @@ export const testUnit = async () => {
701701
await test(['test/unit'], {coverageMode: 1, serialTests: true});
702702
};
703703

704-
export const testBun = async () =>
705-
await execute(
704+
export const testBun = () =>
705+
execute(
706706
'bun test ' +
707707
'test/unit/persisters/database ' +
708708
'test/unit/core/documentation.test.ts',
@@ -729,19 +729,16 @@ export const testPerf = async () => {
729729
};
730730
export const compileAndTestPerf = series(compileForTest, testPerf);
731731

732-
export const compileDocsPagesOnly = async () =>
733-
await compileDocsAndAssets(false);
732+
export const compileDocsPagesOnly = () => compileDocsAndAssets(false);
734733

735-
export const compileDocsAssetsOnly = async () =>
736-
await compileDocsAndAssets(false, false);
734+
export const compileDocsAssetsOnly = () => compileDocsAndAssets(false, false);
737735

738736
export const compileDocs = () => compileDocsAndAssets();
739737

740738
export const compileForProdAndDocs = series(compileForProd, compileDocs);
741739

742-
export const testE2e = async () => {
743-
await test(['test/e2e'], {puppeteer: true});
744-
};
740+
export const testE2e = () => test(['test/e2e'], {puppeteer: true});
741+
745742
export const compileAndTestE2e = series(compileForProdAndDocs, testE2e);
746743

747744
export const testProd = async () => {

site/js/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const thisVersion = 'v6.1.0-beta.4';
1+
export const thisVersion = 'v6.1.0-beta.4';

src/@types/ui-react/docs.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11426,9 +11426,8 @@
1142611426
* const store = useCreateStore(() =>
1142711427
* createStore().setCell('pets', 'fido', 'color', 'brown'),
1142811428
* );
11429-
* const persister = useCreatePersister(
11430-
* store,
11431-
* (store) => createSessionPersister(store, 'pets'),
11429+
* const persister = useCreatePersister(store, (store) =>
11430+
* createSessionPersister(store, 'pets'),
1143211431
* );
1143311432
* useProvidePersister('petPersister', persister);
1143411433
* return null;

src/persisters/common/database/json.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export const createJsonPersister = <
4848
upsert,
4949
);
5050

51-
const getPersisted = async (): Promise<PersistedContent<Persist>> =>
52-
await transaction(async () => {
51+
const getPersisted = (): Promise<PersistedContent<Persist>> =>
52+
transaction(async () => {
5353
await refreshSchema();
5454
return jsonParseWithUndefined(
5555
((await loadTable(storeTableName, storeIdColumnName))[SINGLE_ROW_ID]?.[
@@ -58,10 +58,10 @@ export const createJsonPersister = <
5858
);
5959
});
6060

61-
const setPersisted = async (
61+
const setPersisted = (
6262
getContent: () => PersistedContent<Persist>,
6363
): Promise<void> =>
64-
await transaction(async () => {
64+
transaction(async () => {
6565
await refreshSchema();
6666
await saveTable(
6767
storeTableName,

src/persisters/common/database/postgresql.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,21 @@ export const createCustomPostgreSqlPersister = <
133133
newOrOldOrBoth == 0 ? 'NEW' : 'OLD',
134134
);
135135

136-
const addDataChangedTriggers = async (
136+
const addDataChangedTriggers = (
137137
tableName: string,
138138
dataChangedFunction: string,
139139
) =>
140-
await promiseAll(
141-
arrayMap(
142-
[INSERT, DELETE, UPDATE],
143-
async (action, newOrOldOrBoth) =>
144-
await createTrigger(
145-
OR_REPLACE,
146-
escapeIds(TINYBASE, DATA_CHANGED, configHash, tableName, action),
147-
`AFTER ${action} ON${escapeId(tableName)}FOR EACH ROW WHEN(${when(
148-
tableName,
149-
newOrOldOrBoth as 0 | 1 | 2,
150-
)})`,
151-
dataChangedFunction,
152-
),
140+
promiseAll(
141+
arrayMap([INSERT, DELETE, UPDATE], (action, newOrOldOrBoth) =>
142+
createTrigger(
143+
OR_REPLACE,
144+
escapeIds(TINYBASE, DATA_CHANGED, configHash, tableName, action),
145+
`AFTER ${action} ON${escapeId(tableName)}FOR EACH ROW WHEN(${when(
146+
tableName,
147+
newOrOldOrBoth as 0 | 1 | 2,
148+
)})`,
149+
dataChangedFunction,
150+
),
153151
),
154152
);
155153

@@ -188,8 +186,8 @@ export const createCustomPostgreSqlPersister = <
188186

189187
const listenerHandle = await addChangeListener(
190188
channel,
191-
async (prefixAndTableName) =>
192-
await ifNotUndefined(
189+
(prefixAndTableName) =>
190+
ifNotUndefined(
193191
strMatch(prefixAndTableName, EVENT_REGEX),
194192
async ([, eventType, tableName]) => {
195193
if (collHas(managedTableNamesSet, tableName)) {

src/persisters/common/database/tabular.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const createTabularPersister = <
6969
decode,
7070
);
7171

72-
const saveTables = async (
72+
const saveTables = (
7373
tables:
7474
| Tables
7575
| {
@@ -79,7 +79,7 @@ export const createTabularPersister = <
7979
},
8080
partial?: boolean,
8181
) =>
82-
await promiseAll(
82+
promiseAll(
8383
mapMap(
8484
tablesSaveConfig,
8585
async (
@@ -145,23 +145,21 @@ export const createTabularPersister = <
145145
]
146146
: {};
147147

148-
const getPersisted = async (): Promise<
149-
PersistedContent<Persist> | undefined
150-
> =>
151-
(await transaction(async () => {
148+
const getPersisted = (): Promise<PersistedContent<Persist> | undefined> =>
149+
transaction(async () => {
152150
await refreshSchema();
153151
const tables = await loadTables();
154152
const values = await loadValues();
155153
return !objIsEmpty(tables) || !isUndefined(values)
156154
? [tables as Tables, values as Values]
157155
: undefined;
158-
})) as any;
156+
}) as any;
159157

160-
const setPersisted = async (
158+
const setPersisted = (
161159
getContent: () => PersistedContent<Persist>,
162160
changes?: PersistedChanges<Persist, true>,
163161
): Promise<void> =>
164-
await transaction(async () => {
162+
transaction(async () => {
165163
await refreshSchema();
166164
if (!isUndefined(changes)) {
167165
await saveTables(changes[0] as any, true);

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,11 @@ export const createIndexedDbPersister = ((
7878
'readwrite',
7979
);
8080
const result = await promiseAll(
81-
arrayMap(
82-
OBJECT_STORE_NAMES,
83-
async (objectStoreName, index) =>
84-
await forObjectStore(
85-
transaction.objectStore(objectStoreName),
86-
params[index],
87-
),
81+
arrayMap(OBJECT_STORE_NAMES, (objectStoreName, index) =>
82+
forObjectStore(
83+
transaction.objectStore(objectStoreName),
84+
params[index],
85+
),
8886
),
8987
);
9088
request.result.close();
@@ -108,13 +106,12 @@ export const createIndexedDbPersister = ((
108106
),
109107
);
110108

111-
const setPersisted = async (getContent: () => Content): Promise<void> =>
112-
(await forObjectStores(
113-
async (objectStore, content) =>
114-
await objectStoreMatch(objectStore, content),
109+
const setPersisted = (getContent: () => Content): Promise<void> =>
110+
forObjectStores(
111+
(objectStore, content) => objectStoreMatch(objectStore, content),
115112
getContent(),
116113
1,
117-
)) as any;
114+
) as any;
118115

119116
const addPersisterListener = (listener: PersisterListener): NodeJS.Timeout =>
120117
startInterval(listener, autoLoadIntervalSeconds);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const createPartyKitPersister = ((
5555
})
5656
).json();
5757

58-
const getPersisted = async (): Promise<Content> => await getOrSetStore();
58+
const getPersisted = getOrSetStore;
5959

6060
const setPersisted = async (
6161
getContent: () => Content,

src/persisters/persister-pglite/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export const createPglitePersister = (async (
2525
configOrStoreTableName,
2626
async (sql: string, params: any[] = []): Promise<IdObj<any>[]> =>
2727
(await pglite.query(sql, params)).rows as any,
28-
async (
28+
(
2929
channel: string,
3030
listener: DatabaseChangeListener,
31-
): Promise<() => Promise<void>> => await pglite.listen(channel, listener),
31+
): Promise<() => Promise<void>> => pglite.listen(channel, listener),
3232
(unlisten: () => Promise<void>) => tryCatch(unlisten, onIgnoredError),
3333
onSqlCommand,
3434
onIgnoredError,

test/unit/persisters/common/databases.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ export const NODE_SQLITE_NON_MERGEABLE_VARIANTS: Variants = {
266266
async (client: Client) => client.close(),
267267
],
268268
electricSql: [
269-
async (): Promise<Electric> =>
270-
await suppressWarnings(
269+
(): Promise<Electric> =>
270+
suppressWarnings(
271271
async () =>
272272
await electrify(
273273
await ElectricDatabase.init(':memory:'),
@@ -321,8 +321,8 @@ export const NODE_SQLITE_NON_MERGEABLE_VARIANTS: Variants = {
321321
true,
322322
],
323323
crSqliteWasm: [
324-
async (): Promise<DB> =>
325-
await suppressWarnings(async () => await (await initWasm()).open()),
324+
(): Promise<DB> =>
325+
suppressWarnings(async () => await (await initWasm()).open()),
326326
['getDb', (db: DB) => db],
327327
(
328328
store: Store,
@@ -363,22 +363,22 @@ export const NODE_POSTGRESQL_VARIANTS: Variants = {
363363
return [sql, cmdSql, name];
364364
},
365365
['getSql', ([sql]: SqlClientsAndName) => sql],
366-
async (
366+
(
367367
store: Store,
368368
[sql]: SqlClientsAndName,
369369
storeTableOrConfig?: string | DatabasePersisterConfig,
370370
onSqlCommand?: (sql: string, args?: any[]) => void,
371371
onIgnoredError?: (error: any) => void,
372372
) =>
373-
await (createPostgresPersister as any)(
373+
(createPostgresPersister as any)(
374374
store,
375375
sql,
376376
storeTableOrConfig,
377377
onSqlCommand,
378378
onIgnoredError,
379379
),
380-
async ([, cmdSql]: SqlClientsAndName, sqlStr: string, args: any[] = []) =>
381-
await cmdSql.unsafe(sqlStr, args),
380+
([, cmdSql]: SqlClientsAndName, sqlStr: string, args: any[] = []) =>
381+
cmdSql.unsafe(sqlStr, args),
382382
async ([sql, cmdSql, name]: SqlClientsAndName) => {
383383
cmdSql.release();
384384
await sql.end({timeout: 0.1});

0 commit comments

Comments
 (0)