Skip to content

Commit e20a785

Browse files
committed
Migrated to the latest crstore version
1 parent b48e3ba commit e20a785

26 files changed

+425
-173
lines changed

apps/core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"allowSyntheticDefaultImports": true,
44
"verbatimModuleSyntax": true,
55
"types": ["node", "vite/client"],
6-
"moduleResolution": "node",
6+
"moduleResolution": "Bundler",
77
"resolveJsonModule": true,
88
"esModuleInterop": true,
99
"module": "esnext",

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"devDependencies": {
2020
"@sveltejs/adapter-static": "3.0.1",
21-
"crstore": "^0.19.3",
21+
"crstore": "^0.20.2",
2222
"murmurhash": "^2.0.1"
2323
}
2424
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"@sveltejs/kit": "2.0.6",
2020
"@sveltejs/vite-plugin-svelte": "^3.0.1",
2121
"@types/node": "20.10.6",
22-
"@typescript-eslint/eslint-plugin": "^6.17.0",
23-
"@typescript-eslint/parser": "^6.17.0",
22+
"@typescript-eslint/eslint-plugin": "^6.18.0",
23+
"@typescript-eslint/parser": "^6.18.0",
2424
"@vitest/coverage-v8": "^1.1.3",
2525
"autoprefixer": "^10.4.16",
2626
"cssnano": "^6.0.3",
@@ -32,13 +32,13 @@
3232
"prettier": "^3.1.1",
3333
"prettier-plugin-sort-imports": "^1.8.1",
3434
"prettier-plugin-svelte": "^3.1.2",
35-
"prettier-plugin-tailwindcss": "^0.5.10",
35+
"prettier-plugin-tailwindcss": "^0.5.11",
3636
"rimraf": "^5.0.5",
37-
"rollup": "^4.9.3",
37+
"rollup": "^4.9.4",
3838
"rollup-plugin-node-externals": "^6.1.2",
3939
"svelte": "^4.2.8",
4040
"svelte-check": "^3.6.2",
41-
"tailwindcss": "^3.4.0",
41+
"tailwindcss": "^3.4.1",
4242
"tailwindcss-contain": "^0.1.1",
4343
"tslib": "^2.6.2",
4444
"turbo": "^1.11.3",

packages/crdata/data/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { library } from "../stores/library";
88
import { type DB, schema } from "./schema";
99
import { tracks } from "../stores/tracks";
1010
import { albums } from "../stores/albums";
11-
import { database, sql } from "crstore";
11+
import { database } from "crstore/svelte";
1212
import { feed } from "../stores/feed";
13+
import { sql } from "crstore";
1314

1415
const connections = new Map<string, Connection>();
1516

@@ -32,7 +33,7 @@ function connect(options: Options) {
3233
if (!connections.has(options.name)) {
3334
const db = database(
3435
options.local ? (nocrr(schema) as typeof schema) : schema,
35-
options
36+
options,
3637
) as any as DB;
3738
connections.set(options.name, { ...db, ...stores(db) });
3839
const files = import.meta.glob("../sql/*.sql", { eager: true, as: "raw" });
@@ -62,7 +63,7 @@ function nocrr<T>(schema: T) {
6263
Object.entries((schema as any).schema).map(([key, value]) => [
6364
key,
6465
{ ...(value as object), crr: false },
65-
])
66+
]),
6667
),
6768
} as T;
6869
}

packages/crdata/data/schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
artistBase,
1717
playlistBase,
1818
} from "@amadeus-music/protocol";
19-
import { primary, crr, ordered, index, type Database } from "crstore";
19+
import { primary, crr, ordered, index } from "crstore";
20+
import { type SvelteDatabase } from "crstore/svelte";
2021
import type { Struct } from "superstruct";
2122

2223
const id = integer;
@@ -126,7 +127,7 @@ type Views = {
126127
};
127128

128129
export type Schema = Infer<typeof schema> & Views;
129-
export type DB = Database<Schema>;
130+
export type DB = SvelteDatabase<Schema>;
130131
export const schema = object({
131132
tracks,
132133
albums,

packages/crdata/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"@amadeus-music/protocol": "workspace:*",
10-
"crstore": "^0.19.3",
10+
"crstore": "^0.20.2",
1111
"superstruct": "^1.0.3"
1212
}
1313
}

packages/crdata/stores/albums.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { pushAlbums } from "../operations/push";
44
import { sanitize } from "../operations/utils";
55
import type { DB } from "../data/schema";
66

7-
export const albums = ({ store }: DB) =>
8-
store(
7+
export const albums = ({ replicated }: DB) =>
8+
replicated(
99
(db) =>
1010
db
1111
.with("source", source)
@@ -48,5 +48,5 @@ export const albums = ({ store }: DB) =>
4848
.$castTo<Album>()
4949
.executeTakeFirstOrThrow();
5050
},
51-
}
51+
},
5252
);

packages/crdata/stores/artists.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { sanitize } from "../operations/utils";
55
import { json, groupJSON } from "crstore";
66
import type { DB } from "../data/schema";
77

8-
export const artists = ({ store }: DB) =>
9-
store(
8+
export const artists = ({ replicated }: DB) =>
9+
replicated(
1010
(db) =>
1111
db
1212
.with("source", source)
@@ -31,7 +31,7 @@ export const artists = ({ store }: DB) =>
3131
size: qb.fn.count<number>("track.duration"),
3232
duration: qb.fn.coalesce(
3333
qb.fn.sum<number>("track.duration"),
34-
qb.val(0)
34+
qb.val(0),
3535
),
3636
tracks: groupJSON(qb, {
3737
id: "track.id",
@@ -96,5 +96,5 @@ export const artists = ({ store }: DB) =>
9696
.$castTo<Artist>()
9797
.executeTakeFirstOrThrow();
9898
},
99-
}
99+
},
100100
);

packages/crdata/stores/feed.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { Feed, Playlist } from "@amadeus-music/protocol";
33
import { groupJSON, json } from "crstore";
44
import type { DB } from "../data/schema";
55

6-
export const feed = ({ store }: DB) =>
7-
store(
6+
export const feed = ({ replicated }: DB) =>
7+
replicated(
88
(db) =>
99
db
1010
.with("source", source)
@@ -16,7 +16,7 @@ export const feed = ({ store }: DB) =>
1616
.innerJoin("library", "library.track", "tracks.id")
1717
.select(["library.playlist", "library.id as entry"])
1818
.orderBy("library.order")
19-
.orderBy("library.id")
19+
.orderBy("library.id"),
2020
)
2121
.selectFrom("track")
2222
.fullJoin("playlists", "playlists.id", "track.playlist")
@@ -32,7 +32,7 @@ export const feed = ({ store }: DB) =>
3232
size: qb.fn.count<number>("track.duration"),
3333
duration: qb.fn.coalesce(
3434
qb.fn.sum<number>("track.duration"),
35-
qb.val(0)
35+
qb.val(0),
3636
),
3737
tracks: groupJSON(qb, {
3838
id: "track.id",
@@ -62,5 +62,5 @@ export const feed = ({ store }: DB) =>
6262
.execute()
6363
.then((x) => x.map((y) => y.id as number));
6464
},
65-
}
65+
},
6666
);

packages/crdata/stores/history.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import type { DB } from "../data/schema";
22

3-
export const history = ({ store }: DB) =>
4-
store((db) => db.selectFrom("history").orderBy("date", "desc").selectAll(), {
5-
async log(db, query: string) {
6-
if (!query.trim()) return;
7-
await db
8-
.insertInto("history")
9-
.onConflict((x) => x.doUpdateSet({ date: Date.now() }))
10-
.values({ query, date: Date.now() })
11-
.execute();
3+
export const history = ({ replicated }: DB) =>
4+
replicated(
5+
(db) => db.selectFrom("history").orderBy("date", "desc").selectAll(),
6+
{
7+
async log(db, query: string) {
8+
if (!query.trim()) return;
9+
await db
10+
.insertInto("history")
11+
.onConflict((x) => x.doUpdateSet({ date: Date.now() }))
12+
.values({ query, date: Date.now() })
13+
.execute();
14+
},
15+
async clear(db) {
16+
await db.deleteFrom("history").execute();
17+
},
18+
get(db) {
19+
return db
20+
.selectFrom("history")
21+
.selectAll()
22+
.orderBy("date", "desc")
23+
.execute();
24+
},
1225
},
13-
async clear(db) {
14-
await db.deleteFrom("history").execute();
15-
},
16-
get(db) {
17-
return db
18-
.selectFrom("history")
19-
.selectAll()
20-
.orderBy("date", "desc")
21-
.execute();
22-
},
23-
});
26+
);

packages/crdata/stores/library.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { uuid } from "../operations/utils";
55
import type { DB } from "../data/schema";
66
import { APPEND, sql } from "crstore";
77

8-
export const library = ({ store }: DB) =>
9-
store((db) => db.selectFrom("library").selectAll(), {
8+
export const library = ({ replicated }: DB) =>
9+
replicated((db) => db.selectFrom("library").selectAll(), {
1010
async push(db, tracks: Track[], playlist?: number) {
1111
if (!tracks.length) return;
1212
await pushTracks(db, tracks);
@@ -21,7 +21,7 @@ export const library = ({ store }: DB) =>
2121
date: ~~(Date.now() / 1000),
2222
track: id,
2323
playlist,
24-
}))
24+
})),
2525
)
2626
.execute();
2727
},
@@ -34,7 +34,7 @@ export const library = ({ store }: DB) =>
3434
},
3535
async purge(db, entries: number[]) {
3636
const promises = entries.map((entry) =>
37-
db.deleteFrom("library").where("id", "=", entry).execute()
37+
db.deleteFrom("library").where("id", "=", entry).execute(),
3838
);
3939
await Promise.all(promises);
4040
},

packages/crdata/stores/playback.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { pushTracks } from "../operations/push";
99
import type { DB } from "../data/schema";
1010
import { json, sql } from "crstore";
1111

12-
export const preceding = ({ store }: DB) =>
13-
store((db) =>
12+
export const preceding = ({ replicated }: DB) =>
13+
replicated((db) =>
1414
db
1515
.with("source", source)
1616
.with("asset", asset)
@@ -30,8 +30,8 @@ export const preceding = ({ store }: DB) =>
3030
.$castTo<Track & { entry: number }>(),
3131
);
3232

33-
export const upcoming = ({ store }: DB) =>
34-
store((db) =>
33+
export const upcoming = ({ replicated }: DB) =>
34+
replicated((db) =>
3535
db
3636
.with("source", source)
3737
.with("asset", asset)
@@ -51,8 +51,8 @@ export const upcoming = ({ store }: DB) =>
5151
.$castTo<Track & { entry: number }>(),
5252
);
5353

54-
export const playback = ({ store }: DB) =>
55-
store(
54+
export const playback = ({ replicated }: DB) =>
55+
replicated(
5656
(db) =>
5757
db
5858
.with("source", source)
@@ -98,17 +98,17 @@ export const playback = ({ store }: DB) =>
9898
? Number.isInteger(at)
9999
? at
100100
: at === "first"
101-
? position.first
102-
: at === "next"
103-
? position.next
104-
: position.last
101+
? position.first
102+
: at === "next"
103+
? position.next
104+
: position.last
105105
: Number.isInteger(at)
106-
? position.shift(+at)
107-
: at === "first"
108-
? position.last
109-
: at === "next"
110-
? position.before
111-
: position.first;
106+
? position.shift(+at)
107+
: at === "first"
108+
? position.last
109+
: at === "next"
110+
? position.before
111+
: position.first;
112112

113113
await db
114114
.insertInto("playback_fractindex" as any)
@@ -121,8 +121,8 @@ export const playback = ({ store }: DB) =>
121121
at === "random"
122122
? position.random(ids.slice(0, i))
123123
: i > 0 && direction != 1
124-
? ids[i - 1]
125-
: order,
124+
? ids[i - 1]
125+
: order,
126126
})),
127127
)
128128
.execute();
@@ -173,8 +173,8 @@ export const playback = ({ store }: DB) =>
173173
direction != 1
174174
? after
175175
: after != null
176-
? position.shift(after)
177-
: position.last;
176+
? position.shift(after)
177+
: position.last;
178178

179179
await db
180180
.updateTable("playback_fractindex" as any)

packages/crdata/stores/playlists.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { identify, type Playlist } from "@amadeus-music/protocol";
33
import { APPEND, groupJSON, json } from "crstore";
44
import type { DB } from "../data/schema";
55

6-
export const playlists = ({ store }: DB) =>
7-
store(
6+
export const playlists = ({ replicated }: DB) =>
7+
replicated(
88
(db) =>
99
db
1010
.with("source", source)
@@ -16,7 +16,7 @@ export const playlists = ({ store }: DB) =>
1616
.innerJoin("library", "library.track", "tracks.id")
1717
.select(["library.playlist", "library.id as entry"])
1818
.orderBy("library.order")
19-
.orderBy("library.id")
19+
.orderBy("library.id"),
2020
)
2121
.selectFrom("track")
2222
.fullJoin("playlists", "playlists.id", "track.playlist")
@@ -32,7 +32,7 @@ export const playlists = ({ store }: DB) =>
3232
size: qb.fn.count<number>("track.duration"),
3333
duration: qb.fn.coalesce(
3434
qb.fn.sum<number>("track.duration"),
35-
qb.val(0)
35+
qb.val(0),
3636
),
3737
tracks: groupJSON(qb, {
3838
id: "track.id",
@@ -86,5 +86,5 @@ export const playlists = ({ store }: DB) =>
8686
.where("id", "=", id)
8787
.executeTakeFirstOrThrow();
8888
},
89-
}
89+
},
9090
);

0 commit comments

Comments
 (0)