firetender 0.2.0 → 0.4.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.
- package/LICENSE +20 -0
- package/README.md +86 -39
- package/dist/FiretenderCollection.d.ts +15 -0
- package/dist/FiretenderCollection.js +51 -0
- package/dist/FiretenderCollection.js.map +1 -0
- package/dist/{FireTenderDoc.d.ts → FiretenderDoc.d.ts} +8 -14
- package/dist/{FireTenderDoc.js → FiretenderDoc.js} +12 -18
- package/dist/FiretenderDoc.js.map +1 -0
- package/dist/Timestamps.js +2 -4
- package/dist/Timestamps.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/proxies.js +2 -4
- package/dist/proxies.js.map +1 -1
- package/dist/ts-helpers.d.ts +3 -0
- package/dist/ts-helpers.js.map +1 -1
- package/package.json +6 -2
- package/dist/FireTenderDoc.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Jacob M. Hartman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Firetender
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The goal of Firetender is to make Firestore documents look (almost) like any
|
|
4
|
+
other Typescript objects, reducing boilerplate and conceptual overhead and
|
|
5
|
+
providing type safety and data validation.
|
|
6
6
|
|
|
7
7
|
Querying and concurrency are not yet supported. I'm adding features as I need
|
|
8
8
|
them, but contributions are most welcome. See the list of [alternative
|
|
@@ -11,28 +11,48 @@ something more mature.
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
To illustrate, let's run through the basics of defining, creating,
|
|
15
|
-
|
|
14
|
+
To illustrate, let's run through the basics of defining, creating, modifying,
|
|
15
|
+
and copying a Firestore document.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Initialize Cloud Firestore
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
[
|
|
21
|
-
|
|
22
|
-
`.default([])` to simplify access. Here we define a schema for types of
|
|
23
|
-
pizza, because I was hungry when I wrote this.
|
|
19
|
+
The first step is the usual Firestore configuration and initialization. See
|
|
20
|
+
the [Firestore
|
|
21
|
+
quickstart](https://firebase.google.com/docs/firestore/quickstart) for details.
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
```javascript
|
|
24
|
+
import { doc, initializeApp } from "firebase/app";
|
|
25
|
+
import { getFirestore } from "firebase/firestore";
|
|
26
|
+
|
|
27
|
+
// TODO: Replace the following with your app's Firebase project configuration.
|
|
28
|
+
// See: https://firebase.google.com/docs/web/learn-more#config-object
|
|
29
|
+
const firebaseConfig = {
|
|
30
|
+
// ...
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const app = initializeApp(firebaseConfig);
|
|
34
|
+
const firestore = getFirestore(app);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Define a collection and its schema
|
|
38
|
+
|
|
39
|
+
Firetender uses [Zod](https://github.com/colinhacks/zod) to define the schema
|
|
40
|
+
and validation rules for a collection's documents; if you've used Joi or Yup,
|
|
41
|
+
you will find Zod very similar. In the example below, I've defined a schema for
|
|
42
|
+
types of pizza. I was a little hungry when I wrote this.
|
|
27
43
|
|
|
28
44
|
```javascript
|
|
29
|
-
import {
|
|
30
|
-
|
|
45
|
+
import {
|
|
46
|
+
FiretenderCollection,
|
|
47
|
+
nowTimestamp,
|
|
48
|
+
timestampSchema
|
|
49
|
+
} from "firetender";
|
|
31
50
|
import { z } from "zod";
|
|
32
51
|
|
|
33
52
|
const pizzaSchema = z.object({
|
|
34
53
|
name: z.string(),
|
|
35
54
|
description: z.string().optional(),
|
|
55
|
+
creationTime: timestampSchema,
|
|
36
56
|
toppings: z.record(
|
|
37
57
|
z.string(),
|
|
38
58
|
z.object({
|
|
@@ -48,82 +68,109 @@ const pizzaSchema = z.object({
|
|
|
48
68
|
tags: z.array(z.string()).default([]),
|
|
49
69
|
});
|
|
50
70
|
|
|
51
|
-
const
|
|
71
|
+
const pizzaCollection = new FiretenderCollection(
|
|
72
|
+
pizzaSchema,
|
|
73
|
+
[firestore, "pizzas"],
|
|
74
|
+
{ creationTime: nowTimestamp() }
|
|
75
|
+
);
|
|
52
76
|
```
|
|
53
77
|
|
|
78
|
+
Optional records and arrays should typically use `.default()` to provide an
|
|
79
|
+
empty instances when missing. That isn't required, but it makes accessing these
|
|
80
|
+
fields simpler because they will always be defined. The downside is that empty
|
|
81
|
+
fields are not pruned and will appear in Firestore.
|
|
82
|
+
|
|
54
83
|
### Add a document
|
|
55
84
|
|
|
56
|
-
Let's add a document to the `pizzas` collection with an ID of `margherita`. We
|
|
57
|
-
use the
|
|
58
|
-
|
|
59
|
-
by calling
|
|
85
|
+
Let's add a document to the `pizzas` collection, with an ID of `margherita`. We
|
|
86
|
+
use the collection's `.createNewDoc()` to produce a `FiretenderDoc` representing
|
|
87
|
+
a new document, initialized with validated data. This object is purely local
|
|
88
|
+
until it is written to Firestore by calling `.write()`. Don't forget to do
|
|
89
|
+
that.
|
|
60
90
|
|
|
61
91
|
```javascript
|
|
62
92
|
const docRef = doc(db, "pizzas", "margherita");
|
|
63
93
|
const pizza = pizzaFactory.createNewDoc(docRef, {
|
|
64
94
|
name: "Margherita",
|
|
95
|
+
description: "Neapolitan style pizza"
|
|
65
96
|
toppings: { "fresh mozzarella": {}, "fresh basil": {} },
|
|
66
97
|
tags: ["traditional"],
|
|
67
98
|
});
|
|
68
99
|
await pizza.write();
|
|
69
100
|
```
|
|
70
101
|
|
|
71
|
-
If
|
|
72
|
-
(
|
|
73
|
-
|
|
102
|
+
If you don't care about the doc ID, pass a collection reference to
|
|
103
|
+
`.createNewDoc()` and Firestore will assign an ID at random. It can be read
|
|
104
|
+
from `.id` or `.docRef`.
|
|
74
105
|
|
|
75
106
|
### Read and modify a document
|
|
76
107
|
|
|
77
|
-
To
|
|
78
|
-
`.
|
|
79
|
-
|
|
80
|
-
(
|
|
81
|
-
They can be used in combination:
|
|
108
|
+
To access an existing document, pass its reference to the collection's
|
|
109
|
+
`.getExistingDoc()` method. To read it, call `.load()` and access its data with
|
|
110
|
+
the `.r` property; see the example below. To make changes, use `.w` then call
|
|
111
|
+
`.write()`. Reading and updating can be done in combination:
|
|
82
112
|
|
|
83
113
|
```javascript
|
|
84
114
|
const meats = ["pepperoni", "chicken", "sausage"];
|
|
85
|
-
const pizza = await
|
|
86
|
-
const isMeatIncluded = Object.entries(pizza.
|
|
115
|
+
const pizza = await pizzaCollection.getExistingDoc(docRef).load();
|
|
116
|
+
const isMeatIncluded = Object.entries(pizza.r.toppings).some(
|
|
87
117
|
([name, topping]) => topping.isIncluded && name in meats
|
|
88
118
|
);
|
|
89
119
|
if (!isMeatIncluded) {
|
|
90
|
-
pizza.
|
|
120
|
+
pizza.w.toppings.tags.push("vegetarian");
|
|
91
121
|
}
|
|
92
122
|
await pizza.write();
|
|
93
123
|
```
|
|
94
124
|
|
|
125
|
+
The `.r` and `.w` properties point to the same data, with the read-only accessor
|
|
126
|
+
typed accordingly. Reading from `.r` is more efficient, as `.w` builds a chain
|
|
127
|
+
of proxies to track updates.
|
|
128
|
+
|
|
95
129
|
### Make a copy
|
|
96
130
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
131
|
+
Finally, use `.copy()` to get a deep copy of the document. If an ID is not
|
|
132
|
+
specified, it will be assigned randomly when the new doc is added to Firestore.
|
|
133
|
+
The copy is solely local until `.write()` is called.
|
|
100
134
|
|
|
101
135
|
```javascript
|
|
102
136
|
const sourceRef = doc(db, "pizza", "margherita");
|
|
103
|
-
const sourcePizza = await
|
|
137
|
+
const sourcePizza = await pizzaCollection.getExistingDoc(sourceRef).load();
|
|
104
138
|
const newPizza = sourcePizza.copy("meaty margh");
|
|
105
139
|
newPizza.name = "Meaty Margh";
|
|
106
140
|
newPizza.toppings.sausage = {};
|
|
107
141
|
newPizza.toppings.pepperoni = { included: false, surcharge: 1.25 };
|
|
108
142
|
newPizza.toppings.chicken = { included: false, surcharge: 1.50 };
|
|
143
|
+
delete newPizza.description;
|
|
109
144
|
delete newPizza.toppings["fresh basil"];
|
|
110
145
|
delete newPizza.tags.vegetarian;
|
|
111
146
|
newPizza.write();
|
|
112
147
|
```
|
|
113
148
|
|
|
149
|
+
Note the use of the `delete` operator to remove optional fields and record and
|
|
150
|
+
array items.
|
|
151
|
+
|
|
114
152
|
## TODO
|
|
115
153
|
|
|
154
|
+
The [full list of issues](https://github.com/jakes-space/firetender/issues) is
|
|
155
|
+
tracked on Github. Here are some features on the roadmap:
|
|
156
|
+
|
|
116
157
|
* Javadoc
|
|
158
|
+
* Document the code!
|
|
159
|
+
([#12](https://github.com/jakes-space/firetender/issues/12))
|
|
117
160
|
* Compile them to an API reference page in markdown.
|
|
161
|
+
([#13](https://github.com/jakes-space/firetender/issues/13))
|
|
118
162
|
* Concurrency
|
|
119
163
|
* Listen for changes and update the object if it has not been locally
|
|
120
164
|
modified. Provide an onChange() callback option.
|
|
165
|
+
([#14](https://github.com/jakes-space/firetender/issues/14))
|
|
121
166
|
* Support the Firestore transaction API.
|
|
167
|
+
([#15](https://github.com/jakes-space/firetender/issues/15))
|
|
122
168
|
* Queries
|
|
169
|
+
([#16](https://github.com/jakes-space/firetender/issues/16))
|
|
123
170
|
* Document deletion
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
|
|
171
|
+
([#17](https://github.com/jakes-space/firetender/issues/17))
|
|
172
|
+
* Improved timestamp handling, tests ([multiple
|
|
173
|
+
issues](https://github.com/jakes-space/firetender/issues?q=timestamp))
|
|
127
174
|
|
|
128
175
|
## Alternatives
|
|
129
176
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Firestore } from "firebase/firestore";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { FiretenderDoc, FiretenderDocOptions } from "./FiretenderDoc";
|
|
4
|
+
import { DeepPartial } from "./ts-helpers";
|
|
5
|
+
export declare class FiretenderCollection<SchemaType extends z.SomeZodObject> {
|
|
6
|
+
readonly schema: SchemaType;
|
|
7
|
+
readonly firestore: Firestore;
|
|
8
|
+
readonly collectionNames: string[];
|
|
9
|
+
readonly baseInitialData: DeepPartial<z.infer<SchemaType>>;
|
|
10
|
+
constructor(schema: SchemaType, collectionPath: [Firestore, ...string[]], baseInitialData: DeepPartial<z.infer<SchemaType>>);
|
|
11
|
+
createNewDoc(id?: string[] | string | undefined, initialData?: DeepPartial<z.infer<SchemaType>> | undefined, options?: FiretenderDocOptions): FiretenderDoc<SchemaType, z.TypeOf<SchemaType>>;
|
|
12
|
+
getExistingDoc(id: string[] | string, options?: FiretenderDocOptions): FiretenderDoc<SchemaType, z.TypeOf<SchemaType>>;
|
|
13
|
+
private makeDocRef;
|
|
14
|
+
private makeCollectionRef;
|
|
15
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FiretenderCollection = void 0;
|
|
4
|
+
const firestore_1 = require("firebase/firestore");
|
|
5
|
+
const FiretenderDoc_1 = require("./FiretenderDoc");
|
|
6
|
+
class FiretenderCollection {
|
|
7
|
+
constructor(schema, collectionPath, baseInitialData) {
|
|
8
|
+
this.schema = schema;
|
|
9
|
+
this.firestore = collectionPath[0];
|
|
10
|
+
this.collectionNames = collectionPath.slice(1);
|
|
11
|
+
this.baseInitialData = baseInitialData;
|
|
12
|
+
}
|
|
13
|
+
createNewDoc(id = undefined, initialData = undefined, options = {}) {
|
|
14
|
+
const ids = id instanceof Array ? id : id ? [id] : [];
|
|
15
|
+
let ref = this.makeDocRef(ids);
|
|
16
|
+
if (!ref) {
|
|
17
|
+
ref = this.makeCollectionRef(ids);
|
|
18
|
+
}
|
|
19
|
+
if (!ref) {
|
|
20
|
+
throw Error("createNewDoc() requires an ID for all collections and subcollections except the last.");
|
|
21
|
+
}
|
|
22
|
+
const data = this.baseInitialData;
|
|
23
|
+
if (initialData) {
|
|
24
|
+
Object.assign(data, initialData);
|
|
25
|
+
}
|
|
26
|
+
return FiretenderDoc_1.FiretenderDoc.createNewDoc(this.schema, ref, data, options);
|
|
27
|
+
}
|
|
28
|
+
getExistingDoc(id, options = {}) {
|
|
29
|
+
const ref = this.makeDocRef([id].flat());
|
|
30
|
+
if (!ref) {
|
|
31
|
+
throw Error("getExistingDoc() requires an ID for the collection and IDs for each of its subcollections (if any).");
|
|
32
|
+
}
|
|
33
|
+
return new FiretenderDoc_1.FiretenderDoc(this.schema, ref, options);
|
|
34
|
+
}
|
|
35
|
+
makeDocRef(ids) {
|
|
36
|
+
if (ids.length !== this.collectionNames.length) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const path = ids.flatMap((id, i) => [this.collectionNames[i], id]);
|
|
40
|
+
return (0, firestore_1.doc)(this.firestore, path[0], ...path.slice(1));
|
|
41
|
+
}
|
|
42
|
+
makeCollectionRef(ids) {
|
|
43
|
+
if (ids.length !== this.collectionNames.length - 1) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const subPath = ids.flatMap((id, i) => [id, this.collectionNames[i + 1]]);
|
|
47
|
+
return (0, firestore_1.collection)(this.firestore, this.collectionNames[0], ...subPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.FiretenderCollection = FiretenderCollection;
|
|
51
|
+
//# sourceMappingURL=FiretenderCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FiretenderCollection.js","sourceRoot":"","sources":["../src/FiretenderCollection.ts"],"names":[],"mappings":";;;AAAA,kDAM4B;AAG5B,mDAAsE;AAGtE,MAAa,oBAAoB;IAM/B,YACE,MAAkB,EAClB,cAAwC,EACxC,eAAiD;QAEjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAa,CAAC;QAC3D,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,YAAY,CACV,KAAoC,SAAS,EAC7C,cAA4D,SAAS,EACrE,UAAgC,EAAE;QAElC,MAAM,GAAG,GAAG,EAAE,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,IAAI,GAAG,GACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAA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AC,MAAM,KAAK,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;YAClD,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAA,sBAAU,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC;IACzE,CAAC;CACF;AAjED,oDAiEC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { CollectionReference, DocumentReference } from "firebase/firestore";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { DeepReadonly } from "./ts-helpers";
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type FiretenderDocOptions = {
|
|
5
5
|
createDoc?: true;
|
|
6
|
-
initialData?: any
|
|
6
|
+
initialData?: Record<string, any>;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Helper class for reading and writing Firestore data based on Zod schemas.
|
|
10
10
|
*/
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class FiretenderDoc<SchemaType extends z.SomeZodObject, DataType extends {
|
|
12
12
|
[x: string]: any;
|
|
13
13
|
} = z.infer<SchemaType>> {
|
|
14
14
|
readonly schema: SchemaType;
|
|
@@ -18,22 +18,16 @@ export declare class FireTenderDoc<SchemaType extends z.SomeZodObject, DataType
|
|
|
18
18
|
private data;
|
|
19
19
|
private dataProxy;
|
|
20
20
|
private updates;
|
|
21
|
-
constructor(schema: SchemaType, ref: DocumentReference | CollectionReference, options?:
|
|
21
|
+
constructor(schema: SchemaType, ref: DocumentReference | CollectionReference, options?: FiretenderDocOptions);
|
|
22
22
|
static createNewDoc<SchemaType1 extends z.SomeZodObject, InputType extends {
|
|
23
23
|
[x: string]: any;
|
|
24
|
-
} = z.input<SchemaType1>>(schema: SchemaType1, ref: DocumentReference | CollectionReference, initialData: InputType, options?:
|
|
25
|
-
static makeClassFactoryFor<SchemaType1 extends z.SomeZodObject, InputType extends {
|
|
26
|
-
[x: string]: any;
|
|
27
|
-
} = z.input<SchemaType1>>(schema: SchemaType1): {
|
|
28
|
-
createNewDoc: (ref: DocumentReference | CollectionReference, initialData: InputType, options?: FireTenderDocOptions) => FireTenderDoc<SchemaType1, z.TypeOf<SchemaType1>>;
|
|
29
|
-
wrapExistingDoc: (ref: DocumentReference | CollectionReference, options?: FireTenderDocOptions) => FireTenderDoc<SchemaType1, z.TypeOf<SchemaType1>>;
|
|
30
|
-
};
|
|
24
|
+
} = z.input<SchemaType1>>(schema: SchemaType1, ref: DocumentReference | CollectionReference, initialData: InputType, options?: FiretenderDocOptions): FiretenderDoc<SchemaType1, z.TypeOf<SchemaType1>>;
|
|
31
25
|
get id(): string | undefined;
|
|
32
26
|
get docRef(): DocumentReference;
|
|
33
|
-
copy(dest?: DocumentReference | CollectionReference | string | undefined, options?:
|
|
27
|
+
copy(dest?: DocumentReference | CollectionReference | string | undefined, options?: FiretenderDocOptions): FiretenderDoc<SchemaType, DataType>;
|
|
34
28
|
load(force?: boolean): Promise<this>;
|
|
35
|
-
get
|
|
36
|
-
get
|
|
29
|
+
get r(): DeepReadonly<DataType>;
|
|
30
|
+
get w(): DataType;
|
|
37
31
|
write(): Promise<void>;
|
|
38
32
|
private onChange;
|
|
39
33
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FiretenderDoc = void 0;
|
|
4
4
|
const firestore_1 = require("firebase/firestore");
|
|
5
5
|
const proxies_1 = require("./proxies");
|
|
6
6
|
const ts_helpers_1 = require("./ts-helpers");
|
|
7
7
|
/**
|
|
8
8
|
* Helper class for reading and writing Firestore data based on Zod schemas.
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
class FiretenderDoc {
|
|
11
11
|
constructor(schema, ref, options = {}) {
|
|
12
12
|
this.docID = undefined;
|
|
13
13
|
this.data = undefined;
|
|
@@ -26,7 +26,7 @@ class FireTenderDoc {
|
|
|
26
26
|
this.docID = this.ref.path.split("/").pop();
|
|
27
27
|
}
|
|
28
28
|
else if (!this.isNewDoc) {
|
|
29
|
-
throw TypeError("
|
|
29
|
+
throw TypeError("Firetender can only take a collection reference when creating a new document. Use Firetender.createNewDoc() if this is your intent.");
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
static createNewDoc(schema, ref, initialData, options = {}) {
|
|
@@ -35,13 +35,7 @@ class FireTenderDoc {
|
|
|
35
35
|
createDoc: true,
|
|
36
36
|
initialData,
|
|
37
37
|
};
|
|
38
|
-
return new
|
|
39
|
-
}
|
|
40
|
-
static makeClassFactoryFor(schema) {
|
|
41
|
-
return {
|
|
42
|
-
createNewDoc: (ref, initialData, options = {}) => FireTenderDoc.createNewDoc(schema, ref, initialData, options),
|
|
43
|
-
wrapExistingDoc: (ref, options = {}) => new FireTenderDoc(schema, ref, options),
|
|
44
|
-
};
|
|
38
|
+
return new FiretenderDoc(schema, ref, mergedOptions);
|
|
45
39
|
}
|
|
46
40
|
get id() {
|
|
47
41
|
return this.docID;
|
|
@@ -74,7 +68,7 @@ class FireTenderDoc {
|
|
|
74
68
|
createDoc: true,
|
|
75
69
|
initialData: this.data,
|
|
76
70
|
};
|
|
77
|
-
return new
|
|
71
|
+
return new FiretenderDoc(this.schema, ref, mergedOptions);
|
|
78
72
|
}
|
|
79
73
|
async load(force = false) {
|
|
80
74
|
if (this.isNewDoc || this.ref.type === "collection") {
|
|
@@ -91,20 +85,20 @@ class FireTenderDoc {
|
|
|
91
85
|
}
|
|
92
86
|
return this;
|
|
93
87
|
}
|
|
94
|
-
get
|
|
88
|
+
get r() {
|
|
95
89
|
if (!this.data) {
|
|
96
|
-
throw Error("
|
|
90
|
+
throw Error("load() must be called before reading the document.");
|
|
97
91
|
}
|
|
98
92
|
return this.data;
|
|
99
93
|
}
|
|
100
|
-
get
|
|
94
|
+
get w() {
|
|
101
95
|
if (this.isNewDoc) {
|
|
102
96
|
// No need to monitor changes if we're creating rather than updating.
|
|
103
97
|
return this.data;
|
|
104
98
|
}
|
|
105
99
|
if (!this.dataProxy) {
|
|
106
100
|
if (!this.data) {
|
|
107
|
-
throw Error("
|
|
101
|
+
throw Error("load() must be called before updating the document.");
|
|
108
102
|
}
|
|
109
103
|
this.dataProxy = (0, proxies_1.watchFieldForChanges)([], this.schema, this.data, this.onChange.bind(this));
|
|
110
104
|
}
|
|
@@ -125,7 +119,7 @@ class FireTenderDoc {
|
|
|
125
119
|
else {
|
|
126
120
|
if (!(this.ref.type === "document")) {
|
|
127
121
|
// We should never get here.
|
|
128
|
-
throw Error("Internal error.
|
|
122
|
+
throw Error("Internal error. Firetender object should always reference a document when updating an existing doc.");
|
|
129
123
|
}
|
|
130
124
|
if (this.updates.size === 0) {
|
|
131
125
|
return;
|
|
@@ -138,5 +132,5 @@ class FireTenderDoc {
|
|
|
138
132
|
this.updates.set(fieldPath.join("."), newValue);
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
|
-
exports.
|
|
142
|
-
//# sourceMappingURL=
|
|
135
|
+
exports.FiretenderDoc = FiretenderDoc;
|
|
136
|
+
//# sourceMappingURL=FiretenderDoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FiretenderDoc.js","sourceRoot":"","sources":["../src/FiretenderDoc.ts"],"names":[],"mappings":";;;AAAA,kDAQ4B;AAG5B,uCAAiD;AACjD,6CAA6D;AAQ7D;;GAEG;AACH,MAAa,aAAa;IAYxB,YACE,MAAkB,EAClB,GAA4C,EAC5C,UAAgC,EAAE;QAR5B,UAAK,GAAuB,SAAS,CAAC;QACtC,SAAI,GAAyB,SAAS,CAAC;QACvC,cAAS,GAAuC,SAAS,CAAC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AC,GAAG,EAAE,CAAC;aAC7C;YACD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACvB;aAAM;YACL,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC,EAAE;gBACnC,4BAA4B;gBAC5B,MAAM,KAAK,CACT,sGAAsG,CACvG,CAAC;aACH;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE;gBAC3B,OAAO;aACR;YACD,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACjE,MAAM,IAAA,qBAAS,EACb,IAAI,CAAC,GAAG,EACR,cAAc,CAAC,CAAC,CAAC,EACjB,cAAc,CAAC,CAAC,CAAC,EACjB,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAC3B,CAAC;SACH;IACH,CAAC;IAEO,QAAQ,CACd,SAAmB,EACnB,QAAkC;QAElC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;CACF;AAhLD,sCAgLC"}
|
package/dist/Timestamps.js
CHANGED
|
@@ -10,14 +10,12 @@ exports.timestampSchema = zod_1.z.object({
|
|
|
10
10
|
seconds: zod_1.z.number().positive().int(),
|
|
11
11
|
nanoseconds: zod_1.z.number().nonnegative().int(),
|
|
12
12
|
});
|
|
13
|
-
// TODO: probably want to move these timestamp functions into their own helper
|
|
14
|
-
// module
|
|
15
13
|
function dateFromTimestamp(timestamp) {
|
|
16
14
|
return new Date(timestamp.seconds * 1e3 + timestamp.nanoseconds / 1e6);
|
|
17
15
|
}
|
|
18
16
|
exports.dateFromTimestamp = dateFromTimestamp;
|
|
19
17
|
function makeTTL(daysFromNow = 30) {
|
|
20
|
-
// TODO: is there a way to use the server time rather than Date.now()?
|
|
18
|
+
// TODO: #10 is there a way to use the server time rather than Date.now()?
|
|
21
19
|
return timestampFromUnixMillis(Date.now() + daysFromNow * 24 * 60 * 60 * 1000);
|
|
22
20
|
}
|
|
23
21
|
exports.makeTTL = makeTTL;
|
|
@@ -33,7 +31,7 @@ function timestampFromUnixMillis(msSinceEpoch) {
|
|
|
33
31
|
}
|
|
34
32
|
exports.timestampFromUnixMillis = timestampFromUnixMillis;
|
|
35
33
|
function nowTimestamp() {
|
|
36
|
-
// TODO: is there a way to use the server time rather than Date.now()?
|
|
34
|
+
// TODO: #9 is there a way to use the server time rather than Date.now()?
|
|
37
35
|
return timestampFromUnixMillis(Date.now());
|
|
38
36
|
}
|
|
39
37
|
exports.nowTimestamp = nowTimestamp;
|
package/dist/Timestamps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timestamps.js","sourceRoot":"","sources":["../src/Timestamps.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;GAGG;AACU,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE;IACpC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE;CAC5C,CAAC,CAAC;AAGH,
|
|
1
|
+
{"version":3,"file":"Timestamps.js","sourceRoot":"","sources":["../src/Timestamps.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;GAGG;AACU,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE;IACpC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE;CAC5C,CAAC,CAAC;AAGH,SAAgB,iBAAiB,CAAC,SAAwB;IACxD,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,GAAG,GAAG,SAAS,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC;AACzE,CAAC;AAFD,8CAEC;AAED,SAAgB,OAAO,CAAC,WAAW,GAAG,EAAE;IACtC,0EAA0E;IAC1E,OAAO,uBAAuB,CAC5B,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAC/C,CAAC;AACJ,CAAC;AALD,0BAKC;AAED,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,OAAO,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AAFD,8CAEC;AAED,SAAgB,uBAAuB,CAAC,YAAoB;IAC1D,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;QACxC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC;KACzD,CAAC;AACJ,CAAC;AALD,0DAKC;AAED,SAAgB,YAAY;IAC1B,yEAAyE;IACzE,OAAO,uBAAuB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AAC7C,CAAC;AAHD,oCAGC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,8 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
17
|
+
exports.FiretenderDoc = exports.FiretenderCollection = void 0;
|
|
18
|
+
var FiretenderCollection_1 = require("./FiretenderCollection");
|
|
19
|
+
Object.defineProperty(exports, "FiretenderCollection", { enumerable: true, get: function () { return FiretenderCollection_1.FiretenderCollection; } });
|
|
20
|
+
var FiretenderDoc_1 = require("./FiretenderDoc");
|
|
21
|
+
Object.defineProperty(exports, "FiretenderDoc", { enumerable: true, get: function () { return FiretenderDoc_1.FiretenderDoc; } });
|
|
20
22
|
__exportStar(require("./Timestamps"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,+CAA6B"}
|
package/dist/proxies.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.watchFieldForChanges = exports.watchArrayForChanges = void 0;
|
|
4
|
-
const ts_helpers_1 = require("./ts-helpers");
|
|
5
4
|
const firestore_1 = require("firebase/firestore");
|
|
6
5
|
const zod_1 = require("zod");
|
|
6
|
+
const ts_helpers_1 = require("./ts-helpers");
|
|
7
7
|
function unwrapSchema(schema) {
|
|
8
8
|
if (schema instanceof zod_1.z.ZodOptional || schema instanceof zod_1.z.ZodNullable) {
|
|
9
9
|
return unwrapSchema(schema.unwrap());
|
|
@@ -36,9 +36,7 @@ function watchArrayForChanges(arrayPath, array, fieldSchema, field, onChange) {
|
|
|
36
36
|
const property = target[propertyKey];
|
|
37
37
|
if (property instanceof Function) {
|
|
38
38
|
const result = (...args) => property.apply(field, args);
|
|
39
|
-
// TODO
|
|
40
|
-
// TODO (harder): also handle at, foreach, etc. methods to chain proxies
|
|
41
|
-
// down from them. But life's too short for that.
|
|
39
|
+
// TODO: #11 Only mark the change for mutating function calls.
|
|
42
40
|
onChange(arrayPath, array);
|
|
43
41
|
return result;
|
|
44
42
|
}
|
package/dist/proxies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;AAAA,kDAA8D;AAC9D,6BAAwB;AAExB,6CAAiD;AAEjD,SAAS,YAAY,CAAC,MAAoB;IACxC,IAAI,MAAM,YAAY,OAAC,CAAC,WAAW,IAAI,MAAM,YAAY,OAAC,CAAC,WAAW,EAAE;QACtE,OAAO,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACtC;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,UAAU,EAAE;QAClC,OAAO,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;KAC7C;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,UAAU,EAAE;QAClC,OAAO,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;KACzC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CACxB,YAA0B,EAC1B,WAAmB;IAEnB,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,MAAM,YAAY,OAAC,CAAC,SAAS,EAAE;QACjC,OAAO,MAAM,CAAC,WAAW,CAAC;KAC3B;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,QAAQ,EAAE;QAChC,OAAO,MAAM,CAAC,OAAO,CAAC;KACvB;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,SAAS,EAAE;QACjC,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;KA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IAAI,QAAQ,YAAY,MAAM,EAAE;gBAC9B,OAAO,oBAAoB,CACzB,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAC3B,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,EAC3C,QAAQ,EACR,QAAQ,CACT,CAAC;aACH;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK;YAC5B,IAAA,8BAAiB,EAAC,WAAW,CAAC,CAAC;YAC/B,MAAM,cAAc,GAAG,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YACnE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,QAAQ,CAAC,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC;YACnD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QACvD,CAAC;QACD,cAAc,CAAC,MAAM,EAAE,WAAW;YAChC,IAAA,8BAAiB,EAAC,WAAW,CAAC,CAAC;YAC/B,QAAQ,CAAC,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,IAAA,uBAAW,GAAE,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AA7CD,oDA6CC"}
|
package/dist/ts-helpers.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typescript-related helper functions and types.
|
|
3
3
|
*/
|
|
4
|
+
export declare type DeepPartial<T> = T extends object ? {
|
|
5
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
6
|
+
} : T;
|
|
4
7
|
export declare type DeepReadonly<T> = T extends Array<infer ArrKey> ? ReadonlyArray<DeepReadonly<ArrKey>> : T extends Map<infer MapKey, infer MapVal> ? ReadonlyMap<DeepReadonly<MapKey>, DeepReadonly<MapVal>> : T extends Set<infer SetKey> ? ReadonlySet<DeepReadonly<SetKey>> : T extends Record<any, unknown> ? {
|
|
5
8
|
readonly [ObjKey in keyof T]: DeepReadonly<T[ObjKey]>;
|
|
6
9
|
} : T;
|
package/dist/ts-helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ts-helpers.js","sourceRoot":"","sources":["../src/ts-helpers.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"ts-helpers.js","sourceRoot":"","sources":["../src/ts-helpers.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AA0BH,SAAgB,eAAe,CAAI,KAAQ;IACzC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QACzC,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,iBAAiB,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,0CAIC;AAED,SAAgB,iBAAiB,CAAC,GAAQ;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,SAAS,CAAC,iDAAiD,CAAC,CAAC;KACpE;AACH,CAAC;AAJD,8CAIC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firetender",
|
|
3
|
-
"displayName": "
|
|
3
|
+
"displayName": "Firetender",
|
|
4
4
|
"description": "Typescript wrapper for Firestore documents",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.4.0",
|
|
6
6
|
"author": "Jake Hartman",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/jakes-space/firetender",
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"prettier:fix": "prettier --write src/*.ts src/**/*.ts",
|
|
34
34
|
"check": "npm run lint:check && npm run prettier:check",
|
|
35
35
|
"fix": "npm run lint:fix && npm run prettier:fix",
|
|
36
|
+
"emulate-db": "firebase emulators:start --project=firetender",
|
|
36
37
|
"test": "jest --forceExit --detectOpenHandles",
|
|
38
|
+
"prepare": "husky install",
|
|
37
39
|
"clean": "rm -rf dist/*",
|
|
38
40
|
"build": "npm run clean && tsc && rm -rf dist/__tests__",
|
|
39
41
|
"prepublishOnly": "npm run check && npm run test && npm run build"
|
|
@@ -53,6 +55,8 @@
|
|
|
53
55
|
"eslint-import-resolver-typescript": "^3.5.2",
|
|
54
56
|
"eslint-plugin-import": "^2.26.0",
|
|
55
57
|
"eslint-plugin-prettier": "^4.2.1",
|
|
58
|
+
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
59
|
+
"husky": "^8.0.1",
|
|
56
60
|
"jest": "^29.2.2",
|
|
57
61
|
"prettier": "^2.7.1",
|
|
58
62
|
"ts-jest": "^29.0.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FireTenderDoc.js","sourceRoot":"","sources":["../src/FireTenderDoc.ts"],"names":[],"mappings":";;;AAAA,kDAQ4B;AAE5B,uCAAiD;AACjD,6CAA6D;AAQ7D;;GAEG;AACH,MAAa,aAAa;IAYxB,YACE,MAAkB,EAClB,GAA4C,EAC5C,UAAgC,EAAE;QAR5B,UAAK,GAAuB,SAAS,CAAC;QACtC,SAAI,GAAyB,SAAS,CAAC;QACvC,cAAS,GAAuC,SAAS,CAAC;QAC1D,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;QAOvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;QAC3C,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;gBACxB,MAAM,cAAc,CAClB,qDAAqD,CACtD,CAAC;aACH;YACD,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC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