@lpdjs/firestore-repo-service 3.0.16 → 3.0.17

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.
@@ -1,12 +1,12 @@
1
1
  import { S as SyncQueue } from './queue-NFod6hTT.js';
2
2
  import { F as FirestoreSyncConfig, S as SyncEvent } from './types-B_FrzmO4.js';
3
- import { O as OpenAPIDocument } from './openapi-CKTuB2Yz.js';
3
+ import { O as OpenAPIDocument } from './effects-B8aIXMZ2.js';
4
4
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
5
5
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
6
6
  import { DocumentOptions } from 'firebase-functions/v2/firestore';
7
7
  import { A as ActorResolverOption } from './actor-context-DQZgWqj3.js';
8
8
  import { H as HistoryTriggersConfig } from './types-D6zvWzRt.js';
9
- import { C as ConfiguredRepository, b as CrudRepoConfig, a as CrudServerOptions } from './types-CaCBG76r.js';
9
+ import { C as ConfiguredRepository, r as CrudRepoConfig, a as CrudServerOptions } from './types-wMBgnYjH.js';
10
10
  import { MeilisearchAdapterOptions, MeilisearchAdapter } from './sync/meilisearch.js';
11
11
  import { AdminRepoConfig, AdminServerOptions } from './servers/admin/index.js';
12
12
 
@@ -1,12 +1,12 @@
1
1
  import { S as SyncQueue } from './queue-zw2B7GPx.cjs';
2
2
  import { F as FirestoreSyncConfig, S as SyncEvent } from './types-D78FPJeF.cjs';
3
- import { O as OpenAPIDocument } from './openapi-Cb3QMU0Q.cjs';
3
+ import { O as OpenAPIDocument } from './effects-CqJSneNZ.cjs';
4
4
  import * as firebase_functions_v2_https from 'firebase-functions/v2/https';
5
5
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
6
6
  import { DocumentOptions } from 'firebase-functions/v2/firestore';
7
7
  import { A as ActorResolverOption } from './actor-context-DQZgWqj3.cjs';
8
8
  import { H as HistoryTriggersConfig } from './types-D6zvWzRt.cjs';
9
- import { C as ConfiguredRepository, b as CrudRepoConfig, a as CrudServerOptions } from './types-mKcJozu4.cjs';
9
+ import { C as ConfiguredRepository, r as CrudRepoConfig, a as CrudServerOptions } from './types-DgzPoPvx.cjs';
10
10
  import { MeilisearchAdapterOptions, MeilisearchAdapter } from './sync/meilisearch.cjs';
11
11
  import { AdminRepoConfig, AdminServerOptions } from './servers/admin/index.cjs';
12
12
 
@@ -0,0 +1,158 @@
1
+ import { t as CrudRepoRegistry, O as OpenAPISpecOptions, D as DeepDiffReturn, T as RulesMap, v as CrudUpdateRuleContext, G as MutationsMap, w as CrudWriteOperation, k as CrudBeforeCreateContext, l as CrudBeforeUpdateContext, y as EffectsMap, m as CrudEffectOperation, c as ApplyEffectsResult, j as CrudAfterUpdateContext, E as EffectExecutionResult } from './types-wMBgnYjH.js';
2
+ import { b as AuthUser } from './firebase-auth-nG3prKoj.js';
3
+
4
+ /**
5
+ * OpenAPI 3.1 specification generator for the CRUD server.
6
+ *
7
+ * Introspects each `CrudRepoEntry` and uses Zod 4's native `z.toJSONSchema()`
8
+ * to produce a fully typed OpenAPI document ready for Scalar UI or codegen.
9
+ *
10
+ * @module servers/crud/openapi
11
+ */
12
+
13
+ /** Minimal subset of an OpenAPI 3.1 document we produce. */
14
+ interface OpenAPIDocument {
15
+ openapi: "3.1.0";
16
+ info: OpenAPIInfo;
17
+ servers?: {
18
+ url: string;
19
+ description?: string;
20
+ }[];
21
+ paths: Record<string, Record<string, OpenAPIOperation>>;
22
+ components: {
23
+ schemas: Record<string, Record<string, unknown>>;
24
+ securitySchemes?: Record<string, Record<string, unknown>>;
25
+ };
26
+ security?: Record<string, string[]>[];
27
+ tags?: {
28
+ name: string;
29
+ description?: string;
30
+ }[];
31
+ }
32
+ interface OpenAPIInfo {
33
+ title: string;
34
+ version: string;
35
+ description?: string;
36
+ }
37
+ interface OpenAPIOperation {
38
+ operationId: string;
39
+ summary: string;
40
+ tags: string[];
41
+ parameters?: Record<string, unknown>[];
42
+ requestBody?: Record<string, unknown>;
43
+ responses: Record<string, Record<string, unknown>>;
44
+ security?: Record<string, string[]>[];
45
+ }
46
+ /**
47
+ * Generate a full OpenAPI 3.1 specification from a `CrudRepoRegistry`.
48
+ *
49
+ * Uses Zod 4's native `z.toJSONSchema()` to convert each repo's schema
50
+ * into a JSON Schema component, then assembles paths for the standard
51
+ * CRUD endpoints.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { generateOpenAPISpec } from "@lpdjs/firestore-repo-service/servers/crud";
56
+ *
57
+ * const spec = generateOpenAPISpec(registry, "/api", {
58
+ * title: "My API",
59
+ * version: "1.0.0",
60
+ * servers: [{ url: "https://my-api.example.com" }],
61
+ * auth: "bearer",
62
+ * });
63
+ *
64
+ * // Write to file
65
+ * fs.writeFileSync("openapi.json", JSON.stringify(spec, null, 2));
66
+ * ```
67
+ */
68
+ declare function generateOpenAPISpec(registry: CrudRepoRegistry, basePath: string, options?: OpenAPISpecOptions): OpenAPIDocument;
69
+
70
+ /**
71
+ * Computes a typed diff between the existing document (`before`) and the incoming partial changes (`changesInput`).
72
+ * Only fields whose values have actually changed (via structural equality) are included in `changes`.
73
+ */
74
+ declare function computeDeepDiff<T extends Record<string, unknown>>(before: T, changesInput: Partial<T>): DeepDiffReturn<T>;
75
+ /**
76
+ * Helper to define field-by-field before-rules with strong typing.
77
+ */
78
+ declare function createRules<T>(rules: RulesMap<T>): RulesMap<T>;
79
+ /**
80
+ * Executes a map of field rules against a computed diff.
81
+ * Evaluates rules only for the keys that changed in `diff.changes`.
82
+ * Returns `{ allowed: true }` if all rules pass, or `{ allowed: false, reason: rule.description }` on the first failure.
83
+ */
84
+ declare function applyRules<T>(diff: DeepDiffReturn<T>, rulesMap: RulesMap<T>, user?: AuthUser): Promise<{
85
+ allowed: boolean;
86
+ reason?: string;
87
+ }>;
88
+ /**
89
+ * Wraps a rules map into a standard `rules.update` handler for `createCrudServer`.
90
+ */
91
+ declare function createBeforeRules<T>(rulesMap: RulesMap<T>): (ctx: CrudUpdateRuleContext<T>) => Promise<{
92
+ allowed: boolean;
93
+ reason?: string;
94
+ }>;
95
+
96
+ /**
97
+ * @module servers/crud/mutations
98
+ *
99
+ * Pre-write mutation engine for CRUD payload normalization and server-derived
100
+ * field injection before persisting to Firestore.
101
+ */
102
+
103
+ /**
104
+ * Helper to define field-by-field (and wildcard `"*"`) pre-write mutations
105
+ * with strong typing.
106
+ */
107
+ declare function createMutations<T>(mutations: MutationsMap<T>): MutationsMap<T>;
108
+ /**
109
+ * Executes a map of pre-write mutations against `body` / `diff`:
110
+ * 1. Runs per-field mutations for each key present in `diff.changes`.
111
+ * 2. Runs wildcard `"*"` mutations unconditionally after per-field mutations.
112
+ */
113
+ declare function applyMutations<T>(body: Partial<T>, doc: T | null, diff: DeepDiffReturn<T>, mutationsMap: MutationsMap<T>, user?: AuthUser, operation?: CrudWriteOperation): Promise<void>;
114
+ /**
115
+ * Wraps a {@link MutationsMap} into a `hooks.beforeUpdate` handler
116
+ * (analogous to `createBeforeRules`).
117
+ */
118
+ declare function createBeforeUpdateMutations<T>(mutationsMap: MutationsMap<T>): (ctx: CrudBeforeUpdateContext<T>) => Promise<void>;
119
+ /**
120
+ * Wraps a {@link MutationsMap} into a `hooks.beforeCreate` handler
121
+ * (analogous to `createBeforeRules`).
122
+ */
123
+ declare function createBeforeCreateMutations<T>(mutationsMap: MutationsMap<T>): (ctx: CrudBeforeCreateContext<T>) => Promise<void>;
124
+
125
+ /**
126
+ * @module servers/crud/effects
127
+ *
128
+ * Reactive post-write effects engine aligned with `rules.ts` / `mutations.ts`.
129
+ * Evaluates field-level and wildcard `"*"` effect rules against a recomputed diff,
130
+ * captures per-rule errors without aborting sibling effects, and aggregates
131
+ * optional follow-up document patches (`changesNeeded`).
132
+ */
133
+
134
+ /**
135
+ * Helper to define field-by-field (and wildcard `"*"`) post-write effects
136
+ * with strong typing.
137
+ */
138
+ declare function createEffects<T, TContext>(effects: EffectsMap<T, TContext>): EffectsMap<T, TContext>;
139
+ /**
140
+ * Executes a map of reactive effects against a computed `diff`:
141
+ * 1. Runs per-field effects for every key in `diff.changes`.
142
+ * 2. Runs wildcard `"*"` effects after per-field effects.
143
+ *
144
+ * Each effect is isolated in a `try/catch` so one failure never prevents
145
+ * remaining effects from executing. Any `Partial<T>` patches returned by
146
+ * handlers are merged into `changesNeeded`.
147
+ */
148
+ declare function applyEffects<T, TContext>(diff: DeepDiffReturn<T>, effectsMap: EffectsMap<T, TContext>, context: TContext, user?: AuthUser, operation?: CrudEffectOperation): Promise<ApplyEffectsResult<T>>;
149
+ /**
150
+ * Wraps an {@link EffectsMap} into a `hooks.afterUpdate` handler
151
+ * (analogous to `createBeforeRules`).
152
+ */
153
+ declare function createAfterUpdateEffects<T, TContext>(effectsMap: EffectsMap<T, TContext>, buildContext: (ctx: CrudAfterUpdateContext<T>) => TContext, options?: {
154
+ onRuleError?: (result: EffectExecutionResult, ctx: CrudAfterUpdateContext<T>) => void | Promise<void>;
155
+ }): (ctx: CrudAfterUpdateContext<T>) => Promise<void | Partial<T>>;
156
+
157
+ export { applyEffects as a, applyMutations as b, applyRules as c, computeDeepDiff as d, createAfterUpdateEffects as e, createBeforeCreateMutations as f, createBeforeRules as g, createBeforeUpdateMutations as h, createEffects as i, createMutations as j, createRules as k, generateOpenAPISpec as l };
158
+ export type { OpenAPIDocument as O };
@@ -0,0 +1,158 @@
1
+ import { t as CrudRepoRegistry, O as OpenAPISpecOptions, D as DeepDiffReturn, T as RulesMap, v as CrudUpdateRuleContext, G as MutationsMap, w as CrudWriteOperation, k as CrudBeforeCreateContext, l as CrudBeforeUpdateContext, y as EffectsMap, m as CrudEffectOperation, c as ApplyEffectsResult, j as CrudAfterUpdateContext, E as EffectExecutionResult } from './types-DgzPoPvx.cjs';
2
+ import { b as AuthUser } from './firebase-auth-nG3prKoj.cjs';
3
+
4
+ /**
5
+ * OpenAPI 3.1 specification generator for the CRUD server.
6
+ *
7
+ * Introspects each `CrudRepoEntry` and uses Zod 4's native `z.toJSONSchema()`
8
+ * to produce a fully typed OpenAPI document ready for Scalar UI or codegen.
9
+ *
10
+ * @module servers/crud/openapi
11
+ */
12
+
13
+ /** Minimal subset of an OpenAPI 3.1 document we produce. */
14
+ interface OpenAPIDocument {
15
+ openapi: "3.1.0";
16
+ info: OpenAPIInfo;
17
+ servers?: {
18
+ url: string;
19
+ description?: string;
20
+ }[];
21
+ paths: Record<string, Record<string, OpenAPIOperation>>;
22
+ components: {
23
+ schemas: Record<string, Record<string, unknown>>;
24
+ securitySchemes?: Record<string, Record<string, unknown>>;
25
+ };
26
+ security?: Record<string, string[]>[];
27
+ tags?: {
28
+ name: string;
29
+ description?: string;
30
+ }[];
31
+ }
32
+ interface OpenAPIInfo {
33
+ title: string;
34
+ version: string;
35
+ description?: string;
36
+ }
37
+ interface OpenAPIOperation {
38
+ operationId: string;
39
+ summary: string;
40
+ tags: string[];
41
+ parameters?: Record<string, unknown>[];
42
+ requestBody?: Record<string, unknown>;
43
+ responses: Record<string, Record<string, unknown>>;
44
+ security?: Record<string, string[]>[];
45
+ }
46
+ /**
47
+ * Generate a full OpenAPI 3.1 specification from a `CrudRepoRegistry`.
48
+ *
49
+ * Uses Zod 4's native `z.toJSONSchema()` to convert each repo's schema
50
+ * into a JSON Schema component, then assembles paths for the standard
51
+ * CRUD endpoints.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { generateOpenAPISpec } from "@lpdjs/firestore-repo-service/servers/crud";
56
+ *
57
+ * const spec = generateOpenAPISpec(registry, "/api", {
58
+ * title: "My API",
59
+ * version: "1.0.0",
60
+ * servers: [{ url: "https://my-api.example.com" }],
61
+ * auth: "bearer",
62
+ * });
63
+ *
64
+ * // Write to file
65
+ * fs.writeFileSync("openapi.json", JSON.stringify(spec, null, 2));
66
+ * ```
67
+ */
68
+ declare function generateOpenAPISpec(registry: CrudRepoRegistry, basePath: string, options?: OpenAPISpecOptions): OpenAPIDocument;
69
+
70
+ /**
71
+ * Computes a typed diff between the existing document (`before`) and the incoming partial changes (`changesInput`).
72
+ * Only fields whose values have actually changed (via structural equality) are included in `changes`.
73
+ */
74
+ declare function computeDeepDiff<T extends Record<string, unknown>>(before: T, changesInput: Partial<T>): DeepDiffReturn<T>;
75
+ /**
76
+ * Helper to define field-by-field before-rules with strong typing.
77
+ */
78
+ declare function createRules<T>(rules: RulesMap<T>): RulesMap<T>;
79
+ /**
80
+ * Executes a map of field rules against a computed diff.
81
+ * Evaluates rules only for the keys that changed in `diff.changes`.
82
+ * Returns `{ allowed: true }` if all rules pass, or `{ allowed: false, reason: rule.description }` on the first failure.
83
+ */
84
+ declare function applyRules<T>(diff: DeepDiffReturn<T>, rulesMap: RulesMap<T>, user?: AuthUser): Promise<{
85
+ allowed: boolean;
86
+ reason?: string;
87
+ }>;
88
+ /**
89
+ * Wraps a rules map into a standard `rules.update` handler for `createCrudServer`.
90
+ */
91
+ declare function createBeforeRules<T>(rulesMap: RulesMap<T>): (ctx: CrudUpdateRuleContext<T>) => Promise<{
92
+ allowed: boolean;
93
+ reason?: string;
94
+ }>;
95
+
96
+ /**
97
+ * @module servers/crud/mutations
98
+ *
99
+ * Pre-write mutation engine for CRUD payload normalization and server-derived
100
+ * field injection before persisting to Firestore.
101
+ */
102
+
103
+ /**
104
+ * Helper to define field-by-field (and wildcard `"*"`) pre-write mutations
105
+ * with strong typing.
106
+ */
107
+ declare function createMutations<T>(mutations: MutationsMap<T>): MutationsMap<T>;
108
+ /**
109
+ * Executes a map of pre-write mutations against `body` / `diff`:
110
+ * 1. Runs per-field mutations for each key present in `diff.changes`.
111
+ * 2. Runs wildcard `"*"` mutations unconditionally after per-field mutations.
112
+ */
113
+ declare function applyMutations<T>(body: Partial<T>, doc: T | null, diff: DeepDiffReturn<T>, mutationsMap: MutationsMap<T>, user?: AuthUser, operation?: CrudWriteOperation): Promise<void>;
114
+ /**
115
+ * Wraps a {@link MutationsMap} into a `hooks.beforeUpdate` handler
116
+ * (analogous to `createBeforeRules`).
117
+ */
118
+ declare function createBeforeUpdateMutations<T>(mutationsMap: MutationsMap<T>): (ctx: CrudBeforeUpdateContext<T>) => Promise<void>;
119
+ /**
120
+ * Wraps a {@link MutationsMap} into a `hooks.beforeCreate` handler
121
+ * (analogous to `createBeforeRules`).
122
+ */
123
+ declare function createBeforeCreateMutations<T>(mutationsMap: MutationsMap<T>): (ctx: CrudBeforeCreateContext<T>) => Promise<void>;
124
+
125
+ /**
126
+ * @module servers/crud/effects
127
+ *
128
+ * Reactive post-write effects engine aligned with `rules.ts` / `mutations.ts`.
129
+ * Evaluates field-level and wildcard `"*"` effect rules against a recomputed diff,
130
+ * captures per-rule errors without aborting sibling effects, and aggregates
131
+ * optional follow-up document patches (`changesNeeded`).
132
+ */
133
+
134
+ /**
135
+ * Helper to define field-by-field (and wildcard `"*"`) post-write effects
136
+ * with strong typing.
137
+ */
138
+ declare function createEffects<T, TContext>(effects: EffectsMap<T, TContext>): EffectsMap<T, TContext>;
139
+ /**
140
+ * Executes a map of reactive effects against a computed `diff`:
141
+ * 1. Runs per-field effects for every key in `diff.changes`.
142
+ * 2. Runs wildcard `"*"` effects after per-field effects.
143
+ *
144
+ * Each effect is isolated in a `try/catch` so one failure never prevents
145
+ * remaining effects from executing. Any `Partial<T>` patches returned by
146
+ * handlers are merged into `changesNeeded`.
147
+ */
148
+ declare function applyEffects<T, TContext>(diff: DeepDiffReturn<T>, effectsMap: EffectsMap<T, TContext>, context: TContext, user?: AuthUser, operation?: CrudEffectOperation): Promise<ApplyEffectsResult<T>>;
149
+ /**
150
+ * Wraps an {@link EffectsMap} into a `hooks.afterUpdate` handler
151
+ * (analogous to `createBeforeRules`).
152
+ */
153
+ declare function createAfterUpdateEffects<T, TContext>(effectsMap: EffectsMap<T, TContext>, buildContext: (ctx: CrudAfterUpdateContext<T>) => TContext, options?: {
154
+ onRuleError?: (result: EffectExecutionResult, ctx: CrudAfterUpdateContext<T>) => void | Promise<void>;
155
+ }): (ctx: CrudAfterUpdateContext<T>) => Promise<void | Partial<T>>;
156
+
157
+ export { applyEffects as a, applyMutations as b, applyRules as c, computeDeepDiff as d, createAfterUpdateEffects as e, createBeforeCreateMutations as f, createBeforeRules as g, createBeforeUpdateMutations as h, createEffects as i, createMutations as j, createRules as k, generateOpenAPISpec as l };
158
+ export type { OpenAPIDocument as O };