@visiolab/effect-firebase 0.0.0-stage → 0.3.0

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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -2
  3. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  4. package/dist/app/App.d.mts +27 -0
  5. package/dist/app/App.mjs +27 -0
  6. package/dist/app/index.d.mts +2 -0
  7. package/dist/app/index.mjs +1 -0
  8. package/dist/firestore/Collection.d.mts +423 -0
  9. package/dist/firestore/Collection.mjs +133 -0
  10. package/dist/firestore/CollectionGroup.d.mts +164 -0
  11. package/dist/firestore/CollectionGroup.mjs +84 -0
  12. package/dist/firestore/DocumentPath.d.mts +95 -0
  13. package/dist/firestore/DocumentPath.mjs +71 -0
  14. package/dist/firestore/DocumentSnapshot.d.mts +239 -0
  15. package/dist/firestore/DocumentSnapshot.mjs +134 -0
  16. package/dist/firestore/FieldValue.d.mts +332 -0
  17. package/dist/firestore/FieldValue.mjs +256 -0
  18. package/dist/firestore/Firestore.d.mts +1165 -0
  19. package/dist/firestore/Firestore.mjs +274 -0
  20. package/dist/firestore/FirestoreModel.d.mts +1232 -0
  21. package/dist/firestore/FirestoreModel.mjs +586 -0
  22. package/dist/firestore/FirestoreSchema.d.mts +567 -0
  23. package/dist/firestore/FirestoreSchema.mjs +419 -0
  24. package/dist/firestore/FirestoreValue.d.mts +145 -0
  25. package/dist/firestore/FirestoreValue.mjs +87 -0
  26. package/dist/firestore/GeoPoint.d.mts +90 -0
  27. package/dist/firestore/GeoPoint.mjs +75 -0
  28. package/dist/firestore/Patch.d.mts +73 -0
  29. package/dist/firestore/Patch.mjs +57 -0
  30. package/dist/firestore/QuerySnapshot.d.mts +107 -0
  31. package/dist/firestore/QuerySnapshot.mjs +43 -0
  32. package/dist/firestore/Timestamp.d.mts +273 -0
  33. package/dist/firestore/Timestamp.mjs +255 -0
  34. package/dist/firestore/index.d.mts +14 -0
  35. package/dist/firestore/index.mjs +14 -0
  36. package/dist/firestore/internal/collection.mjs +156 -0
  37. package/dist/firestore/internal/collectionGroup.mjs +64 -0
  38. package/dist/firestore/internal/documentPath.d.mts +4 -0
  39. package/dist/firestore/internal/documentPath.mjs +42 -0
  40. package/dist/firestore/internal/documentSnapshot.mjs +63 -0
  41. package/dist/firestore/internal/fieldValue.d.mts +11 -0
  42. package/dist/firestore/internal/fieldValue.mjs +88 -0
  43. package/dist/firestore/internal/firestore.mjs +145 -0
  44. package/dist/firestore/internal/firestoreError.d.mts +29 -0
  45. package/dist/firestore/internal/firestoreError.mjs +30 -0
  46. package/dist/firestore/internal/firestoreModel.mjs +719 -0
  47. package/dist/firestore/internal/firestoreSchema.mjs +123 -0
  48. package/dist/firestore/internal/firestoreValue.mjs +108 -0
  49. package/dist/firestore/internal/firestoreValueWalk.d.mts +58 -0
  50. package/dist/firestore/internal/firestoreValueWalk.mjs +223 -0
  51. package/dist/firestore/internal/geoPoint.d.mts +4 -0
  52. package/dist/firestore/internal/geoPoint.mjs +39 -0
  53. package/dist/firestore/internal/patch.mjs +19 -0
  54. package/dist/firestore/internal/querySnapshot.mjs +24 -0
  55. package/dist/firestore/internal/schemaAST.mjs +35 -0
  56. package/dist/firestore/internal/snapshotExtra.mjs +35 -0
  57. package/dist/firestore/internal/streamFromListener.mjs +12 -0
  58. package/dist/firestore/internal/timestamp.d.mts +4 -0
  59. package/dist/firestore/internal/timestamp.mjs +66 -0
  60. package/dist/firestore/internal/timestampSchema.mjs +31 -0
  61. package/dist/firestore/internal/transactionFromCallback.mjs +66 -0
  62. package/dist/functions/Callable.d.mts +654 -0
  63. package/dist/functions/Callable.mjs +450 -0
  64. package/dist/functions/CallableError.d.mts +297 -0
  65. package/dist/functions/CallableError.mjs +256 -0
  66. package/dist/functions/CallableMiddleware.d.mts +213 -0
  67. package/dist/functions/CallableMiddleware.mjs +52 -0
  68. package/dist/functions/CallableRequest.d.mts +166 -0
  69. package/dist/functions/CallableRequest.mjs +18 -0
  70. package/dist/functions/Caller.d.mts +103 -0
  71. package/dist/functions/Caller.mjs +115 -0
  72. package/dist/functions/DocumentTrigger.d.mts +795 -0
  73. package/dist/functions/DocumentTrigger.mjs +566 -0
  74. package/dist/functions/FirebaseFunction.d.mts +79 -0
  75. package/dist/functions/FirebaseFunction.mjs +4 -0
  76. package/dist/functions/FunctionGroup.d.mts +175 -0
  77. package/dist/functions/FunctionGroup.mjs +64 -0
  78. package/dist/functions/index.d.mts +9 -0
  79. package/dist/functions/index.mjs +9 -0
  80. package/dist/functions/internal/callable.mjs +167 -0
  81. package/dist/functions/internal/callableMiddleware.d.mts +19 -0
  82. package/dist/functions/internal/callableMiddleware.mjs +15 -0
  83. package/dist/functions/internal/callableRequest.mjs +6 -0
  84. package/dist/functions/internal/documentTrigger.d.mts +10 -0
  85. package/dist/functions/internal/documentTrigger.mjs +73 -0
  86. package/dist/functions/internal/firebaseFunction.d.mts +5 -0
  87. package/dist/functions/internal/firebaseFunction.mjs +24 -0
  88. package/dist/functions/internal/functionGroup.mjs +36 -0
  89. package/package.json +66 -3
  90. package/src/app/App.ts +24 -0
  91. package/src/app/index.ts +7 -0
  92. package/src/firestore/Collection.ts +520 -0
  93. package/src/firestore/CollectionGroup.ts +245 -0
  94. package/src/firestore/DocumentPath.ts +114 -0
  95. package/src/firestore/DocumentSnapshot.ts +308 -0
  96. package/src/firestore/FieldValue.ts +375 -0
  97. package/src/firestore/Firestore.ts +1432 -0
  98. package/src/firestore/FirestoreModel.ts +1884 -0
  99. package/src/firestore/FirestoreSchema.ts +643 -0
  100. package/src/firestore/FirestoreValue.ts +207 -0
  101. package/src/firestore/GeoPoint.ts +105 -0
  102. package/src/firestore/Patch.ts +117 -0
  103. package/src/firestore/QuerySnapshot.ts +150 -0
  104. package/src/firestore/Timestamp.ts +302 -0
  105. package/src/firestore/index.ts +67 -0
  106. package/src/firestore/internal/collection.ts +246 -0
  107. package/src/firestore/internal/collectionGroup.ts +81 -0
  108. package/src/firestore/internal/documentPath.ts +53 -0
  109. package/src/firestore/internal/documentSnapshot.ts +117 -0
  110. package/src/firestore/internal/fieldValue.ts +119 -0
  111. package/src/firestore/internal/firestore.ts +322 -0
  112. package/src/firestore/internal/firestoreError.ts +36 -0
  113. package/src/firestore/internal/firestoreModel.ts +1242 -0
  114. package/src/firestore/internal/firestoreSchema.ts +218 -0
  115. package/src/firestore/internal/firestoreValue.ts +202 -0
  116. package/src/firestore/internal/firestoreValueWalk.ts +349 -0
  117. package/src/firestore/internal/geoPoint.ts +59 -0
  118. package/src/firestore/internal/patch.ts +21 -0
  119. package/src/firestore/internal/querySnapshot.ts +39 -0
  120. package/src/firestore/internal/schemaAST.ts +83 -0
  121. package/src/firestore/internal/snapshotExtra.ts +47 -0
  122. package/src/firestore/internal/streamFromListener.ts +27 -0
  123. package/src/firestore/internal/timestamp.ts +119 -0
  124. package/src/firestore/internal/timestampSchema.ts +42 -0
  125. package/src/firestore/internal/transactionFromCallback.ts +106 -0
  126. package/src/functions/Callable.ts +855 -0
  127. package/src/functions/CallableError.ts +348 -0
  128. package/src/functions/CallableMiddleware.ts +279 -0
  129. package/src/functions/CallableRequest.ts +207 -0
  130. package/src/functions/Caller.ts +141 -0
  131. package/src/functions/DocumentTrigger.ts +927 -0
  132. package/src/functions/FirebaseFunction.ts +96 -0
  133. package/src/functions/FunctionGroup.ts +225 -0
  134. package/src/functions/index.ts +62 -0
  135. package/src/functions/internal/callable.ts +272 -0
  136. package/src/functions/internal/callableMiddleware.ts +54 -0
  137. package/src/functions/internal/callableRequest.ts +8 -0
  138. package/src/functions/internal/documentTrigger.ts +143 -0
  139. package/src/functions/internal/firebaseFunction.ts +58 -0
  140. package/src/functions/internal/functionGroup.ts +47 -0
@@ -0,0 +1,133 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { fromPath as fromPath$1, isCollection as isCollection$1, isCollectionReference as isCollectionReference$1, isDocumentReference as isDocumentReference$1, make as make$1 } from "./internal/collection.mjs";
3
+ // src/firestore/Collection.ts
4
+ var Collection_exports = /* @__PURE__ */ __exportAll({
5
+ fromPath: () => fromPath,
6
+ isCollection: () => isCollection,
7
+ isCollectionReference: () => isCollectionReference,
8
+ isDocumentReference: () => isDocumentReference,
9
+ make: () => make
10
+ });
11
+ /**
12
+ * Checks whether a value is a collection definition.
13
+ *
14
+ * @see {@link isCollectionReference} for a reference to a collection
15
+ * @see {@link CollectionGroup.isCollectionGroup} for a Collection Group
16
+ *
17
+ * @stability unstable
18
+ * @category guards
19
+ * @since 0.1.0
20
+ */
21
+ const isCollection = isCollection$1;
22
+ /**
23
+ * Checks whether a value is a {@link CollectionReference}.
24
+ *
25
+ * @see {@link isCollection} for a collection definition
26
+ * @see {@link isDocumentReference} for a reference to a document
27
+ *
28
+ * @stability unstable
29
+ * @category guards
30
+ * @since 0.1.0
31
+ */
32
+ const isCollectionReference = isCollectionReference$1;
33
+ /**
34
+ * Checks whether a value is a {@link DocumentReference} into any collection.
35
+ *
36
+ * @see {@link Collection.contains} for checking that a reference belongs to one collection, with narrowing
37
+ * @see {@link isCollectionReference} for a reference to a collection
38
+ * @see {@link DocumentPath.isDocumentPath} for the untyped path stored in a field
39
+ *
40
+ * @stability unstable
41
+ * @category guards
42
+ * @since 0.1.0
43
+ */
44
+ const isDocumentReference = isDocumentReference$1;
45
+ /**
46
+ * Defines a root collection and the model of its documents.
47
+ *
48
+ * **When to use**
49
+ *
50
+ * Use once per root collection, at module level, and build every reference to
51
+ * it from the result. Use {@link Collection.subcollection} on the result for a
52
+ * collection nested under its documents.
53
+ *
54
+ * **Details**
55
+ *
56
+ * The documents are described by a {@link FirestoreModel.Class} rather than a
57
+ * plain schema, since a document is written in other shapes than it is read
58
+ * in, and the model carries each of them. Pass a {@link FirestoreModel.Union}
59
+ * of classes for a collection that holds several document shapes.
60
+ *
61
+ * Throws when `segment` is not a collection id Firestore accepts: empty,
62
+ * containing `/`, `.` or `..`, matching `__.*__`, or longer than 1500 bytes. An
63
+ * invalid definition is a programming error, not a failure to recover from.
64
+ *
65
+ * @example Defining a collection with a subcollection
66
+ * ```ts
67
+ * import { Collection, Firestore, FirestoreModel } from "@visiolab/effect-firebase/firestore";
68
+ * import { Effect, Schema } from "effect";
69
+ *
70
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
71
+ * class Post extends FirestoreModel.Class<Post>("Post")({ title: Schema.String }) {}
72
+ *
73
+ * const Users = Collection.make("users", User);
74
+ * const UserPosts = Users.subcollection("posts", Post);
75
+ *
76
+ * const program = Effect.gen(function* () {
77
+ * const firestore = yield* Firestore.Firestore;
78
+ * const alice = Users.id.make("alice");
79
+ *
80
+ * yield* firestore.setDoc(Users.doc(alice), { name: "Alice" });
81
+ * const post = yield* firestore.addDoc(UserPosts.collection(alice), { title: "Hello" });
82
+ * return post.path; // "users/alice/posts/<generated id>"
83
+ * });
84
+ * ```
85
+ *
86
+ * @see {@link fromPath} for a reference to a document of an existing collection from a path string
87
+ * @see {@link CollectionGroup.make} for reading several collections with one collection id together
88
+ *
89
+ * @stability unstable
90
+ * @category constructors
91
+ * @since 0.1.0
92
+ */
93
+ const make = make$1;
94
+ /**
95
+ * References the document of `collection` at a path string, such as
96
+ * `users/alice/posts/hello`, or returns `None` when the path is not in that
97
+ * collection.
98
+ *
99
+ * **When to use**
100
+ *
101
+ * Use when a path arrives as a string, such as from a URL, a message or a
102
+ * stored {@link DocumentPath.DocumentPath}, and you know which collection it
103
+ * should be in.
104
+ *
105
+ * **Details**
106
+ *
107
+ * The path is checked against every segment the collection was defined with,
108
+ * so a path into another collection returns `None`, even one with the same
109
+ * last segment. Every id in the path must be non-empty.
110
+ *
111
+ * @example Parsing a path
112
+ * ```ts
113
+ * import { Collection, FirestoreModel } from "@visiolab/effect-firebase/firestore";
114
+ * import { Option, Schema } from "effect";
115
+ *
116
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
117
+ * class Post extends FirestoreModel.Class<Post>("Post")({ title: Schema.String }) {}
118
+ *
119
+ * const Users = Collection.make("users", User);
120
+ * const UserPosts = Users.subcollection("posts", Post);
121
+ *
122
+ * Option.isSome(Collection.fromPath(UserPosts, "users/alice/posts/hello")); // true
123
+ * Option.isSome(Collection.fromPath(UserPosts, "orgs/acme/posts/hello")); // false
124
+ * ```
125
+ *
126
+ * @see {@link Collection.doc} for a reference built from typed ids
127
+ *
128
+ * @stability unstable
129
+ * @category constructors
130
+ * @since 0.2.0
131
+ */
132
+ const fromPath = fromPath$1;
133
+ export { Collection_exports, fromPath, isCollection, isCollectionReference, isDocumentReference, make };
@@ -0,0 +1,164 @@
1
+ import { Any as Any$1, DocumentReference as DocumentReference$1 } from "./Collection.mjs";
2
+ import { UndefinedCollectionError } from "./internal/firestoreError.mjs";
3
+ import "./Firestore.mjs";
4
+ import { Inspectable, Result } from "effect";
5
+ declare namespace CollectionGroup_d_exports {
6
+ export { Any, CollectionGroup, DocumentReference, Members, Valid, documentAt, isCollectionGroup, make };
7
+ }
8
+ declare const TypeId = "~@visiolab/effect-firebase/firestore/CollectionGroup";
9
+ /**
10
+ * The definition of a Collection Group: the collections in `Members`, which
11
+ * all share one collection id.
12
+ *
13
+ * **Details**
14
+ *
15
+ * Like a {@link Collection.Collection}, a group does not point at any data. It
16
+ * has no ids to fill in, so {@link Firestore.With.getDocs} and
17
+ * {@link Firestore.With.streamDocs} take it as it is. Build one with
18
+ * {@link make}.
19
+ *
20
+ * @see {@link Collection.CollectionReference} for reading one collection, under one parent
21
+ *
22
+ * @stability unstable
23
+ * @category models
24
+ * @since 0.2.0
25
+ */
26
+ export interface CollectionGroup<Members extends Any$1> extends Inspectable.Inspectable {
27
+ readonly [TypeId]: typeof TypeId;
28
+ /** The collections it was defined from, in the order they were given. */
29
+ readonly members: ReadonlyArray<Members>;
30
+ /** The collection id its members share, which Firestore reads the group by. */
31
+ readonly id: string;
32
+ }
33
+ /**
34
+ * Any Collection Group, whatever collections it is made of. Use it as a type
35
+ * bound.
36
+ *
37
+ * @stability unstable
38
+ * @category models
39
+ * @since 0.2.0
40
+ */
41
+ export type Any = CollectionGroup<any>;
42
+ /**
43
+ * The collections `G` was defined from, as a union.
44
+ *
45
+ * @stability unstable
46
+ * @category models
47
+ * @since 0.2.0
48
+ */
49
+ export type Members<G extends Any> = G extends CollectionGroup<infer M> ? M : never;
50
+ /**
51
+ * A reference to a document in one of the collections of `G`, typed by the one
52
+ * it lives in: `DocumentReference<A> | DocumentReference<B>` rather than a
53
+ * reference to `A | B`.
54
+ *
55
+ * @see {@link Collection.DocumentReference} for a reference into one known collection
56
+ * @see {@link Collection.Collection.contains} for narrowing it to one member
57
+ *
58
+ * @stability unstable
59
+ * @category models
60
+ * @since 0.2.0
61
+ */
62
+ export type DocumentReference<G extends Any> = Members<G> extends (infer C extends Any$1) ? C extends Any$1 ? DocumentReference$1<C> : never : never;
63
+ /** Whether `A` and `B` are the same type, rather than one fitting the other. */
64
+ type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => (T extends B ? 1 : 2)) ? true : false;
65
+ /**
66
+ * Whether `A` and `B` are the same path. A path with a segment only known as
67
+ * `string` could be any path, so it is never taken for another here.
68
+ */
69
+ type SamePath<A extends ReadonlyArray<string>, B extends ReadonlyArray<string>> = string extends A[number] | B[number] ? false : Same<A, B>;
70
+ /** Whether a member of `Members` other than the one at `K` sits at `C`'s path. */
71
+ type PathTakenElsewhere<Members extends ReadonlyArray<Any$1>, K, C extends Any$1> = true extends { [J in keyof Members]: J extends K ? false : SamePath<Members[J]["path"], C["path"]>; }[number] ? true : false;
72
+ /**
73
+ * The collections {@link make} accepts as `Members`: each one as it is, or, in
74
+ * place of one that breaks a rule, a message naming the rule. Every member must
75
+ * share the first one's collection id, and no two may sit at the same path.
76
+ *
77
+ * **Details**
78
+ *
79
+ * Members are told apart by their paths, so the same collection listed twice
80
+ * and two definitions built separately at the same path are both refused: a
81
+ * document at that path could belong to either. A path with a segment typed
82
+ * only as `string` is not checked here; {@link make} checks it at runtime.
83
+ *
84
+ * @stability unstable
85
+ * @category models
86
+ * @since 0.2.0
87
+ */
88
+ export type Valid<Members extends ReadonlyArray<Any$1>> = { readonly [K in keyof Members]: Members[K] extends Any$1 ? Members[K]["segment"] extends Members[0]["segment"] ? PathTakenElsewhere<Members, K, Members[K]> extends true ? `Collection Group member '${Members[K]["segment"]}' has the same path as another member` : Members[K] : `Collection Group member '${Members[K]["segment"]}' does not share the collection id '${Members[0]["segment"]}'` : never; };
89
+ /**
90
+ * Checks whether a value is a {@link CollectionGroup}.
91
+ *
92
+ * @see {@link Collection.isCollection} for a collection definition
93
+ * @see {@link Collection.isCollectionReference} for a reference to one collection
94
+ *
95
+ * @stability unstable
96
+ * @category guards
97
+ * @since 0.2.0
98
+ */
99
+ export declare const isCollectionGroup: (u: unknown) => u is Any;
100
+ /**
101
+ * Defines a Collection Group from the collections it covers.
102
+ *
103
+ * **When to use**
104
+ *
105
+ * Use to read or listen to documents across every parent at once, such as
106
+ * every user's posts. To read the collection under one parent, pass a
107
+ * {@link Collection.CollectionReference} to {@link Firestore.With.getDocs}
108
+ * instead.
109
+ *
110
+ * **Details**
111
+ *
112
+ * List every collection with the collection id you want to read. A read of
113
+ * the group fails with an `UndefinedCollectionError` when it finds a document
114
+ * under that collection id at a path none of the members define.
115
+ *
116
+ * The type checker refuses members that do not share the first one's
117
+ * collection id, and two members at the same path. The same checks run at
118
+ * runtime: it throws when given no collection, members with different
119
+ * collection ids, or two members at the same path, whether the same one twice
120
+ * or two built separately. An invalid definition is a programming error, as
121
+ * for {@link Collection.make}.
122
+ *
123
+ * @example Grouping collections under different parents
124
+ * ```ts
125
+ * import {
126
+ * Collection,
127
+ * CollectionGroup,
128
+ * Firestore,
129
+ * FirestoreModel,
130
+ * } from "@visiolab/effect-firebase/firestore";
131
+ * import { Effect, Schema } from "effect";
132
+ *
133
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
134
+ * class Org extends FirestoreModel.Class<Org>("Org")({ name: Schema.String }) {}
135
+ * class Post extends FirestoreModel.Class<Post>("Post")({ title: Schema.String }) {}
136
+ *
137
+ * const UserPosts = Collection.make("users", User).subcollection("posts", Post);
138
+ * const OrgPosts = Collection.make("orgs", Org).subcollection("posts", Post);
139
+ * const AllPosts = CollectionGroup.make(UserPosts, OrgPosts);
140
+ *
141
+ * const program = Effect.gen(function* () {
142
+ * const firestore = yield* Firestore.Firestore;
143
+ * const snapshot = yield* firestore.getDocs(AllPosts);
144
+ * // Only the posts under a user.
145
+ * return snapshot.docs.filter(UserPosts.contains);
146
+ * });
147
+ * ```
148
+ *
149
+ * @see {@link Collection.make} for defining the member collections
150
+ *
151
+ * @stability unstable
152
+ * @category constructors
153
+ * @since 0.2.0
154
+ */
155
+ export declare const make: <const Members extends readonly [Any$1, ...Array<Any$1>]>(...members: Valid<Members>) => CollectionGroup<Members[number]>;
156
+ /**
157
+ * References the document at `path` in whichever collection of `group` sits
158
+ * there, or fails with the {@link UndefinedCollectionError} a group read
159
+ * reports for a document none of them define.
160
+ *
161
+ * @internal
162
+ */
163
+ export declare const documentAt: <G extends Any>(group: G, path: string) => Result.Result<DocumentReference<G>, UndefinedCollectionError>;
164
+ export { CollectionGroup_d_exports };
@@ -0,0 +1,84 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { documentAt as documentAt$1, isCollectionGroup as isCollectionGroup$1, make as make$1 } from "./internal/collectionGroup.mjs";
3
+ // src/firestore/CollectionGroup.ts
4
+ var CollectionGroup_exports = /* @__PURE__ */ __exportAll({
5
+ documentAt: () => documentAt,
6
+ isCollectionGroup: () => isCollectionGroup,
7
+ make: () => make
8
+ });
9
+ /**
10
+ * Checks whether a value is a {@link CollectionGroup}.
11
+ *
12
+ * @see {@link Collection.isCollection} for a collection definition
13
+ * @see {@link Collection.isCollectionReference} for a reference to one collection
14
+ *
15
+ * @stability unstable
16
+ * @category guards
17
+ * @since 0.2.0
18
+ */
19
+ const isCollectionGroup = isCollectionGroup$1;
20
+ /**
21
+ * Defines a Collection Group from the collections it covers.
22
+ *
23
+ * **When to use**
24
+ *
25
+ * Use to read or listen to documents across every parent at once, such as
26
+ * every user's posts. To read the collection under one parent, pass a
27
+ * {@link Collection.CollectionReference} to {@link Firestore.With.getDocs}
28
+ * instead.
29
+ *
30
+ * **Details**
31
+ *
32
+ * List every collection with the collection id you want to read. A read of
33
+ * the group fails with an `UndefinedCollectionError` when it finds a document
34
+ * under that collection id at a path none of the members define.
35
+ *
36
+ * The type checker refuses members that do not share the first one's
37
+ * collection id, and two members at the same path. The same checks run at
38
+ * runtime: it throws when given no collection, members with different
39
+ * collection ids, or two members at the same path, whether the same one twice
40
+ * or two built separately. An invalid definition is a programming error, as
41
+ * for {@link Collection.make}.
42
+ *
43
+ * @example Grouping collections under different parents
44
+ * ```ts
45
+ * import {
46
+ * Collection,
47
+ * CollectionGroup,
48
+ * Firestore,
49
+ * FirestoreModel,
50
+ * } from "@visiolab/effect-firebase/firestore";
51
+ * import { Effect, Schema } from "effect";
52
+ *
53
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
54
+ * class Org extends FirestoreModel.Class<Org>("Org")({ name: Schema.String }) {}
55
+ * class Post extends FirestoreModel.Class<Post>("Post")({ title: Schema.String }) {}
56
+ *
57
+ * const UserPosts = Collection.make("users", User).subcollection("posts", Post);
58
+ * const OrgPosts = Collection.make("orgs", Org).subcollection("posts", Post);
59
+ * const AllPosts = CollectionGroup.make(UserPosts, OrgPosts);
60
+ *
61
+ * const program = Effect.gen(function* () {
62
+ * const firestore = yield* Firestore.Firestore;
63
+ * const snapshot = yield* firestore.getDocs(AllPosts);
64
+ * // Only the posts under a user.
65
+ * return snapshot.docs.filter(UserPosts.contains);
66
+ * });
67
+ * ```
68
+ *
69
+ * @see {@link Collection.make} for defining the member collections
70
+ *
71
+ * @stability unstable
72
+ * @category constructors
73
+ * @since 0.2.0
74
+ */
75
+ const make = make$1;
76
+ /**
77
+ * References the document at `path` in whichever collection of `group` sits
78
+ * there, or fails with the {@link UndefinedCollectionError} a group read
79
+ * reports for a document none of them define.
80
+ *
81
+ * @internal
82
+ */
83
+ const documentAt = documentAt$1;
84
+ export { CollectionGroup_exports, documentAt, isCollectionGroup, make };
@@ -0,0 +1,95 @@
1
+ import { Equal, Inspectable, Option } from "effect";
2
+ declare namespace DocumentPath_d_exports {
3
+ export { DocumentPath, isDocumentPath, make, makeUnsafe };
4
+ }
5
+ declare const TypeId = "~@visiolab/effect-firebase/firestore/DocumentPath";
6
+ /**
7
+ * A reference to a document as Firestore stores it: the document's path, such
8
+ * as `users/alice/posts/hello`.
9
+ *
10
+ * **When to use**
11
+ *
12
+ * Use for a reference whose target collection the model does not know, or
13
+ * does not care about. Prefer {@link Collection.DocumentReference}, through
14
+ * {@link FirestoreSchema.DocumentReference}, when the field always points into
15
+ * a known collection: it keeps the target's ids and model typed.
16
+ *
17
+ * **Details**
18
+ *
19
+ * Two are equal when their paths are.
20
+ *
21
+ * @see {@link Collection.DocumentReference} for a reference that knows its collection and model
22
+ * @see {@link FirestoreSchema.DocumentPath} for the schema of this value
23
+ *
24
+ * @stability unstable
25
+ * @category models
26
+ * @since 0.2.0
27
+ */
28
+ export interface DocumentPath extends Equal.Equal, Inspectable.Inspectable {
29
+ readonly [TypeId]: typeof TypeId;
30
+ /** The path of the document, from the root of the database. */
31
+ readonly path: string;
32
+ }
33
+ /**
34
+ * Checks whether `u` is a {@link DocumentPath} built by this module.
35
+ *
36
+ * An SDK's own `DocumentReference` is not one.
37
+ *
38
+ * @stability unstable
39
+ * @category guards
40
+ * @since 0.2.0
41
+ */
42
+ export declare const isDocumentPath: (u: unknown) => u is DocumentPath;
43
+ /**
44
+ * Builds a reference to the document at `path`, or `None` when `path` does not
45
+ * address a document.
46
+ *
47
+ * **When to use**
48
+ *
49
+ * Use when the path comes from outside the program and may be invalid.
50
+ *
51
+ * **Details**
52
+ *
53
+ * Returns `None` when `path` is empty, has an empty segment, or has an odd
54
+ * number of segments and so ends in a collection.
55
+ *
56
+ * @example Building a reference from untrusted input
57
+ * ```ts
58
+ * import { DocumentPath } from "@visiolab/effect-firebase/firestore";
59
+ *
60
+ * DocumentPath.make("users/alice"); // Option.some(...)
61
+ * DocumentPath.make("users"); // Option.none()
62
+ * ```
63
+ *
64
+ * @see {@link makeUnsafe} for the same check throwing instead
65
+ * @see {@link Collection.Collection} for typed references built from ids
66
+ *
67
+ * @stability unstable
68
+ * @category constructors
69
+ * @since 0.2.0
70
+ */
71
+ export declare const make: (path: string) => Option.Option<DocumentPath>;
72
+ /**
73
+ * Builds a reference to the document at `path`, throwing when `path` does not
74
+ * address a document.
75
+ *
76
+ * **When to use**
77
+ *
78
+ * Use for paths known to be valid, such as constants. Use {@link make} for
79
+ * paths you have not checked.
80
+ *
81
+ * @example Building a reference
82
+ * ```ts
83
+ * import { DocumentPath } from "@visiolab/effect-firebase/firestore";
84
+ *
85
+ * const post = DocumentPath.makeUnsafe("users/alice/posts/hello");
86
+ * ```
87
+ *
88
+ * @see {@link make} for the same check returning an `Option`
89
+ *
90
+ * @stability unstable
91
+ * @category constructors
92
+ * @since 0.2.0
93
+ */
94
+ export declare const makeUnsafe: (path: string) => DocumentPath;
95
+ export { DocumentPath_d_exports };
@@ -0,0 +1,71 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { isDocumentPath as isDocumentPath$1, make as make$1, makeUnsafe as makeUnsafe$1 } from "./internal/documentPath.mjs";
3
+ // src/firestore/DocumentPath.ts
4
+ var DocumentPath_exports = /* @__PURE__ */ __exportAll({
5
+ isDocumentPath: () => isDocumentPath,
6
+ make: () => make,
7
+ makeUnsafe: () => makeUnsafe
8
+ });
9
+ /**
10
+ * Checks whether `u` is a {@link DocumentPath} built by this module.
11
+ *
12
+ * An SDK's own `DocumentReference` is not one.
13
+ *
14
+ * @stability unstable
15
+ * @category guards
16
+ * @since 0.2.0
17
+ */
18
+ const isDocumentPath = isDocumentPath$1;
19
+ /**
20
+ * Builds a reference to the document at `path`, or `None` when `path` does not
21
+ * address a document.
22
+ *
23
+ * **When to use**
24
+ *
25
+ * Use when the path comes from outside the program and may be invalid.
26
+ *
27
+ * **Details**
28
+ *
29
+ * Returns `None` when `path` is empty, has an empty segment, or has an odd
30
+ * number of segments and so ends in a collection.
31
+ *
32
+ * @example Building a reference from untrusted input
33
+ * ```ts
34
+ * import { DocumentPath } from "@visiolab/effect-firebase/firestore";
35
+ *
36
+ * DocumentPath.make("users/alice"); // Option.some(...)
37
+ * DocumentPath.make("users"); // Option.none()
38
+ * ```
39
+ *
40
+ * @see {@link makeUnsafe} for the same check throwing instead
41
+ * @see {@link Collection.Collection} for typed references built from ids
42
+ *
43
+ * @stability unstable
44
+ * @category constructors
45
+ * @since 0.2.0
46
+ */
47
+ const make = make$1;
48
+ /**
49
+ * Builds a reference to the document at `path`, throwing when `path` does not
50
+ * address a document.
51
+ *
52
+ * **When to use**
53
+ *
54
+ * Use for paths known to be valid, such as constants. Use {@link make} for
55
+ * paths you have not checked.
56
+ *
57
+ * @example Building a reference
58
+ * ```ts
59
+ * import { DocumentPath } from "@visiolab/effect-firebase/firestore";
60
+ *
61
+ * const post = DocumentPath.makeUnsafe("users/alice/posts/hello");
62
+ * ```
63
+ *
64
+ * @see {@link make} for the same check returning an `Option`
65
+ *
66
+ * @stability unstable
67
+ * @category constructors
68
+ * @since 0.2.0
69
+ */
70
+ const makeUnsafe = makeUnsafe$1;
71
+ export { DocumentPath_exports, isDocumentPath, make, makeUnsafe };