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