@velocity-astro/cms-db 0.0.0-stage → 0.1.0-beta.11

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/auth-tables.d.ts +881 -0
  4. package/dist/auth-tables.d.ts.map +1 -0
  5. package/dist/auth-tables.js +82 -0
  6. package/dist/auth-tables.js.map +1 -0
  7. package/dist/contact-repository.d.ts +16 -0
  8. package/dist/contact-repository.d.ts.map +1 -0
  9. package/dist/contact-repository.js +108 -0
  10. package/dist/contact-repository.js.map +1 -0
  11. package/dist/custom-fields-store.d.ts +9 -0
  12. package/dist/custom-fields-store.d.ts.map +1 -0
  13. package/dist/custom-fields-store.js +26 -0
  14. package/dist/custom-fields-store.js.map +1 -0
  15. package/dist/database.d.ts +2709 -0
  16. package/dist/database.d.ts.map +1 -0
  17. package/dist/database.js +22 -0
  18. package/dist/database.js.map +1 -0
  19. package/dist/deal-repository.d.ts +14 -0
  20. package/dist/deal-repository.d.ts.map +1 -0
  21. package/dist/deal-repository.js +70 -0
  22. package/dist/deal-repository.js.map +1 -0
  23. package/dist/entry-repository.d.ts +12 -0
  24. package/dist/entry-repository.d.ts.map +1 -0
  25. package/dist/entry-repository.js +107 -0
  26. package/dist/entry-repository.js.map +1 -0
  27. package/dist/form-repository.d.ts +14 -0
  28. package/dist/form-repository.d.ts.map +1 -0
  29. package/dist/form-repository.js +54 -0
  30. package/dist/form-repository.js.map +1 -0
  31. package/dist/index.d.ts +15 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +15 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/media-repository.d.ts +11 -0
  36. package/dist/media-repository.d.ts.map +1 -0
  37. package/dist/media-repository.js +33 -0
  38. package/dist/media-repository.js.map +1 -0
  39. package/dist/pipeline-store.d.ts +9 -0
  40. package/dist/pipeline-store.d.ts.map +1 -0
  41. package/dist/pipeline-store.js +31 -0
  42. package/dist/pipeline-store.js.map +1 -0
  43. package/dist/plugin-store.d.ts +12 -0
  44. package/dist/plugin-store.d.ts.map +1 -0
  45. package/dist/plugin-store.js +35 -0
  46. package/dist/plugin-store.js.map +1 -0
  47. package/dist/schema-repository.d.ts +11 -0
  48. package/dist/schema-repository.d.ts.map +1 -0
  49. package/dist/schema-repository.js +37 -0
  50. package/dist/schema-repository.js.map +1 -0
  51. package/dist/search-index.d.ts +15 -0
  52. package/dist/search-index.d.ts.map +1 -0
  53. package/dist/search-index.js +67 -0
  54. package/dist/search-index.js.map +1 -0
  55. package/dist/settings-store.d.ts +12 -0
  56. package/dist/settings-store.d.ts.map +1 -0
  57. package/dist/settings-store.js +26 -0
  58. package/dist/settings-store.js.map +1 -0
  59. package/dist/submission-repository.d.ts +14 -0
  60. package/dist/submission-repository.d.ts.map +1 -0
  61. package/dist/submission-repository.js +82 -0
  62. package/dist/submission-repository.js.map +1 -0
  63. package/dist/tables.d.ts +1835 -0
  64. package/dist/tables.d.ts.map +1 -0
  65. package/dist/tables.js +166 -0
  66. package/dist/tables.js.map +1 -0
  67. package/migrations/0000_init.sql +33 -0
  68. package/migrations/0001_search.sql +10 -0
  69. package/migrations/0002_published_version.sql +7 -0
  70. package/migrations/0003_auth.sql +71 -0
  71. package/migrations/0004_media.sql +12 -0
  72. package/migrations/0005_plugins.sql +7 -0
  73. package/migrations/0006_trash.sql +3 -0
  74. package/migrations/0007_forms.sql +24 -0
  75. package/migrations/0008_contacts.sql +23 -0
  76. package/migrations/0009_pipeline.sql +11 -0
  77. package/migrations/0010_deals.sql +16 -0
  78. package/migrations/0011_custom_fields.sql +2 -0
  79. package/migrations/0012_deal_subjects.sql +3 -0
  80. package/migrations/0013_submission_subjects.sql +2 -0
  81. package/migrations/0014_stage_moves.sql +2 -0
  82. package/migrations/0015_publish_problem.sql +1 -0
  83. package/migrations/meta/0000_snapshot.json +229 -0
  84. package/migrations/meta/0001_snapshot.json +229 -0
  85. package/migrations/meta/0002_snapshot.json +266 -0
  86. package/migrations/meta/0003_snapshot.json +744 -0
  87. package/migrations/meta/0004_snapshot.json +818 -0
  88. package/migrations/meta/0005_snapshot.json +864 -0
  89. package/migrations/meta/0006_snapshot.json +872 -0
  90. package/migrations/meta/0007_snapshot.json +1022 -0
  91. package/migrations/meta/0008_snapshot.json +1164 -0
  92. package/migrations/meta/0009_snapshot.json +1232 -0
  93. package/migrations/meta/0010_snapshot.json +1335 -0
  94. package/migrations/meta/0011_snapshot.json +1349 -0
  95. package/migrations/meta/0012_snapshot.json +1370 -0
  96. package/migrations/meta/0013_snapshot.json +1384 -0
  97. package/migrations/meta/0014_snapshot.json +1398 -0
  98. package/migrations/meta/0015_snapshot.json +1405 -0
  99. package/migrations/meta/_journal.json +118 -0
  100. package/package.json +43 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-tables.d.ts","sourceRoot":"","sources":["../src/auth-tables.ts"],"names":[],"mappings":"AAmBA,iFAAiF;AACjF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASnB,CAAC;AAEH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAevB,CAAC;AAEF,+FAA+F;AAC/F,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBvB,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW5B,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBvB,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Who can sign in, and their sessions. These tables belong to the sign-in library (`cms-auth`
3
+ * wraps Better Auth), which reads and writes them; their columns are the ones it expects. They
4
+ * live here so one set of migrations sets up the whole database, and carry an `auth_` prefix so
5
+ * they can never collide with a site's own content.
6
+ *
7
+ * Don't query them from anywhere but `cms-auth`.
8
+ */
9
+ import { sql } from 'drizzle-orm';
10
+ import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
11
+ const now = sql `(cast(unixepoch('subsecond') * 1000 as integer))`;
12
+ const createdAt = () => integer('created_at', { mode: 'timestamp_ms' }).default(now).notNull();
13
+ const updatedAt = () => integer('updated_at', { mode: 'timestamp_ms' })
14
+ .default(now)
15
+ .$onUpdate(() => new Date())
16
+ .notNull();
17
+ /** A person who may sign in. `role` is the CMS role: owner, editor or author. */
18
+ export const authUser = sqliteTable('auth_user', {
19
+ id: text('id').primaryKey(),
20
+ name: text('name').notNull(),
21
+ email: text('email').notNull().unique(),
22
+ emailVerified: integer('email_verified', { mode: 'boolean' }).default(false).notNull(),
23
+ image: text('image'),
24
+ createdAt: createdAt(),
25
+ updatedAt: updatedAt(),
26
+ role: text('role').default('author').notNull(),
27
+ });
28
+ export const authSession = sqliteTable('auth_session', {
29
+ id: text('id').primaryKey(),
30
+ expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
31
+ token: text('token').notNull().unique(),
32
+ createdAt: createdAt(),
33
+ updatedAt: updatedAt(),
34
+ ipAddress: text('ip_address'),
35
+ userAgent: text('user_agent'),
36
+ userId: text('user_id')
37
+ .notNull()
38
+ .references(() => authUser.id, { onDelete: 'cascade' }),
39
+ }, (table) => [index('auth_session_user_id').on(table.userId)]);
40
+ /** How a person signs in. The library requires the table; with no passwords it stays small. */
41
+ export const authAccount = sqliteTable('auth_account', {
42
+ id: text('id').primaryKey(),
43
+ accountId: text('account_id').notNull(),
44
+ providerId: text('provider_id').notNull(),
45
+ userId: text('user_id')
46
+ .notNull()
47
+ .references(() => authUser.id, { onDelete: 'cascade' }),
48
+ accessToken: text('access_token'),
49
+ refreshToken: text('refresh_token'),
50
+ idToken: text('id_token'),
51
+ accessTokenExpiresAt: integer('access_token_expires_at', { mode: 'timestamp_ms' }),
52
+ refreshTokenExpiresAt: integer('refresh_token_expires_at', { mode: 'timestamp_ms' }),
53
+ scope: text('scope'),
54
+ password: text('password'),
55
+ createdAt: createdAt(),
56
+ updatedAt: updatedAt(),
57
+ }, (table) => [index('auth_account_user_id').on(table.userId)]);
58
+ /** Sign-in links that have been sent and not yet used. Tokens are stored hashed. */
59
+ export const authVerification = sqliteTable('auth_verification', {
60
+ id: text('id').primaryKey(),
61
+ identifier: text('identifier').notNull(),
62
+ value: text('value').notNull(),
63
+ expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
64
+ createdAt: createdAt(),
65
+ updatedAt: updatedAt(),
66
+ }, (table) => [index('auth_verification_identifier').on(table.identifier)]);
67
+ export const authPasskey = sqliteTable('auth_passkey', {
68
+ id: text('id').primaryKey(),
69
+ name: text('name'),
70
+ publicKey: text('public_key').notNull(),
71
+ userId: text('user_id')
72
+ .notNull()
73
+ .references(() => authUser.id, { onDelete: 'cascade' }),
74
+ credentialID: text('credential_id').notNull(),
75
+ counter: integer('counter').notNull(),
76
+ deviceType: text('device_type').notNull(),
77
+ backedUp: integer('backed_up', { mode: 'boolean' }).notNull(),
78
+ transports: text('transports'),
79
+ createdAt: integer('created_at', { mode: 'timestamp_ms' }),
80
+ aaguid: text('aaguid'),
81
+ }, (table) => [index('auth_passkey_user_id').on(table.userId), index('auth_passkey_credential_id').on(table.credentialID)]);
82
+ //# sourceMappingURL=auth-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-tables.js","sourceRoot":"","sources":["../src/auth-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE5E,MAAM,GAAG,GAAG,GAAG,CAAA,kDAAkD,CAAC;AAClE,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;AAC/F,MAAM,SAAS,GAAG,GAAG,EAAE,CACrB,OAAO,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;KAC5C,OAAO,CAAC,GAAG,CAAC;KACZ,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;KAC3B,OAAO,EAAE,CAAC;AAEf,iFAAiF;AACjF,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,EAAE;IAC/C,EAAE,EAAE,IAAI,CAAC,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AAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CACxH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type Contact, type ContactNote, type ContactQuery, type ContactRepository, type Page } from '@velocity-astro/cms-core';
2
+ import type { Db } from './database.js';
3
+ export declare class SqliteContactRepository implements ContactRepository {
4
+ private readonly db;
5
+ constructor(db: Db);
6
+ get(id: string): Promise<Contact | null>;
7
+ getByEmail(email: string): Promise<Contact | null>;
8
+ find(query?: ContactQuery): Promise<Page<Contact>>;
9
+ save(contact: Contact, expectedRevision: number | null): Promise<Contact>;
10
+ moveStage(from: string, to: string): Promise<number>;
11
+ remove(id: string): Promise<void>;
12
+ notes(contactId: string): Promise<ContactNote[]>;
13
+ addNote(note: ContactNote): Promise<ContactNote>;
14
+ removeNote(contactId: string, noteId: string): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=contact-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-repository.d.ts","sourceRoot":"","sources":["../src/contact-repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAC/I,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AA6BxC,qBAAa,uBAAwB,YAAW,iBAAiB;IACnD,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,EAAE;IAE7B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAKxC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAKlD,IAAI,CAAC,KAAK,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAwBtD,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBzE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKpD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjC,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAKhD,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAOhD,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnE"}
@@ -0,0 +1,108 @@
1
+ import { and, asc, count, desc, eq, isNull, lte, ne, or, sql } from 'drizzle-orm';
2
+ import { ConflictError } from '@velocity-astro/cms-core';
3
+ import { contactNotes, contacts } from './tables.js';
4
+ const toContact = ({ name, phone, sourceFormId, sourcePage, ownerId, followUpAt, data, ...row }) => ({
5
+ ...row,
6
+ ...(name !== null && { name }),
7
+ ...(phone !== null && { phone }),
8
+ ...(sourceFormId !== null && { source: { formId: sourceFormId, ...(sourcePage !== null && { page: sourcePage }) } }),
9
+ ...(ownerId !== null && { ownerId }),
10
+ ...(followUpAt !== null && { followUpAt }),
11
+ ...(data !== null && { data }),
12
+ });
13
+ const toRow = ({ source, ...contact }) => ({
14
+ ...contact,
15
+ name: contact.name ?? null,
16
+ phone: contact.phone ?? null,
17
+ sourceFormId: source?.formId ?? null,
18
+ sourcePage: source?.page ?? null,
19
+ ownerId: contact.ownerId ?? null,
20
+ followUpAt: contact.followUpAt ?? null,
21
+ data: contact.data ?? null,
22
+ });
23
+ /** The words as a pattern that matches them anywhere, with nothing in them read as a wildcard. */
24
+ const containing = (words) => `%${words.toLowerCase().replace(/[\\%_]/g, (mark) => `\\${mark}`)}%`;
25
+ export class SqliteContactRepository {
26
+ db;
27
+ constructor(db) {
28
+ this.db = db;
29
+ }
30
+ async get(id) {
31
+ const [row] = await this.db.select().from(contacts).where(eq(contacts.id, id)).limit(1);
32
+ return row ? toContact(row) : null;
33
+ }
34
+ async getByEmail(email) {
35
+ const [row] = await this.db.select().from(contacts).where(eq(contacts.email, email)).limit(1);
36
+ return row ? toContact(row) : null;
37
+ }
38
+ async find(query = {}) {
39
+ const words = (query.search ?? '').trim();
40
+ const conditions = [];
41
+ if (words !== '') {
42
+ const pattern = containing(words);
43
+ const like = (column) => sql `lower(${column}) like ${pattern} escape '\\'`;
44
+ conditions.push(or(like(contacts.name), like(contacts.email), like(contacts.phone)));
45
+ }
46
+ if (query.stage !== undefined)
47
+ conditions.push(eq(contacts.stage, query.stage));
48
+ if (query.ownerId !== undefined)
49
+ conditions.push(query.ownerId === null ? isNull(contacts.ownerId) : eq(contacts.ownerId, query.ownerId));
50
+ if (query.followUpBy !== undefined)
51
+ conditions.push(lte(contacts.followUpAt, query.followUpBy));
52
+ const where = and(...conditions);
53
+ const order = query.followUpBy === undefined ? [desc(contacts.createdAt), asc(contacts.id)] : [asc(contacts.followUpAt), asc(contacts.id)];
54
+ const rows = await this.db
55
+ .select()
56
+ .from(contacts)
57
+ .where(where)
58
+ .orderBy(...order)
59
+ .limit(query.limit ?? 50)
60
+ .offset(query.offset ?? 0);
61
+ const [counted] = await this.db.select({ total: count() }).from(contacts).where(where);
62
+ return { items: rows.map(toContact), total: counted?.total ?? 0 };
63
+ }
64
+ async save(contact, expectedRevision) {
65
+ // The revision check, the email check and the write happen together or not at all.
66
+ await this.db.transaction(async (tx) => {
67
+ const [stored] = await tx.select({ revision: contacts.revision }).from(contacts).where(eq(contacts.id, contact.id)).limit(1);
68
+ if ((stored?.revision ?? null) !== expectedRevision) {
69
+ throw new ConflictError(`Contact "${contact.id}" changed since it was read.`);
70
+ }
71
+ const [other] = await tx
72
+ .select({ id: contacts.id })
73
+ .from(contacts)
74
+ .where(and(eq(contacts.email, contact.email), ne(contacts.id, contact.id)))
75
+ .limit(1);
76
+ if (other)
77
+ throw new ConflictError(`Another contact has the email "${contact.email}".`);
78
+ const row = toRow(contact);
79
+ await tx.insert(contacts).values(row).onConflictDoUpdate({ target: contacts.id, set: row });
80
+ });
81
+ return contact;
82
+ }
83
+ async moveStage(from, to) {
84
+ const moved = await this.db.update(contacts).set({ stage: to }).where(eq(contacts.stage, from)).returning({ id: contacts.id });
85
+ return moved.length;
86
+ }
87
+ async remove(id) {
88
+ await this.db.transaction(async (tx) => {
89
+ await tx.delete(contactNotes).where(eq(contactNotes.contactId, id));
90
+ await tx.delete(contacts).where(eq(contacts.id, id));
91
+ });
92
+ }
93
+ async notes(contactId) {
94
+ const rows = await this.db.select().from(contactNotes).where(eq(contactNotes.contactId, contactId)).orderBy(desc(contactNotes.createdAt), asc(contactNotes.id));
95
+ return rows.map(({ movedFrom, movedTo, ...note }) => ({ ...note, ...(movedFrom !== null && movedTo !== null && { moved: { from: movedFrom, to: movedTo } }) }));
96
+ }
97
+ async addNote(note) {
98
+ const { moved, ...row } = note;
99
+ const added = await this.db.insert(contactNotes).values({ ...row, movedFrom: moved?.from ?? null, movedTo: moved?.to ?? null }).onConflictDoNothing().returning({ id: contactNotes.id });
100
+ if (added.length === 0)
101
+ throw new ConflictError(`Note "${note.id}" already exists.`);
102
+ return note;
103
+ }
104
+ async removeNote(contactId, noteId) {
105
+ await this.db.delete(contactNotes).where(and(eq(contactNotes.id, noteId), eq(contactNotes.contactId, contactId)));
106
+ }
107
+ }
108
+ //# sourceMappingURL=contact-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-repository.js","sourceRoot":"","sources":["../src/contact-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAA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AI,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,mBAAmB,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;QACzL,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,aAAa,CAAC,SAAS,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC;QACrF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,MAAc;QAChD,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACpH,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { type CustomFields, type CustomFieldsStore } from '@velocity-astro/cms-core';
2
+ import type { Db } from './database.js';
3
+ export declare class SqliteCustomFieldsStore implements CustomFieldsStore {
4
+ private readonly db;
5
+ constructor(db: Db);
6
+ get(): Promise<CustomFields | null>;
7
+ save(fields: CustomFields, expectedRevision: number | null): Promise<CustomFields>;
8
+ }
9
+ //# sourceMappingURL=custom-fields-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-fields-store.d.ts","sourceRoot":"","sources":["../src/custom-fields-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAKxC,qBAAa,uBAAwB,YAAW,iBAAiB;IACnD,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,EAAE;IAE7B,GAAG,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAKnC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC;CAUzF"}
@@ -0,0 +1,26 @@
1
+ import { eq } from 'drizzle-orm';
2
+ import { ConflictError } from '@velocity-astro/cms-core';
3
+ import { siteSettings } from './tables.js';
4
+ const KEY = 'custom-fields';
5
+ export class SqliteCustomFieldsStore {
6
+ db;
7
+ constructor(db) {
8
+ this.db = db;
9
+ }
10
+ async get() {
11
+ const [row] = await this.db.select().from(siteSettings).where(eq(siteSettings.key, KEY)).limit(1);
12
+ return row ? { ...row.value, revision: row.revision } : null;
13
+ }
14
+ async save(fields, expectedRevision) {
15
+ // The revision check and the write happen together or not at all.
16
+ await this.db.transaction(async (tx) => {
17
+ const [stored] = await tx.select({ revision: siteSettings.revision }).from(siteSettings).where(eq(siteSettings.key, KEY)).limit(1);
18
+ if ((stored?.revision ?? null) !== expectedRevision)
19
+ throw new ConflictError('These fields changed since they were read.');
20
+ const { revision, ...kept } = fields;
21
+ await tx.insert(siteSettings).values({ key: KEY, revision, value: kept }).onConflictDoUpdate({ target: siteSettings.key, set: { revision, value: kept } });
22
+ });
23
+ return fields;
24
+ }
25
+ }
26
+ //# sourceMappingURL=custom-fields-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-fields-store.js","sourceRoot":"","sources":["../src/custom-fields-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,aAAa,EAA6C,MAAM,0BAA0B,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,GAAG,GAAG,eAAe,CAAC;AAE5B,MAAM,OAAO,uBAAuB;IACL;IAA7B,YAA6B,EAAM;QAAN,OAAE,GAAF,EAAE,CAAI;IAAG,CAAC;IAEvC,KAAK,CAAC,GAAG;QACP,MAAM,CAAC,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