@indietabletop/appkit 6.1.2 → 6.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,42 +17,81 @@ export type ModernIDBIndexes<Schema extends ModernIDBSchema> = {
17
17
  [K in keyof Schema]?: string;
18
18
  };
19
19
 
20
- export type VersionChangeHandler<
20
+ export type VersionChangeHandlerProps<
21
21
  Schema extends ModernIDBSchema,
22
- IndexNames extends {
23
- [K in keyof Schema]?: string;
24
- },
25
- > = (props: {
22
+ IndexNames extends ModernIDBIndexes<Schema>,
23
+ > = {
26
24
  event: IDBVersionChangeEvent;
27
25
  manager: VersionChangeManager<Schema, IndexNames>;
28
26
  db: ModernIDB<Schema, IndexNames>;
29
- }) => void;
27
+ };
30
28
 
31
- export type BlockingHandler<
29
+ export type VersionChangeHandler<
30
+ Schema extends ModernIDBSchema,
31
+ IndexNames extends ModernIDBIndexes<Schema>,
32
+ > = (props: VersionChangeHandlerProps<Schema, IndexNames>) => void;
33
+
34
+ export type BlockingHandlerProps<
32
35
  Schema extends ModernIDBSchema,
33
- IndexNames extends {
34
- [K in keyof Schema]?: string;
35
- },
36
- > = (props: {
36
+ IndexNames extends ModernIDBIndexes<Schema>,
37
+ > = {
37
38
  event: IDBVersionChangeEvent;
38
39
  db: ModernIDB<Schema, IndexNames>;
39
- }) => void;
40
+ };
41
+
42
+ export type BlockingHandler<
43
+ Schema extends ModernIDBSchema,
44
+ IndexNames extends ModernIDBIndexes<Schema>,
45
+ > = (props: BlockingHandlerProps<Schema, IndexNames>) => void;
40
46
 
41
47
  export type OpenRequestHandlers<
42
48
  Schema extends ModernIDBSchema,
43
- IndexNames extends {
44
- [K in keyof Schema]?: string;
45
- },
49
+ IndexNames extends ModernIDBIndexes<Schema>,
46
50
  > = {
47
51
  /**
48
- * If error is thrown inside the `onInit` handler, the version change
49
- * transaction will be aborted.
52
+ * Called when the database is initialized from scratch.
53
+ *
54
+ * Should be used to set up all required stores and indexes.
55
+ *
56
+ * If error is thrown in this handler, the version change transaction will
57
+ * be aborted.
58
+ *
59
+ * @example
60
+ *
61
+ * ```ts
62
+ * onInit({ manager }) {
63
+ * const store = manager.createObjectStore("items", { keyPath: "id" });
64
+ * store.createIndex("createdTs", "createdTs");
65
+ *
66
+ * console.info("DB initialized.");
67
+ * },
68
+ * ```
50
69
  */
51
70
  onInit?: VersionChangeHandler<Schema, IndexNames>;
52
71
 
53
72
  /**
54
- * If error is thrown inside the `onUpgrade` handler, the version change
55
- * transaction will be aborted.
73
+ * Called when there is an existing IDB database present, but is is of a lower
74
+ * version than the latest.
75
+ *
76
+ * If error is thrown inside this handler, the version change transaction
77
+ * will be aborted.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * onUpgrade({ manager, event }) {
82
+ * switch (event.oldVersion) {
83
+ * case 1: {
84
+ * // We need a `settings` store in v2, but it did't exist in v1
85
+ * const store = manager.createObjectStore("settings", { keyPath: "id" });
86
+ * store.createIndex("createdTs", "createdTs");
87
+ * }
88
+ *
89
+ * default: {
90
+ * console.info(`Migration from DB v${event.oldVersion} complete.`);
91
+ * }
92
+ * }
93
+ * }
94
+ * ```
56
95
  */
57
96
  onUpgrade?: VersionChangeHandler<Schema, IndexNames>;
58
97
 
package/lib/client.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  redeemedPledge,
6
6
  sessionInfo,
7
7
  type FeatureUnlock,
8
- type SpaceGits,
8
+ type UserGameData,
9
9
  } from "@indietabletop/types";
10
10
  import {
11
11
  array,
@@ -20,12 +20,6 @@ import {
20
20
  import { Failure, Success } from "./async-op.ts";
21
21
  import type { CurrentUser, FailurePayload, SessionInfo } from "./types.ts";
22
22
 
23
- export type UserGameData = {
24
- spacegits?: {
25
- gangs?: (SpaceGits.GangData | SpaceGits.GangTombstone)[];
26
- };
27
- };
28
-
29
23
  export type GameCode = keyof UserGameData;
30
24
 
31
25
  export type ClientEventType = keyof ClientEventMap;
@@ -1,8 +1,9 @@
1
+ import type { UserGameData } from "@indietabletop/types";
1
2
  import { createActorContext } from "@xstate/react";
2
3
  import { createContext, useContext, useMemo, type ReactNode } from "react";
3
4
  import { fromCallback, fromPromise } from "xstate";
4
5
  import { Failure, Success } from "../async-op.ts";
5
- import type { GameCode, IndieTabletopClient, UserGameData } from "../client.ts";
6
+ import type { GameCode, IndieTabletopClient } from "../client.ts";
6
7
  import type { ModernIDB } from "../ModernIDB/ModernIDB.ts";
7
8
  import type { ModernIDBIndexes, ModernIDBSchema } from "../ModernIDB/types.ts";
8
9
  import type { CurrentUser } from "../types.ts";
@@ -1,16 +1,24 @@
1
+ import type { UserGameData } from "@indietabletop/types";
1
2
  import { Failure } from "../async-op.js";
2
- import type { UserGameData } from "../client.ts";
3
3
  import type { FailurePayload } from "../types.ts";
4
4
  import type { SyncedItem } from "./types.ts";
5
5
 
6
6
  /**
7
7
  * Flattens the UserGameData structure to a flat SyncedItem[].
8
8
  */
9
-
10
9
  export function toSyncedItems(data: UserGameData) {
11
10
  return Object.values(data).flatMap((groups) => {
12
11
  return Object.values(groups).flatMap((items) => {
13
12
  return items.map((item): SyncedItem => {
13
+ if ("type" in item) {
14
+ return {
15
+ id: item.type,
16
+ name: item.type,
17
+ deleted: false,
18
+ updatedTs: item.updatedTs,
19
+ };
20
+ }
21
+
14
22
  return {
15
23
  id: item.id,
16
24
  name: item.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indietabletop/appkit",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
4
4
  "description": "A collection of modules used in apps built by Indie Tabletop Club",
5
5
  "private": false,
6
6
  "type": "module",
@@ -8,7 +8,9 @@
8
8
  "release": "np",
9
9
  "build": "tsc",
10
10
  "dev": "tsc --watch",
11
- "test": "vitest",
11
+ "test": "vitest run",
12
+ "test:dev": "vitest watch",
13
+ "test:release": "npm run test && npm run typecheck",
12
14
  "storybook": "storybook dev",
13
15
  "typecheck": "tsc --noEmit"
14
16
  },
@@ -32,19 +34,19 @@
32
34
  "@storybook/addon-docs": "^10.1.11",
33
35
  "@storybook/addon-links": "^10.1.11",
34
36
  "@storybook/react-vite": "^10.1.11",
35
- "@types/react": "^19.2.7",
37
+ "@types/react": "^19.2.8",
36
38
  "msw": "^2.12.7",
37
39
  "msw-storybook-addon": "^2.0.6",
38
40
  "np": "^10.2.0",
39
41
  "storybook": "^10.1.11",
40
42
  "typescript": "^5.9.3",
41
43
  "vite": "^7.3.1",
42
- "vitest": "^4.0.16"
44
+ "vitest": "^4.0.17"
43
45
  },
44
46
  "dependencies": {
45
- "@ariakit/react": "^0.4.20",
47
+ "@ariakit/react": "^0.4.21",
46
48
  "@indietabletop/tooling": "^5.2.0",
47
- "@indietabletop/types": "^1.2.0",
49
+ "@indietabletop/types": "^1.3.0",
48
50
  "@vanilla-extract/css": "^1.18.0",
49
51
  "@vanilla-extract/dynamic": "^2.1.5",
50
52
  "@vanilla-extract/recipes": "^0.5.7",
@@ -61,5 +63,8 @@
61
63
  "public"
62
64
  ]
63
65
  },
66
+ "np": {
67
+ "testScript": "test:release"
68
+ },
64
69
  "packageManager": "npm@11.7.0+sha512.c22099a6fff8d5b2286c2a09df5352b4858a7c0c716320f58989d60ad8b29ecf2ce6fdfe97ccb41c23ffb1272e1fa079f868487dd6b81d02a2a9e199c095a117"
65
70
  }