better-supabase 0.3.0 → 0.5.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 (211) hide show
  1. package/README.md +9 -6
  2. package/bin/better-supabase.js +4 -0
  3. package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
  4. package/dist/channel-FQW-CnGR.d.ts +70 -0
  5. package/dist/claims-BAf6c7is.js +48 -0
  6. package/dist/cli/_format-Cax5EsM9.js +101 -0
  7. package/dist/cli/bin.d.ts +1 -0
  8. package/dist/cli/bin.js +48 -0
  9. package/dist/cli/codemod-DqV7612m.js +388 -0
  10. package/dist/cli/command-CK14fP91.js +502 -0
  11. package/dist/cli/compare-BmIWVEui.js +9 -0
  12. package/dist/cli/config-CPVpXP5I.js +1965 -0
  13. package/dist/cli/config-dtoekM0v.js +2 -0
  14. package/dist/cli/db-DOBPt660.js +52 -0
  15. package/dist/cli/diff-SjkO5rNr.js +752 -0
  16. package/dist/cli/dist-DBPdlPYK.js +1112 -0
  17. package/dist/cli/dist-DreZ24Sz.js +129 -0
  18. package/dist/cli/dist-xn4wlboc.js +732 -0
  19. package/dist/cli/doctor-L7Z8mYTx.js +2863 -0
  20. package/dist/cli/env-DmKv_G4A.js +108 -0
  21. package/dist/cli/env-jIFUADLY.js +511 -0
  22. package/dist/cli/errors-4v4DTtda.js +56 -0
  23. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  24. package/dist/cli/gen-BJc9vdyu.js +2 -0
  25. package/dist/cli/gen-C2osRcr5.js +2204 -0
  26. package/dist/cli/index.d.ts +493 -0
  27. package/dist/cli/index.js +184 -0
  28. package/dist/cli/init-Saf5-R9T.js +550 -0
  29. package/dist/cli/introspect--H7oGmcd.js +81 -0
  30. package/dist/cli/io-k41_z-jT.js +24 -0
  31. package/dist/cli/json5-ChRycquj.js +787 -0
  32. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  33. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  34. package/dist/cli/keys-ByKHnvP9.js +83 -0
  35. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  36. package/dist/cli/openapi-Cp5Fyta-.js +66 -0
  37. package/dist/cli/project-B_GeXyHh.js +70 -0
  38. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  39. package/dist/cli/prompts-BTYQGunc.js +2 -0
  40. package/dist/cli/read-sets-BfMQcKy8.js +289 -0
  41. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  42. package/dist/cli/run-BKR2W_79.js +351 -0
  43. package/dist/cli/seed-CUlqWh-8.js +98 -0
  44. package/dist/cli/skills-LJJIhLFR.js +137 -0
  45. package/dist/cli/sql-DzPbfngx.js +348 -0
  46. package/dist/cli/style-C0NFdJRL.js +29 -0
  47. package/dist/cli/toml-DB-MNnFs.js +424 -0
  48. package/dist/cli/version-BDJuO0UR.js +4 -0
  49. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  50. package/dist/client/index.d.ts +2 -2
  51. package/dist/client/index.js +15 -22
  52. package/dist/clone-BfgmLU90.js +21 -0
  53. package/dist/{compiler-2zqGzxVZ.d.ts → compiler-BXH_aZ7N.d.ts} +2 -2
  54. package/dist/config/index.d.ts +4 -4
  55. package/dist/config/index.js +5 -5
  56. package/dist/{config-DOsGYSiT.js → config-DreERlKo.js} +1 -1
  57. package/dist/{config-C1CYcm6o.d.ts → config-T_ejwyd3.d.ts} +176 -11
  58. package/dist/{define-DUbydmJa.d.ts → define-Bp_BZa5h.d.ts} +37 -29
  59. package/dist/{define-DF341GDj.js → define-cNKzqwL_.js} +356 -89
  60. package/dist/edge/index.d.ts +20 -13
  61. package/dist/edge/index.js +55 -26
  62. package/dist/{entitlements-DvJXoI02.d.ts → entitlements-DUxU4oHe.d.ts} +2 -2
  63. package/dist/env/index.d.ts +2 -2
  64. package/dist/env/index.js +34 -1
  65. package/dist/{errors-Bl3rkOzo.js → errors-DtwXa6b8.js} +2 -1
  66. package/dist/events/index.d.ts +3 -2
  67. package/dist/events/index.js +69 -16
  68. package/dist/events-aIO7vsIk.d.ts +230 -0
  69. package/dist/executor-BunPOO-k.d.ts +402 -0
  70. package/dist/{executor-B26lgbHD.d.ts → executor-Cghdstwu.d.ts} +1 -2
  71. package/dist/{executor-C57jx2pn.js → executor-XycESQPH.js} +3 -3
  72. package/dist/hono/index.d.ts +27 -23
  73. package/dist/hono/index.js +46 -11
  74. package/dist/impersonation-VfaGc4Q_.js +41 -0
  75. package/dist/{index-BNsABq7P.d.ts → index-BGdgBPdf.d.ts} +66 -25
  76. package/dist/{index-qriRM9cZ.d.ts → index-C7f8cOBM.d.ts} +4 -4
  77. package/dist/{index-Dy6kuF0P.d.ts → index-CLg87OBW.d.ts} +6 -1
  78. package/dist/{index-GV77NpRP.d.ts → index-DOESKG27.d.ts} +34 -9
  79. package/dist/{index-CriFFJ_p.d.ts → index-DgILJRXj.d.ts} +43 -17
  80. package/dist/{index-UJ-LUxtI.d.ts → index-DmXSxbLi.d.ts} +14 -14
  81. package/dist/{index-Cf-D2jk1.d.ts → index-Dxn2a5cw.d.ts} +2 -2
  82. package/dist/{index-CTTMS6_1.d.ts → index-SaTsEfGP.d.ts} +86 -9
  83. package/dist/{index-CADlNHK-.d.ts → index-fag8VJZ2.d.ts} +5 -6
  84. package/dist/index.d.ts +34 -17
  85. package/dist/index.js +15 -14
  86. package/dist/jobs/index.d.ts +147 -95
  87. package/dist/jobs/index.js +773 -250
  88. package/dist/{json-schema--aOXAGfU.js → json-schema-m1fiwKgN.js} +23 -2
  89. package/dist/kit-events-CTFDfSwb.js +60 -0
  90. package/dist/kit-transport-B82k1djG.d.ts +33 -0
  91. package/dist/kit-transport-DJlHQUBU.js +55 -0
  92. package/dist/{config-Be4GwsqI.js → kits-CGLLrNPd.js} +38 -10
  93. package/dist/list/index.d.ts +1 -1
  94. package/dist/list/index.js +3 -3
  95. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  96. package/dist/{live-QE3UPbGm.d.ts → live-D9W2M5aO.d.ts} +16 -15
  97. package/dist/lookup-BaP5bI27.js +18 -0
  98. package/dist/mcp/index.d.ts +39 -22
  99. package/dist/mcp/index.js +39 -25
  100. package/dist/{mfa-x3V3vGh-.d.ts → mfa-CusDgPaD.d.ts} +5 -1
  101. package/dist/next/image/index.js +6 -3
  102. package/dist/next/index.d.ts +60 -36
  103. package/dist/next/index.js +167 -50
  104. package/dist/notifications/index.d.ts +162 -0
  105. package/dist/notifications/index.js +264 -0
  106. package/dist/openapi/index.d.ts +1 -1
  107. package/dist/openapi/index.js +6 -6
  108. package/dist/orgs/index.d.ts +132 -0
  109. package/dist/orgs/index.js +245 -0
  110. package/dist/orpc/index.d.ts +37 -20
  111. package/dist/orpc/index.js +24 -11
  112. package/dist/otel/index.d.ts +24 -5
  113. package/dist/otel/index.js +124 -64
  114. package/dist/permdock-sql-C2Inc6Xc.d.ts +29 -0
  115. package/dist/permdock-sql-DgOfeixi.js +51 -0
  116. package/dist/plugin-DwARMuQp.js +59 -0
  117. package/dist/{plugin-DVRB8qNE.d.ts → plugin-o144f322.d.ts} +17 -5
  118. package/dist/plugins/actor/index.d.ts +5 -2
  119. package/dist/plugins/actor/index.js +22 -8
  120. package/dist/plugins/rules/index.d.ts +2 -2
  121. package/dist/plugins/rules/index.js +52 -17
  122. package/dist/plugins/soft-delete/index.d.ts +3 -3
  123. package/dist/plugins/soft-delete/index.js +14 -5
  124. package/dist/plugins/tenant/index.d.ts +3 -3
  125. package/dist/plugins/tenant/index.js +45 -21
  126. package/dist/plugins/timestamps/index.d.ts +1 -1
  127. package/dist/plugins/timestamps/index.js +4 -3
  128. package/dist/plugins/validation/index.d.ts +2 -2
  129. package/dist/plugins/validation/index.js +26 -6
  130. package/dist/{pool-B9qsLyFR.d.ts → pool-C9voM4Kw.d.ts} +24 -6
  131. package/dist/postgres/index.d.ts +5 -5
  132. package/dist/postgres/index.js +20 -10
  133. package/dist/{postgrest-DmBlevh-.d.ts → postgrest-CruYKAvV.d.ts} +1 -1
  134. package/dist/{problem-CGt1ADix.js → problem-BW1KhzSG.js} +2 -1
  135. package/dist/{problem-Z2RTQjZD.d.ts → problem-Blxe8S31.d.ts} +1 -1
  136. package/dist/query/index.d.ts +2 -2
  137. package/dist/query/index.js +3 -3
  138. package/dist/{query-BdKLTPlj.js → query-CCbo44lG.js} +18 -18
  139. package/dist/queue-BYUCjr59.d.ts +252 -0
  140. package/dist/react/index.d.ts +8 -7
  141. package/dist/react/index.js +4 -3
  142. package/dist/react/server.d.ts +16 -5
  143. package/dist/react/server.js +12 -4
  144. package/dist/react/session.d.ts +10 -4
  145. package/dist/react/session.js +11 -3
  146. package/dist/{react-DNBYNazu.js → react-C_s7kiNz.js} +138 -46
  147. package/dist/{read-set-D0qBcboM.js → read-set-DQFt1N_Y.js} +71 -15
  148. package/dist/realtime/index.d.ts +3 -3
  149. package/dist/realtime/index.js +14 -12
  150. package/dist/{index-kpgopLNv.d.ts → refresh-BTrQ_ZTp.d.ts} +6 -3
  151. package/dist/{resolve-BRciX2jK.d.ts → resolve-C15TJq77.d.ts} +22 -11
  152. package/dist/{resource-D30rp0GN.js → resource-CRxxwkQq.js} +24 -9
  153. package/dist/{resource-CwVgiI5q.d.ts → resource-D8iqWMr-.d.ts} +6 -6
  154. package/dist/respond-D2OQl62-.d.ts +371 -0
  155. package/dist/{result-DWXatkd6.js → result-BKiliPY7.js} +2 -2
  156. package/dist/server/index.d.ts +17 -15
  157. package/dist/server/index.js +16 -22
  158. package/dist/server-Csx2sRjg.js +655 -0
  159. package/dist/{shared-_6-uPL7E.js → shared-D1dRUrAg.js} +19 -4
  160. package/dist/signers-Cc6r98SW.d.ts +162 -0
  161. package/dist/{simplify-LakqK1vH.js → simplify-_0oUKqCd.js} +27 -95
  162. package/dist/sql/index.d.ts +247 -10
  163. package/dist/sql/index.js +8591 -780
  164. package/dist/{sql-BIgk12ew.js → sql-Coh6n4cC.js} +11 -3
  165. package/dist/ssr/index.d.ts +4 -4
  166. package/dist/ssr/index.js +1 -2
  167. package/dist/{standard-FUi3Z3-7.js → standard-D7r6dMUu.js} +6 -3
  168. package/dist/{standard-eudBiRk1.d.ts → standard-J4YgMOLm.d.ts} +1 -1
  169. package/dist/{stats-D78UQ8Yu.js → stats-Bqob3WqT.js} +34 -9
  170. package/dist/storage/index.d.ts +4 -4
  171. package/dist/storage/index.js +174 -27
  172. package/dist/support-DT-OhSxD.d.ts +88 -0
  173. package/dist/support-Dk6vdmEw.js +291 -0
  174. package/dist/support-view-Da5peKFg.d.ts +17 -0
  175. package/dist/support-view-g4YLBeqX.js +18 -0
  176. package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
  177. package/dist/{permdock-sql-Bta_G0v-.js → template-TxrGI5jR.js} +2 -31
  178. package/dist/{temporal-BwshQk0W.js → temporal-CVlIV2DZ.js} +17 -4
  179. package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CAt4Dc9Z.js} +2 -2
  180. package/dist/testing/index.d.ts +113 -24
  181. package/dist/testing/index.js +375 -47
  182. package/dist/{types-DONv9SHN.d.ts → types-Dnf_wRDz.d.ts} +26 -3
  183. package/dist/user-change-CHFEUro1.js +49 -0
  184. package/dist/{webhooks-CAIFQSTM.js → verify-Ce49ETPz.js} +38 -19
  185. package/dist/{version-BfpG2gks.js → version-DM_Roffb.js} +1 -1
  186. package/dist/{view-3Po_PVlr.d.ts → view-BEf0diC5.d.ts} +10 -5
  187. package/dist/{mfa-BxoR1RkN.js → view-Bq64ki8-.js} +210 -64
  188. package/dist/webhooks/index.d.ts +136 -5
  189. package/dist/webhooks/index.js +588 -2
  190. package/dist/wire-D2dT86vi.js +35 -0
  191. package/package.json +50 -10
  192. package/schemas/config-v1.json +131 -1
  193. package/schemas/doctor-report-v1.json +10 -0
  194. package/skills/better-supabase/SKILL.md +60 -10
  195. package/skills/better-supabase/references/plugins.md +13 -14
  196. package/skills/better-supabase/references/troubleshooting.md +25 -4
  197. package/skills/better-supabase-api/SKILL.md +74 -19
  198. package/skills/better-supabase-api/references/adapters.md +48 -27
  199. package/skills/better-supabase-auth/SKILL.md +149 -0
  200. package/skills/better-supabase-auth/references/permdock.md +100 -0
  201. package/skills/better-supabase-testing/SKILL.md +58 -4
  202. package/dist/claims-CoTobNC-.js +0 -25
  203. package/dist/events-Do8jXh4D.d.ts +0 -84
  204. package/dist/executor-DynmIWhq.d.ts +0 -195
  205. package/dist/invalidate-DbxuL2jL.js +0 -18
  206. package/dist/permdock-sql-DImJULY-.d.ts +0 -17
  207. package/dist/plugin-BqR6wKMB.js +0 -23
  208. package/dist/respond-C44EZAJo.js +0 -399
  209. package/dist/respond-DAkPIdTH.d.ts +0 -175
  210. package/dist/result-c2OYgCV2.d.ts +0 -203
  211. package/dist/view-wZ-9qIUz.js +0 -45
@@ -1,203 +0,0 @@
1
- //#region src/core/errors.d.ts
2
- /**
3
- * Extra fields carried by each error kind. Plugins can add kinds through the
4
- * `errors` extension point; apps that want the new kinds in the union can add
5
- * them to this interface.
6
- */
7
- interface DbErrorKinds {
8
- not_found: Record<never, never>;
9
- unauthorized: Record<never, never>;
10
- /**
11
- * `required`: the assurance level the route needs, when a second factor is
12
- * missing. `scopes`: the OAuth scopes the route needs, when a delegated
13
- * token lacks one (`INSUFFICIENT_SCOPE`).
14
- */
15
- forbidden: {
16
- required?: "aal1" | "aal2";
17
- scopes?: readonly string[];
18
- };
19
- conflict: {
20
- constraint?: string;
21
- columns?: readonly string[];
22
- };
23
- foreign_key: {
24
- constraint?: string;
25
- columns?: readonly string[];
26
- };
27
- check: {
28
- constraint?: string;
29
- };
30
- not_null: {
31
- column?: string;
32
- };
33
- exclusion: {
34
- constraint?: string;
35
- };
36
- invalid_input: Record<never, never>;
37
- raised: Record<never, never>;
38
- timeout: Record<never, never>;
39
- serialization: Record<never, never>;
40
- network: Record<never, never>;
41
- aborted: Record<never, never>;
42
- invalid_request: Record<never, never>;
43
- validation: {
44
- issues: readonly ValidationIssue[];
45
- };
46
- multiple_rows: Record<never, never>;
47
- stale: Record<never, never>;
48
- /** `retryAfter`: seconds until the window resets (the `Retry-After` header). */
49
- rate_limited: {
50
- retryAfter?: number;
51
- };
52
- unexpected: Record<never, never>;
53
- }
54
- type DbErrorKind = keyof DbErrorKinds;
55
- interface ValidationIssue {
56
- readonly message: string;
57
- readonly path?: readonly PropertyKey[];
58
- }
59
- interface DbErrorBase<K extends DbErrorKind> {
60
- readonly kind: K;
61
- readonly message: string;
62
- /** SQLSTATE or PostgREST code (`23505`, `PGRST116`), when known. */
63
- readonly code?: string;
64
- /** Suggested HTTP status, used by the RFC 9457 mapping. */
65
- readonly status: number;
66
- readonly details?: string;
67
- /** Postgres `HINT`. `raised` errors use it as an app-level error code. */
68
- readonly hint?: string;
69
- /** App-cased table key the operation ran against. */
70
- readonly table?: string;
71
- }
72
- /**
73
- * A database error as plain, serializable data. Safe to send across server
74
- * action and RPC boundaries.
75
- */
76
- type DbError = { [K in DbErrorKind]: DbErrorBase<K> & DbErrorKinds[K]; }[DbErrorKind];
77
- type DbErrorOf<K extends DbErrorKind> = Extract<DbError, {
78
- kind: K;
79
- }>;
80
- declare function statusOf(kind: DbErrorKind): number;
81
- type ExtraOf<K extends DbErrorKind> = Record<never, never> extends DbErrorKinds[K] ? [extra?: DbErrorKinds[K] & Partial<Omit<DbErrorBase<K>, "kind">>] : [extra: DbErrorKinds[K] & Partial<Omit<DbErrorBase<K>, "kind">>];
82
- /** Creates a `DbError` with the default status for its kind. */
83
- declare function dbError<K extends DbErrorKind>(kind: K, message: string, ...[extra]: ExtraOf<K>): DbErrorOf<K>;
84
- declare function isDbError(value: unknown): value is DbError;
85
- /**
86
- * A unique violation, optionally for one constraint. Accepts a `DbError` or a
87
- * `DbException`. Pass the generated `UniqueConstraint` type to check names:
88
- * `isConflict<UniqueConstraint>(error, 'customers_organization_id_kvk_key')`.
89
- */
90
- declare const isConflict: <C extends string = string>(error: unknown, constraint?: NoInfer<C>) => error is DbErrorOf<"conflict"> & {
91
- readonly constraint: C;
92
- };
93
- /** A CHECK violation, optionally for one constraint (`CheckConstraint`). */
94
- declare const isCheck: <C extends string = string>(error: unknown, constraint?: NoInfer<C>) => error is DbErrorOf<"check"> & {
95
- readonly constraint: C;
96
- };
97
- /** A foreign key violation, optionally for one constraint (`ForeignKeyConstraint`). */
98
- declare const isForeignKey: <C extends string = string>(error: unknown, constraint?: NoInfer<C>) => error is DbErrorOf<"foreign_key"> & {
99
- readonly constraint: C;
100
- };
101
- /** Thrown by `.orThrow()`. Carries the plain `DbError` as `error`. */
102
- declare class DbException extends Error {
103
- override readonly name = "DbException";
104
- readonly error: DbError;
105
- constructor(error: DbError);
106
- get kind(): DbErrorKind;
107
- }
108
- /** Raw error shape shared by PostgREST responses and `pg` errors. */
109
- interface RawDbError {
110
- readonly message?: string;
111
- readonly code?: string;
112
- readonly details?: string | null;
113
- readonly hint?: string | null;
114
- readonly constraint?: string;
115
- readonly column?: string;
116
- readonly table?: string;
117
- readonly name?: string;
118
- }
119
- type ErrorMapper = (raw: RawDbError, fallback: DbError) => DbError | undefined;
120
- /**
121
- * Maps a PostgREST or Postgres error to a `DbError`. Custom mappers run
122
- * first; the first one that returns an error wins.
123
- */
124
- declare function mapDbError(raw: RawDbError, mappers?: readonly ErrorMapper[]): DbError;
125
- //#endregion
126
- //#region src/core/result.d.ts
127
- /** Turns a `DbError` into the error `.orThrow()` throws; set with `sb.mapError()`. */
128
- type ThrowMapper = (error: DbError) => unknown;
129
- type Ok<T> = {
130
- readonly ok: true;
131
- readonly data: T;
132
- readonly error: null;
133
- };
134
- type Err<E = DbError> = {
135
- readonly ok: false;
136
- readonly data: null;
137
- readonly error: E;
138
- };
139
- type Result<T, E = DbError> = Ok<T> | Err<E>;
140
- declare function ok<T>(data: T): Ok<T>;
141
- declare function err<E = DbError>(error: E): Err<E>;
142
- /**
143
- * A lazy-free `PromiseLike<Result<T>>` with helpers. `await` gives the
144
- * `Result`; `.orThrow()` gives the data or throws a `DbException`.
145
- */
146
- declare class AsyncResult<T> implements PromiseLike<Result<T>> {
147
- #private;
148
- constructor(promise: Promise<Result<T>>);
149
- static from<T>(run: () => Promise<Result<T>>): AsyncResult<T>;
150
- static ok<T>(data: T): AsyncResult<T>;
151
- static err<T = never>(error: DbError): AsyncResult<T>;
152
- then<R1 = Result<T>, R2 = never>(onfulfilled?: ((value: Result<T>) => R1 | PromiseLike<R1>) | null, onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
153
- /**
154
- * Resolves with the data, or rejects with a `DbException`. Pass `factory`
155
- * to throw your own error instead, e.g. an HTTP error for your framework;
156
- * without it, the mapper from `sb.mapError()` applies when one is set.
157
- */
158
- orThrow(factory?: (error: DbError) => unknown): Promise<T>;
159
- /** Resolves with the data, or `fallback` when the result is an error. */
160
- unwrapOr<F>(fallback: F): Promise<T | F>;
161
- map<U>(fn: (data: T) => U): AsyncResult<U>;
162
- mapError(fn: (error: DbError) => DbError): AsyncResult<T>;
163
- andThen<U>(fn: (data: T) => PromiseLike<Result<U>>): AsyncResult<U>;
164
- }
165
- /** What `toBetterResult` returns: the `status`/`value`/`error` fields every better-result value has. */
166
- type BetterResultValue<T, E> = {
167
- readonly status: "ok";
168
- readonly value: T;
169
- } | {
170
- readonly status: "error";
171
- readonly error: E;
172
- };
173
- /** The part of better-result's `Result` namespace `toBetterResult` calls. */
174
- interface BetterResultApi<T, E> {
175
- ok(value: NoInfer<T>): unknown;
176
- err(error: NoInfer<E>): unknown;
177
- }
178
- /**
179
- * Builds a better-result value with the `Result` namespace you pass, so
180
- * better-result stays your dependency. Errors go through `mapError`, or, for a
181
- * result from a `db` of `sb.mapError(fn)`, through `fn` (typed `unknown`).
182
- * The value is a real `Ok`/`Err`: cast it (`as Result<T, E>`) for its
183
- * methods in types; the cast itself is not checked against `T`.
184
- *
185
- * ```ts
186
- * import { Result } from 'better-result';
187
- * const customer = toBetterResult(await db.customers.findById(id), Result, toAppError);
188
- * ```
189
- */
190
- declare function toBetterResult<T, E>(result: Result<T>, api: BetterResultApi<T, E>, mapError: (error: DbError) => E): BetterResultValue<T, E>;
191
- declare function toBetterResult<T>(result: Result<T>, api: BetterResultApi<T, DbError>): BetterResultValue<T, DbError>;
192
- declare function toBetterResult<T, E>(result: AsyncResult<T>, api: BetterResultApi<T, E>, mapError: (error: DbError) => E): Promise<BetterResultValue<T, E>>;
193
- declare function toBetterResult<T>(result: AsyncResult<T>, api: BetterResultApi<T, unknown>): Promise<BetterResultValue<T, unknown>>;
194
- /**
195
- * Converts a better-result value back into a `Result`, by its `status`
196
- * field, so it works across better-result versions. A `DbError`, or an
197
- * error whose `cause` is one, is kept; others go through `mapError`
198
- * (default `toDbError`).
199
- */
200
- declare function fromBetterResult<T>(result: BetterResultValue<T, unknown>, mapError?: (error: unknown) => DbError): Result<T>;
201
- declare function toDbError(cause: unknown): DbError;
202
- //#endregion
203
- export { isConflict as C, statusOf as D, mapDbError as E, isCheck as S, isForeignKey as T, DbException as _, Ok as a, ValidationIssue as b, err as c, toBetterResult as d, toDbError as f, DbErrorOf as g, DbErrorKinds as h, Err as i, fromBetterResult as l, DbErrorKind as m, BetterResultApi as n, Result as o, DbError as p, BetterResultValue as r, ThrowMapper as s, AsyncResult as t, ok as u, ErrorMapper as v, isDbError as w, dbError as x, RawDbError as y };
@@ -1,45 +0,0 @@
1
- import { g as delegationOf, h as actorOf, n as amrOf, t as aalOf, v as impersonatorOf } from "./mfa-BxoR1RkN.js";
2
- //#region src/auth/view.ts
3
- /** Drops the token from an `AuthState`, leaving only serializable fields. */
4
- function toSession(auth) {
5
- switch (auth.kind) {
6
- case "user": {
7
- const impersonator = impersonatorOf(auth.claims);
8
- const outcome = actorOf(auth.claims);
9
- const actor = outcome.ok ? outcome.actor : void 0;
10
- const scopes = actor ? delegationOf(auth.claims)?.scopes : void 0;
11
- const delegation = actor && (scopes || actor.chain) ? {
12
- scopes: scopes ?? [],
13
- ...actor.chain ? { chain: actor.chain } : {}
14
- } : void 0;
15
- return {
16
- kind: "user",
17
- user: auth.user,
18
- claims: auth.claims,
19
- expiresAt: auth.expiresAt,
20
- ...auth.profile === void 0 ? {} : { profile: auth.profile },
21
- aal: aalOf(auth.claims),
22
- amr: amrOf(auth.claims),
23
- ...impersonator ? { impersonator } : {},
24
- ...actor ? { actor } : {},
25
- ...delegation ? { delegation } : {}
26
- };
27
- }
28
- case "service": return {
29
- kind: "service",
30
- keyName: auth.keyName
31
- };
32
- case "anon": return {
33
- kind: "anon",
34
- reason: auth.reason
35
- };
36
- case "invalid": return {
37
- kind: "invalid",
38
- reason: auth.reason,
39
- error: auth.error
40
- };
41
- default: return auth;
42
- }
43
- }
44
- //#endregion
45
- export { toSession as t };