@lpdjs/firestore-repo-service 3.0.16 → 3.0.18
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.
- package/dist/{actor-context-DQZgWqj3.d.cts → actor-context-zNobm6nG.d.cts} +17 -2
- package/dist/{actor-context-DQZgWqj3.d.ts → actor-context-zNobm6nG.d.ts} +17 -2
- package/dist/{create-servers-BMpE8oAc.d.cts → create-servers-DydjOOOS.d.cts} +3 -3
- package/dist/{create-servers-DSXdPM6o.d.ts → create-servers-bMJVVjPj.d.ts} +3 -3
- package/dist/effects-BYvL8JUK.d.ts +158 -0
- package/dist/effects-DcM19dy4.d.cts +158 -0
- package/dist/history/index.cjs +1 -1
- package/dist/history/index.cjs.map +1 -1
- package/dist/history/index.d.cts +1 -1
- package/dist/history/index.d.ts +1 -1
- package/dist/history/index.js +1 -1
- package/dist/history/index.js.map +1 -1
- package/dist/index.cjs +95 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +95 -95
- package/dist/index.js.map +1 -1
- package/dist/llms-full.txt +139 -2
- package/dist/llms.txt +1 -1
- package/dist/servers/admin/index.d.cts +3 -3
- package/dist/servers/admin/index.d.ts +3 -3
- package/dist/servers/crud/index.cjs +2 -2
- package/dist/servers/crud/index.cjs.map +1 -1
- package/dist/servers/crud/index.d.cts +6 -7
- package/dist/servers/crud/index.d.ts +6 -7
- package/dist/servers/crud/index.js +2 -2
- package/dist/servers/crud/index.js.map +1 -1
- package/dist/servers/hono/index.cjs +12 -12
- package/dist/servers/hono/index.cjs.map +1 -1
- package/dist/servers/hono/index.d.cts +4 -4
- package/dist/servers/hono/index.d.ts +4 -4
- package/dist/servers/hono/index.js +12 -12
- package/dist/servers/hono/index.js.map +1 -1
- package/dist/servers/index.cjs +101 -101
- package/dist/servers/index.cjs.map +1 -1
- package/dist/servers/index.d.cts +6 -7
- package/dist/servers/index.d.ts +6 -7
- package/dist/servers/index.js +101 -101
- package/dist/servers/index.js.map +1 -1
- package/dist/sync/index.cjs +44 -44
- package/dist/sync/index.cjs.map +1 -1
- package/dist/sync/index.js +44 -44
- package/dist/sync/index.js.map +1 -1
- package/dist/{types-CaCBG76r.d.ts → types-5Q7JDDba.d.ts} +332 -3
- package/dist/{types-w1rEqs0Z.d.ts → types-BJ6MAavL.d.ts} +1 -1
- package/dist/{types-mKcJozu4.d.cts → types-BYPdlGSL.d.cts} +332 -3
- package/dist/{types-BDTx8VPg.d.cts → types-XvVG8_9J.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/openapi-CKTuB2Yz.d.ts +0 -70
- package/dist/openapi-Cb3QMU0Q.d.cts +0 -70
- package/dist/rules-DY5f_wPw.d.ts +0 -30
- package/dist/rules-DhNUzbIl.d.cts +0 -30
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { b as AuthUser } from './firebase-auth-nG3prKoj.cjs';
|
|
2
|
-
import { H as HonoServerOptions, O as OpenAPIConfig } from './types-
|
|
2
|
+
import { H as HonoServerOptions, O as OpenAPIConfig } from './types-XvVG8_9J.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { Context } from 'hono';
|
|
4
5
|
import { HttpsOptions } from 'firebase-functions/v2/https';
|
|
5
6
|
import { H as HistoryMethods } from './read-Dfah1PPl.cjs';
|
|
6
7
|
import { DocumentSnapshot, Query, CollectionReference, WriteBatch, Transaction, DocumentReference } from 'firebase-admin/firestore';
|
|
@@ -562,6 +563,36 @@ interface SecurityHeadersOptions {
|
|
|
562
563
|
*/
|
|
563
564
|
declare function securityHeaders(opts?: SecurityHeadersOptions): (_req: AnyReq, res: AnyRes, next: Next) => Promise<void>;
|
|
564
565
|
|
|
566
|
+
/**
|
|
567
|
+
* Descriptor for an extra custom HTTP header parameter emitted in OpenAPI 3.1
|
|
568
|
+
* (e.g. a custom header read by `actorResolver.extras`).
|
|
569
|
+
*/
|
|
570
|
+
interface OpenAPIHeaderParamSpec {
|
|
571
|
+
/** HTTP header name (e.g. `"X-App-Source"`). */
|
|
572
|
+
name: string;
|
|
573
|
+
/** Optional description displayed in Scalar / OpenAPI docs. */
|
|
574
|
+
description?: string;
|
|
575
|
+
/** Whether the header is required (default: `false`). */
|
|
576
|
+
required?: boolean;
|
|
577
|
+
/** Optional JSON Schema for the header value (default: `{ type: "string" }`). */
|
|
578
|
+
schema?: Record<string, unknown>;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Configuration controlling which history audit headers (`in: "header"`) are
|
|
582
|
+
* emitted on write endpoints (`POST`, `PUT`, `PATCH`, `POST /batch`) for
|
|
583
|
+
* repositories with active shadow history (`history.enabled: true`).
|
|
584
|
+
*/
|
|
585
|
+
interface OpenAPIHistoryHeadersConfig {
|
|
586
|
+
/** Header name for change reason, or `false` to omit. Default: auto-detected from `actorResolver` (`"X-History-Reason"`). */
|
|
587
|
+
reasonHeader?: string | false;
|
|
588
|
+
/** Header name for change comment, or `false` to omit. Default: auto-detected from `actorResolver` (`"X-History-Comment"`). */
|
|
589
|
+
commentHeader?: string | false;
|
|
590
|
+
/**
|
|
591
|
+
* Optional extra headers (string shorthand or full descriptor) to emit alongside
|
|
592
|
+
* history headers on history-enabled write endpoints (e.g. headers read by `actorResolver.extras`).
|
|
593
|
+
*/
|
|
594
|
+
extraHeaders?: Array<string | OpenAPIHeaderParamSpec>;
|
|
595
|
+
}
|
|
565
596
|
/**
|
|
566
597
|
* Options to control OpenAPI 3.1 spec generation for the CRUD server.
|
|
567
598
|
* Defined here (rather than in `./openapi`) to avoid a circular import:
|
|
@@ -587,6 +618,16 @@ interface OpenAPISpecOptions {
|
|
|
587
618
|
docsPath?: string | false;
|
|
588
619
|
/** Auth guards for the docs UI (same as HonoServer DocsAuthExtension or middleware) */
|
|
589
620
|
docsAuth?: OpenAPIConfig["docsAuth"];
|
|
621
|
+
/**
|
|
622
|
+
* Control automatic emission of history audit header parameters (`X-History-Reason`,
|
|
623
|
+
* `X-History-Comment`, or custom names from `actorResolver`) on write operations
|
|
624
|
+
* (`POST`, `PUT`, `PATCH`, `POST /batch`) for repositories with active shadow history.
|
|
625
|
+
*
|
|
626
|
+
* - Omitted: auto-detected from `actorResolver`.
|
|
627
|
+
* - `false`: disable emitting history headers in the OpenAPI spec.
|
|
628
|
+
* - Object: override `reasonHeader` / `commentHeader` and/or declare `extraHeaders`.
|
|
629
|
+
*/
|
|
630
|
+
historyHeaders?: false | OpenAPIHistoryHeadersConfig;
|
|
590
631
|
}
|
|
591
632
|
/**
|
|
592
633
|
* Extracts the model type `T` from a `ConfiguredRepository`.
|
|
@@ -729,6 +770,27 @@ interface CrudRepoConfig<TRepo extends ConfiguredRepository<any> = ConfiguredRep
|
|
|
729
770
|
* ```
|
|
730
771
|
*/
|
|
731
772
|
rules?: CrudRules<TRepo>;
|
|
773
|
+
/**
|
|
774
|
+
* Post-write lifecycle hooks executed **after** Firestore writes commit and
|
|
775
|
+
* `await`ed before the HTTP response is sent.
|
|
776
|
+
*
|
|
777
|
+
* Unlike `rules` (which govern pre-write authorization and `preWrite`
|
|
778
|
+
* mutations), `hooks` are dedicated to side effects (recalculations,
|
|
779
|
+
* notifications, cascading writes). Errors thrown by hooks are caught and
|
|
780
|
+
* forwarded to `onHookError` (or the server logger) so a committed write
|
|
781
|
+
* never returns a misleading HTTP 500.
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```ts
|
|
785
|
+
* hooks: {
|
|
786
|
+
* afterCreate: async ({ doc, id, user }) => { ... },
|
|
787
|
+
* afterUpdate: async ({ before, after, diff, pathArgs }) => { ... },
|
|
788
|
+
* afterDelete: async ({ doc, id }) => { ... },
|
|
789
|
+
* afterBatch: async ({ created, updated, deleted }) => { ... },
|
|
790
|
+
* }
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
hooks?: CrudHooks<TRepo>;
|
|
732
794
|
}
|
|
733
795
|
/** Return type of a diff computation comparing before and after states. */
|
|
734
796
|
interface DeepDiffReturn<T> {
|
|
@@ -820,6 +882,252 @@ interface CrudRules<TRepo extends ConfiguredRepository<any> = ConfiguredReposito
|
|
|
820
882
|
}
|
|
821
883
|
/** Erased rules type stored on the runtime registry entry. */
|
|
822
884
|
type AnyCrudRules = CrudRules<any>;
|
|
885
|
+
/** Write operations that support pre-write mutations. */
|
|
886
|
+
type CrudWriteOperation = "create" | "update";
|
|
887
|
+
/** Context passed to each pre-write mutation entry. */
|
|
888
|
+
interface MutationContext<T> {
|
|
889
|
+
/** Validated payload mutated by reference before writing to Firestore. */
|
|
890
|
+
body: Partial<T>;
|
|
891
|
+
/** Existing document (`null` on `create`). */
|
|
892
|
+
doc: T | null;
|
|
893
|
+
/** Current diff (on `create`: `before = {}`, `changes = body`). */
|
|
894
|
+
diff: DeepDiffReturn<T>;
|
|
895
|
+
/** Triggering field key, or `"*"` for global mutations executed on every write. */
|
|
896
|
+
key: keyof T | "*";
|
|
897
|
+
operation: CrudWriteOperation;
|
|
898
|
+
user?: AuthUser;
|
|
899
|
+
}
|
|
900
|
+
/** Bare pre-write mutation callback. */
|
|
901
|
+
type PreWriteMutationFn<T> = (ctx: MutationContext<T>) => void | Promise<void>;
|
|
902
|
+
/** Declarative pre-write mutation rule with description and optional operation filter. */
|
|
903
|
+
interface MutationRule<T> {
|
|
904
|
+
description: string;
|
|
905
|
+
/** Restrict execution to `"create"` or `"update"` (default: both). */
|
|
906
|
+
operations?: CrudWriteOperation[];
|
|
907
|
+
mutation: PreWriteMutationFn<T>;
|
|
908
|
+
}
|
|
909
|
+
/** A single pre-write mutation entry (either a bare function or a structured rule). */
|
|
910
|
+
type PreWriteMutation<T> = MutationRule<T> | PreWriteMutationFn<T>;
|
|
911
|
+
/**
|
|
912
|
+
* Map of pre-write mutations indexed by model field key, plus an optional `"*"`
|
|
913
|
+
* wildcard bucket executed on every write after per-field mutations.
|
|
914
|
+
*/
|
|
915
|
+
type MutationsMap<T> = Partial<Record<keyof T, PreWriteMutation<T>[]>> & {
|
|
916
|
+
"*"?: PreWriteMutation<T>[];
|
|
917
|
+
};
|
|
918
|
+
/** Operations that can trigger reactive effects. */
|
|
919
|
+
type CrudEffectOperation = "create" | "update" | "delete";
|
|
920
|
+
/** Arguments passed to a {@link RuleEffect.rule} predicate. */
|
|
921
|
+
interface EffectPredicateArgs<T> {
|
|
922
|
+
diff: DeepDiffReturn<T>;
|
|
923
|
+
key: keyof T | "*";
|
|
924
|
+
operation?: CrudEffectOperation;
|
|
925
|
+
user?: AuthUser;
|
|
926
|
+
}
|
|
927
|
+
/** A reactive post-write effect attached to a field (or `"*"`). */
|
|
928
|
+
interface RuleEffect<T, TContext> {
|
|
929
|
+
description: string;
|
|
930
|
+
rule: (args: EffectPredicateArgs<T>) => boolean | void | Promise<boolean | void>;
|
|
931
|
+
/** May return corrective fields (`Partial<T>`) to patch onto the current document. */
|
|
932
|
+
handler: (ctx: TContext) => Promise<void | Partial<T>> | void | Partial<T>;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Map of post-write effects indexed by model field key, plus an optional `"*"`
|
|
936
|
+
* wildcard bucket executed after per-field effects (e.g. cross-field recalculations).
|
|
937
|
+
*/
|
|
938
|
+
type EffectsMap<T, TContext> = Partial<Record<keyof T, RuleEffect<T, TContext>[]>> & {
|
|
939
|
+
"*"?: RuleEffect<T, TContext>[];
|
|
940
|
+
};
|
|
941
|
+
/** Execution outcome for a single {@link RuleEffect}. */
|
|
942
|
+
interface EffectExecutionResult {
|
|
943
|
+
key: string;
|
|
944
|
+
description: string;
|
|
945
|
+
isCalled: boolean;
|
|
946
|
+
error: null | unknown;
|
|
947
|
+
}
|
|
948
|
+
/** Aggregated result returned by {@link applyEffects}. */
|
|
949
|
+
interface ApplyEffectsResult<T> {
|
|
950
|
+
results: EffectExecutionResult[];
|
|
951
|
+
changesNeeded: Partial<T>;
|
|
952
|
+
hasErrors: boolean;
|
|
953
|
+
}
|
|
954
|
+
/** Context passed to {@link CrudHooks.beforeCreate}. */
|
|
955
|
+
interface CrudBeforeCreateContext<T = Record<string, unknown>> {
|
|
956
|
+
user: AuthUser;
|
|
957
|
+
/** Validated payload mutated by reference before persisting to Firestore. */
|
|
958
|
+
body: Partial<T>;
|
|
959
|
+
params: Record<string, string>;
|
|
960
|
+
/** Hono request context (headers, auth, etc.). */
|
|
961
|
+
c: Context;
|
|
962
|
+
}
|
|
963
|
+
/** Context passed to {@link CrudHooks.beforeUpdate}. */
|
|
964
|
+
interface CrudBeforeUpdateContext<T = Record<string, unknown>> {
|
|
965
|
+
user: AuthUser;
|
|
966
|
+
/** Existing document snapshot before update. */
|
|
967
|
+
doc: T;
|
|
968
|
+
/** Validated payload mutated by reference before persisting to Firestore. */
|
|
969
|
+
body: Partial<T>;
|
|
970
|
+
/** Current diff before `beforeUpdate` mutations. */
|
|
971
|
+
diff: DeepDiffReturn<T>;
|
|
972
|
+
params: Record<string, string>;
|
|
973
|
+
/** Hono request context (headers, auth, etc.). */
|
|
974
|
+
c: Context;
|
|
975
|
+
}
|
|
976
|
+
/** Context passed to {@link CrudHooks.afterCreate}. */
|
|
977
|
+
interface CrudAfterCreateContext<T = Record<string, unknown>> {
|
|
978
|
+
user: AuthUser;
|
|
979
|
+
/** Created document as persisted in Firestore. */
|
|
980
|
+
doc: T;
|
|
981
|
+
/** Created document ID. */
|
|
982
|
+
id: string;
|
|
983
|
+
/** Positional Firestore document path arguments (e.g. `[docId]` or `[workshopId, docId]`). */
|
|
984
|
+
pathArgs: string[];
|
|
985
|
+
params: Record<string, string>;
|
|
986
|
+
/** Hono request context (headers, auth, etc.). */
|
|
987
|
+
c: Context;
|
|
988
|
+
}
|
|
989
|
+
/** Context passed to {@link CrudHooks.afterUpdate}. */
|
|
990
|
+
interface CrudAfterUpdateContext<T = Record<string, unknown>> {
|
|
991
|
+
user: AuthUser;
|
|
992
|
+
/** Existing document snapshot BEFORE write. */
|
|
993
|
+
before: T;
|
|
994
|
+
/** Document returned AFTER write (including `preWrite` mutations). */
|
|
995
|
+
after: T;
|
|
996
|
+
/** Final persisted payload (after `rules.update` / `preWrite` mutations). */
|
|
997
|
+
body: Partial<T>;
|
|
998
|
+
/** Diff recomputed AFTER `rules.update` (`preWrite`) so mutated fields are captured. */
|
|
999
|
+
diff: DeepDiffReturn<T>;
|
|
1000
|
+
id: string;
|
|
1001
|
+
/** Positional Firestore document path arguments (e.g. `[docId]` or `[workshopId, eventId]`). */
|
|
1002
|
+
pathArgs: string[];
|
|
1003
|
+
params: Record<string, string>;
|
|
1004
|
+
/** Hono request context (headers, auth, etc.). */
|
|
1005
|
+
c: Context;
|
|
1006
|
+
}
|
|
1007
|
+
/** Context passed to {@link CrudHooks.afterDelete}. */
|
|
1008
|
+
interface CrudAfterDeleteContext<T = Record<string, unknown>> {
|
|
1009
|
+
user: AuthUser;
|
|
1010
|
+
/** Deleted document snapshot captured before deletion. */
|
|
1011
|
+
doc: T;
|
|
1012
|
+
id: string;
|
|
1013
|
+
/** Positional Firestore document path arguments. */
|
|
1014
|
+
pathArgs: string[];
|
|
1015
|
+
params: Record<string, string>;
|
|
1016
|
+
/** Hono request context (headers, auth, etc.). */
|
|
1017
|
+
c: Context;
|
|
1018
|
+
}
|
|
1019
|
+
/** Created item metadata passed inside {@link CrudAfterBatchContext.created}. */
|
|
1020
|
+
interface CrudAfterBatchCreatedItem<T = Record<string, unknown>> {
|
|
1021
|
+
id: string;
|
|
1022
|
+
pathArgs: string[];
|
|
1023
|
+
doc: T;
|
|
1024
|
+
}
|
|
1025
|
+
/** Updated item metadata passed inside {@link CrudAfterBatchContext.updated}. */
|
|
1026
|
+
interface CrudAfterBatchUpdatedItem<T = Record<string, unknown>> {
|
|
1027
|
+
id: string;
|
|
1028
|
+
pathArgs: string[];
|
|
1029
|
+
before: T;
|
|
1030
|
+
/** Projected state after applying the final payload (including `preWrite` mutations). */
|
|
1031
|
+
after: T;
|
|
1032
|
+
body: Partial<T>;
|
|
1033
|
+
/** Diff recomputed AFTER `rules.update` (`preWrite`). */
|
|
1034
|
+
diff: DeepDiffReturn<T>;
|
|
1035
|
+
}
|
|
1036
|
+
/** Deleted item metadata passed inside {@link CrudAfterBatchContext.deleted}. */
|
|
1037
|
+
interface CrudAfterBatchDeletedItem<T = Record<string, unknown>> {
|
|
1038
|
+
id: string;
|
|
1039
|
+
pathArgs: string[];
|
|
1040
|
+
doc: T;
|
|
1041
|
+
}
|
|
1042
|
+
/** Context passed to {@link CrudHooks.afterBatch}. */
|
|
1043
|
+
interface CrudAfterBatchContext<T = Record<string, unknown>> {
|
|
1044
|
+
user: AuthUser;
|
|
1045
|
+
created: Array<CrudAfterBatchCreatedItem<T>>;
|
|
1046
|
+
updated: Array<CrudAfterBatchUpdatedItem<T>>;
|
|
1047
|
+
deleted: Array<CrudAfterBatchDeletedItem<T>>;
|
|
1048
|
+
params: Record<string, string>;
|
|
1049
|
+
/** Hono request context (headers, auth, etc.). */
|
|
1050
|
+
c: Context;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Per-repo post-write lifecycle hooks.
|
|
1054
|
+
*
|
|
1055
|
+
* All hooks are `await`ed before sending the HTTP response (critical on
|
|
1056
|
+
* Cloud Functions v2 where CPU is throttled once the response finishes) while
|
|
1057
|
+
* the `actorResolver` `AsyncLocalStorage` scope is still active.
|
|
1058
|
+
*
|
|
1059
|
+
* @template TRepo - The configured repository (used to type `doc`, `before`, `after`, `body`, `diff`).
|
|
1060
|
+
*/
|
|
1061
|
+
interface CrudHooks<TRepo extends ConfiguredRepository<any> = ConfiguredRepository<any>> {
|
|
1062
|
+
/**
|
|
1063
|
+
* Called after schema validation and `rules.create` pass, right before
|
|
1064
|
+
* persisting the new document (`POST /:repoName` and batch `create`).
|
|
1065
|
+
* Mutate `ctx.body` in place to normalize or inject server-derived fields.
|
|
1066
|
+
*/
|
|
1067
|
+
beforeCreate?: (ctx: CrudBeforeCreateContext<RepoModelType<TRepo>>) => void | Promise<void>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Called after schema validation and `rules.update` pass, right before
|
|
1070
|
+
* persisting the update (`PUT/PATCH /:repoName/:id` and batch `update`).
|
|
1071
|
+
* Mutate `ctx.body` in place; `diff` is recomputed afterward for `afterUpdate` / `afterBatch`.
|
|
1072
|
+
*/
|
|
1073
|
+
beforeUpdate?: (ctx: CrudBeforeUpdateContext<RepoModelType<TRepo>>) => void | Promise<void>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Called after a document is created (`POST /:repoName`).
|
|
1076
|
+
* Returning a non-empty `Partial<T>` patches the newly created document via
|
|
1077
|
+
* `repo.update(...pathArgs, changes)` and returns the updated document in the response.
|
|
1078
|
+
*/
|
|
1079
|
+
afterCreate?: (ctx: CrudAfterCreateContext<RepoModelType<TRepo>>) => Promise<void | Partial<RepoModelType<TRepo>>> | void | Partial<RepoModelType<TRepo>>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Called after a document is updated (`PUT/PATCH /:repoName/:id`).
|
|
1082
|
+
* Returning a non-empty `Partial<T>` patches the updated document via
|
|
1083
|
+
* `repo.update(...pathArgs, changes)` and returns the final document in the response.
|
|
1084
|
+
*/
|
|
1085
|
+
afterUpdate?: (ctx: CrudAfterUpdateContext<RepoModelType<TRepo>>) => Promise<void | Partial<RepoModelType<TRepo>>> | void | Partial<RepoModelType<TRepo>>;
|
|
1086
|
+
/**
|
|
1087
|
+
* Called after a document is deleted (`DELETE /:repoName/:id`).
|
|
1088
|
+
*/
|
|
1089
|
+
afterDelete?: (ctx: CrudAfterDeleteContext<RepoModelType<TRepo>>) => Promise<void> | void;
|
|
1090
|
+
/**
|
|
1091
|
+
* Called ONCE after `batch.commit()` (`POST /:repoName/batch`).
|
|
1092
|
+
* When omitted, the server falls back to calling `afterCreate` / `afterUpdate` /
|
|
1093
|
+
* `afterDelete` sequentially on each committed item.
|
|
1094
|
+
*/
|
|
1095
|
+
afterBatch?: (ctx: CrudAfterBatchContext<RepoModelType<TRepo>>) => Promise<void> | void;
|
|
1096
|
+
/**
|
|
1097
|
+
* Per-repo error callback for `after*` hooks (and follow-up `changesNeeded`
|
|
1098
|
+
* patches), since the primary Firestore write has already committed.
|
|
1099
|
+
*/
|
|
1100
|
+
onAfterError?: (err: unknown, phase: CrudHookName) => void | Promise<void>;
|
|
1101
|
+
}
|
|
1102
|
+
/** Erased hooks type stored on the runtime registry entry. */
|
|
1103
|
+
type AnyCrudHooks = CrudHooks<any>;
|
|
1104
|
+
/** Hook name reported to {@link CrudHookErrorCallback}. */
|
|
1105
|
+
type CrudHookName = "afterCreate" | "afterUpdate" | "afterDelete" | "afterBatch";
|
|
1106
|
+
/** Context provided to {@link CrudServerOptions.onHookError} when a post-write hook throws. */
|
|
1107
|
+
interface CrudHookErrorContext {
|
|
1108
|
+
/** Hook that threw (or whose follow-up `changesNeeded` update failed). */
|
|
1109
|
+
hook: CrudHookName;
|
|
1110
|
+
/** Repository name in the CRUD registry. */
|
|
1111
|
+
repoName: string;
|
|
1112
|
+
/** Firestore collection path. */
|
|
1113
|
+
path: string;
|
|
1114
|
+
/** Document ID (present for single-doc hooks and batch fallback; undefined for `afterBatch`). */
|
|
1115
|
+
id?: string;
|
|
1116
|
+
/** Positional path args (present for single-doc hooks and batch fallback; undefined for `afterBatch`). */
|
|
1117
|
+
pathArgs?: string[];
|
|
1118
|
+
/** Authenticated user (or `null` when auth is off). */
|
|
1119
|
+
user: AuthUser | null;
|
|
1120
|
+
/** The thrown error. */
|
|
1121
|
+
error: unknown;
|
|
1122
|
+
/** Hono request context. */
|
|
1123
|
+
c: Context;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Callback invoked when a CRUD post-write hook throws an error.
|
|
1127
|
+
* Because the primary Firestore write is already committed, the HTTP request
|
|
1128
|
+
* still succeeds and this callback lets you log / alert without returning a 500.
|
|
1129
|
+
*/
|
|
1130
|
+
type CrudHookErrorCallback = (ctx: CrudHookErrorContext) => void | Promise<void>;
|
|
823
1131
|
/**
|
|
824
1132
|
* Internal repo entry for the CRUD server.
|
|
825
1133
|
*/
|
|
@@ -855,6 +1163,17 @@ interface CrudRepoEntry {
|
|
|
855
1163
|
validate?: (data: any, operation: "create" | "update") => string | undefined | Promise<string | undefined>;
|
|
856
1164
|
/** Per-operation authorization rules (see {@link CrudRules}). */
|
|
857
1165
|
rules?: AnyCrudRules;
|
|
1166
|
+
/** Post-write lifecycle hooks (see {@link CrudHooks}). */
|
|
1167
|
+
hooks?: AnyCrudHooks;
|
|
1168
|
+
/**
|
|
1169
|
+
* Active history shadow header flags (auto-detected when `history.enabled`
|
|
1170
|
+
* is true, `autoInjectMeta !== false`, and shadow storage is active).
|
|
1171
|
+
* Used by OpenAPI generation to emit optional audit headers on write endpoints.
|
|
1172
|
+
*/
|
|
1173
|
+
historyHeaders?: {
|
|
1174
|
+
reason: boolean;
|
|
1175
|
+
comment: boolean;
|
|
1176
|
+
};
|
|
858
1177
|
}
|
|
859
1178
|
type CrudRepoRegistry = Record<string, CrudRepoEntry>;
|
|
860
1179
|
/**
|
|
@@ -943,6 +1262,16 @@ interface CrudServerOptions<TRepos extends Record<string, ConfiguredRepository<a
|
|
|
943
1262
|
* Alias for {@link indexesError}.
|
|
944
1263
|
*/
|
|
945
1264
|
onIndexError?: IndexErrorCallback;
|
|
1265
|
+
/**
|
|
1266
|
+
* Callback invoked when a post-write lifecycle hook (`afterCreate`,
|
|
1267
|
+
* `afterUpdate`, `afterDelete`, `afterBatch`) or its optional `changesNeeded`
|
|
1268
|
+
* follow-up update throws.
|
|
1269
|
+
*
|
|
1270
|
+
* Because the primary Firestore write has already committed, hook errors are
|
|
1271
|
+
* caught so the client does not receive a misleading HTTP 500. When omitted,
|
|
1272
|
+
* errors are logged via the server `logger` (if configured) or `console.error`.
|
|
1273
|
+
*/
|
|
1274
|
+
onHookError?: CrudHookErrorCallback;
|
|
946
1275
|
}
|
|
947
1276
|
/**
|
|
948
1277
|
* Context provided to the `indexesError` callback when a Firestore query fails due to a missing composite index.
|
|
@@ -1080,5 +1409,5 @@ interface QueryRequestBody {
|
|
|
1080
1409
|
withTotal?: boolean;
|
|
1081
1410
|
}
|
|
1082
1411
|
|
|
1083
|
-
export {
|
|
1084
|
-
export type {
|
|
1412
|
+
export { DEFAULT_HTML_CSP as a2, securityHeaders as a3, createPaginationIterator as af, executePaginatedQuery as ag };
|
|
1413
|
+
export type { FilterState as $, AnyCrudHooks as A, MutationRule as B, ConfiguredRepository as C, DeepDiffReturn as D, EffectExecutionResult as E, FieldRole as F, MutationsMap as G, OpenAPIHistoryHeadersConfig as H, IndexErrorCallback as I, OpenAPISpecOptions as J, PreWriteMutationFn as K, ListResponseData as L, MutationContext as M, RepoRelationKeys as N, OpenAPIHeaderParamSpec as O, PreWriteMutation as P, QueryRequestBody as Q, RepoFieldPath as R, Rule as S, RuleEffect as T, RuleResult as U, RulesMap as V, UserFieldPath as W, RelationalFieldMeta as X, SecurityHeadersOptions as Y, PageOptions as Z, ColumnMeta as _, CrudServerOptions as a, SortState as a0, QueryError as a1, PaginationOptions as a4, GenerateGetMethods as a5, GenerateQueryMethods as a6, IncludeConfigTyped as a7, PaginationResult as a8, PaginationWithIncludeOptionsTyped as a9, PopulateOptionsTyped as aa, SystemBackfillFailure as ab, SystemBackfillOptions as ac, SystemBackfillResult as ad, UpdatableData as ae, ApiResponse as b, ApplyEffectsResult as c, CrudAfterBatchContext as d, CrudAfterBatchCreatedItem as e, CrudAfterBatchDeletedItem as f, CrudAfterBatchUpdatedItem as g, CrudAfterCreateContext as h, CrudAfterDeleteContext as i, CrudAfterUpdateContext as j, CrudBeforeCreateContext as k, CrudBeforeUpdateContext as l, CrudEffectOperation as m, CrudHookErrorCallback as n, CrudHookErrorContext as o, CrudHookName as p, CrudHooks as q, CrudRepoConfig as r, CrudRepoEntry as s, CrudRepoRegistry as t, CrudRules as u, CrudUpdateRuleContext as v, CrudWriteOperation as w, EffectPredicateArgs as x, EffectsMap as y, IndexErrorContext as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z, ZodError } from 'zod';
|
|
2
2
|
import { Env, Context, MiddlewareHandler } from 'hono';
|
|
3
3
|
import { F as FirebaseAdminAuthLike, D as DecodedIdTokenLike } from './firebase-auth-nG3prKoj.cjs';
|
|
4
|
-
import { A as ActorResolverOption } from './actor-context-
|
|
4
|
+
import { A as ActorResolverOption } from './actor-context-zNobm6nG.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Global DI services container for the Hono server.
|
package/package.json
CHANGED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-CaCBG76r.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* OpenAPI 3.1 specification generator for the CRUD server.
|
|
5
|
-
*
|
|
6
|
-
* Introspects each `CrudRepoEntry` and uses Zod 4's native `z.toJSONSchema()`
|
|
7
|
-
* to produce a fully typed OpenAPI document ready for Scalar UI or codegen.
|
|
8
|
-
*
|
|
9
|
-
* @module servers/crud/openapi
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** Minimal subset of an OpenAPI 3.1 document we produce. */
|
|
13
|
-
interface OpenAPIDocument {
|
|
14
|
-
openapi: "3.1.0";
|
|
15
|
-
info: OpenAPIInfo;
|
|
16
|
-
servers?: {
|
|
17
|
-
url: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
}[];
|
|
20
|
-
paths: Record<string, Record<string, OpenAPIOperation>>;
|
|
21
|
-
components: {
|
|
22
|
-
schemas: Record<string, Record<string, unknown>>;
|
|
23
|
-
securitySchemes?: Record<string, Record<string, unknown>>;
|
|
24
|
-
};
|
|
25
|
-
security?: Record<string, string[]>[];
|
|
26
|
-
tags?: {
|
|
27
|
-
name: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
}[];
|
|
30
|
-
}
|
|
31
|
-
interface OpenAPIInfo {
|
|
32
|
-
title: string;
|
|
33
|
-
version: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
}
|
|
36
|
-
interface OpenAPIOperation {
|
|
37
|
-
operationId: string;
|
|
38
|
-
summary: string;
|
|
39
|
-
tags: string[];
|
|
40
|
-
parameters?: Record<string, unknown>[];
|
|
41
|
-
requestBody?: Record<string, unknown>;
|
|
42
|
-
responses: Record<string, Record<string, unknown>>;
|
|
43
|
-
security?: Record<string, string[]>[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate a full OpenAPI 3.1 specification from a `CrudRepoRegistry`.
|
|
47
|
-
*
|
|
48
|
-
* Uses Zod 4's native `z.toJSONSchema()` to convert each repo's schema
|
|
49
|
-
* into a JSON Schema component, then assembles paths for the standard
|
|
50
|
-
* CRUD endpoints.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* import { generateOpenAPISpec } from "@lpdjs/firestore-repo-service/servers/crud";
|
|
55
|
-
*
|
|
56
|
-
* const spec = generateOpenAPISpec(registry, "/api", {
|
|
57
|
-
* title: "My API",
|
|
58
|
-
* version: "1.0.0",
|
|
59
|
-
* servers: [{ url: "https://my-api.example.com" }],
|
|
60
|
-
* auth: "bearer",
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* // Write to file
|
|
64
|
-
* fs.writeFileSync("openapi.json", JSON.stringify(spec, null, 2));
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function generateOpenAPISpec(registry: CrudRepoRegistry, basePath: string, options?: OpenAPISpecOptions): OpenAPIDocument;
|
|
68
|
-
|
|
69
|
-
export { generateOpenAPISpec as g };
|
|
70
|
-
export type { OpenAPIDocument as O };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-mKcJozu4.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* OpenAPI 3.1 specification generator for the CRUD server.
|
|
5
|
-
*
|
|
6
|
-
* Introspects each `CrudRepoEntry` and uses Zod 4's native `z.toJSONSchema()`
|
|
7
|
-
* to produce a fully typed OpenAPI document ready for Scalar UI or codegen.
|
|
8
|
-
*
|
|
9
|
-
* @module servers/crud/openapi
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** Minimal subset of an OpenAPI 3.1 document we produce. */
|
|
13
|
-
interface OpenAPIDocument {
|
|
14
|
-
openapi: "3.1.0";
|
|
15
|
-
info: OpenAPIInfo;
|
|
16
|
-
servers?: {
|
|
17
|
-
url: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
}[];
|
|
20
|
-
paths: Record<string, Record<string, OpenAPIOperation>>;
|
|
21
|
-
components: {
|
|
22
|
-
schemas: Record<string, Record<string, unknown>>;
|
|
23
|
-
securitySchemes?: Record<string, Record<string, unknown>>;
|
|
24
|
-
};
|
|
25
|
-
security?: Record<string, string[]>[];
|
|
26
|
-
tags?: {
|
|
27
|
-
name: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
}[];
|
|
30
|
-
}
|
|
31
|
-
interface OpenAPIInfo {
|
|
32
|
-
title: string;
|
|
33
|
-
version: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
}
|
|
36
|
-
interface OpenAPIOperation {
|
|
37
|
-
operationId: string;
|
|
38
|
-
summary: string;
|
|
39
|
-
tags: string[];
|
|
40
|
-
parameters?: Record<string, unknown>[];
|
|
41
|
-
requestBody?: Record<string, unknown>;
|
|
42
|
-
responses: Record<string, Record<string, unknown>>;
|
|
43
|
-
security?: Record<string, string[]>[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate a full OpenAPI 3.1 specification from a `CrudRepoRegistry`.
|
|
47
|
-
*
|
|
48
|
-
* Uses Zod 4's native `z.toJSONSchema()` to convert each repo's schema
|
|
49
|
-
* into a JSON Schema component, then assembles paths for the standard
|
|
50
|
-
* CRUD endpoints.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* import { generateOpenAPISpec } from "@lpdjs/firestore-repo-service/servers/crud";
|
|
55
|
-
*
|
|
56
|
-
* const spec = generateOpenAPISpec(registry, "/api", {
|
|
57
|
-
* title: "My API",
|
|
58
|
-
* version: "1.0.0",
|
|
59
|
-
* servers: [{ url: "https://my-api.example.com" }],
|
|
60
|
-
* auth: "bearer",
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* // Write to file
|
|
64
|
-
* fs.writeFileSync("openapi.json", JSON.stringify(spec, null, 2));
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function generateOpenAPISpec(registry: CrudRepoRegistry, basePath: string, options?: OpenAPISpecOptions): OpenAPIDocument;
|
|
68
|
-
|
|
69
|
-
export { generateOpenAPISpec as g };
|
|
70
|
-
export type { OpenAPIDocument as O };
|
package/dist/rules-DY5f_wPw.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { b as AuthUser } from './firebase-auth-nG3prKoj.js';
|
|
2
|
-
import { D as DeepDiffReturn, k as RulesMap, f as CrudUpdateRuleContext } from './types-CaCBG76r.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Computes a typed diff between the existing document (`before`) and the incoming partial changes (`changesInput`).
|
|
6
|
-
* Only fields whose values have actually changed (via structural equality) are included in `changes`.
|
|
7
|
-
*/
|
|
8
|
-
declare function computeDeepDiff<T extends Record<string, unknown>>(before: T, changesInput: Partial<T>): DeepDiffReturn<T>;
|
|
9
|
-
/**
|
|
10
|
-
* Helper to define field-by-field before-rules with strong typing.
|
|
11
|
-
*/
|
|
12
|
-
declare function createRules<T>(rules: RulesMap<T>): RulesMap<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Executes a map of field rules against a computed diff.
|
|
15
|
-
* Evaluates rules only for the keys that changed in `diff.changes`.
|
|
16
|
-
* Returns `{ allowed: true }` if all rules pass, or `{ allowed: false, reason: rule.description }` on the first failure.
|
|
17
|
-
*/
|
|
18
|
-
declare function applyRules<T>(diff: DeepDiffReturn<T>, rulesMap: RulesMap<T>, user?: AuthUser): Promise<{
|
|
19
|
-
allowed: boolean;
|
|
20
|
-
reason?: string;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Wraps a rules map into a standard `rules.update` handler for `createCrudServer`.
|
|
24
|
-
*/
|
|
25
|
-
declare function createBeforeRules<T>(rulesMap: RulesMap<T>): (ctx: CrudUpdateRuleContext<T>) => Promise<{
|
|
26
|
-
allowed: boolean;
|
|
27
|
-
reason?: string;
|
|
28
|
-
}>;
|
|
29
|
-
|
|
30
|
-
export { applyRules as a, createBeforeRules as b, computeDeepDiff as c, createRules as d };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { b as AuthUser } from './firebase-auth-nG3prKoj.cjs';
|
|
2
|
-
import { D as DeepDiffReturn, k as RulesMap, f as CrudUpdateRuleContext } from './types-mKcJozu4.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Computes a typed diff between the existing document (`before`) and the incoming partial changes (`changesInput`).
|
|
6
|
-
* Only fields whose values have actually changed (via structural equality) are included in `changes`.
|
|
7
|
-
*/
|
|
8
|
-
declare function computeDeepDiff<T extends Record<string, unknown>>(before: T, changesInput: Partial<T>): DeepDiffReturn<T>;
|
|
9
|
-
/**
|
|
10
|
-
* Helper to define field-by-field before-rules with strong typing.
|
|
11
|
-
*/
|
|
12
|
-
declare function createRules<T>(rules: RulesMap<T>): RulesMap<T>;
|
|
13
|
-
/**
|
|
14
|
-
* Executes a map of field rules against a computed diff.
|
|
15
|
-
* Evaluates rules only for the keys that changed in `diff.changes`.
|
|
16
|
-
* Returns `{ allowed: true }` if all rules pass, or `{ allowed: false, reason: rule.description }` on the first failure.
|
|
17
|
-
*/
|
|
18
|
-
declare function applyRules<T>(diff: DeepDiffReturn<T>, rulesMap: RulesMap<T>, user?: AuthUser): Promise<{
|
|
19
|
-
allowed: boolean;
|
|
20
|
-
reason?: string;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Wraps a rules map into a standard `rules.update` handler for `createCrudServer`.
|
|
24
|
-
*/
|
|
25
|
-
declare function createBeforeRules<T>(rulesMap: RulesMap<T>): (ctx: CrudUpdateRuleContext<T>) => Promise<{
|
|
26
|
-
allowed: boolean;
|
|
27
|
-
reason?: string;
|
|
28
|
-
}>;
|
|
29
|
-
|
|
30
|
-
export { applyRules as a, createBeforeRules as b, computeDeepDiff as c, createRules as d };
|