@lpdjs/firestore-repo-service 2.6.29 → 2.6.31

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,4 +1,4 @@
1
- # @lpdjs/firestore-repo-service (v2.6.29) — full documentation
1
+ # @lpdjs/firestore-repo-service (v2.6.31) — full documentation
2
2
 
3
3
  > ⚡ Type-safe Firestore ORM with auto-generated repositories, advanced queries, relations with typed select, pagination with include, batch/bulk operations, aggregations and transactions.
4
4
 
@@ -315,16 +315,21 @@ Returns `{ scanned, written, skipped, failures }`.
315
315
  ```typescript
316
316
  const mappingWithRelations = buildRepositoryRelations(repositoryMapping, {
317
317
  users: {
318
- docId: { repo: "posts", key: "userId", type: "many" as const },
318
+ docId: { repo: "posts", key: "userId", type: "many" },
319
319
  },
320
320
  posts: {
321
- userId: { repo: "users", key: "docId", type: "one" as const },
322
- docId: { repo: "comments", key: "postId", type: "many" as const },
321
+ userId: { repo: "users", key: "docId", type: "one" },
322
+ docId: { repo: "comments", key: "postId", type: "many" },
323
323
  },
324
324
  comments: {
325
- postId: { repo: "posts", key: "docId", type: "one" as const },
326
- userId: { repo: "users", key: "docId", type: "one" as const },
325
+ postId: { repo: "posts", key: "docId", type: "one" },
326
+ userId: { repo: "users", key: "docId", type: "one" },
327
327
  },
328
+ residences: {
329
+ // Multiple relations originating from the same source field
330
+ events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" },
331
+ quotes: { repo: "quotes", key: "residenceId", type: "many", sourceKey: "docId" }
332
+ }
328
333
  });
329
334
  ```
330
335
 
@@ -334,8 +339,9 @@ Each entry maps a field in the source model to a target repository:
334
339
  |----------------|------------------------------------------------|
335
340
  | `repo` | Name of the target repository |
336
341
  | `key` | Field on the target repo used for the lookup |
337
- | `type: "one"` | The field holds a single ID → returns one doc |
338
- | `type: "many"` | The field holds an ID used to filter → returns array |
342
+ | `type: "one"` | The target key must exist in `foreignKeys` → returns one doc |
343
+ | `type: "many"` | The target key must exist in `queryKeys` → returns array |
344
+ | `sourceKey` | Optional. Field in the current document containing the value to look up (required if the relation name is not a valid model key) |
339
345
 
340
346
  ## `populate()` — on a single document
341
347
 
package/dist/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # @lpdjs/firestore-repo-service (v2.6.29)
1
+ # @lpdjs/firestore-repo-service (v2.6.31)
2
2
 
3
3
  > ⚡ Type-safe Firestore ORM with auto-generated repositories, advanced queries, relations with typed select, pagination with include, batch/bulk operations, aggregations and transactions.
4
4
 
@@ -1,4 +1,4 @@
1
- import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-Qd4tuEq9.cjs';
1
+ import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-CpkQQn4b.cjs';
2
2
 
3
3
  /**
4
4
  * OpenAPI 3.1 specification generator for the CRUD server.
@@ -1,4 +1,4 @@
1
- import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-wzqw45jH.js';
1
+ import { d as CrudRepoRegistry, O as OpenAPISpecOptions } from './types-BcT92G9B.js';
2
2
 
3
3
  /**
4
4
  * OpenAPI 3.1 specification generator for the CRUD server.
@@ -1,8 +1,8 @@
1
1
  import 'zod';
2
2
  import 'firebase-functions/v2/https';
3
- import '../../types-Qd4tuEq9.cjs';
3
+ import '../../types-CpkQQn4b.cjs';
4
4
  export { h as Middleware, M as MiniRouter, R as RouteHandler } from '../../firebase-auth-DZ8lb2Ec.cjs';
5
- export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry, d as createAdminServer } from '../../index-D0KRndyL.cjs';
5
+ export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry, d as createAdminServer } from '../../index-BfTEw4r1.cjs';
6
6
  import '../../read-CTWZjxyh.cjs';
7
7
  import 'firebase-admin/firestore';
8
8
  import 'firebase-functions/v2/firestore';
@@ -1,8 +1,8 @@
1
1
  import 'zod';
2
2
  import 'firebase-functions/v2/https';
3
- import '../../types-wzqw45jH.js';
3
+ import '../../types-BcT92G9B.js';
4
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-TTSjUi4p.js';
5
+ export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry, d as createAdminServer } from '../../index-Da_8eLPb.js';
6
6
  import '../../read-CTWZjxyh.js';
7
7
  import 'firebase-admin/firestore';
8
8
  import 'firebase-functions/v2/firestore';
@@ -1,8 +1,8 @@
1
1
  import { HttpsOptions } from 'firebase-functions/v2/https';
2
- import { C as ConfiguredRepository, a as CrudServerOptions } from '../../types-Qd4tuEq9.cjs';
3
- export { A as ApiResponse, B as BasicAuthConfig, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, F as FieldRole, L as ListResponseData, M as Middleware, O as OpenAPISpecOptions, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, U as UserFieldPath } from '../../types-Qd4tuEq9.cjs';
4
- import { O as OpenAPIDocument } from '../../openapi-BdatGOqK.cjs';
5
- export { g as generateOpenAPISpec } from '../../openapi-BdatGOqK.cjs';
2
+ import { C as ConfiguredRepository, a as CrudServerOptions } from '../../types-CpkQQn4b.cjs';
3
+ export { A as ApiResponse, B as BasicAuthConfig, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, F as FieldRole, L as ListResponseData, M as Middleware, O as OpenAPISpecOptions, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, U as UserFieldPath } from '../../types-CpkQQn4b.cjs';
4
+ import { O as OpenAPIDocument } from '../../openapi-BHW1HViI.cjs';
5
+ export { g as generateOpenAPISpec } from '../../openapi-BHW1HViI.cjs';
6
6
  import '../../firebase-auth-DZ8lb2Ec.cjs';
7
7
  import 'zod';
8
8
  import '../../read-CTWZjxyh.cjs';
@@ -1,8 +1,8 @@
1
1
  import { HttpsOptions } from 'firebase-functions/v2/https';
2
- import { C as ConfiguredRepository, a as CrudServerOptions } from '../../types-wzqw45jH.js';
3
- export { A as ApiResponse, B as BasicAuthConfig, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, F as FieldRole, L as ListResponseData, M as Middleware, O as OpenAPISpecOptions, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, U as UserFieldPath } from '../../types-wzqw45jH.js';
4
- import { O as OpenAPIDocument } from '../../openapi-uTAic4s0.js';
5
- export { g as generateOpenAPISpec } from '../../openapi-uTAic4s0.js';
2
+ import { C as ConfiguredRepository, a as CrudServerOptions } from '../../types-BcT92G9B.js';
3
+ export { A as ApiResponse, B as BasicAuthConfig, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, F as FieldRole, L as ListResponseData, M as Middleware, O as OpenAPISpecOptions, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, U as UserFieldPath } from '../../types-BcT92G9B.js';
4
+ import { O as OpenAPIDocument } from '../../openapi-BupSdudk.js';
5
+ export { g as generateOpenAPISpec } from '../../openapi-BupSdudk.js';
6
6
  import '../../firebase-auth-DZ8lb2Ec.js';
7
7
  import 'zod';
8
8
  import '../../read-CTWZjxyh.js';
@@ -1,7 +1,7 @@
1
- export { B as BoundAdminRepoConfig, a as BoundAdminServerOptions, b as BoundCrudRepoConfig, d as BoundCrudServerOptions, e as BoundFirestoreSyncConfig, C as CreateServersDeps, c as createServers } from '../create-servers-C3CIViuc.cjs';
2
- import { P as PageOptions, C as ColumnMeta, F as FilterState, R as RelationalFieldMeta, S as SortState, Q as QueryError } from '../index-D0KRndyL.cjs';
3
- export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry } from '../index-D0KRndyL.cjs';
4
- export { A as ApiResponse, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, a as CrudServerOptions, D as DEFAULT_HTML_CSP, F as FieldRole, L as ListResponseData, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, S as SecurityHeadersOptions, U as UserFieldPath, s as securityHeaders } from '../types-Qd4tuEq9.cjs';
1
+ export { B as BoundAdminRepoConfig, a as BoundAdminServerOptions, b as BoundCrudRepoConfig, d as BoundCrudServerOptions, e as BoundFirestoreSyncConfig, C as CreateServersDeps, c as createServers } from '../create-servers-DlVgnO_m.cjs';
2
+ import { P as PageOptions, C as ColumnMeta, F as FilterState, R as RelationalFieldMeta, S as SortState, Q as QueryError } from '../index-BfTEw4r1.cjs';
3
+ export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry } from '../index-BfTEw4r1.cjs';
4
+ export { A as ApiResponse, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, a as CrudServerOptions, D as DEFAULT_HTML_CSP, F as FieldRole, L as ListResponseData, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, S as SecurityHeadersOptions, U as UserFieldPath, s as securityHeaders } from '../types-CpkQQn4b.cjs';
5
5
  import { z } from 'zod';
6
6
  export { h as Middleware, M as MiniRouter, R as RouteHandler } from '../firebase-auth-DZ8lb2Ec.cjs';
7
7
  import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
@@ -10,7 +10,7 @@ import '../types-BwH1C-wi.cjs';
10
10
  import 'firebase-functions/v2/firestore';
11
11
  import 'firebase-functions/v2/https';
12
12
  import 'firebase-functions/v2/pubsub';
13
- import '../openapi-BdatGOqK.cjs';
13
+ import '../openapi-BHW1HViI.cjs';
14
14
  import '../read-CTWZjxyh.cjs';
15
15
  import 'firebase-admin/firestore';
16
16
 
@@ -1,7 +1,7 @@
1
- export { B as BoundAdminRepoConfig, a as BoundAdminServerOptions, b as BoundCrudRepoConfig, d as BoundCrudServerOptions, e as BoundFirestoreSyncConfig, C as CreateServersDeps, c as createServers } from '../create-servers-O2stZ-yF.js';
2
- import { P as PageOptions, C as ColumnMeta, F as FilterState, R as RelationalFieldMeta, S as SortState, Q as QueryError } from '../index-TTSjUi4p.js';
3
- export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry } from '../index-TTSjUi4p.js';
4
- export { A as ApiResponse, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, a as CrudServerOptions, D as DEFAULT_HTML_CSP, F as FieldRole, L as ListResponseData, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, S as SecurityHeadersOptions, U as UserFieldPath, s as securityHeaders } from '../types-wzqw45jH.js';
1
+ export { B as BoundAdminRepoConfig, a as BoundAdminServerOptions, b as BoundCrudRepoConfig, d as BoundCrudServerOptions, e as BoundFirestoreSyncConfig, C as CreateServersDeps, c as createServers } from '../create-servers-n4q5BhVK.js';
2
+ import { P as PageOptions, C as ColumnMeta, F as FilterState, R as RelationalFieldMeta, S as SortState, Q as QueryError } from '../index-Da_8eLPb.js';
3
+ export { a as AdminRepoConfig, b as AdminRepoEntry, A as AdminServerOptions, B as BasicAuthConfig, c as RepoRegistry } from '../index-Da_8eLPb.js';
4
+ export { A as ApiResponse, b as CrudRepoConfig, c as CrudRepoEntry, d as CrudRepoRegistry, a as CrudServerOptions, D as DEFAULT_HTML_CSP, F as FieldRole, L as ListResponseData, Q as QueryRequestBody, R as RepoFieldPath, e as RepoRelationKeys, S as SecurityHeadersOptions, U as UserFieldPath, s as securityHeaders } from '../types-BcT92G9B.js';
5
5
  import { z } from 'zod';
6
6
  export { h as Middleware, M as MiniRouter, R as RouteHandler } from '../firebase-auth-DZ8lb2Ec.js';
7
7
  import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
@@ -10,7 +10,7 @@ import '../types-DT7Nypd_.js';
10
10
  import 'firebase-functions/v2/firestore';
11
11
  import 'firebase-functions/v2/https';
12
12
  import 'firebase-functions/v2/pubsub';
13
- import '../openapi-uTAic4s0.js';
13
+ import '../openapi-BupSdudk.js';
14
14
  import '../read-CTWZjxyh.js';
15
15
  import 'firebase-admin/firestore';
16
16
 
@@ -133,6 +133,7 @@ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends s
133
133
  repo: TRepoKey;
134
134
  key: TForeignKey;
135
135
  type: TType;
136
+ sourceKey?: string;
136
137
  targetType?: TTargetModel;
137
138
  }
138
139
  /**
@@ -141,17 +142,21 @@ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends s
141
142
  * @template T - Current model type
142
143
  * @template TMapping - All repositories mapping for validation
143
144
  * @example { userId: { repo: "users", key: "docId", type: "one" } }
144
- *
145
- * IMPORTANT: Keys must exist in T (the current model)
146
- * This prevents creating relations on non-existent fields
145
+ * @example { events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" } }
147
146
  */
148
147
  type RelationalKeys<T = any, TMapping = any> = {
149
- [K in keyof T]?: TMapping extends Record<string, any> ? {
150
- [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys, any, any, any, any, any, any, any, any, any> ? {
148
+ [K in string]?: TMapping extends Record<string, any> ? {
149
+ [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys extends readonly any[], infer QKeys extends readonly any[], any, any, any, any, any, any, any, any> ? ({
151
150
  repo: R;
152
151
  key: FKeys[number];
153
- type: "one" | "many";
154
- } : never;
152
+ type: "one";
153
+ sourceKey?: keyof T;
154
+ } | {
155
+ repo: R;
156
+ key: QKeys[number];
157
+ type: "many";
158
+ sourceKey?: keyof T;
159
+ }) : never;
155
160
  }[keyof TMapping] : RelationConfig;
156
161
  };
157
162
  /**
@@ -133,6 +133,7 @@ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends s
133
133
  repo: TRepoKey;
134
134
  key: TForeignKey;
135
135
  type: TType;
136
+ sourceKey?: string;
136
137
  targetType?: TTargetModel;
137
138
  }
138
139
  /**
@@ -141,17 +142,21 @@ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends s
141
142
  * @template T - Current model type
142
143
  * @template TMapping - All repositories mapping for validation
143
144
  * @example { userId: { repo: "users", key: "docId", type: "one" } }
144
- *
145
- * IMPORTANT: Keys must exist in T (the current model)
146
- * This prevents creating relations on non-existent fields
145
+ * @example { events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" } }
147
146
  */
148
147
  type RelationalKeys<T = any, TMapping = any> = {
149
- [K in keyof T]?: TMapping extends Record<string, any> ? {
150
- [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys, any, any, any, any, any, any, any, any, any> ? {
148
+ [K in string]?: TMapping extends Record<string, any> ? {
149
+ [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys extends readonly any[], infer QKeys extends readonly any[], any, any, any, any, any, any, any, any> ? ({
151
150
  repo: R;
152
151
  key: FKeys[number];
153
- type: "one" | "many";
154
- } : never;
152
+ type: "one";
153
+ sourceKey?: keyof T;
154
+ } | {
155
+ repo: R;
156
+ key: QKeys[number];
157
+ type: "many";
158
+ sourceKey?: keyof T;
159
+ }) : never;
155
160
  }[keyof TMapping] : RelationConfig;
156
161
  };
157
162
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdjs/firestore-repo-service",
3
- "version": "2.6.29",
3
+ "version": "2.6.31",
4
4
  "workspaces": [
5
5
  "test/functions"
6
6
  ],