@drfed/models 0.0.0-stage → 0.1.0-dev.0

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 (132) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +230 -2
  3. package/dist/activity-delivery.d.mts +111 -0
  4. package/dist/activity-delivery.d.mts.map +1 -0
  5. package/dist/activity-delivery.mjs +240 -0
  6. package/dist/activity-delivery.mjs.map +1 -0
  7. package/dist/db-DtcLuISw.d.mts +3098 -0
  8. package/dist/db-DtcLuISw.d.mts.map +1 -0
  9. package/dist/db.d.mts +2 -0
  10. package/dist/db.mjs +3 -0
  11. package/dist/email.d.mts +39 -0
  12. package/dist/email.d.mts.map +1 -0
  13. package/dist/email.mjs +12 -0
  14. package/dist/email.mjs.map +1 -0
  15. package/dist/index.d.mts +14 -0
  16. package/dist/index.mjs +18 -0
  17. package/dist/instance.d.mts +11 -0
  18. package/dist/instance.d.mts.map +1 -0
  19. package/dist/instance.mjs +21 -0
  20. package/dist/instance.mjs.map +1 -0
  21. package/dist/key.d.mts +2 -0
  22. package/dist/key.mjs +86 -0
  23. package/dist/key.mjs.map +1 -0
  24. package/dist/login.d.mts +49 -0
  25. package/dist/login.d.mts.map +1 -0
  26. package/dist/login.mjs +71 -0
  27. package/dist/login.mjs.map +1 -0
  28. package/dist/migrate.d.mts +46 -0
  29. package/dist/migrate.d.mts.map +1 -0
  30. package/dist/migrate.mjs +58 -0
  31. package/dist/migrate.mjs.map +1 -0
  32. package/dist/migration-manifest.d.mts +39 -0
  33. package/dist/migration-manifest.d.mts.map +1 -0
  34. package/dist/migration-manifest.mjs +77 -0
  35. package/dist/migration-manifest.mjs.map +1 -0
  36. package/dist/migration-session-B4xHeU_a.d.mts +56 -0
  37. package/dist/migration-session-B4xHeU_a.d.mts.map +1 -0
  38. package/dist/migration-session.d.mts +2 -0
  39. package/dist/migration-session.mjs +204 -0
  40. package/dist/migration-session.mjs.map +1 -0
  41. package/dist/migration-snapshot-OM5jQN1-.mjs +69 -0
  42. package/dist/migration-snapshot-OM5jQN1-.mjs.map +1 -0
  43. package/dist/migration-state.d.mts +41 -0
  44. package/dist/migration-state.d.mts.map +1 -0
  45. package/dist/migration-state.mjs +155 -0
  46. package/dist/migration-state.mjs.map +1 -0
  47. package/dist/migrations-manifest.json +109 -0
  48. package/dist/pglite-preparation.d.mts +23 -0
  49. package/dist/pglite-preparation.d.mts.map +1 -0
  50. package/dist/pglite-preparation.mjs +77 -0
  51. package/dist/pglite-preparation.mjs.map +1 -0
  52. package/dist/pglite-store.d.mts +29 -0
  53. package/dist/pglite-store.d.mts.map +1 -0
  54. package/dist/pglite-store.mjs +117 -0
  55. package/dist/pglite-store.mjs.map +1 -0
  56. package/dist/relations.d.mts +2 -0
  57. package/dist/relations.mjs +307 -0
  58. package/dist/relations.mjs.map +1 -0
  59. package/dist/resource.d.mts +50 -0
  60. package/dist/resource.d.mts.map +1 -0
  61. package/dist/resource.mjs +123 -0
  62. package/dist/resource.mjs.map +1 -0
  63. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  64. package/dist/schema.d.mts +2 -0
  65. package/dist/schema.mjs +495 -0
  66. package/dist/schema.mjs.map +1 -0
  67. package/dist/slug.d.mts +28 -0
  68. package/dist/slug.d.mts.map +1 -0
  69. package/dist/slug.mjs +55 -0
  70. package/dist/slug.mjs.map +1 -0
  71. package/dist/text.d.mts +10 -0
  72. package/dist/text.d.mts.map +1 -0
  73. package/dist/text.mjs +11 -0
  74. package/dist/text.mjs.map +1 -0
  75. package/dist/uuid-CKMzlIND.d.mts +26 -0
  76. package/dist/uuid-CKMzlIND.d.mts.map +1 -0
  77. package/dist/uuid.d.mts +2 -0
  78. package/dist/uuid.mjs +28 -0
  79. package/dist/uuid.mjs.map +1 -0
  80. package/drizzle/20260622021748_init/migration.sql +25 -0
  81. package/drizzle/20260622021748_init/snapshot.json +246 -0
  82. package/drizzle/20260623162238_dear_felicia_hardy/migration.sql +5 -0
  83. package/drizzle/20260623162238_dear_felicia_hardy/snapshot.json +321 -0
  84. package/drizzle/20260624094817_lethal_sinister_six/migration.sql +2 -0
  85. package/drizzle/20260624094817_lethal_sinister_six/snapshot.json +347 -0
  86. package/drizzle/20260716000333_email_auth/migration.sql +20 -0
  87. package/drizzle/20260716000333_email_auth/snapshot.json +575 -0
  88. package/drizzle/20260723065002_chief_colleen_wing/migration.sql +2 -0
  89. package/drizzle/20260723065002_chief_colleen_wing/snapshot.json +595 -0
  90. package/drizzle/20260802205417_separate-instance-local-remote/migration.sql +26 -0
  91. package/drizzle/20260802205417_separate-instance-local-remote/snapshot.json +768 -0
  92. package/drizzle/20260804061119_instances-local-remote-constraint/migration.sql +7 -0
  93. package/drizzle/20260804061119_instances-local-remote-constraint/snapshot.json +843 -0
  94. package/drizzle/20260818080259_dark_night_thrasher/migration.sql +15 -0
  95. package/drizzle/20260818080259_dark_night_thrasher/snapshot.json +722 -0
  96. package/drizzle/20260821072150_merge_remote_actors/migration.sql +54 -0
  97. package/drizzle/20260821072150_merge_remote_actors/snapshot.json +1312 -0
  98. package/drizzle/20260906052949_rename_followees_to_following/migration.sql +2 -0
  99. package/drizzle/20260906052949_rename_followees_to_following/snapshot.json +1315 -0
  100. package/drizzle/20260908062446_rename_login_tokens_to_login_challenges/migration.sql +1 -0
  101. package/drizzle/20260908062446_rename_login_tokens_to_login_challenges/snapshot.json +1312 -0
  102. package/drizzle/20260908065945_simplify_login_challenges/migration.sql +7 -0
  103. package/drizzle/20260908065945_simplify_login_challenges/snapshot.json +1290 -0
  104. package/drizzle/20260915061356_tighten_slug_constraint/migration.sql +12 -0
  105. package/drizzle/20260915061356_tighten_slug_constraint/snapshot.json +1290 -0
  106. package/drizzle/20260915063339_widen_instance_host/migration.sql +1 -0
  107. package/drizzle/20260915063339_widen_instance_host/snapshot.json +1290 -0
  108. package/drizzle/20260916085902_add_objects_activities_and_resources/migration.sql +110 -0
  109. package/drizzle/20260916085902_add_objects_activities_and_resources/snapshot.json +2263 -0
  110. package/drizzle/20260917163517_order_local_outbox_items/migration.sql +22 -0
  111. package/drizzle/20260917163517_order_local_outbox_items/snapshot.json +2263 -0
  112. package/drizzle/20260918071839_add_activity_object_index/migration.sql +1 -0
  113. package/drizzle/20260918071839_add_activity_object_index/snapshot.json +2298 -0
  114. package/drizzle/20261006061745_add_activity_deliveries_and_keys/migration.sql +106 -0
  115. package/drizzle/20261006061745_add_activity_deliveries_and_keys/snapshot.json +3538 -0
  116. package/drizzle/20261006085045_snake_case_columns/migration.sql +42 -0
  117. package/drizzle/20261006085045_snake_case_columns/snapshot.json +3570 -0
  118. package/drizzle/20261006122653_local_actor_keys/migration.sql +11 -0
  119. package/drizzle/20261006122653_local_actor_keys/snapshot.json +3627 -0
  120. package/drizzle/20261010044954_link_activity_deliveries_to_activities/migration.sql +8 -0
  121. package/drizzle/20261010044954_link_activity_deliveries_to_activities/snapshot.json +3714 -0
  122. package/drizzle/20261010073134_check_inbound_activity_link/migration.sql +1 -0
  123. package/drizzle/20261010073134_check_inbound_activity_link/snapshot.json +3721 -0
  124. package/drizzle/20261010104304_record_object_activity/migration.sql +3 -0
  125. package/drizzle/20261010104304_record_object_activity/snapshot.json +3756 -0
  126. package/drizzle/20261010111648_record_delivery_snapshot/migration.sql +29 -0
  127. package/drizzle/20261010111648_record_delivery_snapshot/snapshot.json +3769 -0
  128. package/drizzle/20261011144453_record_object_snapshot/migration.sql +10 -0
  129. package/drizzle/20261011144453_record_object_snapshot/snapshot.json +3808 -0
  130. package/drizzle/20261011192718_record_actor_followers/migration.sql +1 -0
  131. package/drizzle/20261011192718_record_actor_followers/snapshot.json +3821 -0
  132. package/package.json +181 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-DtcLuISw.d.mts","names":[],"sources":["../src/key.ts","../src/schema.ts","../src/relations.ts","../src/db.ts"],"mappings":";;;;;KAuBY,YAAY,QACtB,QAAQ,WAAW,6BACnB;EACI;EAAc;;;;;;iBAiBJ,YAAY,KAAK,YAAY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,kBAAgB,uBAAuB,aACjD,wBAA4B,WAAW,WAAW"}
package/dist/db.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { n as RelationsFilter, r as Transaction, t as Database } from "./db-DtcLuISw.mjs";
2
+ export { Database, RelationsFilter, Transaction };
package/dist/db.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import "./schema.mjs";
2
+ import "./relations.mjs";
3
+ export {};
@@ -0,0 +1,39 @@
1
+ //#region src/email.d.ts
2
+ /**
3
+ * Normalizes an email address by trimming whitespace, converting the host
4
+ * to lowercase (and to punycode if necessary), and ensuring it has a
5
+ * single "@" character. If the email is invalid, it throws a `TypeError`.
6
+ * @param email The email address to normalize.
7
+ * @returns The normalized email address.
8
+ */
9
+ declare function normalizeEmail(email: string): string;
10
+ /**
11
+ * Normalizes an email address by trimming whitespace, converting the host
12
+ * to lowercase (and to punycode if necessary), and ensuring it has a
13
+ * single "@" character. If the email is invalid, it throws a `TypeError`.
14
+ * @param email The email address to normalize.
15
+ * @returns The normalized email address. If the input is `null`,
16
+ * it returns `null`.
17
+ */
18
+ declare function normalizeEmail(email: string | null): string | null;
19
+ /**
20
+ * Normalizes an email address by trimming whitespace, converting the host
21
+ * to lowercase (and to punycode if necessary), and ensuring it has a
22
+ * single "@" character. If the email is invalid, it throws a `TypeError`.
23
+ * @param email The email address to normalize.
24
+ * @returns The normalized email address. If the input is `undefined`,
25
+ * it returns `undefined`.
26
+ */
27
+ declare function normalizeEmail(email: string | undefined): string | undefined;
28
+ /**
29
+ * Normalizes an email address by trimming whitespace, converting the host
30
+ * to lowercase (and to punycode if necessary), and ensuring it has a
31
+ * single "@" character. If the email is invalid, it throws a `TypeError`.
32
+ * @param email The email address to normalize.
33
+ * @returns The normalized email address. If the input is `undefined`,
34
+ * it returns `undefined`. If the input is `null`, it returns `null`.
35
+ */
36
+ declare function normalizeEmail(email: string | null | undefined): string | null | undefined;
37
+ //#endregion
38
+ export { normalizeEmail };
39
+ //# sourceMappingURL=email.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.mts","names":[],"sources":["../src/email.ts"],"mappings":";;;;;;;;iBAuBgB,eAAe;;;;;;;;;iBAUf,eAAe;;;;;;;;;iBAUf,eAAe;;;;;;;;;iBAUf,eACd"}
package/dist/email.mjs ADDED
@@ -0,0 +1,12 @@
1
+ //#region src/email.ts
2
+ function normalizeEmail(email) {
3
+ if (typeof email === "undefined") return;
4
+ else if (email == null) return null;
5
+ const [local, host, shouldNotExist] = email.trim().split("@");
6
+ if (local == null || local.trim() === "" || host == null || host.trim() === "" || shouldNotExist != null) throw new TypeError("Invalid email format.");
7
+ return `${local}@${new URL(`https://${host}/`).host}`;
8
+ }
9
+ //#endregion
10
+ export { normalizeEmail };
11
+
12
+ //# sourceMappingURL=email.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.mjs","names":[],"sources":["../src/email.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n/**\n * Normalizes an email address by trimming whitespace, converting the host\n * to lowercase (and to punycode if necessary), and ensuring it has a\n * single \"@\" character. If the email is invalid, it throws a `TypeError`.\n * @param email The email address to normalize.\n * @returns The normalized email address.\n */\nexport function normalizeEmail(email: string): string;\n\n/**\n * Normalizes an email address by trimming whitespace, converting the host\n * to lowercase (and to punycode if necessary), and ensuring it has a\n * single \"@\" character. If the email is invalid, it throws a `TypeError`.\n * @param email The email address to normalize.\n * @returns The normalized email address. If the input is `null`,\n * it returns `null`.\n */\nexport function normalizeEmail(email: string | null): string | null;\n\n/**\n * Normalizes an email address by trimming whitespace, converting the host\n * to lowercase (and to punycode if necessary), and ensuring it has a\n * single \"@\" character. If the email is invalid, it throws a `TypeError`.\n * @param email The email address to normalize.\n * @returns The normalized email address. If the input is `undefined`,\n * it returns `undefined`.\n */\nexport function normalizeEmail(email: string | undefined): string | undefined;\n\n/**\n * Normalizes an email address by trimming whitespace, converting the host\n * to lowercase (and to punycode if necessary), and ensuring it has a\n * single \"@\" character. If the email is invalid, it throws a `TypeError`.\n * @param email The email address to normalize.\n * @returns The normalized email address. If the input is `undefined`,\n * it returns `undefined`. If the input is `null`, it returns `null`.\n */\nexport function normalizeEmail(\n email: string | null | undefined,\n): string | null | undefined;\n\nexport function normalizeEmail(\n email: string | null | undefined,\n): string | null | undefined {\n if (typeof email === \"undefined\") {\n return undefined;\n } else if (email == null) {\n return null;\n }\n const [local, host, shouldNotExist] = email.trim().split(\"@\");\n if (\n local == null ||\n local.trim() === \"\" ||\n host == null ||\n host.trim() === \"\" ||\n shouldNotExist != null\n ) {\n throw new TypeError(\"Invalid email format.\");\n }\n const normalizedHost = new URL(`https://${host}/`).host;\n return `${local}@${normalizedHost}`;\n}\n"],"mappings":";AAyDA,SAAgB,eACd,OAC2B;CAC3B,IAAI,OAAO,UAAU,aACnB;MACK,IAAI,SAAS,MAClB,OAAO;CAET,MAAM,CAAC,OAAO,MAAM,kBAAkB,MAAM,KAAK,CAAC,CAAC,MAAM,GAAG;CAC5D,IACE,SAAS,QACT,MAAM,KAAK,MAAM,MACjB,QAAQ,QACR,KAAK,KAAK,MAAM,MAChB,kBAAkB,MAElB,MAAM,IAAI,UAAU,uBAAuB;CAG7C,OAAO,GAAG,MAAM,GADO,IAAI,IAAI,WAAW,KAAK,EAAE,CAAC,CAAC;AAErD"}
@@ -0,0 +1,14 @@
1
+ import { At as observeKeyVersion, Et as schema_d_exports, Mt as toPublicJwk, Ot as PublicJwk, i as relations, jt as thumbprintInput, kt as jwkThumbprint, n as RelationsFilter, r as Transaction, t as Database } from "./db-DtcLuISw.mjs";
2
+ import { AddressedActor, InboundDeliveryEntry, OutboundDeliveryEntry, OutboundSettlement, inboundActorRows, linkInboundActivity, receiveInbound, recordFetchedObject, recordInbound, recordOutbound, settleOutbound } from "./activity-delivery.mjs";
3
+ import { normalizeEmail } from "./email.mjs";
4
+ import { MigrateCredentials, MigrateOptions, PGliteMigrateCredentials, PostgresMigrateCredentials, migrate } from "./migrate.mjs";
5
+ import { LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, consumeLoginChallenge, findLoginChallenge } from "./login.mjs";
6
+ import { AddressingInput, PUBLIC_IRI, PUBLIC_RESOURCE_ID, ResourceKindConflictError, addActorCollectionItem, ensureResource, lockActorCollection, lockResources, promoteResource, storeAddressing } from "./resource.mjs";
7
+ import { ensureRemoteInstance } from "./instance.mjs";
8
+ import { storableText } from "./text.mjs";
9
+ import { MigrationIdentity, MigrationManifest, MigrationManifestPaths, assertMigrationManifestPrefix, migrationTimestamp, parseMigrationManifest, verifyMigrationManifest } from "./migration-manifest.mjs";
10
+ import { InspectMigrationStateOptions, MigrationHistoryFormat, MigrationQueryClient, MigrationState, MigrationStatus, classifyMigrationHistory, inspectMigrationState } from "./migration-state.mjs";
11
+ import { a as preparePostgresDatabase, i as migrationLockKey, n as PostgresPreparationCredentials, o as MigrationPreparationCode, r as PreparePostgresOptions, s as MigrationPreparationError, t as MigrationClientFactory } from "./migration-session-B4xHeU_a.mjs";
12
+ import { PersistentPgliteStore, PgliteStoreCode, PgliteStoreError, openPersistentPglite } from "./pglite-store.mjs";
13
+ import { PreparePgliteOptions, preparePgliteDatabase } from "./pglite-preparation.mjs";
14
+ export { AddressedActor, AddressingInput, Database, InboundDeliveryEntry, InspectMigrationStateOptions, LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, MigrateCredentials, MigrateOptions, MigrationClientFactory, MigrationHistoryFormat, MigrationIdentity, MigrationManifest, MigrationManifestPaths, type MigrationPreparationCode, MigrationPreparationError, MigrationQueryClient, MigrationState, MigrationStatus, OutboundDeliveryEntry, OutboundSettlement, PGliteMigrateCredentials, PUBLIC_IRI, PUBLIC_RESOURCE_ID, PersistentPgliteStore, PgliteStoreCode, PgliteStoreError, PostgresMigrateCredentials, PostgresPreparationCredentials, PreparePgliteOptions, PreparePostgresOptions, PublicJwk, RelationsFilter, ResourceKindConflictError, Transaction, addActorCollectionItem, assertMigrationManifestPrefix, classifyMigrationHistory, consumeLoginChallenge, ensureRemoteInstance, ensureResource, findLoginChallenge, inboundActorRows, inspectMigrationState, jwkThumbprint, linkInboundActivity, lockActorCollection, lockResources, migrate, migrationLockKey, migrationTimestamp, normalizeEmail, observeKeyVersion, openPersistentPglite, parseMigrationManifest, preparePgliteDatabase, preparePostgresDatabase, promoteResource, receiveInbound, recordFetchedObject, recordInbound, recordOutbound, relations, schema_d_exports as schema, settleOutbound, storableText, storeAddressing, thumbprintInput, toPublicJwk, verifyMigrationManifest };
package/dist/index.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import { normalizeEmail } from "./email.mjs";
2
+ import { t as schema_exports } from "./schema.mjs";
3
+ import relations from "./relations.mjs";
4
+ import "./db.mjs";
5
+ import { migrate } from "./migrate.mjs";
6
+ import { LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, consumeLoginChallenge, findLoginChallenge } from "./login.mjs";
7
+ import { PUBLIC_IRI, PUBLIC_RESOURCE_ID, ResourceKindConflictError, addActorCollectionItem, ensureResource, lockActorCollection, lockResources, promoteResource, storeAddressing } from "./resource.mjs";
8
+ import { jwkThumbprint, observeKeyVersion, thumbprintInput, toPublicJwk } from "./key.mjs";
9
+ import { storableText } from "./text.mjs";
10
+ import { inboundActorRows, linkInboundActivity, receiveInbound, recordFetchedObject, recordInbound, recordOutbound, settleOutbound } from "./activity-delivery.mjs";
11
+ import { ensureRemoteInstance } from "./instance.mjs";
12
+ import { assertMigrationManifestPrefix, migrationTimestamp, parseMigrationManifest, verifyMigrationManifest } from "./migration-manifest.mjs";
13
+ import { classifyMigrationHistory, inspectMigrationState } from "./migration-state.mjs";
14
+ import { n as MigrationPreparationError } from "./migration-snapshot-OM5jQN1-.mjs";
15
+ import { migrationLockKey, preparePostgresDatabase } from "./migration-session.mjs";
16
+ import { PgliteStoreError, openPersistentPglite } from "./pglite-store.mjs";
17
+ import { preparePgliteDatabase } from "./pglite-preparation.mjs";
18
+ export { LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, MigrationPreparationError, PUBLIC_IRI, PUBLIC_RESOURCE_ID, PgliteStoreError, ResourceKindConflictError, addActorCollectionItem, assertMigrationManifestPrefix, classifyMigrationHistory, consumeLoginChallenge, ensureRemoteInstance, ensureResource, findLoginChallenge, inboundActorRows, inspectMigrationState, jwkThumbprint, linkInboundActivity, lockActorCollection, lockResources, migrate, migrationLockKey, migrationTimestamp, normalizeEmail, observeKeyVersion, openPersistentPglite, parseMigrationManifest, preparePgliteDatabase, preparePostgresDatabase, promoteResource, receiveInbound, recordFetchedObject, recordInbound, recordOutbound, relations, schema_exports as schema, settleOutbound, storableText, storeAddressing, thumbprintInput, toPublicJwk, verifyMigrationManifest };
@@ -0,0 +1,11 @@
1
+ import { r as Transaction, t as Database, x as Instance } from "./db-DtcLuISw.mjs";
2
+ //#region src/instance.d.ts
3
+ /**
4
+ * Returns the remote instance of a host, registering it if it is new. The
5
+ * host is compared as given, so it must already be canonical.
6
+ * @returns The remote instance, or null when the host is a local instance's.
7
+ */
8
+ declare function ensureRemoteInstance(tx: Database | Transaction, host: string): Promise<Instance | null>;
9
+ //#endregion
10
+ export { ensureRemoteInstance };
11
+ //# sourceMappingURL=instance.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.d.mts","names":[],"sources":["../src/instance.ts"],"mappings":";;;;;;;iBAyBsB,qBACpB,IAAI,WAAW,aACf,eACC,QAAQ"}
@@ -0,0 +1,21 @@
1
+ import { instances } from "./schema.mjs";
2
+ import { uuidV7 } from "./uuid.mjs";
3
+ //#region src/instance.ts
4
+ /**
5
+ * Returns the remote instance of a host, registering it if it is new. The
6
+ * host is compared as given, so it must already be canonical.
7
+ * @returns The remote instance, or null when the host is a local instance's.
8
+ */
9
+ async function ensureRemoteInstance(tx, host) {
10
+ const [inserted] = await tx.insert(instances).values({
11
+ id: uuidV7(),
12
+ host
13
+ }).onConflictDoNothing({ target: instances.host }).returning();
14
+ const instance = inserted ?? await tx.query.instances.findFirst({ where: { host } }) ?? null;
15
+ if (instance == null) throw new Error("Instance insertion returned no row.");
16
+ return instance.localId == null ? instance : null;
17
+ }
18
+ //#endregion
19
+ export { ensureRemoteInstance };
20
+
21
+ //# sourceMappingURL=instance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.mjs","names":[],"sources":["../src/instance.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { Database, Transaction } from \"./db.ts\";\nimport { type Instance, instances } from \"./schema.ts\";\nimport { uuidV7 } from \"./uuid.ts\";\n\n/**\n * Returns the remote instance of a host, registering it if it is new. The\n * host is compared as given, so it must already be canonical.\n * @returns The remote instance, or null when the host is a local instance's.\n */\nexport async function ensureRemoteInstance(\n tx: Database | Transaction,\n host: string,\n): Promise<Instance | null> {\n const [inserted] = await tx\n .insert(instances)\n .values({ id: uuidV7(), host })\n .onConflictDoNothing({ target: instances.host })\n .returning();\n // A concurrent insertion can win; a separate statement sees that committed\n // row under PostgreSQL's READ COMMITTED.\n const instance =\n inserted ??\n (await tx.query.instances.findFirst({ where: { host } })) ??\n null;\n if (instance == null) throw new Error(\"Instance insertion returned no row.\");\n return instance.localId == null ? instance : null;\n}\n"],"mappings":";;;;;;;;AAyBA,eAAsB,qBACpB,IACA,MAC0B;CAC1B,MAAM,CAAC,YAAY,MAAM,GACtB,OAAO,SAAS,CAAC,CACjB,OAAO;EAAE,IAAI,OAAO;EAAG;CAAK,CAAC,CAAC,CAC9B,oBAAoB,EAAE,QAAQ,UAAU,KAAK,CAAC,CAAC,CAC/C,UAAU;CAGb,MAAM,WACJ,YACC,MAAM,GAAG,MAAM,UAAU,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KACvD;CACF,IAAI,YAAY,MAAM,MAAM,IAAI,MAAM,qCAAqC;CAC3E,OAAO,SAAS,WAAW,OAAO,WAAW;AAC/C"}
package/dist/key.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { At as observeKeyVersion, Mt as toPublicJwk, Ot as PublicJwk, jt as thumbprintInput, kt as jwkThumbprint } from "./db-DtcLuISw.mjs";
2
+ export { PublicJwk, jwkThumbprint, observeKeyVersion, thumbprintInput, toPublicJwk };
package/dist/key.mjs ADDED
@@ -0,0 +1,86 @@
1
+ import { keyVersions, keys } from "./schema.mjs";
2
+ import { uuidV7 } from "./uuid.mjs";
3
+ import { eq, sql } from "drizzle-orm";
4
+ //#region src/key.ts
5
+ const privateParameters = [
6
+ "d",
7
+ "p",
8
+ "q",
9
+ "dp",
10
+ "dq",
11
+ "qi",
12
+ "oth",
13
+ "k"
14
+ ];
15
+ /**
16
+ * Reject private/symmetric key material and remove mutable Web Crypto metadata.
17
+ * @returns The public JWK without key_ops and ext.
18
+ */
19
+ function toPublicJwk(jwk) {
20
+ if (privateParameters.some((name) => name in jwk)) throw new TypeError("Expected an asymmetric public JWK.");
21
+ const { key_ops: _operations, ext: _extractable, ...publicKey } = jwk;
22
+ return publicKey;
23
+ }
24
+ /**
25
+ * RFC 7638 / RFC 8037 required members in lexicographic order.
26
+ * @returns Canonical JSON for the thumbprint hash.
27
+ */
28
+ function thumbprintInput(jwk) {
29
+ const key = toPublicJwk(jwk);
30
+ const required = key.kty === "RSA" ? {
31
+ e: key.e,
32
+ kty: key.kty,
33
+ n: key.n
34
+ } : key.kty === "OKP" && key.crv === "Ed25519" ? {
35
+ crv: key.crv,
36
+ kty: key.kty,
37
+ x: key.x
38
+ } : null;
39
+ if (required == null || Object.values(required).some((value) => typeof value !== "string" || value.length === 0)) throw new TypeError("Unsupported or incomplete public JWK.");
40
+ return JSON.stringify(required);
41
+ }
42
+ /**
43
+ * SHA-256 JWK thumbprint, base64url without padding.
44
+ * @returns The public key fingerprint.
45
+ */
46
+ async function jwkThumbprint(jwk) {
47
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(thumbprintInput(jwk)));
48
+ return new Uint8Array(digest).toBase64({
49
+ alphabet: "base64url",
50
+ omitPadding: true
51
+ });
52
+ }
53
+ /**
54
+ * Observe immutable public key material, reusing a version if a key returns to it.
55
+ * @returns The observed, immutable version with its updated lastSeen.
56
+ */
57
+ async function observeKeyVersion(db, entry) {
58
+ const publicKey = toPublicJwk(entry.publicKey);
59
+ const fingerprint = await jwkThumbprint(publicKey);
60
+ return await db.transaction(async (tx) => {
61
+ await tx.insert(keys).values({
62
+ id: uuidV7(),
63
+ iri: entry.iri
64
+ }).onConflictDoNothing({ target: keys.iri });
65
+ const [key] = await tx.select().from(keys).where(eq(keys.iri, entry.iri));
66
+ if (key == null) throw new Error("Missing logical key after insertion.");
67
+ const observed = entry.observed ?? Temporal.Now.instant();
68
+ const [version] = await tx.insert(keyVersions).values({
69
+ id: uuidV7(),
70
+ keyId: key.id,
71
+ publicKey,
72
+ fingerprint,
73
+ firstSeen: observed,
74
+ lastSeen: observed
75
+ }).onConflictDoUpdate({
76
+ target: [keyVersions.keyId, keyVersions.fingerprint],
77
+ set: { lastSeen: sql`greatest(${keyVersions.lastSeen}, excluded.last_seen)` }
78
+ }).returning();
79
+ if (version == null) throw new Error("Missing key version after insertion.");
80
+ return version;
81
+ });
82
+ }
83
+ //#endregion
84
+ export { jwkThumbprint, observeKeyVersion, thumbprintInput, toPublicJwk };
85
+
86
+ //# sourceMappingURL=key.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.mjs","names":[],"sources":["../src/key.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { eq, sql } from \"drizzle-orm\";\n\nimport type { Database } from \"./db.ts\";\nimport { type KeyVersion, keyVersions, keys } from \"./schema.ts\";\nimport { uuidV7 } from \"./uuid.ts\";\n\n/** Web Crypto's JWK export type, including optional JOSE metadata. */\nexport type PublicJwk = Exclude<\n Awaited<ReturnType<SubtleCrypto[\"exportKey\"]>>,\n ArrayBuffer\n> & { kid?: string; use?: string };\n\nconst privateParameters = [\n \"d\",\n \"p\",\n \"q\",\n \"dp\",\n \"dq\",\n \"qi\",\n \"oth\",\n \"k\",\n] as const;\n\n/**\n * Reject private/symmetric key material and remove mutable Web Crypto metadata.\n * @returns The public JWK without key_ops and ext.\n */\nexport function toPublicJwk(jwk: PublicJwk): PublicJwk {\n if (privateParameters.some((name) => name in jwk)) {\n throw new TypeError(\"Expected an asymmetric public JWK.\");\n }\n const { key_ops: _operations, ext: _extractable, ...publicKey } = jwk;\n return publicKey;\n}\n\n/**\n * RFC 7638 / RFC 8037 required members in lexicographic order.\n * @returns Canonical JSON for the thumbprint hash.\n */\nexport function thumbprintInput(jwk: PublicJwk): string {\n const key = toPublicJwk(jwk);\n const required =\n key.kty === \"RSA\"\n ? // oxlint-disable id-length\n { e: key.e, kty: key.kty, n: key.n }\n : key.kty === \"OKP\" && key.crv === \"Ed25519\"\n ? { crv: key.crv, kty: key.kty, x: key.x }\n : null;\n // oxlint-enable id-length\n if (\n required == null ||\n Object.values(required).some(\n (value) => typeof value !== \"string\" || value.length === 0,\n )\n ) {\n throw new TypeError(\"Unsupported or incomplete public JWK.\");\n }\n return JSON.stringify(required);\n}\n\n/**\n * SHA-256 JWK thumbprint, base64url without padding.\n * @returns The public key fingerprint.\n */\nexport async function jwkThumbprint(jwk: PublicJwk): Promise<string> {\n const digest = await crypto.subtle.digest(\n \"SHA-256\",\n new TextEncoder().encode(thumbprintInput(jwk)),\n );\n return new Uint8Array(digest).toBase64({\n alphabet: \"base64url\",\n omitPadding: true,\n });\n}\n\n/**\n * Observe immutable public key material, reusing a version if a key returns to it.\n * @returns The observed, immutable version with its updated lastSeen.\n */\nexport async function observeKeyVersion(\n db: Database,\n entry: {\n readonly iri: string;\n readonly publicKey: PublicJwk;\n readonly observed?: Temporal.Instant;\n },\n): Promise<KeyVersion> {\n const publicKey = toPublicJwk(entry.publicKey);\n const fingerprint = await jwkThumbprint(publicKey);\n return await db.transaction(async (tx) => {\n await tx\n .insert(keys)\n .values({ id: uuidV7(), iri: entry.iri })\n .onConflictDoNothing({ target: keys.iri });\n const [key] = await tx.select().from(keys).where(eq(keys.iri, entry.iri));\n if (key == null) throw new Error(\"Missing logical key after insertion.\");\n // Take the observation time after serializing competing key insertions.\n const observed = entry.observed ?? Temporal.Now.instant();\n const [version] = await tx\n .insert(keyVersions)\n .values({\n id: uuidV7(),\n keyId: key.id,\n publicKey,\n fingerprint,\n firstSeen: observed,\n lastSeen: observed,\n })\n .onConflictDoUpdate({\n target: [keyVersions.keyId, keyVersions.fingerprint],\n set: {\n lastSeen: sql`greatest(${keyVersions.lastSeen}, excluded.last_seen)`,\n },\n })\n .returning();\n if (version == null) {\n throw new Error(\"Missing key version after insertion.\");\n }\n return version;\n });\n}\n"],"mappings":";;;;AA4BA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,SAAgB,YAAY,KAA2B;CACrD,IAAI,kBAAkB,MAAM,SAAS,QAAQ,GAAG,GAC9C,MAAM,IAAI,UAAU,oCAAoC;CAE1D,MAAM,EAAE,SAAS,aAAa,KAAK,cAAc,GAAG,cAAc;CAClE,OAAO;AACT;;;;;AAMA,SAAgB,gBAAgB,KAAwB;CACtD,MAAM,MAAM,YAAY,GAAG;CAC3B,MAAM,WACJ,IAAI,QAAQ,QAER;EAAE,GAAG,IAAI;EAAG,KAAK,IAAI;EAAK,GAAG,IAAI;CAAE,IACnC,IAAI,QAAQ,SAAS,IAAI,QAAQ,YAC/B;EAAE,KAAK,IAAI;EAAK,KAAK,IAAI;EAAK,GAAG,IAAI;CAAE,IACvC;CAER,IACE,YAAY,QACZ,OAAO,OAAO,QAAQ,CAAC,CAAC,MACrB,UAAU,OAAO,UAAU,YAAY,MAAM,WAAW,CAC3D,GAEA,MAAM,IAAI,UAAU,uCAAuC;CAE7D,OAAO,KAAK,UAAU,QAAQ;AAChC;;;;;AAMA,eAAsB,cAAc,KAAiC;CACnE,MAAM,SAAS,MAAM,OAAO,OAAO,OACjC,WACA,IAAI,YAAY,CAAC,CAAC,OAAO,gBAAgB,GAAG,CAAC,CAC/C;CACA,OAAO,IAAI,WAAW,MAAM,CAAC,CAAC,SAAS;EACrC,UAAU;EACV,aAAa;CACf,CAAC;AACH;;;;;AAMA,eAAsB,kBACpB,IACA,OAKqB;CACrB,MAAM,YAAY,YAAY,MAAM,SAAS;CAC7C,MAAM,cAAc,MAAM,cAAc,SAAS;CACjD,OAAO,MAAM,GAAG,YAAY,OAAO,OAAO;EACxC,MAAM,GACH,OAAO,IAAI,CAAC,CACZ,OAAO;GAAE,IAAI,OAAO;GAAG,KAAK,MAAM;EAAI,CAAC,CAAC,CACxC,oBAAoB,EAAE,QAAQ,KAAK,IAAI,CAAC;EAC3C,MAAM,CAAC,OAAO,MAAM,GAAG,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,KAAK,KAAK,MAAM,GAAG,CAAC;EACxE,IAAI,OAAO,MAAM,MAAM,IAAI,MAAM,sCAAsC;EAEvE,MAAM,WAAW,MAAM,YAAY,SAAS,IAAI,QAAQ;EACxD,MAAM,CAAC,WAAW,MAAM,GACrB,OAAO,WAAW,CAAC,CACnB,OAAO;GACN,IAAI,OAAO;GACX,OAAO,IAAI;GACX;GACA;GACA,WAAW;GACX,UAAU;EACZ,CAAC,CAAC,CACD,mBAAmB;GAClB,QAAQ,CAAC,YAAY,OAAO,YAAY,WAAW;GACnD,KAAK,EACH,UAAU,GAAG,YAAY,YAAY,SAAS,uBAChD;EACF,CAAC,CAAC,CACD,UAAU;EACb,IAAI,WAAW,MACb,MAAM,IAAI,MAAM,sCAAsC;EAExD,OAAO;CACT,CAAC;AACH"}
@@ -0,0 +1,49 @@
1
+ import { A as LoginChallenge, r as Transaction, t as Database } from "./db-DtcLuISw.mjs";
2
+ import { t as Uuid } from "./uuid-CKMzlIND.mjs";
3
+ import { SQL } from "drizzle-orm/sql";
4
+ //#region src/login.d.ts
5
+ /**
6
+ * An error that occurs when a login challenge operation fails.
7
+ */
8
+ declare class LoginChallengeError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /**
12
+ * An error that occurs when a login challenge is not found.
13
+ */
14
+ declare class LoginChallengeNotFoundError extends LoginChallengeError {
15
+ constructor(message: string);
16
+ }
17
+ /**
18
+ * Finds a login challenge by its ID, ensuring that it has not been consumed
19
+ * and has not expired. If the login challenge is not found, it throws a
20
+ * {@link LoginChallengeNotFoundError}.
21
+ * @param db The {@link Database} instance to use for the operation.
22
+ * It can be a {@link Transaction} as well.
23
+ * @param id The UUID of the login challenge to find.
24
+ * @param now An optional timestamp to use for checking expiration.
25
+ * If not provided, the current timestamp will be used.
26
+ * @returns A promise that resolves to the found {@link LoginChallenge}.
27
+ * @throws {LoginChallengeNotFoundError} if the login challenge is not found
28
+ * or has been consumed or expired.
29
+ */
30
+ declare function findLoginChallenge(db: Database | Transaction, id: Uuid, now?: Temporal.Instant | SQL): Promise<LoginChallenge>;
31
+ /**
32
+ * An error that occurs when consuming a login challenge fails.
33
+ */
34
+ declare class LoginChallengeConsumptionError extends LoginChallengeError {
35
+ constructor(message: string);
36
+ }
37
+ /**
38
+ * Consumes a login challenge by setting its `consumed` timestamp to
39
+ * the current time.
40
+ * @param db The {@link Database} instance to use for the operation.
41
+ * It can be a {@link Transaction} as well.
42
+ * @param id The UUID of the login challenge to consume.
43
+ * @param now An optional timestamp to set as the `consumed` time.
44
+ * If not provided, the current timestamp will be used.
45
+ */
46
+ declare function consumeLoginChallenge(db: Database | Transaction, id: Uuid, now?: Temporal.Instant | SQL): Promise<void>;
47
+ //#endregion
48
+ export { LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, consumeLoginChallenge, findLoginChallenge };
49
+ //# sourceMappingURL=login.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.mts","names":[],"sources":["../src/login.ts"],"mappings":";;;;;;;cA0Ba,4BAA4B;EACvC,YAAY;;;;;cASD,oCAAoC;EAC/C,YAAY;;;;;;;;;;;;;;;iBAmBQ,mBACpB,IAAI,WAAW,aACf,IAAI,MACJ,MAAM,SAAS,UAAU,MACxB,QAAQ;;;;cAqBE,uCAAuC;EAClD,YAAY;;;;;;;;;;;iBAeQ,sBACpB,IAAI,WAAW,aACf,IAAI,MACJ,MAAM,SAAS,UAAU,MACxB"}
package/dist/login.mjs ADDED
@@ -0,0 +1,71 @@
1
+ import { loginChallenges } from "./schema.mjs";
2
+ import { and, eq, gt, isNull, sql } from "drizzle-orm/sql";
3
+ //#region src/login.ts
4
+ /**
5
+ * An error that occurs when a login challenge operation fails.
6
+ */
7
+ var LoginChallengeError = class extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "LoginChallengeError";
11
+ }
12
+ };
13
+ /**
14
+ * An error that occurs when a login challenge is not found.
15
+ */
16
+ var LoginChallengeNotFoundError = class extends LoginChallengeError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "LoginChallengeNotFoundError";
20
+ }
21
+ };
22
+ /**
23
+ * Finds a login challenge by its ID, ensuring that it has not been consumed
24
+ * and has not expired. If the login challenge is not found, it throws a
25
+ * {@link LoginChallengeNotFoundError}.
26
+ * @param db The {@link Database} instance to use for the operation.
27
+ * It can be a {@link Transaction} as well.
28
+ * @param id The UUID of the login challenge to find.
29
+ * @param now An optional timestamp to use for checking expiration.
30
+ * If not provided, the current timestamp will be used.
31
+ * @returns A promise that resolves to the found {@link LoginChallenge}.
32
+ * @throws {LoginChallengeNotFoundError} if the login challenge is not found
33
+ * or has been consumed or expired.
34
+ */
35
+ async function findLoginChallenge(db, id, now) {
36
+ now ??= sql`CURRENT_TIMESTAMP`;
37
+ const result = await db.query.loginChallenges.findFirst({ where: {
38
+ id,
39
+ consumed: { isNull: true },
40
+ ...now instanceof Temporal.Instant ? { expires: { gt: now } } : { RAW: (t) => sql`${t.expires} > ${now}` }
41
+ } });
42
+ if (result == null) throw new LoginChallengeNotFoundError("Login challenge not found.");
43
+ return result;
44
+ }
45
+ /**
46
+ * An error that occurs when consuming a login challenge fails.
47
+ */
48
+ var LoginChallengeConsumptionError = class extends LoginChallengeError {
49
+ constructor(message) {
50
+ super(message);
51
+ this.name = "LoginChallengeConsumptionError";
52
+ }
53
+ };
54
+ /**
55
+ * Consumes a login challenge by setting its `consumed` timestamp to
56
+ * the current time.
57
+ * @param db The {@link Database} instance to use for the operation.
58
+ * It can be a {@link Transaction} as well.
59
+ * @param id The UUID of the login challenge to consume.
60
+ * @param now An optional timestamp to set as the `consumed` time.
61
+ * If not provided, the current timestamp will be used.
62
+ */
63
+ async function consumeLoginChallenge(db, id, now) {
64
+ now ??= sql`CURRENT_TIMESTAMP`;
65
+ const result = await db.update(loginChallenges).set({ consumed: now }).where(and(eq(loginChallenges.id, id), isNull(loginChallenges.consumed), gt(loginChallenges.expires, now))).returning({ consumed: loginChallenges.consumed });
66
+ if (result.length < 1 || result[0]?.consumed == null) throw new LoginChallengeConsumptionError("Login challenge not found or already consumed.");
67
+ }
68
+ //#endregion
69
+ export { LoginChallengeConsumptionError, LoginChallengeError, LoginChallengeNotFoundError, consumeLoginChallenge, findLoginChallenge };
70
+
71
+ //# sourceMappingURL=login.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.mjs","names":[],"sources":["../src/login.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n// oxlint-disable max-classes-per-file -- Keep the related challenge errors together.\n\nimport { type SQL, and, eq, gt, isNull, sql } from \"drizzle-orm/sql\";\n\nimport type { Database, Transaction } from \"./db.ts\";\nimport { type LoginChallenge, loginChallenges } from \"./schema.ts\";\nimport type { Uuid } from \"./uuid.ts\";\n\n/**\n * An error that occurs when a login challenge operation fails.\n */\nexport class LoginChallengeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"LoginChallengeError\";\n }\n}\n\n/**\n * An error that occurs when a login challenge is not found.\n */\nexport class LoginChallengeNotFoundError extends LoginChallengeError {\n constructor(message: string) {\n super(message);\n this.name = \"LoginChallengeNotFoundError\";\n }\n}\n\n/**\n * Finds a login challenge by its ID, ensuring that it has not been consumed\n * and has not expired. If the login challenge is not found, it throws a\n * {@link LoginChallengeNotFoundError}.\n * @param db The {@link Database} instance to use for the operation.\n * It can be a {@link Transaction} as well.\n * @param id The UUID of the login challenge to find.\n * @param now An optional timestamp to use for checking expiration.\n * If not provided, the current timestamp will be used.\n * @returns A promise that resolves to the found {@link LoginChallenge}.\n * @throws {LoginChallengeNotFoundError} if the login challenge is not found\n * or has been consumed or expired.\n */\nexport async function findLoginChallenge(\n db: Database | Transaction,\n id: Uuid,\n now?: Temporal.Instant | SQL,\n): Promise<LoginChallenge> {\n // oxlint-disable-next-line no-param-reassign\n now ??= sql`CURRENT_TIMESTAMP`;\n const result = await db.query.loginChallenges.findFirst({\n where: {\n id,\n consumed: { isNull: true },\n ...(now instanceof Temporal.Instant\n ? { expires: { gt: now } }\n : { RAW: (t) => sql`${t.expires} > ${now}` }),\n },\n });\n if (result == null) {\n throw new LoginChallengeNotFoundError(\"Login challenge not found.\");\n }\n return result;\n}\n\n/**\n * An error that occurs when consuming a login challenge fails.\n */\nexport class LoginChallengeConsumptionError extends LoginChallengeError {\n constructor(message: string) {\n super(message);\n this.name = \"LoginChallengeConsumptionError\";\n }\n}\n\n/**\n * Consumes a login challenge by setting its `consumed` timestamp to\n * the current time.\n * @param db The {@link Database} instance to use for the operation.\n * It can be a {@link Transaction} as well.\n * @param id The UUID of the login challenge to consume.\n * @param now An optional timestamp to set as the `consumed` time.\n * If not provided, the current timestamp will be used.\n */\nexport async function consumeLoginChallenge(\n db: Database | Transaction,\n id: Uuid,\n now?: Temporal.Instant | SQL,\n): Promise<void> {\n // oxlint-disable-next-line no-param-reassign\n now ??= sql`CURRENT_TIMESTAMP`;\n const result = await db\n .update(loginChallenges)\n .set({ consumed: now })\n .where(\n and(\n eq(loginChallenges.id, id),\n isNull(loginChallenges.consumed),\n gt(loginChallenges.expires, now),\n ),\n )\n .returning({ consumed: loginChallenges.consumed });\n if (result.length < 1 || result[0]?.consumed == null) {\n throw new LoginChallengeConsumptionError(\n \"Login challenge not found or already consumed.\",\n );\n }\n}\n"],"mappings":";;;;;;AA0BA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;AAKA,IAAa,8BAAb,cAAiD,oBAAoB;CACnE,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;;AAeA,eAAsB,mBACpB,IACA,IACA,KACyB;CAEzB,QAAQ,GAAG;CACX,MAAM,SAAS,MAAM,GAAG,MAAM,gBAAgB,UAAU,EACtD,OAAO;EACL;EACA,UAAU,EAAE,QAAQ,KAAK;EACzB,GAAI,eAAe,SAAS,UACxB,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,IACvB,EAAE,MAAM,MAAM,GAAG,GAAG,EAAE,QAAQ,KAAK,MAAM;CAC/C,EACF,CAAC;CACD,IAAI,UAAU,MACZ,MAAM,IAAI,4BAA4B,4BAA4B;CAEpE,OAAO;AACT;;;;AAKA,IAAa,iCAAb,cAAoD,oBAAoB;CACtE,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;;;;;;;AAWA,eAAsB,sBACpB,IACA,IACA,KACe;CAEf,QAAQ,GAAG;CACX,MAAM,SAAS,MAAM,GAClB,OAAO,eAAe,CAAC,CACvB,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC,CACtB,MACC,IACE,GAAG,gBAAgB,IAAI,EAAE,GACzB,OAAO,gBAAgB,QAAQ,GAC/B,GAAG,gBAAgB,SAAS,GAAG,CACjC,CACF,CAAC,CACA,UAAU,EAAE,UAAU,gBAAgB,SAAS,CAAC;CACnD,IAAI,OAAO,SAAS,KAAK,OAAO,EAAE,EAAE,YAAY,MAC9C,MAAM,IAAI,+BACR,gDACF;AAEJ"}
@@ -0,0 +1,46 @@
1
+ import { PGlite, PGliteOptions } from "@electric-sql/pglite";
2
+ import { Options, Sql } from "postgres";
3
+ //#region src/migrate.d.ts
4
+ type MigrateCredentials = PostgresMigrateCredentials | PGliteMigrateCredentials;
5
+ type PostgresMigrateCredentials = {
6
+ readonly driver?: never;
7
+ readonly url: string;
8
+ readonly options?: Omit<Options<Record<string, never>>, "max">;
9
+ } | {
10
+ readonly driver?: never;
11
+ readonly client: Sql;
12
+ };
13
+ type PGliteMigrateCredentials = {
14
+ readonly driver: "pglite";
15
+ readonly url: string;
16
+ readonly options?: PGliteOptions;
17
+ } | {
18
+ readonly driver: "pglite";
19
+ readonly client: PGlite;
20
+ };
21
+ interface MigrateOptions {
22
+ /**
23
+ * PostgreSQL or PGlite credentials.
24
+ */
25
+ readonly credentials: MigrateCredentials;
26
+ /**
27
+ * Custom migrations table/schema. Equivalent to drizzle-kit config's
28
+ * `migrations` option.
29
+ */
30
+ readonly migrations?: {
31
+ readonly table?: string;
32
+ readonly schema?: string;
33
+ };
34
+ /**
35
+ * Custom migrations table. Takes precedence over `migrations.table`.
36
+ */
37
+ readonly migrationsTable?: string;
38
+ /**
39
+ * Custom migrations schema. Takes precedence over `migrations.schema`.
40
+ */
41
+ readonly migrationsSchema?: string;
42
+ }
43
+ declare function migrate(options: MigrateOptions): Promise<void>;
44
+ //#endregion
45
+ export { MigrateCredentials, MigrateOptions, PGliteMigrateCredentials, PostgresMigrateCredentials, migrate };
46
+ //# sourceMappingURL=migrate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.mts","names":[],"sources":["../src/migrate.ts"],"mappings":";;;KA0BY,qBACR,6BACA;KAEQ;WAEG;WACA;WACA,UAAU,KAAK,QAAQ;;WAGvB;WACA,QAAQ;;KAGX;WAEG;WACA;WACA,UAAU;;WAGV;WACA,QAAQ;;UAGN;;;;WAIN,aAAa;;;;;WAMb;aACE;aACA;;;;;WAMF;;;;WAKA;;iBASW,QAAQ,SAAS,iBAAiB"}
@@ -0,0 +1,58 @@
1
+ import { existsSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { PGlite } from "@electric-sql/pglite";
5
+ import { drizzle } from "drizzle-orm/pglite";
6
+ import { migrate as migrate$1 } from "drizzle-orm/pglite/migrator";
7
+ import { drizzle as drizzle$1 } from "drizzle-orm/postgres-js";
8
+ import { migrate as migrate$2 } from "drizzle-orm/postgres-js/migrator";
9
+ import postgres from "postgres";
10
+ //#region src/migrate.ts
11
+ const migrationsFolder = join(dirname(fileURLToPath(import.meta.url)), "..", "drizzle");
12
+ async function migrate(options) {
13
+ assertV3MigrationsFolder(migrationsFolder);
14
+ const config = {
15
+ migrationsFolder,
16
+ migrationsSchema: options.migrationsSchema ?? options.migrations?.schema ?? "drizzle",
17
+ migrationsTable: options.migrationsTable ?? options.migrations?.table ?? "__drizzle_migrations"
18
+ };
19
+ if (isPGliteMigrateCredentials(options.credentials)) await migratePGliteDatabase(options.credentials, config);
20
+ else await migratePostgresDatabase(options.credentials, config);
21
+ }
22
+ function assertV3MigrationsFolder(migrationsDir) {
23
+ if (!existsSync(join(migrationsDir, "meta", "_journal.json"))) return;
24
+ throw new Error(`The migrations folder format is outdated: ${migrationsDir}. Run \`drizzle-kit up\` before using migrate().`);
25
+ }
26
+ function isPGliteMigrateCredentials(credentials) {
27
+ return credentials.driver === "pglite";
28
+ }
29
+ async function migratePGliteDatabase(credentials, config) {
30
+ const client = "client" in credentials ? credentials.client : new PGlite(normalizePGliteUrl(credentials.url), credentials.options);
31
+ const shouldCloseClient = !("client" in credentials);
32
+ try {
33
+ await client.waitReady;
34
+ await migrate$1(drizzle({ client }), config);
35
+ } finally {
36
+ if (shouldCloseClient) await client.close();
37
+ }
38
+ }
39
+ async function migratePostgresDatabase(credentials, config) {
40
+ const client = "client" in credentials ? credentials.client : postgres(credentials.url, {
41
+ ...credentials.options,
42
+ max: 1
43
+ });
44
+ const shouldCloseClient = !("client" in credentials);
45
+ try {
46
+ await migrate$2(drizzle$1({ client }), config);
47
+ } finally {
48
+ if (shouldCloseClient) await client.end();
49
+ }
50
+ }
51
+ function normalizePGliteUrl(url) {
52
+ if (url.startsWith("file:")) return url.slice(5);
53
+ return url;
54
+ }
55
+ //#endregion
56
+ export { migrate };
57
+
58
+ //# sourceMappingURL=migrate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.mjs","names":["migratePglite","drizzlePglite","migratePostgres","drizzlePostgres"],"sources":["../src/migrate.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { PGlite, type PGliteOptions } from \"@electric-sql/pglite\";\nimport { drizzle as drizzlePglite } from \"drizzle-orm/pglite\";\nimport { migrate as migratePglite } from \"drizzle-orm/pglite/migrator\";\nimport { drizzle as drizzlePostgres } from \"drizzle-orm/postgres-js\";\nimport { migrate as migratePostgres } from \"drizzle-orm/postgres-js/migrator\";\nimport postgres, { type Options, type Sql } from \"postgres\";\n\nexport type MigrateCredentials =\n | PostgresMigrateCredentials\n | PGliteMigrateCredentials;\n\nexport type PostgresMigrateCredentials =\n | {\n readonly driver?: never;\n readonly url: string;\n readonly options?: Omit<Options<Record<string, never>>, \"max\">;\n }\n | {\n readonly driver?: never;\n readonly client: Sql;\n };\n\nexport type PGliteMigrateCredentials =\n | {\n readonly driver: \"pglite\";\n readonly url: string;\n readonly options?: PGliteOptions;\n }\n | {\n readonly driver: \"pglite\";\n readonly client: PGlite;\n };\n\nexport interface MigrateOptions {\n /**\n * PostgreSQL or PGlite credentials.\n */\n readonly credentials: MigrateCredentials;\n\n /**\n * Custom migrations table/schema. Equivalent to drizzle-kit config's\n * `migrations` option.\n */\n readonly migrations?: {\n readonly table?: string;\n readonly schema?: string;\n };\n\n /**\n * Custom migrations table. Takes precedence over `migrations.table`.\n */\n readonly migrationsTable?: string;\n\n /**\n * Custom migrations schema. Takes precedence over `migrations.schema`.\n */\n readonly migrationsSchema?: string;\n}\n\nconst migrationsFolder = join(\n dirname(fileURLToPath(import.meta.url)),\n \"..\",\n \"drizzle\",\n);\n\nexport async function migrate(options: MigrateOptions): Promise<void> {\n assertV3MigrationsFolder(migrationsFolder);\n\n const config = {\n migrationsFolder,\n migrationsSchema:\n options.migrationsSchema ?? options.migrations?.schema ?? \"drizzle\",\n migrationsTable:\n options.migrationsTable ??\n options.migrations?.table ??\n \"__drizzle_migrations\",\n };\n\n if (isPGliteMigrateCredentials(options.credentials)) {\n await migratePGliteDatabase(options.credentials, config);\n } else {\n await migratePostgresDatabase(options.credentials, config);\n }\n}\n\nfunction assertV3MigrationsFolder(migrationsDir: string): void {\n // oxlint-disable-next-line node/no-sync\n if (!existsSync(join(migrationsDir, \"meta\", \"_journal.json\"))) {\n return;\n }\n\n throw new Error(\n `The migrations folder format is outdated: ${migrationsDir}. ` +\n \"Run `drizzle-kit up` before using migrate().\",\n );\n}\n\nfunction isPGliteMigrateCredentials(\n credentials: MigrateCredentials,\n): credentials is PGliteMigrateCredentials {\n return credentials.driver === \"pglite\";\n}\n\nasync function migratePGliteDatabase(\n credentials: PGliteMigrateCredentials,\n config: MigrationConfig,\n): Promise<void> {\n const client =\n \"client\" in credentials\n ? credentials.client\n : new PGlite(normalizePGliteUrl(credentials.url), credentials.options);\n const shouldCloseClient = !(\"client\" in credentials);\n\n try {\n await client.waitReady;\n await migratePglite(drizzlePglite({ client }), config);\n } finally {\n if (shouldCloseClient) {\n await client.close();\n }\n }\n}\n\nasync function migratePostgresDatabase(\n credentials: PostgresMigrateCredentials,\n config: MigrationConfig,\n): Promise<void> {\n const client =\n \"client\" in credentials\n ? credentials.client\n : postgres(credentials.url, { ...credentials.options, max: 1 });\n const shouldCloseClient = !(\"client\" in credentials);\n\n try {\n await migratePostgres(drizzlePostgres({ client }), config);\n } finally {\n if (shouldCloseClient) {\n await client.end();\n }\n }\n}\n\nfunction normalizePGliteUrl(url: string): string {\n if (url.startsWith(\"file:\")) {\n return url.slice(\"file:\".length);\n }\n return url;\n}\n\ninterface MigrationConfig {\n readonly migrationsFolder: string;\n readonly migrationsTable: string;\n readonly migrationsSchema: string;\n}\n"],"mappings":";;;;;;;;;;AA8EA,MAAM,mBAAmB,KACvB,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC,GACtC,MACA,SACF;AAEA,eAAsB,QAAQ,SAAwC;CACpE,yBAAyB,gBAAgB;CAEzC,MAAM,SAAS;EACb;EACA,kBACE,QAAQ,oBAAoB,QAAQ,YAAY,UAAU;EAC5D,iBACE,QAAQ,mBACR,QAAQ,YAAY,SACpB;CACJ;CAEA,IAAI,2BAA2B,QAAQ,WAAW,GAChD,MAAM,sBAAsB,QAAQ,aAAa,MAAM;MAEvD,MAAM,wBAAwB,QAAQ,aAAa,MAAM;AAE7D;AAEA,SAAS,yBAAyB,eAA6B;CAE7D,IAAI,CAAC,WAAW,KAAK,eAAe,QAAQ,eAAe,CAAC,GAC1D;CAGF,MAAM,IAAI,MACR,6CAA6C,cAAc,iDAE7D;AACF;AAEA,SAAS,2BACP,aACyC;CACzC,OAAO,YAAY,WAAW;AAChC;AAEA,eAAe,sBACb,aACA,QACe;CACf,MAAM,SACJ,YAAY,cACR,YAAY,SACZ,IAAI,OAAO,mBAAmB,YAAY,GAAG,GAAG,YAAY,OAAO;CACzE,MAAM,oBAAoB,EAAE,YAAY;CAExC,IAAI;EACF,MAAM,OAAO;EACb,MAAMA,UAAcC,QAAc,EAAE,OAAO,CAAC,GAAG,MAAM;CACvD,UAAU;EACR,IAAI,mBACF,MAAM,OAAO,MAAM;CAEvB;AACF;AAEA,eAAe,wBACb,aACA,QACe;CACf,MAAM,SACJ,YAAY,cACR,YAAY,SACZ,SAAS,YAAY,KAAK;EAAE,GAAG,YAAY;EAAS,KAAK;CAAE,CAAC;CAClE,MAAM,oBAAoB,EAAE,YAAY;CAExC,IAAI;EACF,MAAMC,UAAgBC,UAAgB,EAAE,OAAO,CAAC,GAAG,MAAM;CAC3D,UAAU;EACR,IAAI,mBACF,MAAM,OAAO,IAAI;CAErB;AACF;AAEA,SAAS,mBAAmB,KAAqB;CAC/C,IAAI,IAAI,WAAW,OAAO,GACxB,OAAO,IAAI,MAAM,CAAc;CAEjC,OAAO;AACT"}
@@ -0,0 +1,39 @@
1
+ //#region src/migration-manifest.d.ts
2
+ /** Immutable identity of one raw SQL migration. */
3
+ interface MigrationIdentity {
4
+ readonly name: string;
5
+ readonly sha256: string;
6
+ }
7
+ /** Versioned, chronological migration identities bundled with the package. */
8
+ interface MigrationManifest {
9
+ readonly formatVersion: 1;
10
+ readonly migrations: readonly MigrationIdentity[];
11
+ }
12
+ /** Paths override the installed package defaults, for tooling and fixtures. */
13
+ interface MigrationManifestPaths {
14
+ readonly manifestPath?: string;
15
+ readonly migrationsFolder?: string;
16
+ }
17
+ /**
18
+ * Parse a migration directory's UTC timestamp, rejecting invalid dates.
19
+ * @returns The timestamp in milliseconds since the Unix epoch.
20
+ */
21
+ declare function migrationTimestamp(name: string): number;
22
+ /**
23
+ * Validate the manifest format and strictly increasing migration timestamps.
24
+ * @returns A validated manifest, independent of the caller's object.
25
+ */
26
+ declare function parseMigrationManifest(value: unknown): MigrationManifest;
27
+ /**
28
+ * Ensure a newer manifest preserves every baseline entry as an exact prefix.
29
+ * @returns Nothing; throws if historical migrations were rewritten or removed.
30
+ */
31
+ declare function assertMigrationManifestPrefix(baseline: MigrationManifest, current: MigrationManifest): void;
32
+ /**
33
+ * Load and verify raw SQL identities without opening a database or executing SQL.
34
+ * @returns The validated manifest after all bundled SQL files match it.
35
+ */
36
+ declare function verifyMigrationManifest(paths?: MigrationManifestPaths): Promise<MigrationManifest>;
37
+ //#endregion
38
+ export { MigrationIdentity, MigrationManifest, MigrationManifestPaths, assertMigrationManifestPrefix, migrationTimestamp, parseMigrationManifest, verifyMigrationManifest };
39
+ //# sourceMappingURL=migration-manifest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-manifest.d.mts","names":[],"sources":["../src/migration-manifest.ts"],"mappings":";;UAqBiB;WACN;WACA;;;UAIM;WACN;WACA,qBAAqB;;;UAIf;WACN;WACA;;;;;;iBAOK,mBAAmB;;;;;iBAwBnB,uBAAuB,iBAAiB;;;;;iBAmCxC,8BACd,UAAU,mBACV,SAAS;;;;;iBAmBW,wBACpB,QAAO,yBACN,QAAQ"}