@indietabletop/appkit 6.1.1 → 6.1.3

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.
@@ -2,8 +2,8 @@ import { useAppConfig } from "../AppConfig/AppConfig.tsx";
2
2
 
3
3
  export function DocumentTitle(props: { children: string }) {
4
4
  const { children: children } = props;
5
- const { appName, isDev } = useAppConfig();
6
- const itc = `${appName} · Indie Tabletop Club`;
5
+ const { app, isDev } = useAppConfig();
6
+ const itc = `${app.name} · Indie Tabletop Club`;
7
7
  const title = children ? `${children} | ${itc}` : itc;
8
8
 
9
9
  return <title>{isDev ? `[DEV] ${title}` : title}</title>;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indietabletop/appkit",
3
- "version": "6.1.1",
3
+ "version": "6.1.3",
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
  },
@@ -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
  }