@storyshelf/db-sqlite 0.3.2 → 0.5.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.
Files changed (73) hide show
  1. package/README.md +29 -3
  2. package/dist/better-sqlite3.d.mts +29 -0
  3. package/dist/better-sqlite3.mjs +116 -0
  4. package/dist/better-sqlite3.mjs.map +1 -0
  5. package/dist/bun-sqlite.d.mts +30 -0
  6. package/dist/bun-sqlite.mjs +120 -0
  7. package/dist/bun-sqlite.mjs.map +1 -0
  8. package/dist/d1.d.mts +38 -0
  9. package/dist/d1.mjs +108 -0
  10. package/dist/d1.mjs.map +1 -0
  11. package/dist/ddl.d.mts +14 -0
  12. package/dist/ddl.mjs +342 -0
  13. package/dist/ddl.mjs.map +1 -0
  14. package/dist/drizzle-factory.d.mts +19 -0
  15. package/dist/drizzle-factory.mjs +121 -0
  16. package/dist/drizzle-factory.mjs.map +1 -0
  17. package/dist/index.mjs +102 -36
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/schema/baseline.d.mts +204 -0
  20. package/dist/schema/baseline.mjs +23 -0
  21. package/dist/schema/baseline.mjs.map +1 -0
  22. package/dist/schema/build.d.mts +405 -0
  23. package/dist/schema/build.mjs +33 -0
  24. package/dist/schema/build.mjs.map +1 -0
  25. package/dist/schema/capture-attempt.d.mts +482 -0
  26. package/dist/schema/capture-attempt.mjs +40 -0
  27. package/dist/schema/capture-attempt.mjs.map +1 -0
  28. package/dist/schema/comment.d.mts +215 -0
  29. package/dist/schema/comment.mjs +26 -0
  30. package/dist/schema/comment.mjs.map +1 -0
  31. package/dist/schema/content-refs.d.mts +95 -0
  32. package/dist/schema/content-refs.mjs +16 -0
  33. package/dist/schema/content-refs.mjs.map +1 -0
  34. package/dist/schema/label.d.mts +288 -0
  35. package/dist/schema/label.mjs +30 -0
  36. package/dist/schema/label.mjs.map +1 -0
  37. package/dist/schema/member.d.mts +140 -0
  38. package/dist/schema/member.mjs +20 -0
  39. package/dist/schema/member.mjs.map +1 -0
  40. package/dist/schema/notification.d.mts +344 -0
  41. package/dist/schema/notification.mjs +33 -0
  42. package/dist/schema/notification.mjs.map +1 -0
  43. package/dist/schema/project-group-mapping.d.mts +119 -0
  44. package/dist/schema/project-group-mapping.mjs +18 -0
  45. package/dist/schema/project-group-mapping.mjs.map +1 -0
  46. package/dist/schema/project.d.mts +358 -0
  47. package/dist/schema/project.mjs +29 -0
  48. package/dist/schema/project.mjs.map +1 -0
  49. package/dist/schema/snapshot.d.mts +487 -0
  50. package/dist/schema/snapshot.mjs +38 -0
  51. package/dist/schema/snapshot.mjs.map +1 -0
  52. package/dist/schema/status-config.d.mts +157 -0
  53. package/dist/schema/status-config.mjs +20 -0
  54. package/dist/schema/status-config.mjs.map +1 -0
  55. package/dist/schema/token.d.mts +157 -0
  56. package/dist/schema/token.mjs +21 -0
  57. package/dist/schema/token.mjs.map +1 -0
  58. package/dist/schema/user-invite.d.mts +137 -0
  59. package/dist/schema/user-invite.mjs +19 -0
  60. package/dist/schema/user-invite.mjs.map +1 -0
  61. package/dist/schema/user.d.mts +238 -0
  62. package/dist/schema/user.mjs +23 -0
  63. package/dist/schema/user.mjs.map +1 -0
  64. package/dist/schema/webhook.d.mts +157 -0
  65. package/dist/schema/webhook.mjs +20 -0
  66. package/dist/schema/webhook.mjs.map +1 -0
  67. package/dist/schema.d.mts +47 -0
  68. package/dist/schema.mjs +46 -0
  69. package/dist/schema.mjs.map +1 -0
  70. package/dist/turso.d.mts +32 -0
  71. package/dist/turso.mjs +134 -0
  72. package/dist/turso.mjs.map +1 -0
  73. package/package.json +66 -10
@@ -0,0 +1,157 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ //#region src/schema/webhook.d.ts
4
+ /** Narrow `webhooks` table definition. */
5
+ declare const webhooks: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
6
+ name: "webhooks";
7
+ schema: undefined;
8
+ columns: {
9
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
10
+ name: "id";
11
+ tableName: "webhooks";
12
+ dataType: "string";
13
+ columnType: "SQLiteText";
14
+ data: string;
15
+ driverParam: string;
16
+ notNull: true;
17
+ hasDefault: false;
18
+ isPrimaryKey: true;
19
+ isAutoincrement: false;
20
+ hasRuntimeDefault: false;
21
+ enumValues: [string, ...string[]];
22
+ baseColumn: never;
23
+ identity: undefined;
24
+ generated: undefined;
25
+ }, {}, {
26
+ length: number | undefined;
27
+ }>;
28
+ projectId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
29
+ name: "project_id";
30
+ tableName: "webhooks";
31
+ dataType: "string";
32
+ columnType: "SQLiteText";
33
+ data: string;
34
+ driverParam: string;
35
+ notNull: true;
36
+ hasDefault: false;
37
+ isPrimaryKey: false;
38
+ isAutoincrement: false;
39
+ hasRuntimeDefault: false;
40
+ enumValues: [string, ...string[]];
41
+ baseColumn: never;
42
+ identity: undefined;
43
+ generated: undefined;
44
+ }, {}, {
45
+ length: number | undefined;
46
+ }>;
47
+ url: import("drizzle-orm/sqlite-core").SQLiteColumn<{
48
+ name: "url";
49
+ tableName: "webhooks";
50
+ dataType: "string";
51
+ columnType: "SQLiteText";
52
+ data: string;
53
+ driverParam: string;
54
+ notNull: true;
55
+ hasDefault: false;
56
+ isPrimaryKey: false;
57
+ isAutoincrement: false;
58
+ hasRuntimeDefault: false;
59
+ enumValues: [string, ...string[]];
60
+ baseColumn: never;
61
+ identity: undefined;
62
+ generated: undefined;
63
+ }, {}, {
64
+ length: number | undefined;
65
+ }>;
66
+ secretEncrypted: import("drizzle-orm/sqlite-core").SQLiteColumn<{
67
+ name: "secret_encrypted";
68
+ tableName: "webhooks";
69
+ dataType: "string";
70
+ columnType: "SQLiteText";
71
+ data: string;
72
+ driverParam: string;
73
+ notNull: true;
74
+ hasDefault: false;
75
+ isPrimaryKey: false;
76
+ isAutoincrement: false;
77
+ hasRuntimeDefault: false;
78
+ enumValues: [string, ...string[]];
79
+ baseColumn: never;
80
+ identity: undefined;
81
+ generated: undefined;
82
+ }, {}, {
83
+ length: number | undefined;
84
+ }>;
85
+ events: import("drizzle-orm/sqlite-core").SQLiteColumn<{
86
+ name: "events";
87
+ tableName: "webhooks";
88
+ dataType: "string";
89
+ columnType: "SQLiteText";
90
+ data: string;
91
+ driverParam: string;
92
+ notNull: false;
93
+ hasDefault: false;
94
+ isPrimaryKey: false;
95
+ isAutoincrement: false;
96
+ hasRuntimeDefault: false;
97
+ enumValues: [string, ...string[]];
98
+ baseColumn: never;
99
+ identity: undefined;
100
+ generated: undefined;
101
+ }, {}, {
102
+ length: number | undefined;
103
+ }>;
104
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
105
+ name: "created_at";
106
+ tableName: "webhooks";
107
+ dataType: "string";
108
+ columnType: "SQLiteText";
109
+ data: string;
110
+ driverParam: string;
111
+ notNull: true;
112
+ hasDefault: false;
113
+ isPrimaryKey: false;
114
+ isAutoincrement: false;
115
+ hasRuntimeDefault: false;
116
+ enumValues: [string, ...string[]];
117
+ baseColumn: never;
118
+ identity: undefined;
119
+ generated: undefined;
120
+ }, {}, {
121
+ length: number | undefined;
122
+ }>;
123
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
124
+ name: "updated_at";
125
+ tableName: "webhooks";
126
+ dataType: "string";
127
+ columnType: "SQLiteText";
128
+ data: string;
129
+ driverParam: string;
130
+ notNull: true;
131
+ hasDefault: false;
132
+ isPrimaryKey: false;
133
+ isAutoincrement: false;
134
+ hasRuntimeDefault: false;
135
+ enumValues: [string, ...string[]];
136
+ baseColumn: never;
137
+ identity: undefined;
138
+ generated: undefined;
139
+ }, {}, {
140
+ length: number | undefined;
141
+ }>;
142
+ };
143
+ dialect: 'sqlite';
144
+ }>;
145
+ /** A webhook subscription row. */
146
+ interface Webhook {
147
+ id: string;
148
+ projectId: string;
149
+ url: string;
150
+ secretEncrypted: string;
151
+ events: string | null;
152
+ createdAt: string;
153
+ updatedAt: string;
154
+ }
155
+ //#endregion
156
+ export { Webhook, webhooks };
157
+ //# sourceMappingURL=webhook.d.mts.map
@@ -0,0 +1,20 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { projects } from "./project.mjs";
5
+ import { sqliteTable, text } from "drizzle-orm/sqlite-core";
6
+ //#region src/schema/webhook.ts
7
+ /** Narrow `webhooks` table definition. */
8
+ const webhooks = sqliteTable("webhooks", {
9
+ id: text("id").primaryKey(),
10
+ projectId: text("project_id").notNull().references(() => projects.id, { onDelete: "cascade" }),
11
+ url: text("url").notNull(),
12
+ secretEncrypted: text("secret_encrypted").notNull(),
13
+ events: text("events"),
14
+ createdAt: text("created_at").notNull(),
15
+ updatedAt: text("updated_at").notNull()
16
+ });
17
+ //#endregion
18
+ export { webhooks };
19
+
20
+ //# sourceMappingURL=webhook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.mjs","names":[],"sources":["../../src/schema/webhook.ts"],"sourcesContent":["import { sqliteTable, text } from \"drizzle-orm/sqlite-core\";\nimport { projects } from \"./project.ts\";\n\n/** Narrow `webhooks` table definition. */\nexport const webhooks = sqliteTable(\"webhooks\", {\n id: text(\"id\").primaryKey(),\n projectId: text(\"project_id\")\n .notNull()\n .references(() => projects.id, { onDelete: \"cascade\" }),\n url: text(\"url\").notNull(),\n secretEncrypted: text(\"secret_encrypted\").notNull(),\n events: text(\"events\"),\n createdAt: text(\"created_at\").notNull(),\n updatedAt: text(\"updated_at\").notNull(),\n});\n\n/** A webhook subscription row. */\nexport interface Webhook {\n id: string;\n projectId: string;\n url: string;\n secretEncrypted: string;\n events: string | null;\n createdAt: string;\n updatedAt: string;\n}\n"],"mappings":";;;;;;;AAIA,MAAa,WAAW,YAAY,YAAY;CAC9C,IAAI,KAAK,IAAI,CAAC,CAAC,WAAW;CAC1B,WAAW,KAAK,YAAY,CAAC,CAC1B,QAAQ,CAAC,CACT,iBAAiB,SAAS,IAAI,EAAE,UAAU,UAAU,CAAC;CACxD,KAAK,KAAK,KAAK,CAAC,CAAC,QAAQ;CACzB,iBAAiB,KAAK,kBAAkB,CAAC,CAAC,QAAQ;CAClD,QAAQ,KAAK,QAAQ;CACrB,WAAW,KAAK,YAAY,CAAC,CAAC,QAAQ;CACtC,WAAW,KAAK,YAAY,CAAC,CAAC,QAAQ;AACxC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ import { Build, builds } from "./schema/build.mjs";
4
+ import { CaptureAttempt, CaptureLog, captureAttempts, captureLogs } from "./schema/capture-attempt.mjs";
5
+ import { baselines } from "./schema/baseline.mjs";
6
+ import { Comment, comments } from "./schema/comment.mjs";
7
+ import { BuildLabel, LabelType, buildLabels, labelTypes } from "./schema/label.mjs";
8
+ import { ProjectMember, projectMembers } from "./schema/member.mjs";
9
+ import { NotificationChannel, NotificationSubscription, notificationChannels, notificationSubscriptions } from "./schema/notification.mjs";
10
+ import { ProjectGroupMapping, projectGroupMappings } from "./schema/project-group-mapping.mjs";
11
+ import { Project, StorybookMeta, projects } from "./schema/project.mjs";
12
+ import { Snapshot, snapshots } from "./schema/snapshot.mjs";
13
+ import { ProjectStatusConfig, projectStatusConfigs } from "./schema/status-config.mjs";
14
+ import { Token, tokens } from "./schema/token.mjs";
15
+ import { User, users } from "./schema/user.mjs";
16
+ import { UserInviteToken, userInviteTokens } from "./schema/user-invite.mjs";
17
+ import { Webhook, webhooks } from "./schema/webhook.mjs";
18
+ import { ContentRef, contentRefs } from "./schema/content-refs.mjs";
19
+ import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
20
+ //#region src/schema/index.d.ts
21
+ /** Full Drizzle schema object passed to the database client. */
22
+ declare const schema: {
23
+ projects: AnySQLiteTable;
24
+ projectStatusConfigs: AnySQLiteTable;
25
+ builds: AnySQLiteTable;
26
+ captureAttempts: AnySQLiteTable;
27
+ captureLogs: AnySQLiteTable;
28
+ snapshots: AnySQLiteTable;
29
+ baselines: AnySQLiteTable;
30
+ comments: AnySQLiteTable;
31
+ labelTypes: AnySQLiteTable;
32
+ buildLabels: AnySQLiteTable;
33
+ tokens: AnySQLiteTable;
34
+ webhooks: AnySQLiteTable;
35
+ notificationChannels: AnySQLiteTable;
36
+ notificationSubscriptions: AnySQLiteTable;
37
+ users: AnySQLiteTable;
38
+ userInviteTokens: AnySQLiteTable;
39
+ projectMembers: AnySQLiteTable;
40
+ projectGroupMappings: AnySQLiteTable;
41
+ contentRefs: AnySQLiteTable;
42
+ };
43
+ /** The full database schema type. */
44
+ type Schema = typeof schema;
45
+ //#endregion
46
+ export { type Build, type BuildLabel, type CaptureAttempt, type CaptureLog, type Comment, type ContentRef, type LabelType, type NotificationChannel, type NotificationSubscription, type Project, type ProjectGroupMapping, type ProjectMember, type ProjectStatusConfig, Schema, type Snapshot, type StorybookMeta, type Token, type User, type UserInviteToken, type Webhook, baselines, buildLabels, builds, captureAttempts, captureLogs, comments, contentRefs, labelTypes, notificationChannels, notificationSubscriptions, projectGroupMappings, projectMembers, projectStatusConfigs, projects, schema, snapshots, tokens, userInviteTokens, users, webhooks };
47
+ //# sourceMappingURL=schema.d.mts.map
@@ -0,0 +1,46 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { projects } from "./schema/project.mjs";
5
+ import { baselines } from "./schema/baseline.mjs";
6
+ import { builds } from "./schema/build.mjs";
7
+ import { captureAttempts, captureLogs } from "./schema/capture-attempt.mjs";
8
+ import { snapshots } from "./schema/snapshot.mjs";
9
+ import { users } from "./schema/user.mjs";
10
+ import { comments } from "./schema/comment.mjs";
11
+ import { contentRefs } from "./schema/content-refs.mjs";
12
+ import { buildLabels, labelTypes } from "./schema/label.mjs";
13
+ import { projectMembers } from "./schema/member.mjs";
14
+ import { notificationChannels, notificationSubscriptions } from "./schema/notification.mjs";
15
+ import { projectGroupMappings } from "./schema/project-group-mapping.mjs";
16
+ import { projectStatusConfigs } from "./schema/status-config.mjs";
17
+ import { tokens } from "./schema/token.mjs";
18
+ import { userInviteTokens } from "./schema/user-invite.mjs";
19
+ import { webhooks } from "./schema/webhook.mjs";
20
+ //#region src/schema/index.ts
21
+ /** Full Drizzle schema object passed to the database client. */
22
+ const schema = {
23
+ projects,
24
+ projectStatusConfigs,
25
+ builds,
26
+ captureAttempts,
27
+ captureLogs,
28
+ snapshots,
29
+ baselines,
30
+ comments,
31
+ labelTypes,
32
+ buildLabels,
33
+ tokens,
34
+ webhooks,
35
+ notificationChannels,
36
+ notificationSubscriptions,
37
+ users,
38
+ userInviteTokens,
39
+ projectMembers,
40
+ projectGroupMappings,
41
+ contentRefs
42
+ };
43
+ //#endregion
44
+ export { baselines, buildLabels, builds, captureAttempts, captureLogs, comments, contentRefs, labelTypes, notificationChannels, notificationSubscriptions, projectGroupMappings, projectMembers, projectStatusConfigs, projects, schema, snapshots, tokens, userInviteTokens, users, webhooks };
45
+
46
+ //# sourceMappingURL=schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","names":["projectsTable","projectStatusConfigsTable","buildsTable","captureAttemptsTable","captureLogsTable","snapshotsTable","baselinesTable","commentsTable","labelTypesTable","buildLabelsTable","tokensTable","webhooksTable","notificationChannelsTable","notificationSubscriptionsTable","usersTable","userInviteTokensTable","projectMembersTable","projectGroupMappingsTable","contentRefsTable"],"sources":["../src/schema/index.ts"],"sourcesContent":["/**\n * Database schema: table handles, row types, and the schema object passed\n * to the database client.\n *\n * Table handles are available on the `schema` object with full type\n * inference (`schema.builds`, …); exact column types live on the narrow\n * per-entity definitions, and the row interfaces are pinned to them by\n * `schema-types.test.ts`.\n */\nimport type { AnySQLiteTable } from \"drizzle-orm/sqlite-core\";\nimport { baselines as baselinesTable } from \"./baseline.ts\";\nimport { builds as buildsTable } from \"./build.ts\";\nimport {\n captureAttempts as captureAttemptsTable,\n captureLogs as captureLogsTable,\n} from \"./capture-attempt.ts\";\nimport { comments as commentsTable } from \"./comment.ts\";\nimport { contentRefs as contentRefsTable } from \"./content-refs.ts\";\nimport { buildLabels as buildLabelsTable, labelTypes as labelTypesTable } from \"./label.ts\";\nimport { projectMembers as projectMembersTable } from \"./member.ts\";\nimport {\n notificationChannels as notificationChannelsTable,\n notificationSubscriptions as notificationSubscriptionsTable,\n} from \"./notification.ts\";\nimport { projectGroupMappings as projectGroupMappingsTable } from \"./project-group-mapping.ts\";\nimport { projects as projectsTable } from \"./project.ts\";\nimport { snapshots as snapshotsTable } from \"./snapshot.ts\";\nimport { projectStatusConfigs as projectStatusConfigsTable } from \"./status-config.ts\";\nimport { tokens as tokensTable } from \"./token.ts\";\nimport { userInviteTokens as userInviteTokensTable } from \"./user-invite.ts\";\nimport { users as usersTable } from \"./user.ts\";\nimport { webhooks as webhooksTable } from \"./webhook.ts\";\n\nexport { builds } from \"./build.ts\";\nexport { captureAttempts, captureLogs } from \"./capture-attempt.ts\";\nexport { baselines } from \"./baseline.ts\";\nexport { comments } from \"./comment.ts\";\nexport { buildLabels, labelTypes } from \"./label.ts\";\nexport { projectMembers } from \"./member.ts\";\nexport { notificationChannels, notificationSubscriptions } from \"./notification.ts\";\nexport { projectGroupMappings } from \"./project-group-mapping.ts\";\nexport { projects } from \"./project.ts\";\nexport { snapshots } from \"./snapshot.ts\";\nexport { projectStatusConfigs } from \"./status-config.ts\";\nexport { tokens } from \"./token.ts\";\nexport { users } from \"./user.ts\";\nexport { userInviteTokens } from \"./user-invite.ts\";\nexport { webhooks } from \"./webhook.ts\";\nexport { contentRefs } from \"./content-refs.ts\";\n\n/** A capture attempt and its log lines for a single build run. */\nexport type { CaptureAttempt, CaptureLog } from \"./capture-attempt.ts\";\n/** Build row as stored in the `builds` table. */\nexport type { Build } from \"./build.ts\";\n/** Review comment row as stored in the `comments` table. */\nexport type { Comment } from \"./comment.ts\";\n/** Build label and label type rows. */\nexport type { BuildLabel, LabelType } from \"./label.ts\";\n/** Project membership row linking a user to a project role. */\nexport type { ProjectMember } from \"./member.ts\";\n/** Identity-provider group to project-role mapping row. */\nexport type { ProjectGroupMapping } from \"./project-group-mapping.ts\";\n/** Project row and its embedded Storybook metadata. */\nexport type { Project, StorybookMeta } from \"./project.ts\";\n/** Per-project git provider status-check configuration row. */\nexport type { ProjectStatusConfig } from \"./status-config.ts\";\n/** Snapshot row capturing a single story at one viewport. */\nexport type { Snapshot } from \"./snapshot.ts\";\n/** CI token row (stores only the hash). */\nexport type { Token } from \"./token.ts\";\n/** User row for authenticated identities. */\nexport type { User } from \"./user.ts\";\n/** One-time invite token for local accounts. */\nexport type { UserInviteToken } from \"./user-invite.ts\";\n/** Webhook subscription row. */\nexport type { Webhook } from \"./webhook.ts\";\n/** Notification channel and subscription rows. */\nexport type { NotificationChannel, NotificationSubscription } from \"./notification.ts\";\n/** Content ref row for deduplicated assets. */\nexport type { ContentRef } from \"./content-refs.ts\";\n\n/** Full Drizzle schema object passed to the database client. */\nexport const schema: {\n projects: AnySQLiteTable;\n projectStatusConfigs: AnySQLiteTable;\n builds: AnySQLiteTable;\n captureAttempts: AnySQLiteTable;\n captureLogs: AnySQLiteTable;\n snapshots: AnySQLiteTable;\n baselines: AnySQLiteTable;\n comments: AnySQLiteTable;\n labelTypes: AnySQLiteTable;\n buildLabels: AnySQLiteTable;\n tokens: AnySQLiteTable;\n webhooks: AnySQLiteTable;\n notificationChannels: AnySQLiteTable;\n notificationSubscriptions: AnySQLiteTable;\n users: AnySQLiteTable;\n userInviteTokens: AnySQLiteTable;\n projectMembers: AnySQLiteTable;\n projectGroupMappings: AnySQLiteTable;\n contentRefs: AnySQLiteTable;\n} = {\n projects: projectsTable,\n projectStatusConfigs: projectStatusConfigsTable,\n builds: buildsTable,\n captureAttempts: captureAttemptsTable,\n captureLogs: captureLogsTable,\n snapshots: snapshotsTable,\n baselines: baselinesTable,\n comments: commentsTable,\n labelTypes: labelTypesTable,\n buildLabels: buildLabelsTable,\n tokens: tokensTable,\n webhooks: webhooksTable,\n notificationChannels: notificationChannelsTable,\n notificationSubscriptions: notificationSubscriptionsTable,\n users: usersTable,\n userInviteTokens: userInviteTokensTable,\n projectMembers: projectMembersTable,\n projectGroupMappings: projectGroupMappingsTable,\n contentRefs: contentRefsTable,\n};\n\n/** The full database schema type. */\nexport type Schema = typeof schema;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkFA,MAAa,SAoBT;CACQA;CACYC;CACdC;CACSC;CACJC;CACFC;CACAC;CACDC;CACEC;CACCC;CACLC;CACEC;CACYC;CACKC;CACpBC;CACWC;CACFC;CACMC;CACTC;AACf"}
@@ -0,0 +1,32 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
3
+ import { createClient } from "@libsql/client";
4
+ import { DatabaseAdapter } from "@storyshelf/core/adapter/database";
5
+ //#region src/turso.d.ts
6
+ type LibsqlClient = ReturnType<typeof createClient>;
7
+ /**
8
+ * Options for creating a Turso-backed DatabaseAdapter.
9
+ *
10
+ * When `client` is supplied, all other connection options are ignored and
11
+ * the caller owns the lifecycle of the client (teardown is a no-op). This
12
+ * is the hook for embedded replicas with custom sync loops and hermetic
13
+ * tests.
14
+ */
15
+ interface TursoDatabaseOptions {
16
+ url?: string;
17
+ authToken?: string;
18
+ syncUrl?: string;
19
+ syncInterval?: number;
20
+ client?: LibsqlClient;
21
+ }
22
+ /**
23
+ * Create a Turso/libSQL-backed DatabaseAdapter using Drizzle ORM.
24
+ *
25
+ * @param options - Either a connection `url` (plus `authToken`/`syncUrl`/
26
+ * `syncInterval`) or a preconfigured libSQL `client`.
27
+ * @returns A DatabaseAdapter backed by the Turso database.
28
+ */
29
+ declare function createTursoDatabase(options: TursoDatabaseOptions): DatabaseAdapter;
30
+ //#endregion
31
+ export { TursoDatabaseOptions, createTursoDatabase };
32
+ //# sourceMappingURL=turso.d.mts.map
package/dist/turso.mjs ADDED
@@ -0,0 +1,134 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { DDL, tableColumns } from "./ddl.mjs";
5
+ import { createDrizzleAdapter } from "./drizzle-factory.mjs";
6
+ import { schema } from "./schema.mjs";
7
+ import { createClient } from "@libsql/client";
8
+ import { drizzle } from "drizzle-orm/libsql";
9
+ //#region src/turso.ts
10
+ /**
11
+ * Turso/libSQL preset for the SQLite database adapter.
12
+ *
13
+ * Same schema, DDL, and Drizzle factory as the `node:sqlite` default;
14
+ * only the transport differs (`@libsql/client`: `file:`, `libsql://`,
15
+ * `wss://`, or embedded replica via `syncUrl`). Requires the optional
16
+ * `@libsql/client` peer (`nub add @libsql/client`).
17
+ */
18
+ /**
19
+ * Create a Turso/libSQL-backed DatabaseAdapter using Drizzle ORM.
20
+ *
21
+ * @param options - Either a connection `url` (plus `authToken`/`syncUrl`/
22
+ * `syncInterval`) or a preconfigured libSQL `client`.
23
+ * @returns A DatabaseAdapter backed by the Turso database.
24
+ */
25
+ function createTursoDatabase(options) {
26
+ const { client, owned } = resolveClient(options);
27
+ const db = drizzle(client, { schema });
28
+ return createDrizzleAdapter(db, {
29
+ metadata: {
30
+ name: "Turso",
31
+ version: globalThis.__PKG_VERSION__ ?? "0.0.0",
32
+ description: "Turso/libSQL database adapter",
33
+ kind: "turso",
34
+ category: "database"
35
+ },
36
+ tables: schema,
37
+ migrate: async () => {
38
+ await runMigrations(client);
39
+ },
40
+ close: () => {
41
+ if (owned) client.close();
42
+ },
43
+ ping: async () => {
44
+ await client.execute("SELECT 1");
45
+ }
46
+ });
47
+ }
48
+ const SUPPORTED_URL = /^(?<proto>libsql|https?|wss?):\/\/|^file:|^:memory:/u;
49
+ function isSupportedUrl(url) {
50
+ return SUPPORTED_URL.test(url);
51
+ }
52
+ /** Resolve the libSQL client, distinguishing caller-owned from owned. */
53
+ function resolveClient(options) {
54
+ if (options.client) return {
55
+ client: options.client,
56
+ owned: false
57
+ };
58
+ const url = options.url?.trim();
59
+ if (!url) throw new Error("createTursoDatabase: provide `url` (or `syncUrl` with a `file:` url) or a preconfigured `client`");
60
+ if (!isSupportedUrl(url)) throw new Error(`createTursoDatabase: unsupported url "${url}" (expected libsql://, https://, wss://, file:, or :memory:)`);
61
+ return {
62
+ client: createClient({
63
+ url,
64
+ authToken: options.authToken,
65
+ syncUrl: options.syncUrl,
66
+ syncInterval: options.syncInterval
67
+ }),
68
+ owned: true
69
+ };
70
+ }
71
+ const WEBHOOK_SECRET_DROP = "ALTER TABLE webhooks DROP COLUMN secret";
72
+ async function runMigrations(client) {
73
+ await client.executeMultiple(DDL);
74
+ await ensureColumns(client, DDL);
75
+ await execIgnore(client, WEBHOOK_SECRET_DROP);
76
+ await migrateCommentsTable(client);
77
+ }
78
+ /** Add any DDL column missing from a volume created before it shipped. */
79
+ async function ensureColumns(client, ddl) {
80
+ const statements = (await Promise.all([...tableColumns(ddl)].map(async ([table, columns]) => {
81
+ const rows = (await client.execute(`PRAGMA table_info(${table})`)).rows;
82
+ return {
83
+ table,
84
+ columns,
85
+ existing: new Set(rows.map((row) => String(row.name)))
86
+ };
87
+ }))).flatMap(({ table, columns, existing }) => columns.filter((column) => isMissing(column, existing)).map((column) => [table, column]));
88
+ await Promise.all(statements.map(async ([table, column]) => {
89
+ await execIgnore(client, `ALTER TABLE ${table} ADD COLUMN ${column}`);
90
+ }));
91
+ }
92
+ function isMissing(column, existing) {
93
+ const [name] = column.split(/\s+/u);
94
+ return name !== void 0 && !existing.has(name);
95
+ }
96
+ async function execIgnore(client, sql) {
97
+ try {
98
+ await client.execute(sql);
99
+ } catch {}
100
+ }
101
+ async function migrateCommentsTable(client) {
102
+ try {
103
+ if (!((await client.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name='comments'")).rows[0]?.sql)?.includes("user_id TEXT NOT NULL REFERENCES users")) return;
104
+ await recreateCommentsTable(client);
105
+ } catch {
106
+ await execIgnore(client, "PRAGMA foreign_keys = ON");
107
+ }
108
+ }
109
+ async function recreateCommentsTable(client) {
110
+ await client.execute("PRAGMA foreign_keys = OFF");
111
+ await client.execute(`
112
+ CREATE TABLE comments_new (
113
+ id TEXT PRIMARY KEY,
114
+ project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
115
+ build_id TEXT NOT NULL REFERENCES builds(id) ON DELETE CASCADE,
116
+ snapshot_id TEXT REFERENCES snapshots(id) ON DELETE CASCADE,
117
+ user_id TEXT REFERENCES users(id) ON DELETE CASCADE,
118
+ body TEXT NOT NULL,
119
+ parent_id TEXT,
120
+ resolved INTEGER NOT NULL DEFAULT 0,
121
+ created_at TEXT NOT NULL,
122
+ updated_at TEXT NOT NULL
123
+ )
124
+ `);
125
+ await client.execute("INSERT INTO comments_new SELECT * FROM comments");
126
+ await client.execute("DROP TABLE comments");
127
+ await client.execute("ALTER TABLE comments_new RENAME TO comments");
128
+ await client.execute("CREATE INDEX IF NOT EXISTS comments_build_id_idx ON comments (build_id)");
129
+ await client.execute("PRAGMA foreign_keys = ON");
130
+ }
131
+ //#endregion
132
+ export { createTursoDatabase };
133
+
134
+ //# sourceMappingURL=turso.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turso.mjs","names":[],"sources":["../src/turso.ts"],"sourcesContent":["/**\n * Turso/libSQL preset for the SQLite database adapter.\n *\n * Same schema, DDL, and Drizzle factory as the `node:sqlite` default;\n * only the transport differs (`@libsql/client`: `file:`, `libsql://`,\n * `wss://`, or embedded replica via `syncUrl`). Requires the optional\n * `@libsql/client` peer (`nub add @libsql/client`).\n */\nimport { createClient } from \"@libsql/client\";\nimport type { DatabaseAdapter } from \"@storyshelf/core/adapter/database\";\nimport { drizzle } from \"drizzle-orm/libsql\";\nimport { DDL, tableColumns } from \"./ddl.ts\";\nimport { createDrizzleAdapter } from \"./drizzle-factory.ts\";\nimport { schema } from \"./schema/index.ts\";\n\ndeclare const __PKG_VERSION__: string | undefined;\n\ntype LibsqlClient = ReturnType<typeof createClient>;\n\n/**\n * Options for creating a Turso-backed DatabaseAdapter.\n *\n * When `client` is supplied, all other connection options are ignored and\n * the caller owns the lifecycle of the client (teardown is a no-op). This\n * is the hook for embedded replicas with custom sync loops and hermetic\n * tests.\n */\nexport interface TursoDatabaseOptions {\n url?: string;\n authToken?: string;\n syncUrl?: string;\n syncInterval?: number;\n client?: LibsqlClient;\n}\n\n/**\n * Create a Turso/libSQL-backed DatabaseAdapter using Drizzle ORM.\n *\n * @param options - Either a connection `url` (plus `authToken`/`syncUrl`/\n * `syncInterval`) or a preconfigured libSQL `client`.\n * @returns A DatabaseAdapter backed by the Turso database.\n */\nexport function createTursoDatabase(options: TursoDatabaseOptions): DatabaseAdapter {\n const { client, owned } = resolveClient(options);\n const db = drizzle(client, { schema });\n\n return createDrizzleAdapter(db, {\n metadata: {\n name: \"Turso\",\n version: (globalThis as unknown as { __PKG_VERSION__?: string }).__PKG_VERSION__ ?? \"0.0.0\",\n description: \"Turso/libSQL database adapter\",\n kind: \"turso\",\n category: \"database\",\n },\n tables: schema,\n migrate: async () => {\n await runMigrations(client);\n },\n close: () => {\n if (owned) {\n client.close();\n }\n },\n ping: async () => {\n await client.execute(\"SELECT 1\");\n },\n });\n}\n\nconst SUPPORTED_URL = /^(?<proto>libsql|https?|wss?):\\/\\/|^file:|^:memory:/u;\n\nfunction isSupportedUrl(url: string): boolean {\n return SUPPORTED_URL.test(url);\n}\n\n/** Resolve the libSQL client, distinguishing caller-owned from owned. */\nfunction resolveClient(options: TursoDatabaseOptions): { client: LibsqlClient; owned: boolean } {\n if (options.client) {\n return { client: options.client, owned: false };\n }\n const url = options.url?.trim();\n if (!url) {\n throw new Error(\n \"createTursoDatabase: provide `url` (or `syncUrl` with a `file:` url) or a preconfigured `client`\",\n );\n }\n if (!isSupportedUrl(url)) {\n throw new Error(\n `createTursoDatabase: unsupported url \"${url}\" (expected libsql://, https://, wss://, file:, or :memory:)`,\n );\n }\n return {\n client: createClient({\n url,\n authToken: options.authToken,\n syncUrl: options.syncUrl,\n syncInterval: options.syncInterval,\n }),\n owned: true,\n };\n}\n\nconst WEBHOOK_SECRET_DROP = \"ALTER TABLE webhooks DROP COLUMN secret\";\n\nasync function runMigrations(client: LibsqlClient): Promise<void> {\n await client.executeMultiple(DDL);\n await ensureColumns(client, DDL);\n await execIgnore(client, WEBHOOK_SECRET_DROP);\n await migrateCommentsTable(client);\n}\n\n/** Add any DDL column missing from a volume created before it shipped. */\nasync function ensureColumns(client: LibsqlClient, ddl: string): Promise<void> {\n const inspected = await Promise.all(\n [...tableColumns(ddl)].map(async ([table, columns]) => {\n const result = await client.execute(`PRAGMA table_info(${table})`);\n const rows = result.rows as unknown as { name: unknown }[];\n const existing = new Set(rows.map((row) => String(row.name)));\n return { table, columns, existing };\n }),\n );\n const statements = inspected.flatMap(({ table, columns, existing }) =>\n columns\n .filter((column) => isMissing(column, existing))\n .map((column) => [table, column] as const),\n );\n await Promise.all(\n statements.map(async ([table, column]) => {\n await execIgnore(client, `ALTER TABLE ${table} ADD COLUMN ${column}`);\n }),\n );\n}\n\nfunction isMissing(column: string, existing: Set<string>): boolean {\n const [name] = column.split(/\\s+/u);\n return name !== undefined && !existing.has(name);\n}\n\nasync function execIgnore(client: LibsqlClient, sql: string): Promise<void> {\n try {\n await client.execute(sql);\n } catch {\n // idempotent — already migrated\n }\n}\n\nasync function migrateCommentsTable(client: LibsqlClient): Promise<void> {\n try {\n const result = await client.execute(\n \"SELECT sql FROM sqlite_master WHERE type='table' AND name='comments'\",\n );\n const sql = (result.rows[0] as unknown as { sql: string } | undefined)?.sql;\n if (!sql?.includes(\"user_id TEXT NOT NULL REFERENCES users\")) {\n return;\n }\n await recreateCommentsTable(client);\n } catch {\n await execIgnore(client, \"PRAGMA foreign_keys = ON\");\n }\n}\n\nasync function recreateCommentsTable(client: LibsqlClient): Promise<void> {\n await client.execute(\"PRAGMA foreign_keys = OFF\");\n await client.execute(`\n CREATE TABLE comments_new (\n id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,\n build_id TEXT NOT NULL REFERENCES builds(id) ON DELETE CASCADE,\n snapshot_id TEXT REFERENCES snapshots(id) ON DELETE CASCADE,\n user_id TEXT REFERENCES users(id) ON DELETE CASCADE,\n body TEXT NOT NULL,\n parent_id TEXT,\n resolved INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n )\n `);\n await client.execute(\"INSERT INTO comments_new SELECT * FROM comments\");\n await client.execute(\"DROP TABLE comments\");\n await client.execute(\"ALTER TABLE comments_new RENAME TO comments\");\n await client.execute(\"CREATE INDEX IF NOT EXISTS comments_build_id_idx ON comments (build_id)\");\n await client.execute(\"PRAGMA foreign_keys = ON\");\n}\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@storyshelf/db-sqlite",
3
- "version": "0.3.2",
3
+ "version": "0.5.3",
4
4
  "description": "SQLite database adapter for StoryShelf (node:sqlite + Drizzle).",
5
+ "keywords": [
6
+ "database",
7
+ "drizzle",
8
+ "self-hosted",
9
+ "sqlite",
10
+ "storybook"
11
+ ],
5
12
  "homepage": "https://github.com/GuptaSiddhant/StoryShelf#readme",
6
13
  "bugs": {
7
14
  "url": "https://github.com/GuptaSiddhant/StoryShelf/issues"
@@ -27,11 +34,46 @@
27
34
  "source": "./src/index.ts",
28
35
  "default": "./dist/index.mjs"
29
36
  },
37
+ "./better-sqlite3": {
38
+ "source": "./src/better-sqlite3.ts",
39
+ "default": "./dist/better-sqlite3.mjs"
40
+ },
41
+ "./bun-sqlite": {
42
+ "source": "./src/bun-sqlite.ts",
43
+ "default": "./dist/bun-sqlite.mjs"
44
+ },
45
+ "./d1": {
46
+ "source": "./src/d1.ts",
47
+ "default": "./dist/d1.mjs"
48
+ },
49
+ "./ddl": {
50
+ "source": "./src/ddl.ts",
51
+ "default": "./dist/ddl.mjs"
52
+ },
53
+ "./drizzle-factory": {
54
+ "source": "./src/drizzle-factory.ts",
55
+ "default": "./dist/drizzle-factory.mjs"
56
+ },
57
+ "./schema": {
58
+ "source": "./src/schema/index.ts",
59
+ "default": "./dist/schema.mjs"
60
+ },
61
+ "./turso": {
62
+ "source": "./src/turso.ts",
63
+ "default": "./dist/turso.mjs"
64
+ },
30
65
  "./package.json": "./package.json"
31
66
  },
32
67
  "publishConfig": {
33
68
  "exports": {
34
69
  ".": "./dist/index.mjs",
70
+ "./better-sqlite3": "./dist/better-sqlite3.mjs",
71
+ "./bun-sqlite": "./dist/bun-sqlite.mjs",
72
+ "./d1": "./dist/d1.mjs",
73
+ "./ddl": "./dist/ddl.mjs",
74
+ "./drizzle-factory": "./dist/drizzle-factory.mjs",
75
+ "./schema": "./dist/schema.mjs",
76
+ "./turso": "./dist/turso.mjs",
35
77
  "./package.json": "./package.json"
36
78
  },
37
79
  "access": "public"
@@ -45,18 +87,32 @@
45
87
  "prepublishOnly": "nub run build"
46
88
  },
47
89
  "dependencies": {
48
- "@storyshelf/core": "^0.3.2",
90
+ "@storyshelf/core": "0.5.3",
49
91
  "drizzle-orm": "^0.44.0"
50
92
  },
51
93
  "devDependencies": {
52
- "@types/node": "catalog:",
53
- "@vitest/coverage-v8": "catalog:",
54
- "oxfmt": "catalog:",
55
- "oxlint": "catalog:",
56
- "oxlint-tsgolint": "catalog:",
57
- "tsdown": "catalog:",
58
- "typescript": "catalog:",
59
- "vitest": "catalog:"
94
+ "@libsql/client": "^0.18.0",
95
+ "@types/node": "^26.0.0",
96
+ "@vitest/coverage-v8": "^4.0.0",
97
+ "better-sqlite3": "^12.0.0",
98
+ "oxfmt": "^0.65.0",
99
+ "oxlint": "^1.80.0",
100
+ "oxlint-tsgolint": "^7.0.2001",
101
+ "tsdown": "^0.22.14",
102
+ "typescript": "^7.0.2",
103
+ "vitest": "^5.0.0"
104
+ },
105
+ "peerDependencies": {
106
+ "@libsql/client": "^0.18.0",
107
+ "better-sqlite3": "^12.0.0"
108
+ },
109
+ "peerDependenciesMeta": {
110
+ "@libsql/client": {
111
+ "optional": true
112
+ },
113
+ "better-sqlite3": {
114
+ "optional": true
115
+ }
60
116
  },
61
117
  "jsr": {
62
118
  "runtimeCompat": {