@lpdjs/firestore-repo-service 2.6.57 → 3.0.1

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 (64) hide show
  1. package/README.md +45 -27
  2. package/dist/{create-servers-BxkVVkg9.d.cts → create-servers-Cbvzs_ou.d.cts} +5 -5
  3. package/dist/{create-servers-B84cbslf.d.ts → create-servers-aWdDTcSu.d.ts} +5 -5
  4. package/dist/{firebase-auth-DZ8lb2Ec.d.cts → firebase-auth-Ds5P0kXT.d.cts} +1 -1
  5. package/dist/{firebase-auth-DZ8lb2Ec.d.ts → firebase-auth-Ds5P0kXT.d.ts} +1 -1
  6. package/dist/index.cjs +97 -85
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +9 -9
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +97 -85
  11. package/dist/index.js.map +1 -1
  12. package/dist/llms-full.txt +237 -263
  13. package/dist/llms.txt +5 -4
  14. package/dist/{openapi-BpbfjSHK.d.ts → openapi-BTu_1vSc.d.ts} +1 -1
  15. package/dist/{openapi-DG7aQUlX.d.cts → openapi-CoKsSOIU.d.cts} +1 -1
  16. package/dist/{queue-B4uwef6c.d.ts → queue-BQxyuEXb.d.ts} +8 -23
  17. package/dist/{queue-CQyWCQBk.d.cts → queue-CMiKvIW1.d.cts} +8 -23
  18. package/dist/rules-B3b-BZLf.d.cts +30 -0
  19. package/dist/rules-BJMT0N0i.d.ts +30 -0
  20. package/dist/servers/admin/index.d.cts +402 -6
  21. package/dist/servers/admin/index.d.ts +402 -6
  22. package/dist/servers/auth/index.d.cts +1 -1
  23. package/dist/servers/auth/index.d.ts +1 -1
  24. package/dist/servers/crud/index.cjs +2 -2
  25. package/dist/servers/crud/index.cjs.map +1 -1
  26. package/dist/servers/crud/index.d.cts +7 -6
  27. package/dist/servers/crud/index.d.ts +7 -6
  28. package/dist/servers/crud/index.js +2 -2
  29. package/dist/servers/crud/index.js.map +1 -1
  30. package/dist/servers/hono/index.d.cts +3 -3
  31. package/dist/servers/hono/index.d.ts +3 -3
  32. package/dist/servers/index.cjs +106 -94
  33. package/dist/servers/index.cjs.map +1 -1
  34. package/dist/servers/index.d.cts +10 -9
  35. package/dist/servers/index.d.ts +10 -9
  36. package/dist/servers/index.js +106 -94
  37. package/dist/servers/index.js.map +1 -1
  38. package/dist/sync/bigquery.cjs +5 -5
  39. package/dist/sync/bigquery.cjs.map +1 -1
  40. package/dist/sync/bigquery.d.cts +28 -3
  41. package/dist/sync/bigquery.d.ts +28 -3
  42. package/dist/sync/bigquery.js +5 -5
  43. package/dist/sync/bigquery.js.map +1 -1
  44. package/dist/sync/index.cjs +74 -54
  45. package/dist/sync/index.cjs.map +1 -1
  46. package/dist/sync/index.d.cts +63 -17
  47. package/dist/sync/index.d.ts +63 -17
  48. package/dist/sync/index.js +74 -54
  49. package/dist/sync/index.js.map +1 -1
  50. package/dist/sync/meilisearch.cjs +4 -0
  51. package/dist/sync/meilisearch.cjs.map +1 -0
  52. package/dist/sync/meilisearch.d.cts +114 -0
  53. package/dist/sync/meilisearch.d.ts +114 -0
  54. package/dist/sync/meilisearch.js +4 -0
  55. package/dist/sync/meilisearch.js.map +1 -0
  56. package/dist/{types-CE-EfugW.d.cts → types-B2e-T8EM.d.cts} +160 -8
  57. package/dist/{types-B4dMmfet.d.cts → types-BIZz3sxN.d.cts} +1 -1
  58. package/dist/{types-DT7Nypd_.d.ts → types-BbFZ57eK.d.ts} +101 -41
  59. package/dist/{types-DyKJJ9UQ.d.ts → types-DSMiiOrU.d.ts} +1 -1
  60. package/dist/{types-cY03CMya.d.ts → types-XRjVKN9r.d.ts} +160 -8
  61. package/dist/{types-BwH1C-wi.d.cts → types-zFrp8RnM.d.cts} +101 -41
  62. package/package.json +19 -1
  63. package/dist/index-D47y5giY.d.ts +0 -469
  64. package/dist/index-dW_7jrlK.d.cts +0 -469
@@ -1,10 +1,406 @@
1
- import 'zod';
2
- import 'firebase-functions/v2/https';
3
- import '../../types-cY03CMya.js';
4
- export { h as Middleware, M as MiniRouter, R as RouteHandler } from '../../firebase-auth-DZ8lb2Ec.js';
5
- export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry, d as createAdminServer } from '../../index-D47y5giY.js';
6
- import '../../types-DyKJJ9UQ.js';
1
+ import { z } from 'zod';
2
+ import { HttpsOptions } from 'firebase-functions/v2/https';
3
+ import { C as ConfiguredRepository, l as RepositoryConfig, m as RelationalFieldMeta, n as FieldPath, F as FieldRole, S as SecurityHeadersOptions } from '../../types-XRjVKN9r.js';
4
+ import { b as AuthExtension, M as Middleware } from '../../firebase-auth-Ds5P0kXT.js';
5
+ export { h as MiniRouter, R as RouteHandler } from '../../firebase-auth-Ds5P0kXT.js';
6
+ import '../../types-DSMiiOrU.js';
7
7
  import 'hono';
8
8
  import '../../read-CTWZjxyh.js';
9
9
  import 'firebase-admin/firestore';
10
10
  import 'firebase-functions/v2/firestore';
11
+
12
+ /**
13
+ * HTTP route handlers for the admin ORM server.
14
+ * Each handler corresponds to a URL pattern registered in the router.
15
+ *
16
+ * Routes:
17
+ * GET / → dashboard GET /:repoName → document list (paginated)
18
+ * GET /:repoName/create → create form
19
+ * POST /:repoName/create → submit create
20
+ * GET /:repoName/:id/edit → edit form (pre-filled)
21
+ * POST /:repoName/:id/edit → submit update
22
+ * POST /:repoName/:id/delete → delete document
23
+ */
24
+
25
+ interface AdminRepoEntry {
26
+ name: string;
27
+ path: string;
28
+ repo: ConfiguredRepository<RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>>;
29
+ schema: z.ZodObject<any>;
30
+ /** document key field name (default: "docId") */
31
+ documentKey?: string;
32
+ /** Field name that stores the full Firestore document path (e.g. "documentPath") */
33
+ pathKey?: string;
34
+ /** Whether this repo is a collection group (subcollection) */
35
+ isGroup?: boolean;
36
+ /** Parent key field names needed to build a subcollection document ref (auto-detected from refCb) */
37
+ parentKeys?: string[];
38
+ /** Field name for the creation timestamp (auto-set on create) */
39
+ createdKey?: string;
40
+ /** List of columns to display in the table (defaults to schema keys) */
41
+ listColumns?: string[];
42
+ /** Page size for list view (default: 25) */
43
+ pageSize?: number;
44
+ /** Fields exposed in the filter bar (defaults to all schema keys) */
45
+ filterableFields?: string[];
46
+ /** Fields shown in the edit form (defaults to all schema fields if unset) */
47
+ mutableFields?: string[];
48
+ /** Fields shown in the create form (defaults to all schema fields if unset) */
49
+ createFields?: string[];
50
+ /** Whether delete is allowed (default: false) */
51
+ allowDelete?: boolean;
52
+ /**
53
+ * Fields that link to another repository.
54
+ * Populated automatically from the repo's relationalKeys.
55
+ */
56
+ relationalMeta?: RelationalFieldMeta[];
57
+ /**
58
+ * Auto-detected from `repo.history`. When true, the admin renders an
59
+ * extra "History" button on each row and exposes a dedicated route at
60
+ * `GET /:repoName/:id/history` that lists the change-log entries.
61
+ */
62
+ historyEnabled?: boolean;
63
+ /** Subcollection name used to store history docs (display only). */
64
+ historySubcollection?: string;
65
+ }
66
+ type RepoRegistry = Record<string, AdminRepoEntry>;
67
+
68
+ /**
69
+ * @module servers/admin
70
+ *
71
+ * Creates a static ORM admin interface served as a Firebase HTTPS function.
72
+ *
73
+ * Features:
74
+ * - Dashboard listing all registered repositories
75
+ * - Document list with cursor-based pagination
76
+ * - Create / Edit / Delete forms generated from Zod schemas
77
+ * - Forms map **exactly** to the repository model type
78
+ * - Zero JavaScript framework — plain HTML + inline CSS + vanilla JS
79
+ * - Body parsing for `application/x-www-form-urlencoded` (default HTML forms)
80
+ * and `application/json` (API clients)
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import * as functions from "firebase-functions";
85
+ * import { z } from "zod";
86
+ * import { createAdminServer } from "@lpdjs/firestore-repo-service/servers/admin";
87
+ *
88
+ * const postSchema = z.object({
89
+ * title: z.string().min(1),
90
+ * content: z.string(),
91
+ * status: z.enum(["draft", "published"]),
92
+ * authorId: z.string(),
93
+ * });
94
+ *
95
+ * export const adminApp = functions.https.onRequest(
96
+ * createAdminServer({
97
+ * basePath: "/admin",
98
+ * repos: {
99
+ * posts: { repo: repos.posts, schema: postSchema, path: "posts" },
100
+ * },
101
+ * })
102
+ * );
103
+ * ```
104
+ */
105
+
106
+ /**
107
+ * Extracts the model type `T` from a `ConfiguredRepository`.
108
+ * Two-step inference so it survives intersection types
109
+ * (e.g. `RepositoryConfig<...> & { schema: ZodObject }` produced by
110
+ * `createRepositoryConfig(schema)`).
111
+ * @internal
112
+ */
113
+ type RepoModelType<TRepo> = TRepo extends ConfiguredRepository<infer C> ? C extends RepositoryConfig<infer T, any, any, any, any, any, any, any, any, any, any> ? T : never : never;
114
+ /**
115
+ * Configuration for a single repository in the admin server.
116
+ *
117
+ * @template TRepo - The `ConfiguredRepository` type; used to derive typed field names.
118
+ *
119
+ * If the repository was created with `createRepositoryConfig(schema)(config)`,
120
+ * the `schema` field is optional — it is auto-detected from the repo.
121
+ * Otherwise, pass `schema` explicitly.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * posts: {
126
+ * repo: repos.posts,
127
+ * fieldsConfig: {
128
+ * title: ["create", "mutable", "filterable"],
129
+ * content: ["create", "mutable"],
130
+ * status: ["create", "filterable"],
131
+ * },
132
+ * allowDelete: true,
133
+ * }
134
+ * ```
135
+ */
136
+ interface AdminRepoConfig<TRepo extends ConfiguredRepository<any> = ConfiguredRepository<any>> {
137
+ /** The configured repository instance. Drives type inference for all other fields. */
138
+ repo: TRepo;
139
+ /**
140
+ * Zod schema — optional when the repo was created with `createRepositoryConfig(schema)`.
141
+ * Pass explicitly for repos created with the legacy `createRepositoryConfig<T>()` form.
142
+ */
143
+ schema?: z.ZodObject<any>;
144
+ /** Firestore collection path (for display only) */
145
+ path: string;
146
+ /** Key used to identify documents (default: "docId") */
147
+ documentKey?: string;
148
+ /** Columns to display in the list view (default: all schema keys) */
149
+ listColumns?: string[];
150
+ /** Number of documents per page in the list view (default: 25) */
151
+ pageSize?: number;
152
+ /**
153
+ * Per-field role configuration.
154
+ * Each key is a model field (with autocomplete); the value is an array of roles.
155
+ *
156
+ * Roles:
157
+ * - `"create"` — field is shown in the create form
158
+ * - `"mutable"` — field is shown in the edit form
159
+ * - `"filterable"` — field is shown in the filter bar
160
+ *
161
+ * If omitted, all schema fields are shown in all contexts.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * fieldsConfig: {
166
+ * title: ["create", "mutable", "filterable"],
167
+ * content: ["create", "mutable"],
168
+ * status: ["create", "filterable"],
169
+ * }
170
+ * ```
171
+ */
172
+ fieldsConfig?: Partial<Record<FieldPath<RepoModelType<TRepo>>, readonly FieldRole[]>>;
173
+ /**
174
+ * Whether to show the delete button in the list view.
175
+ * Default: false — delete is disabled unless explicitly set to true.
176
+ */
177
+ allowDelete?: boolean;
178
+ /**
179
+ * Relational action columns appended to the list table.
180
+ * Each entry adds a dedicated button that navigates to the linked repository.
181
+ *
182
+ * - **type "one"** (e.g. `userId` on a post) → button links to the target
183
+ * document edit page: `/{targetRepo}/{value}/edit`
184
+ * - **type "many"** (e.g. `docId` on a user) → button links to the target
185
+ * repo list filtered by value: `/{targetRepo}?fv_{targetKey}={value}`
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * users: {
190
+ * repo: repos.users,
191
+ * relationalFields: [
192
+ * { key: "docId", column: "Posts" }, // many → list of posts by this user
193
+ * ]
194
+ * }
195
+ * posts: {
196
+ * repo: repos.posts,
197
+ * relationalFields: [
198
+ * { key: "userId", column: "Author" }, // one → edit page of the user
199
+ * ]
200
+ * }
201
+ * ```
202
+ */
203
+ relationalFields?: {
204
+ /** The relation name defined in buildRepositoryRelations (or the model property name) */
205
+ key: string;
206
+ column: string;
207
+ }[];
208
+ }
209
+ /**
210
+ * HTTP Basic Auth configuration.
211
+ * The browser will show a native login dialog.
212
+ */
213
+ interface BasicAuthConfig {
214
+ type: "basic";
215
+ /** Realm displayed in the browser login dialog */
216
+ realm?: string;
217
+ username: string;
218
+ password: string;
219
+ }
220
+ /**
221
+ * Options for `createAdminServer`.
222
+ *
223
+ * Made generic so TypeScript can infer the model type of each repo entry
224
+ * and provide autocomplete + type-checking on `fieldsConfig`.
225
+ *
226
+ * @template TRepos - Shape of the repos map (inferred automatically at the call site)
227
+ */
228
+ interface AdminServerOptions<TRepos extends Record<string, ConfiguredRepository<any>> = Record<string, ConfiguredRepository<any>>> {
229
+ /**
230
+ * Base URL path of the function (e.g. "/admin").
231
+ * Must match the path where the Firebase Function is mounted.
232
+ * Default: "/"
233
+ */
234
+ basePath?: string;
235
+ /**
236
+ * Repository entries keyed by a display name.
237
+ * TypeScript infers the model type from each `repo` field,
238
+ * so `fieldsConfig` keys are typed to that model's field paths.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * repos: {
243
+ * posts: {
244
+ * repo: repos.posts,
245
+ * fieldsConfig: {
246
+ * title: ["create", "mutable", "filterable"],
247
+ * content: ["create", "mutable"],
248
+ * status: ["create", "filterable"],
249
+ * },
250
+ * },
251
+ * }
252
+ * ```
253
+ */
254
+ repos: {
255
+ [K in keyof TRepos]: AdminRepoConfig<TRepos[K]>;
256
+ };
257
+ /** Whether to parse URL-encoded bodies. Default: true. */
258
+ parseBody?: boolean;
259
+ /**
260
+ * Baseline security response headers (CSP, X-Frame-Options, nosniff,
261
+ * Referrer-Policy, Cache-Control). Enabled by default with HTML-safe
262
+ * defaults (see {@link DEFAULT_HTML_CSP}). Pass an options object to
263
+ * customise, or `false` to disable entirely (issues #12, #13).
264
+ */
265
+ securityHeaders?: SecurityHeadersOptions | false;
266
+ /**
267
+ * Authentication guard executed before every request.
268
+ * - Pass an {@link AuthExtension} (e.g. result of `firebaseAuth({...})`) to
269
+ * wire Firebase Auth with a bundled `/__login` page and session cookie.
270
+ * - Pass a `BasicAuthConfig` to enable HTTP Basic Auth.
271
+ * - Pass a `Middleware` function for fully custom auth logic.
272
+ */
273
+ auth?: AuthExtension | BasicAuthConfig | Middleware;
274
+ /**
275
+ * Additional middleware functions executed after auth, before route handlers.
276
+ */
277
+ middleware?: Middleware[];
278
+ /**
279
+ * Options forwarded to `onRequest()` from `firebase-functions/v2/https`.
280
+ * Stored on the returned handler as `.httpsOptions` for easy access.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * const handler = createAdminServer({ httpsOptions: { invoker: "public" }, ... });
285
+ * export const admin = onRequest(handler.httpsOptions!, handler);
286
+ * ```
287
+ */
288
+ httpsOptions?: HttpsOptions;
289
+ }
290
+ /**
291
+ * Creates an Express-compatible request handler for the admin ORM UI.
292
+ * Generates a complete admin interface with dashboard, lists, and CRUD forms.
293
+ *
294
+ * @template TRepos - Shape of the repos map (inferred automatically)
295
+ * @param options - Admin server configuration
296
+ * @returns Express-compatible request handler for Firebase Functions
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * // Basic admin server
301
+ * import { onRequest } from "firebase-functions/https";
302
+ * import { createAdminServer } from "@lpdjs/firestore-repo-service/servers/admin";
303
+ *
304
+ * export const admin = onRequest(
305
+ * createAdminServer({
306
+ * basePath: "/admin",
307
+ * repos: {
308
+ * users: {
309
+ * repo: repos.users,
310
+ * path: "users",
311
+ * },
312
+ * posts: {
313
+ * repo: repos.posts,
314
+ * path: "posts",
315
+ * },
316
+ * },
317
+ * })
318
+ * );
319
+ *
320
+ * // With HTTP Basic Auth
321
+ * export const admin = onRequest(
322
+ * createAdminServer({
323
+ * basePath: "/admin",
324
+ * auth: {
325
+ * type: "basic",
326
+ * realm: "Admin Area",
327
+ * username: "admin",
328
+ * password: process.env.ADMIN_PASSWORD!,
329
+ * },
330
+ * repos: { ... },
331
+ * })
332
+ * );
333
+ *
334
+ * // With custom auth middleware
335
+ * export const admin = onRequest(
336
+ * createAdminServer({
337
+ * auth: async (req, res, next) => {
338
+ * const token = req.headers?.authorization?.replace("Bearer ", "");
339
+ * if (!token || !(await verifyToken(token))) {
340
+ * res.status(401).send("Unauthorized");
341
+ * return;
342
+ * }
343
+ * next();
344
+ * },
345
+ * repos: { ... },
346
+ * })
347
+ * );
348
+ *
349
+ * // Full configuration with all options
350
+ * export const admin = onRequest(
351
+ * createAdminServer({
352
+ * basePath: "/admin",
353
+ * parseBody: true, // Parse URL-encoded bodies
354
+ * auth: { type: "basic", username: "admin", password: "secret" },
355
+ * middleware: [loggingMiddleware], // Additional middleware
356
+ * repos: {
357
+ * posts: {
358
+ * repo: repos.posts,
359
+ * path: "posts",
360
+ * documentKey: "docId", // Field used as document ID
361
+ * listColumns: ["title", "status", "createdAt"], // Columns in list
362
+ * pageSize: 25, // Items per page in list
363
+ * fieldsConfig: {
364
+ * title: ["create", "mutable", "filterable"],
365
+ * content: ["create", "mutable"],
366
+ * status: ["create", "mutable", "filterable"],
367
+ * userId: ["filterable"],
368
+ * },
369
+ * allowDelete: true, // Enable delete button
370
+ * relationalFields: [ // Relation navigation buttons
371
+ * { key: "userId", column: "Author" }, // Link to user
372
+ * { key: "docId", column: "Comments" }, // Link to comments list
373
+ * ],
374
+ * },
375
+ * users: {
376
+ * repo: repos.users,
377
+ * path: "users",
378
+ * fieldsConfig: {
379
+ * name: ["create", "mutable"],
380
+ * email: ["create", "mutable", "filterable"],
381
+ * isActive: ["mutable", "filterable"],
382
+ * },
383
+ * allowDelete: false,
384
+ * relationalFields: [
385
+ * { key: "docId", column: "Posts" },
386
+ * ],
387
+ * },
388
+ * },
389
+ * })
390
+ * );
391
+ *
392
+ * // Routes generated automatically:
393
+ * // GET /admin/ → Dashboard (list of repos)
394
+ * // GET /admin/:repo → Document list with pagination
395
+ * // GET /admin/:repo/create → Create form
396
+ * // POST /admin/:repo/create → Submit create
397
+ * // GET /admin/:repo/:id/edit → Edit form
398
+ * // POST /admin/:repo/:id/edit → Submit edit
399
+ * // POST /admin/:repo/:id/delete → Delete document
400
+ * ```
401
+ */
402
+ declare function createAdminServer<TRepos extends Record<string, ConfiguredRepository<any>>>(options: AdminServerOptions<TRepos>): ((req: any, res: any) => Promise<void>) & {
403
+ httpsOptions?: HttpsOptions;
404
+ };
405
+
406
+ export { type AdminRepoConfig, type AdminRepoEntry, type AdminServerOptions, type BasicAuthConfig, Middleware, type RepoRegistry, createAdminServer };
@@ -1,4 +1,4 @@
1
- export { A as AuthExtension, b as AuthRoute, c as AuthUser, D as DecodedIdTokenLike, F as FirebaseAdminAuthLike, d as FirebaseAuthConfig, e as FirebaseAuthLoginPageConfig, g as FirebaseAuthMode, a as allowAll, f as firebaseAuth, i as isAuthExtension } from '../../firebase-auth-DZ8lb2Ec.cjs';
1
+ export { b as AuthExtension, c as AuthRoute, A as AuthUser, D as DecodedIdTokenLike, F as FirebaseAdminAuthLike, d as FirebaseAuthConfig, e as FirebaseAuthLoginPageConfig, g as FirebaseAuthMode, a as allowAll, f as firebaseAuth, i as isAuthExtension } from '../../firebase-auth-Ds5P0kXT.cjs';
2
2
 
3
3
  /**
4
4
  * Session cookie + logout handlers for `firebaseAuth`.
@@ -1,4 +1,4 @@
1
- export { A as AuthExtension, b as AuthRoute, c as AuthUser, D as DecodedIdTokenLike, F as FirebaseAdminAuthLike, d as FirebaseAuthConfig, e as FirebaseAuthLoginPageConfig, g as FirebaseAuthMode, a as allowAll, f as firebaseAuth, i as isAuthExtension } from '../../firebase-auth-DZ8lb2Ec.js';
1
+ export { b as AuthExtension, c as AuthRoute, A as AuthUser, D as DecodedIdTokenLike, F as FirebaseAdminAuthLike, d as FirebaseAuthConfig, e as FirebaseAuthLoginPageConfig, g as FirebaseAuthMode, a as allowAll, f as firebaseAuth, i as isAuthExtension } from '../../firebase-auth-Ds5P0kXT.js';
2
2
 
3
3
  /**
4
4
  * Session cookie + logout handlers for `firebaseAuth`.