@alwatr/nitrobase-reference 7.10.1 โ 9.1.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/dist/logger.d.ts.map +1 -1
- package/dist/main.js +5 -0
- package/dist/main.js.map +12 -0
- package/package.json +52 -48
- package/src/collection-reference.ts +684 -0
- package/src/document-reference.ts +429 -0
- package/src/logger.ts +4 -0
- package/src/main.ts +2 -0
- package/CHANGELOG.md +0 -417
- package/dist/main.cjs +0 -4
- package/dist/main.cjs.map +0 -7
- package/dist/main.mjs +0 -4
- package/dist/main.mjs.map +0 -7
package/CHANGELOG.md
DELETED
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [7.10.1](https://github.com/Alwatr/nitrobase/compare/v7.10.0...v7.10.1) (2025-12-14)
|
|
7
|
-
|
|
8
|
-
### ๐งน Miscellaneous Chores
|
|
9
|
-
|
|
10
|
-
* update tsconfig extends to use @alwatr/nanolib ([ffbc8ce](https://github.com/Alwatr/nitrobase/commit/ffbc8ce74d47d7f4e1ff0061722df10f68af11cc))
|
|
11
|
-
|
|
12
|
-
### ๐ Dependencies update
|
|
13
|
-
|
|
14
|
-
* replace '@alwatr/nano-build' with '@alwatr/nanolib' in logger imports ([9a355b9](https://github.com/Alwatr/nitrobase/commit/9a355b92b27434a3cd132e7e52df5c2e112ca97e))
|
|
15
|
-
* update `@alwatr/nanolib` and `@types/node` dependencies across all packages. ([bc6d96f](https://github.com/Alwatr/nitrobase/commit/bc6d96f4fd423bcfb817d74b526596669d8a8aed))
|
|
16
|
-
* update dependencies and switch prettier config to @alwatr/nanolib ([adf97f3](https://github.com/Alwatr/nitrobase/commit/adf97f3b4e26088f8e054a349c7f77e07755e7f9))
|
|
17
|
-
|
|
18
|
-
## [7.10.0](https://github.com/Alwatr/nitrobase/compare/v7.9.0...v7.10.0) (2025-09-21)
|
|
19
|
-
|
|
20
|
-
### ๐ Bug Fixes
|
|
21
|
-
|
|
22
|
-
* add "sideEffects": false to package.json files for better tree-shaking ([cb6f75b](https://github.com/Alwatr/nitrobase/commit/cb6f75b86eb7dba6812aaad5136fcd867e885562))
|
|
23
|
-
* add missing dependencies for delay and logger modules ([514ccbc](https://github.com/Alwatr/nitrobase/commit/514ccbc64a0d7165080ec4ddc5ea90bc04648425))
|
|
24
|
-
* add type imports for nano-build and type-helper in logger files ([6ca3627](https://github.com/Alwatr/nitrobase/commit/6ca362761c0d30a2813369bda49c927960c787f8))
|
|
25
|
-
* remove unused packageTracer import from logger.ts ([44690db](https://github.com/Alwatr/nitrobase/commit/44690dbc6628f65b0ac91c9d96c09beb1c4f2d34))
|
|
26
|
-
* update imports for delay and logger modules ([892a47d](https://github.com/Alwatr/nitrobase/commit/892a47d66611a44078da7319b52b04385f9d0c1e))
|
|
27
|
-
* update imports for logger and delay modules ([615f596](https://github.com/Alwatr/nitrobase/commit/615f596a883714638c469cc1e783edd5da719a7d))
|
|
28
|
-
|
|
29
|
-
### ๐จ Code Refactoring
|
|
30
|
-
|
|
31
|
-
* update access modifiers to public for class properties and methods in nitrobase and user management ([a988d63](https://github.com/Alwatr/nitrobase/commit/a988d63b61828f6ce360e7179cbaccfa19dc1ae2))
|
|
32
|
-
|
|
33
|
-
### ๐งน Miscellaneous Chores
|
|
34
|
-
|
|
35
|
-
* remove Exir Studio sponsorship logo from multiple README files ([506459f](https://github.com/Alwatr/nitrobase/commit/506459fea7d29b97e478da562590dd202ce7e833))
|
|
36
|
-
* remove unused types from tsconfig.json files and update references ([b504ced](https://github.com/Alwatr/nitrobase/commit/b504ced4a8f98de4fe79a2c974937278bd4e46cb))
|
|
37
|
-
* Update license from AGPL-3.0 to MPL-2.0 ([af1746e](https://github.com/Alwatr/nitrobase/commit/af1746ee9a3786c1cb2e0014f138e9f3b7086b8d))
|
|
38
|
-
* update package.json files across all packages for consistency and improved metadata ([647900d](https://github.com/Alwatr/nitrobase/commit/647900d9966f8df275c4e2ef0550c501be38ece0))
|
|
39
|
-
|
|
40
|
-
### ๐ Dependencies update
|
|
41
|
-
|
|
42
|
-
* update dependencies in package.json files across all packages to latest versions ([72c20ef](https://github.com/Alwatr/nitrobase/commit/72c20efbc1cac9825fb4880772e3fad797d74a23))
|
|
43
|
-
|
|
44
|
-
## [7.8.0](https://github.com/Alwatr/nitrobase/compare/v7.7.0...v7.8.0) (2025-03-06)
|
|
45
|
-
|
|
46
|
-
### Features
|
|
47
|
-
|
|
48
|
-
* **reference:** update save and saveImmediate methods to accept itemId parameter ([8fe304e](https://github.com/Alwatr/nitrobase/commit/8fe304ec47a2d86a6ca78e8cbea3efe7d231bc88)) by @
|
|
49
|
-
|
|
50
|
-
### Miscellaneous Chores
|
|
51
|
-
|
|
52
|
-
* **reference:** remove unnecessary blank line in DocumentReference class ([eeb63b9](https://github.com/Alwatr/nitrobase/commit/eeb63b96e07e6638b1fcc4976de65571ed4267eb)) by @
|
|
53
|
-
|
|
54
|
-
### Dependencies update
|
|
55
|
-
|
|
56
|
-
* **deps-dev:** bump the dependencies group across 1 directory with 5 updates ([fe6ab37](https://github.com/Alwatr/nitrobase/commit/fe6ab37263f609f8bce8398462b7105b8e5a55fe)) by @dependabot[bot]
|
|
57
|
-
* update @alwatr/nanolib, @alwatr/nano-build, and @alwatr/type-helper to latest versions ([5f3f89b](https://github.com/Alwatr/nitrobase/commit/5f3f89b1236f66e9167957d60d43c8d0abff108d)) by @
|
|
58
|
-
|
|
59
|
-
## [7.7.0](https://github.com/Alwatr/nitrobase/compare/v7.6.1...v7.7.0) (2025-02-26)
|
|
60
|
-
|
|
61
|
-
**Note:** Version bump only for package @alwatr/nitrobase-reference
|
|
62
|
-
|
|
63
|
-
## [7.6.0](https://github.com/Alwatr/nitrobase/compare/v7.5.9...v7.6.0) (2025-02-26)
|
|
64
|
-
|
|
65
|
-
### Miscellaneous Chores
|
|
66
|
-
|
|
67
|
-
* rollback all versions ([9ff6c11](https://github.com/Alwatr/nitrobase/commit/9ff6c11ef3e44ea669a814da73ed39ddc2c8e971)) by @alimd
|
|
68
|
-
|
|
69
|
-
## [7.5.8](https://github.com/Alwatr/nitrobase/compare/v7.5.7...v7.5.8) (2025-02-18)
|
|
70
|
-
|
|
71
|
-
### Dependencies update
|
|
72
|
-
|
|
73
|
-
* bump @alwatr/nanolib, @alwatr/nano-build, and @types/node to latest versions across multiple packages ([3e89c62](https://github.com/Alwatr/nitrobase/commit/3e89c62ad20f3afe0c38c6ae36d91bcb6199b231)) by @
|
|
74
|
-
* **deps-dev:** bump the dependencies group across 1 directory with 2 updates ([03715d0](https://github.com/Alwatr/nitrobase/commit/03715d0b5534b127dfb57ffe0ea713fb168eefe6)) by @dependabot[bot]
|
|
75
|
-
|
|
76
|
-
## [7.5.7](https://github.com/Alwatr/nitrobase/compare/v7.5.6...v7.5.7) (2025-02-03)
|
|
77
|
-
|
|
78
|
-
### Dependencies update
|
|
79
|
-
|
|
80
|
-
* update [@alwatr](https://github.com/alwatr) dependencies to latest versions ([f8bb10f](https://github.com/Alwatr/nitrobase/commit/f8bb10fa3343f25e2a442e80fbddb88c55fac813)) by @
|
|
81
|
-
|
|
82
|
-
## [7.5.5](https://github.com/Alwatr/nitrobase/compare/v7.5.4...v7.5.5) (2025-02-02)
|
|
83
|
-
|
|
84
|
-
### Bug Fixes
|
|
85
|
-
|
|
86
|
-
* update callback invocation to use correct context in CollectionReference and DocumentReference ([7cc9fc9](https://github.com/Alwatr/nitrobase/commit/7cc9fc95967d5047b41b2c9c6fd56608256fdbeb)) by @alimd
|
|
87
|
-
|
|
88
|
-
### Dependencies update
|
|
89
|
-
|
|
90
|
-
* **deps-dev:** bump @types/node ([d60ee96](https://github.com/Alwatr/nitrobase/commit/d60ee96716b8df7837b3d7f9fe4b8705c94e5af0)) by @dependabot[bot]
|
|
91
|
-
* update ([0b9eccd](https://github.com/Alwatr/nitrobase/commit/0b9eccd3b54dade17e3eeb94bd08612c57356801)) by @alimd
|
|
92
|
-
|
|
93
|
-
## [7.5.4](https://github.com/Alwatr/nitrobase/compare/v7.5.3...v7.5.4) (2025-01-12)
|
|
94
|
-
|
|
95
|
-
### Bug Fixes
|
|
96
|
-
|
|
97
|
-
* **reference:** remove initialData parameter from newRefFromData method and default data to an empty object ([c89c172](https://github.com/Alwatr/nitrobase/commit/c89c172d8ee1f6f5b7b56b2cef6f129cdf680277)) by @alimd
|
|
98
|
-
* **reference:** rename initialData parameter to data in newRefFromData method ([cf389b8](https://github.com/Alwatr/nitrobase/commit/cf389b8c80cccbf9e327c680c8ffbd3c595f2155)) by @alimd
|
|
99
|
-
|
|
100
|
-
### Dependencies update
|
|
101
|
-
|
|
102
|
-
* **deps-dev:** bump the dependencies group across 1 directory with 11 updates ([fdd30a6](https://github.com/Alwatr/nitrobase/commit/fdd30a6639ae7ead4e8dbfaca0295cb2bf0e6649)) by @dependabot[bot]
|
|
103
|
-
|
|
104
|
-
## [7.5.0](https://github.com/Alwatr/nitrobase/compare/v7.4.1...v7.5.0) (2024-11-09)
|
|
105
|
-
|
|
106
|
-
**Note:** Version bump only for package @alwatr/nitrobase-reference
|
|
107
|
-
|
|
108
|
-
## [7.4.0](https://github.com/Alwatr/nitrobase/compare/v7.3.1...v7.4.0) (2024-11-08)
|
|
109
|
-
|
|
110
|
-
### Dependencies update
|
|
111
|
-
|
|
112
|
-
* bump @alwatr/nanolib from 5.2.0 to 5.2.1 across multiple packages ([e1f87b0](https://github.com/Alwatr/nitrobase/commit/e1f87b07d33e8227440256a70f012aa63410f153)) by @
|
|
113
|
-
* **deps-dev:** bump @types/node in the dependencies group ([67ffbad](https://github.com/Alwatr/nitrobase/commit/67ffbad06c95c304d47acbe46fd137fb4cf69f95)) by @dependabot[bot]
|
|
114
|
-
* **deps:** bump @alwatr/nanolib from 5.0.0 to 5.2.0 in the alwatr group ([dfa1eef](https://github.com/Alwatr/nitrobase/commit/dfa1eefb191bbaac2ff2fff410bb1d3ec615d959)) by @dependabot[bot]
|
|
115
|
-
|
|
116
|
-
## [7.3.1](https://github.com/Alwatr/nitrobase/compare/v7.3.0...v7.3.1) (2024-11-02)
|
|
117
|
-
|
|
118
|
-
### Miscellaneous Chores
|
|
119
|
-
|
|
120
|
-
* **deps-dev:** bump the development-dependencies group with 8 updates ([63f7adc](https://github.com/Alwatr/nitrobase/commit/63f7adc5ff83d4876f34d4f089a4be9b95b711a6)) by @dependabot[bot]
|
|
121
|
-
* **deps:** bump the alwatr-dependencies group with 2 updates ([20fb436](https://github.com/Alwatr/nitrobase/commit/20fb436b9f146d5ec7452a693c7af8faa32bedff)) by @dependabot[bot]
|
|
122
|
-
|
|
123
|
-
### Dependencies update
|
|
124
|
-
|
|
125
|
-
* **deps-dev:** bump @types/node in the dependencies group ([dd3e94a](https://github.com/Alwatr/nitrobase/commit/dd3e94a4c007da8fddda4cfeffe5f0763d74952e)) by @dependabot[bot]
|
|
126
|
-
* **deps:** bump the alwatr group with 6 updates ([eb9eeb1](https://github.com/Alwatr/nitrobase/commit/eb9eeb1901f7947cde783bf6f06340c984d6f59d)) by @dependabot[bot]
|
|
127
|
-
|
|
128
|
-
## [7.3.0](https://github.com/Alwatr/nitrobase/compare/v7.2.1...v7.3.0) (2024-10-11)
|
|
129
|
-
|
|
130
|
-
### Features
|
|
131
|
-
|
|
132
|
-
* update `import`s & packages based on the latest changes of `nanolib` & prevent side-effects ([0d66f89](https://github.com/Alwatr/nitrobase/commit/0d66f894dc4ff615ab73ebd27c275f98dc384fbe)) by @mohammadhonarvar
|
|
133
|
-
|
|
134
|
-
### Code Refactoring
|
|
135
|
-
|
|
136
|
-
* update `import`s & packages based on the latest changes of `nanolib` ([ce990a2](https://github.com/Alwatr/nitrobase/commit/ce990a2fedc5545e971c3bb6e58b55bfba8c0bd9)) by @mohammadhonarvar
|
|
137
|
-
|
|
138
|
-
### Miscellaneous Chores
|
|
139
|
-
|
|
140
|
-
* **deps-dev:** bump the development-dependencies group with 10 updates ([7bdcf3f](https://github.com/Alwatr/nitrobase/commit/7bdcf3f47ddb8e1376a1c7ae6e221811182bae58)) by @dependabot[bot]
|
|
141
|
-
* **deps:** bump the alwatr-dependencies group with 10 updates ([60afdde](https://github.com/Alwatr/nitrobase/commit/60afdde98562f3023e6624ee0579d6bdee80bc32)) by @dependabot[bot]
|
|
142
|
-
* **deps:** bump the alwatr-dependencies group with 6 updates ([1cf29b2](https://github.com/Alwatr/nitrobase/commit/1cf29b20055554945cd669ea9d022ab7c503d9fc)) by @dependabot[bot]
|
|
143
|
-
|
|
144
|
-
## [7.2.1](https://github.com/Alwatr/nitrobase/compare/v7.2.0...v7.2.1) (2024-09-29)
|
|
145
|
-
|
|
146
|
-
### Miscellaneous Chores
|
|
147
|
-
|
|
148
|
-
* **deps-dev:** bump @types/node in the development-dependencies group ([9b146d2](https://github.com/Alwatr/nitrobase/commit/9b146d2f6cf7d1d79a2a6f46a5e8f50e7fb2ac75)) by @dependabot[bot]
|
|
149
|
-
* **reference:** change the license to AGPL-3.0 ([44ff664](https://github.com/Alwatr/nitrobase/commit/44ff664e5bd5838ae773af1f3de5230df8378b19)) by @ArmanAsadian
|
|
150
|
-
|
|
151
|
-
### Dependencies update
|
|
152
|
-
|
|
153
|
-
* update ([90a0fe1](https://github.com/Alwatr/nitrobase/commit/90a0fe146eb703c183c116776d7c5748918282da)) by @
|
|
154
|
-
|
|
155
|
-
## [7.2.0](https://github.com/Alwatr/nitrobase/compare/v7.1.1...v7.2.0) (2024-09-24)
|
|
156
|
-
|
|
157
|
-
### Code Refactoring
|
|
158
|
-
|
|
159
|
-
* rename all store to nitrobase ([0928420](https://github.com/Alwatr/nitrobase/commit/0928420d8751e16ff1e8d91e1d3048a5895885a6)) by @AliMD
|
|
160
|
-
* rename all store to nitrobase ([9e31765](https://github.com/Alwatr/nitrobase/commit/9e31765b63ecd94bcf600cb44cfd9e341dd11a4e)) by @AliMD
|
|
161
|
-
|
|
162
|
-
## [7.1.1](https://github.com/Alwatr/nitrobase/compare/v7.1.0...v7.1.1) (2024-09-24)
|
|
163
|
-
|
|
164
|
-
### Miscellaneous Chores
|
|
165
|
-
|
|
166
|
-
* **deps-dev:** bump the development-dependencies group across 1 directory with 3 updates ([122251c](https://github.com/Alwatr/nitrobase/commit/122251c315c422b7e9c2d5aba827f27b321194bb)) by @dependabot[bot]
|
|
167
|
-
* **deps:** bump the alwatr-dependencies group with 9 updates ([2a94694](https://github.com/Alwatr/nitrobase/commit/2a94694b2ec12c2915aa77934023328751d13837)) by @dependabot[bot]
|
|
168
|
-
|
|
169
|
-
### Dependencies update
|
|
170
|
-
|
|
171
|
-
* update ([82c475e](https://github.com/Alwatr/nitrobase/commit/82c475e29bd7f42ad03660556f40f180b3b6c9c6)) by @AliMD
|
|
172
|
-
|
|
173
|
-
## [7.1.0](https://github.com/Alwatr/nitrobase/compare/v7.0.0...v7.1.0) (2024-09-08)
|
|
174
|
-
|
|
175
|
-
### Features
|
|
176
|
-
|
|
177
|
-
* **helper:** add @alwatr/nitrobase-helper package ([158377c](https://github.com/Alwatr/nitrobase/commit/158377c69a2fe9ead17fa8160f95298fbbae19ec)) by @AliMD
|
|
178
|
-
* **reference:** add @alwatr/nitrobase-helper package ([a9077ae](https://github.com/Alwatr/nitrobase/commit/a9077aeff62c8c06ad2ac9eed1f2e637a1ba0b9b)) by @AliMD
|
|
179
|
-
|
|
180
|
-
### Miscellaneous Chores
|
|
181
|
-
|
|
182
|
-
* **deps-dev:** bump the development-dependencies group with 2 updates ([f6d8374](https://github.com/Alwatr/nitrobase/commit/f6d837417886ccf3719100570194434455fda365)) by @dependabot[bot]
|
|
183
|
-
|
|
184
|
-
## [7.0.0](https://github.com/Alwatr/nitrobase/compare/v7.0.0-beta.1...v7.0.0) (2024-09-02)
|
|
185
|
-
|
|
186
|
-
### โ BREAKING CHANGES
|
|
187
|
-
|
|
188
|
-
* The `StoreFileMeta` interface has been updated to include the `extra` property. Developers should update their code to handle the new property.
|
|
189
|
-
* The `update` method has been replaced with `replaceData` in the `DocumentReference` class. Developers should update their code to use the new method name.
|
|
190
|
-
* The `updateMetadata_` method has been replaced with `refreshMetadata_` in the `CollectionReference` class. Developers should update their code to use the new method name.
|
|
191
|
-
* The `updatePartial` method has been replaced with `mergeItemData` in the `CollectionReference` class. Developers should update their code to use the new method name.
|
|
192
|
-
* `update` method in CollectionReference has been replaced with `replaceItemData`
|
|
193
|
-
* `remove` renamed to `removeItem` in CollectionReference
|
|
194
|
-
* `append` renamed to `appendItem` in CollectionReference
|
|
195
|
-
* `add` renamed to `addItem` in CollectionReference
|
|
196
|
-
* `getItem` renamed to `getItemData` in CollectionReference
|
|
197
|
-
* exists renamed to itemExists in CollectionReference
|
|
198
|
-
* version in metadata removed
|
|
199
|
-
|
|
200
|
-
### Features
|
|
201
|
-
|
|
202
|
-
* Add `extra` meta for `collection-reference.ts` and `document-reference.ts` with migrate old versions ([8182369](https://github.com/Alwatr/nitrobase/commit/81823692edacacb95a53d55218c2c818c9fa13cb)) by @AliMD
|
|
203
|
-
* Add methods for managing extra metadata in DocumentReference ([5c0ae83](https://github.com/Alwatr/nitrobase/commit/5c0ae83980ba863b99f3d53ee7c7b91c31bf61c0)) by @AliMD
|
|
204
|
-
|
|
205
|
-
### Bug Fixes
|
|
206
|
-
|
|
207
|
-
* **CollectionReference:** logger issues ([9660fb2](https://github.com/Alwatr/nitrobase/commit/9660fb22dce5670c16028441c60f0715f537467a)) by @AliMD
|
|
208
|
-
* **reference:** set the correct names ([e55300e](https://github.com/Alwatr/nitrobase/commit/e55300e908526b38b17274c65b9e3b8fa0387a96)) by @mohammadhonarvar
|
|
209
|
-
|
|
210
|
-
### Code Refactoring
|
|
211
|
-
|
|
212
|
-
* Add methods for managing extra metadata in CollectionReference ([eed99f5](https://github.com/Alwatr/nitrobase/commit/eed99f5d596885b715a6a51fc3b6fb885dbeadb5)) by @AliMD
|
|
213
|
-
* **reference:** rename `itemExists` to `hasItem` ([f49e776](https://github.com/Alwatr/nitrobase/commit/f49e77655e3507bce2d4359dcebabb4e048bc6ec)) by @mohammadhonarvar
|
|
214
|
-
* Refresh metadata in CollectionReference when updating or refreshing items ([b7108c7](https://github.com/Alwatr/nitrobase/commit/b7108c72a04441afddabd2bb30432b22a4d31f51)) by @AliMD
|
|
215
|
-
* Refresh metadata in DocumentReference when updating ([50d3ea8](https://github.com/Alwatr/nitrobase/commit/50d3ea82ea6044e194eed7554be42c509b8377f1)) by @AliMD
|
|
216
|
-
* Remove unused "ALWATR_DEBUG" environment variable from build script ([26e7642](https://github.com/Alwatr/nitrobase/commit/26e764280e0a2827904762ed3de21a9966ddfc63)) by @AliMD
|
|
217
|
-
* remove ver in metadata and Update file format version to 3 in CollectionReference and DocumentReference ([4bf146e](https://github.com/Alwatr/nitrobase/commit/4bf146ed5b1cbd2b340b3c0f3c5f6911aeed6f6d)) by @AliMD
|
|
218
|
-
* Rename add method to addItem in CollectionReference ([60a859b](https://github.com/Alwatr/nitrobase/commit/60a859b920ba57e2e98b2cc7b4d25d978e649944)) by @AliMD
|
|
219
|
-
* Rename append method to appendItem in CollectionReference ([949f261](https://github.com/Alwatr/nitrobase/commit/949f261fc12c93cd89b3480a2c1aaa8054af477a)) by @AliMD
|
|
220
|
-
* Rename exists method to itemExists in CollectionReference ([7555803](https://github.com/Alwatr/nitrobase/commit/7555803cdf5fd737b013f2ecd340f5b6936b9c65)) by @AliMD
|
|
221
|
-
* Rename getItem method to getItemData in CollectionReference ([e592ae5](https://github.com/Alwatr/nitrobase/commit/e592ae5511e8e81a702f3d0283b2aa20a93edc74)) by @AliMD
|
|
222
|
-
* Rename remove method to removeItem in CollectionReference ([6238cae](https://github.com/Alwatr/nitrobase/commit/6238cae8e46b379d00559b54c27aedc793ca77c2)) by @AliMD
|
|
223
|
-
* Rename update method to replaceData in DocumentReference ([367257c](https://github.com/Alwatr/nitrobase/commit/367257c13255a1537d87d948ed0f303368b2ae2d)) by @AliMD
|
|
224
|
-
* Rename updatePartial method to mergeData in DocumentReference ([cbc1194](https://github.com/Alwatr/nitrobase/commit/cbc119410b3a58d554c30dfc01eafbdb91b4c49a)) by @AliMD
|
|
225
|
-
* Rename updatePartial method to mergeItemData in CollectionReference ([e091900](https://github.com/Alwatr/nitrobase/commit/e09190062e9387d7abad0d395a921b94b4efea18)) by @AliMD
|
|
226
|
-
* Replace update method with replaceItemData in CollectionReference ([45a9309](https://github.com/Alwatr/nitrobase/commit/45a9309887ed6db4ac452b6dbc48a8cb4b38c7c7)) by @AliMD
|
|
227
|
-
* Update migrate process in CollectionReference and DocumentReference ([5a25ae2](https://github.com/Alwatr/nitrobase/commit/5a25ae2674dfa3eda78b6995b0af3beb4ab885c5)) by @AliMD
|
|
228
|
-
* Update type imports in alwatr-nitrobase.ts ([b6a4aba](https://github.com/Alwatr/nitrobase/commit/b6a4aba2e5fc51585d69b047a9bd22c49ed2098a)) by @AliMD
|
|
229
|
-
* Update validateContext__ method in CollectionReference and DocumentReference ([4dfee95](https://github.com/Alwatr/nitrobase/commit/4dfee95f7eb04cf12afc4df1f275c5495f78ad6a)) by @AliMD
|
|
230
|
-
* Update validateContext__ method in CollectionReference and DocumentReference ([bb0ae6a](https://github.com/Alwatr/nitrobase/commit/bb0ae6ab62e6fe34ff916adba74aba6a2a0b304a)) by @AliMD
|
|
231
|
-
|
|
232
|
-
### Dependencies update
|
|
233
|
-
|
|
234
|
-
* update ([6411ff7](https://github.com/Alwatr/nitrobase/commit/6411ff7d49323b8bbf0dbb03fbc3c640b433a8bb)) by @
|
|
235
|
-
|
|
236
|
-
## [7.0.0-beta.1](https://github.com/Alwatr/nitrobase/compare/v7.0.0-beta.0...v7.0.0-beta.1) (2024-08-31)
|
|
237
|
-
|
|
238
|
-
### Code Refactoring
|
|
239
|
-
|
|
240
|
-
* move schemaVer to storeId ([322b76d](https://github.com/Alwatr/nitrobase/commit/322b76d8432752f979e1d4fc3c2250e22945fd36)) by @
|
|
241
|
-
|
|
242
|
-
## [7.0.0-beta.0](https://github.com/Alwatr/nitrobase/compare/v6.2.1...v7.0.0-beta.0) (2024-08-31)
|
|
243
|
-
|
|
244
|
-
### โ BREAKING CHANGES
|
|
245
|
-
|
|
246
|
-
* The `update` method in the `DocumentReference` not available anymore. use `updatePartial` instead.
|
|
247
|
-
|
|
248
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
249
|
-
|
|
250
|
-
* **DocumentReference:** The `set` method in the `DocumentReference` not available anymore. use `update` instead.
|
|
251
|
-
|
|
252
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
253
|
-
|
|
254
|
-
* **DocumentReference:** The `meta` method in the `DocumentReference` not available anymore. use `getStoreMetadata` instead.
|
|
255
|
-
|
|
256
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
257
|
-
|
|
258
|
-
* **DocumentReference:** The `get` method in the `DocumentReference` not available anymore. use `getData` instead.
|
|
259
|
-
|
|
260
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
261
|
-
|
|
262
|
-
* **CollectionReference:** The `updateMeta_` method in the `CollectionReference` not available anymore. use `updateMetadata_` instead.
|
|
263
|
-
|
|
264
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
265
|
-
|
|
266
|
-
* **CollectionReference:** The `update` method in the `CollectionReference` not available anymore. use `updatePartial` instead.
|
|
267
|
-
|
|
268
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
269
|
-
|
|
270
|
-
* **CollectionReference:** The `set` method in the `CollectionReference` not available anymore. use `update` instead.
|
|
271
|
-
|
|
272
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
273
|
-
|
|
274
|
-
* The `delete` method in the `CollectionReference` not available anymore. use `remove` instead.
|
|
275
|
-
|
|
276
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
277
|
-
|
|
278
|
-
* The `create` method in the `CollectionReference` not available anymore. use `add` instead.
|
|
279
|
-
|
|
280
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
281
|
-
|
|
282
|
-
* The `access_` method in the `CollectionReference` not available anymore. use `getItemContext_` instead.
|
|
283
|
-
|
|
284
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
285
|
-
|
|
286
|
-
* **CollectionReference:** The `metaItem` method in the `CollectionReference` not available anymore. use `getItemMetadata` instead.
|
|
287
|
-
|
|
288
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
289
|
-
|
|
290
|
-
* The `meta` method in the `CollectionReference` not available anymore. use `getStoreMetadata` instead.
|
|
291
|
-
|
|
292
|
-
Co-authored-by: Mohammad Honarvar <honarvar.info@gmail.com>
|
|
293
|
-
|
|
294
|
-
### Features
|
|
295
|
-
|
|
296
|
-
* Rename `meta` method to `getStoreMetadata` in CollectionReference ([44ee78e](https://github.com/Alwatr/nitrobase/commit/44ee78eaf50d8529aa6362f6dfa13804081a0f7d)) by @AliMD
|
|
297
|
-
|
|
298
|
-
### Bug Fixes
|
|
299
|
-
|
|
300
|
-
* logger method name in CollectionReference and DocumentReference ([f84f288](https://github.com/Alwatr/nitrobase/commit/f84f288f906fdc707fdc7f49fd6159c1c270e1ec)) by @AliMD
|
|
301
|
-
|
|
302
|
-
### Code Refactoring
|
|
303
|
-
|
|
304
|
-
* **CollectionReference:** Rename `item__` method parameter from `id` to `itemId` ([c0cde18](https://github.com/Alwatr/nitrobase/commit/c0cde18b1ac456e29118132ee88c9f115cc44442)) by @AliMD
|
|
305
|
-
* **CollectionReference:** Rename `metaItem` method to `getItemMetadata` in CollectionReference ([3c9cfdb](https://github.com/Alwatr/nitrobase/commit/3c9cfdb741312aa626538a795f7980a140b12f6e)) by @AliMD
|
|
306
|
-
* **CollectionReference:** Rename `set` method to `update` in CollectionReference ([258d739](https://github.com/Alwatr/nitrobase/commit/258d739e2f00b4f2f548de6158dcdcbfdf6ddf63)) by @AliMD
|
|
307
|
-
* **CollectionReference:** Rename `update` method to `updatePartial` in CollectionReference ([d8a438a](https://github.com/Alwatr/nitrobase/commit/d8a438a5b9f5b3d9145ccb74ad980c4f22e40914)) by @AliMD
|
|
308
|
-
* **CollectionReference:** Rename `updateMeta_` method to `updateMetadata_` in CollectionReference ([815fd1d](https://github.com/Alwatr/nitrobase/commit/815fd1d3a301d60304c58117a64fc20a2ac9ef64)) by @AliMD
|
|
309
|
-
* **DocumentReference:** Rename `get` method to `getData` in DocumentReference ([0c3c37e](https://github.com/Alwatr/nitrobase/commit/0c3c37eb733a94bce78c532bac6167be312c6a9f)) by @AliMD
|
|
310
|
-
* **DocumentReference:** Rename `meta` method to `getStoreMetadata` in DocumentReference ([3bed92f](https://github.com/Alwatr/nitrobase/commit/3bed92f482444d048edfb369355a61f115a78b09)) by @AliMD
|
|
311
|
-
* **DocumentReference:** Rename `set` method to `update` in DocumentReference ([5467a66](https://github.com/Alwatr/nitrobase/commit/5467a66daddbd8976953aaac1a900abe67e9c4a3)) by @AliMD
|
|
312
|
-
* Rename `access_` method to `getItemContext_` ([76dd262](https://github.com/Alwatr/nitrobase/commit/76dd26210e4252ef536f304a43f83007d362af32)) by @AliMD
|
|
313
|
-
* Rename `create` method to `add` in CollectionReference ([0a0ee28](https://github.com/Alwatr/nitrobase/commit/0a0ee28b200173c615bb8835929e8baa7a0a5463)) by @AliMD
|
|
314
|
-
* Rename `delete` method to `remove` in CollectionReference ([017b315](https://github.com/Alwatr/nitrobase/commit/017b31591aa69078492f262ccb41b857b937994e)) by @AliMD
|
|
315
|
-
* Rename `get` method to `getItem` in CollectionReference ([846ccff](https://github.com/Alwatr/nitrobase/commit/846ccff9012e52d930771946b98a7dd93c82977c)) by @AliMD
|
|
316
|
-
* Rename `update` method to `updatePartial` in DocumentReference ([c16d164](https://github.com/Alwatr/nitrobase/commit/c16d164900954b7d51c516b5f7637e54b1fb8ab7)) by @AliMD
|
|
317
|
-
* update parameter name in CollectionReference.exists method ([bb06487](https://github.com/Alwatr/nitrobase/commit/bb06487a1fe94d84bf3ff7ba7c44ae5600b1d689)) by @AliMD
|
|
318
|
-
* update StoreFileStat type to make extension property optional ([e75a186](https://github.com/Alwatr/nitrobase/commit/e75a186fbafd30a3d745467a973bec06e1d8109e)) by @AliMD
|
|
319
|
-
|
|
320
|
-
### Dependencies update
|
|
321
|
-
|
|
322
|
-
* update ([2657638](https://github.com/Alwatr/nitrobase/commit/26576384c4a8ffcf35776f19008432e194fb39de)) by @AliMD
|
|
323
|
-
|
|
324
|
-
## [6.2.1](https://github.com/Alwatr/nitrobase/compare/v6.2.0...v6.2.1) (2024-08-31)
|
|
325
|
-
|
|
326
|
-
### Miscellaneous Chores
|
|
327
|
-
|
|
328
|
-
* **deps-dev:** bump the development-dependencies group across 1 directory with 13 updates ([7e6aa11](https://github.com/Alwatr/nitrobase/commit/7e6aa11e1b4507111993a6070b481ebc95e534c7)) by @dependabot[bot]
|
|
329
|
-
* **deps:** bump the alwatr-dependencies group with 10 updates ([faf1fc1](https://github.com/Alwatr/nitrobase/commit/faf1fc15f8b4c9c4c451dd5fa1d564eb3bf3d9a3)) by @dependabot[bot]
|
|
330
|
-
* **deps:** bump the alwatr-dependencies group with 9 updates ([64ac4f2](https://github.com/Alwatr/nitrobase/commit/64ac4f239c0f0a8ccdadbd736c16973bd684f811)) by @dependabot[bot]
|
|
331
|
-
|
|
332
|
-
## [6.2.0](https://github.com/Alwatr/nitrobase/compare/v6.1.0...v6.2.0) (2024-07-03)
|
|
333
|
-
|
|
334
|
-
### Features
|
|
335
|
-
|
|
336
|
-
* Add freeze property to CollectionReference and DocumentReference ([beeb378](https://github.com/Alwatr/nitrobase/commit/beeb37884f5798c3c3b6612dc0626c8cf9c44676)) by @AliMD
|
|
337
|
-
* Add saveImmediate method to CollectionReference and DocumentReference ([aa5ab87](https://github.com/Alwatr/nitrobase/commit/aa5ab871a5157dd70d55768843aeeab521258a49)) by @AliMD
|
|
338
|
-
* **schemaVer:** log schema version changes ([6a5bc90](https://github.com/Alwatr/nitrobase/commit/6a5bc9089cd509be141e1d9ee10f2cedc5490925)) by @AliMD
|
|
339
|
-
|
|
340
|
-
### Bug Fixes
|
|
341
|
-
|
|
342
|
-
* **schemaVer:** save after change schema version ([99cf345](https://github.com/Alwatr/nitrobase/commit/99cf345cfe34edef4f8af2c83157b894f9fb0be0)) by @AliMD
|
|
343
|
-
|
|
344
|
-
## [6.1.0](https://github.com/Alwatr/nitrobase/compare/v6.0.5...v6.1.0) (2024-07-03)
|
|
345
|
-
|
|
346
|
-
### Features
|
|
347
|
-
|
|
348
|
-
* schema version ([2590674](https://github.com/Alwatr/nitrobase/commit/259067435512b71f1f0aaea07566441cbb85e539)) by @AliMD
|
|
349
|
-
|
|
350
|
-
### Dependencies update
|
|
351
|
-
|
|
352
|
-
* bump the development-dependencies ([546ca1b](https://github.com/Alwatr/nitrobase/commit/546ca1be049090eb3c8304fcb75e98ac0b984510)) by @AliMD
|
|
353
|
-
|
|
354
|
-
## [6.0.5](https://github.com/Alwatr/nitrobase/compare/v6.0.4...v6.0.5) (2024-05-12)
|
|
355
|
-
|
|
356
|
-
### Miscellaneous Chores
|
|
357
|
-
|
|
358
|
-
* **deps-dev:** bump the development-dependencies group across 1 directory with 3 updates ([f97552d](https://github.com/Alwatr/nitrobase/commit/f97552d0e8e85bc2e2f0863da17502b8e55799e8)) by @dependabot[bot]
|
|
359
|
-
* **deps:** bump the alwatr-dependencies group with 8 updates ([1aa95ca](https://github.com/Alwatr/nitrobase/commit/1aa95ca232a7b706eda4b0eb537316d38b27aa28)) by @dependabot[bot]
|
|
360
|
-
|
|
361
|
-
## [6.0.4](https://github.com/Alwatr/nitrobase/compare/v6.0.3...v6.0.4) (2024-04-25)
|
|
362
|
-
|
|
363
|
-
### Bug Fixes
|
|
364
|
-
|
|
365
|
-
* **refrence:** set created meta to now ([9cacc0f](https://github.com/Alwatr/nitrobase/commit/9cacc0fc84743ccbb5a8a2581963545bb493c2bb)) by @njfamirm
|
|
366
|
-
|
|
367
|
-
## [6.0.3](https://github.com/Alwatr/nitrobase/compare/v6.0.2...v6.0.3) (2024-03-28)
|
|
368
|
-
|
|
369
|
-
### Miscellaneous Chores
|
|
370
|
-
|
|
371
|
-
* **deps-dev:** bump the development-dependencies group with 13 updates ([23fb121](https://github.com/Alwatr/nitrobase/commit/23fb1217470593d386b658f2a1d85fe4ef6e55df)) by @dependabot[bot]
|
|
372
|
-
* **deps:** bump the alwatr-dependencies group with 10 updates ([ce6ee74](https://github.com/Alwatr/nitrobase/commit/ce6ee7495aaa67a8d3bb0a3f2b2ea8389e161552)) by @dependabot[bot]
|
|
373
|
-
* **deps:** bump the alwatr-dependencies group with 9 updates ([686e155](https://github.com/Alwatr/nitrobase/commit/686e155d4c0ccab6daf81d280cf91299152b8583)) by @dependabot[bot]
|
|
374
|
-
|
|
375
|
-
## [6.0.0](https://github.com/Alwatr/nitrobase/compare/v6.0.0-alpha.0...v6.0.0) (2024-01-24)
|
|
376
|
-
|
|
377
|
-
### Features
|
|
378
|
-
|
|
379
|
-
* Enhance types, add Jsonifiable type and update method signatures ([57502d2](https://github.com/Alwatr/nitrobase/commit/57502d230f0c9cb88aa9a9e71a3460f1219955b0)) by @AliMD
|
|
380
|
-
|
|
381
|
-
### Miscellaneous Chores
|
|
382
|
-
|
|
383
|
-
* **deps-dev:** bump the development-dependencies group with 4 updates ([7d71044](https://github.com/Alwatr/nitrobase/commit/7d71044165583f9d56fb61a05bdf51ccb104f422)) by @dependabot[bot]
|
|
384
|
-
* **deps:** bump the alwatr-dependencies group with 10 updates ([cc42e89](https://github.com/Alwatr/nitrobase/commit/cc42e895179c53ee2dd60802d994ba84f5a37fde)) by @dependabot[bot]
|
|
385
|
-
* **deps:** update ([0e85743](https://github.com/Alwatr/nitrobase/commit/0e85743f76f0efdd0f6cd4001eebc4550b43f43f)) by @AliMD
|
|
386
|
-
* **deps:** update ([a894bfc](https://github.com/Alwatr/nitrobase/commit/a894bfc62124a3eb027cad4e8d1c974761e22dad)) by @AliMD
|
|
387
|
-
|
|
388
|
-
## [6.0.0-alpha.0](https://github.com/Alwatr/nitrobase/compare/v5.1.0...v6.0.0-alpha.0) (2024-01-15)
|
|
389
|
-
|
|
390
|
-
### Miscellaneous Chores
|
|
391
|
-
|
|
392
|
-
* **deps:** update ([8f3edcf](https://github.com/Alwatr/nitrobase/commit/8f3edcf8a489927a6c43dfcaa5db88a579ecac80)) by @
|
|
393
|
-
|
|
394
|
-
## [5.1.0](https://github.com/Alwatr/nitrobase/compare/v5.0.0...v5.1.0) (2024-01-13)
|
|
395
|
-
|
|
396
|
-
**Note:** Version bump only for package @alwatr/nitrobase-reference
|
|
397
|
-
|
|
398
|
-
# [5.0.0](https://github.com/Alwatr/nitrobase/compare/v5.0.0-beta...v5.0.0) (2024-01-12)
|
|
399
|
-
|
|
400
|
-
**Note:** Version bump only for package @alwatr/nitrobase-reference
|
|
401
|
-
|
|
402
|
-
# [5.0.0-beta](https://github.com/Alwatr/nitrobase/compare/v4.1.0...v5.0.0-beta) (2023-12-31)
|
|
403
|
-
|
|
404
|
-
### Bug Fixes
|
|
405
|
-
|
|
406
|
-
* **reference:** add types to deps ([23788e6](https://github.com/Alwatr/nitrobase/commit/23788e6cdcd8f26378896bcf469a1308d49300aa)) by @njfamirm
|
|
407
|
-
* **reference:** Refactor update delay logic in updated\_\_ to prevent data lost ([c7282fe](https://github.com/Alwatr/nitrobase/commit/c7282fe66685843aad4396461ab8c7060742683a)) by @AliMD
|
|
408
|
-
|
|
409
|
-
### Features
|
|
410
|
-
|
|
411
|
-
* **engine:** impediment exit hook ([68695a9](https://github.com/Alwatr/nitrobase/commit/68695a975e0ec6c473bbd2d9a62c81720f090352)) by @AliMD
|
|
412
|
-
* **reference:** add debugDomain ([83dd29a](https://github.com/Alwatr/nitrobase/commit/83dd29ad07e0a80ae1882f0a459402cf671708ef)) by @AliMD
|
|
413
|
-
* **reference:** Add hasUnprocessedChanges\_ flag to CollectionReference and DocumentReference ([dff3553](https://github.com/Alwatr/nitrobase/commit/dff35530732cce20d21337cb14df9b4ada9022b6)) by @AliMD
|
|
414
|
-
* **reference:** add immediate option to save methods ([9267cfd](https://github.com/Alwatr/nitrobase/commit/9267cfd13a19ab70cbf2857fe7160314d6a192d8)) by @AliMD
|
|
415
|
-
* **reference:** debounce for save file ([b40f9e9](https://github.com/Alwatr/nitrobase/commit/b40f9e9d4a2d2501471488b07266576a595380c3)) by @AliMD
|
|
416
|
-
* **reference:** enhance logging ([4eab5a2](https://github.com/Alwatr/nitrobase/commit/4eab5a277f1bf818fdba2e49ae3ecf0d7e68b4f7)) by @AliMD
|
|
417
|
-
* **reference:** Refactor save method to include debounce option and public updateMeta\_ ([d9abf84](https://github.com/Alwatr/nitrobase/commit/d9abf8415dbe8e189a6dcba3d837fbe2a0e3cdb0)) by @AliMD
|
package/dist/main.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/nitrobase-reference v7.10.1 */
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/nitrobase-reference v7.10.1");
|
|
3
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{CollectionReference:()=>CollectionReference,DocumentReference:()=>DocumentReference});module.exports=__toCommonJS(main_exports);var import_delay=require("@alwatr/delay");var import_logger2=require("@alwatr/logger");var import_nitrobase_helper=require("@alwatr/nitrobase-helper");var import_nitrobase_types=require("@alwatr/nitrobase-types");var import_logger=require("@alwatr/logger");var logger=(0,import_logger.createLogger)("@alwatr/nitrobase-reference");__dev_mode__:logger.logFileModule?.("collection-reference");var CollectionReference=class _CollectionReference{constructor(context__,updatedCallback__,debugDomain){this.context__=context__;this.updatedCallback__=updatedCallback__;this.hasUnprocessedChanges_=false;this._freeze=false;this.updateDelayed_=false;this.id=(0,import_nitrobase_helper.getStoreId)(this.context__.meta);this.path=(0,import_nitrobase_helper.getStorePath)(this.context__.meta);debugDomain??=this.id.slice(0,20);this.logger__=(0,import_logger2.createLogger)(`col:${debugDomain}`);this.logger__.logMethodArgs?.("new",{id:this.id});this.validateContext__()}static{this.version="7.10.1"}static{this.fileFormatVersion=3}static newRefFromData(stat,updatedCallback,debugDomain){logger.logMethodArgs?.("col.newRefFromData",stat);const now=Date.now();const initialContext={ok:true,meta:{...stat,rev:1,updated:now,created:now,lastAutoId:0,type:import_nitrobase_types.StoreFileType.Collection,extension:import_nitrobase_types.StoreFileExtension.Json,fv:_CollectionReference.fileFormatVersion,extra:{}},data:{}};return new _CollectionReference(initialContext,updatedCallback,debugDomain)}static newRefFromContext(context,updatedCallback,debugDomain){logger.logMethodArgs?.("col.newRefFromContext",context.meta);return new _CollectionReference(context,updatedCallback,debugDomain)}validateContext__(){this.logger__.logMethod?.("validateContext__");if(this.context__.ok!==true){this.logger__.accident?.("validateContext__","store_not_ok");throw new Error("store_not_ok",{cause:{context:this.context__}})}if(this.context__.meta===void 0){this.logger__.accident?.("validateContext__","store_meta_undefined");throw new Error("store_meta_undefined",{cause:{context:this.context__}})}if(this.context__.meta.type!==import_nitrobase_types.StoreFileType.Collection){this.logger__.accident?.("validateContext__","collection_type_invalid",this.context__.meta);throw new Error("collection_type_invalid",{cause:this.context__.meta})}if(this.context__.meta.fv!==_CollectionReference.fileFormatVersion){this.logger__.incident?.("validateContext__","store_file_version_incompatible",{old:this.context__.meta.fv,new:_CollectionReference.fileFormatVersion});this.migrateContext__()}}migrateContext__(){if(this.context__.meta.fv===_CollectionReference.fileFormatVersion)return;this.logger__.logMethod?.("migrateContext__");if(this.context__.meta.fv>_CollectionReference.fileFormatVersion){this.logger__.accident("migrateContext__","store_version_incompatible",this.context__.meta);throw new Error("store_version_incompatible",{cause:this.context__.meta})}if(this.context__.meta.fv===1){this.context__.meta.fv=2}if(this.context__.meta.fv===2){if(this.context__.meta.schemaVer===void 0||this.context__.meta.schemaVer===0){this.context__.meta.schemaVer=1}delete this.context__.meta["ver"];this.context__.meta.extra??={};this.context__.meta.fv=3}this.updated__()}get schemaVer(){return this.context__.meta.schemaVer??1}set schemaVer(ver){this.logger__.logMethodArgs?.("set schemaVer",{old:this.context__.meta.schemaVer,new:ver});this.context__.meta.schemaVer=ver;this.updated__()}get freeze(){return this._freeze}set freeze(value){this.logger__.logMethodArgs?.("freeze changed",{value});this._freeze=value}hasItem(itemId){const exists=Object.hasOwn(this.context__.data,itemId);this.logger__.logMethodFull?.("hasItem",itemId,exists);return exists}getStoreMeta(){this.logger__.logMethod?.("getStoreMeta");return this.context__.meta}item__(itemId){const item=this.context__.data[itemId];if(item===void 0){this.logger__.accident("item__","collection_item_not_found",{itemId});throw new Error("collection_item_not_found",{cause:{itemId}})}return item}getItemMeta(itemId){const meta=this.item__(itemId).meta;this.logger__.logMethodFull?.("getItemMeta",itemId,meta);return meta}getItemData(itemId){this.logger__.logMethodArgs?.("getItemData",itemId);return this.item__(itemId).data}getItemContext_(itemId){this.logger__.logMethodArgs?.("getItemContext_",itemId);return this.context__.data[itemId]}addItem(itemId,data){this.logger__.logMethodArgs?.("addItem",{itemId,data});if(this.hasItem(itemId)){this.logger__.accident("addItem","collection_item_exist",{itemId});throw new Error("collection_item_exist",{cause:{itemId}})}const now=Date.now();this.context__.data[itemId]={meta:{id:itemId,rev:0,created:now,updated:now},data};this.updated__(itemId)}appendItem(data){this.logger__.logMethodArgs?.("appendItem",data);const id=this.nextAutoIncrementId__();this.addItem(id,data);return id}removeItem(itemId){this.logger__.logMethodArgs?.("removeItem",itemId);delete this.context__.data[itemId];this.updated__()}replaceItemData(itemId,data){this.logger__.logMethodArgs?.("replaceItemData",{itemId,data});this.item__(itemId).data=data;this.updated__(itemId)}mergeItemData(itemId,data){this.logger__.logMethodArgs?.("mergeItemData",{itemId,data});Object.assign(this.item__(itemId).data,data);this.updated__(itemId)}save(itemId){this.logger__.logMethod?.("save");this.updated__(itemId,false)}saveImmediate(itemId){this.logger__.logMethod?.("saveImmediate");this.updated__(itemId,true)}keys(){this.logger__.logMethod?.("keys");return Object.keys(this.context__.data)}values(){this.logger__.logMethod?.("values");return Object.values(this.context__.data)}*ids(){this.logger__.logMethod?.("ids");for(const id in this.context__.data){yield id}}*items(){this.logger__.logMethod?.("items");for(const id in this.context__.data){yield this.context__.data[id]}}getFullContext_(){this.logger__.logMethod?.("getFullContext_");return this.context__}async updated__(itemId=null,immediate=false){this.logger__.logMethodArgs?.("updated__",{id:itemId,immediate,delayed:this.updateDelayed_});this.hasUnprocessedChanges_=true;if(itemId!==null)this.refreshMeta_(itemId);if(immediate===false&&this.updateDelayed_===true)return;this.updateDelayed_=true;if(immediate===true||this.context__.meta.changeDebounce===void 0){await import_delay.delay.nextMacrotask()}else{await import_delay.delay.by(this.context__.meta.changeDebounce)}if(this.updateDelayed_!==true)return;this.updateDelayed_=false;if(itemId===null)this.refreshMeta_(itemId);if(this._freeze===true)return;this.updatedCallback__(this)}refreshMeta_(itemId){this.logger__.logMethodArgs?.("refreshMeta_",{id:itemId});const now=Date.now();this.context__.meta.rev++;this.context__.meta.updated=now;if(itemId!==null){const itemMeta=this.item__(itemId).meta;itemMeta.rev++;itemMeta.updated=now}}nextAutoIncrementId__(){this.logger__.logMethod?.("nextAutoIncrementId__");const meta=this.context__.meta;do{meta.lastAutoId++}while(meta.lastAutoId in this.context__.data);return meta.lastAutoId}getExtraMeta(){this.logger__.logMethod?.("getExtraMeta");return this.context__.meta.extra}replaceExtraMeta(extraMeta){this.logger__.logMethodArgs?.("replaceExtraMeta",extraMeta);this.context__.meta.extra=extraMeta;this.updated__()}mergeExtraMeta(extraMeta){this.logger__.logMethodArgs?.("mergeExtraMeta",extraMeta);Object.assign(this.context__.meta.extra,extraMeta);this.updated__()}};var import_delay2=require("@alwatr/delay");var import_logger4=require("@alwatr/logger");var import_nitrobase_helper2=require("@alwatr/nitrobase-helper");var import_nitrobase_types2=require("@alwatr/nitrobase-types");__dev_mode__:logger.logFileModule?.("document-reference");var DocumentReference=class _DocumentReference{constructor(context__,updatedCallback__,debugDomain){this.context__=context__;this.updatedCallback__=updatedCallback__;this.hasUnprocessedChanges_=false;this._freeze=false;this.updateDelayed_=false;this.id=(0,import_nitrobase_helper2.getStoreId)(this.context__.meta);this.path=(0,import_nitrobase_helper2.getStorePath)(this.context__.meta);debugDomain??=this.id.slice(0,20);this.logger__=(0,import_logger4.createLogger)(`doc:${debugDomain}`);this.logger__.logMethodArgs?.("new",{path:this.path});this.validateContext__()}static{this.version="7.10.1"}static{this.fileFormatVersion=3}static newRefFromData(statId,data,updatedCallback,debugDomain){logger.logMethodArgs?.("doc.newRefFromData",statId);const now=Date.now();const initialContext={ok:true,meta:{...statId,rev:1,updated:now,created:now,type:import_nitrobase_types2.StoreFileType.Document,extension:import_nitrobase_types2.StoreFileExtension.Json,fv:_DocumentReference.fileFormatVersion,extra:{}},data};return new _DocumentReference(initialContext,updatedCallback,debugDomain)}static newRefFromContext(context,updatedCallback,debugDomain){logger.logMethodArgs?.("doc.newRefFromContext",context.meta);return new _DocumentReference(context,updatedCallback,debugDomain)}validateContext__(){this.logger__.logMethod?.("validateContext__");if(this.context__.ok!==true){this.logger__.accident?.("validateContext__","store_not_ok");throw new Error("store_not_ok",{cause:{context:this.context__}})}if(this.context__.meta===void 0){this.logger__.accident?.("validateContext__","store_meta_undefined");throw new Error("store_meta_undefined",{cause:{context:this.context__}})}if(this.context__.meta.type!==import_nitrobase_types2.StoreFileType.Document){this.logger__.accident?.("validateContext__","document_type_invalid",this.context__.meta);throw new Error("document_type_invalid",{cause:this.context__.meta})}if(this.context__.meta.fv!==_DocumentReference.fileFormatVersion){this.logger__.incident?.("validateContext__","store_file_version_incompatible",{old:this.context__.meta.fv,new:_DocumentReference.fileFormatVersion});this.migrateContext__()}}migrateContext__(){if(this.context__.meta.fv===_DocumentReference.fileFormatVersion)return;this.logger__.logMethod?.("migrateContext__");if(this.context__.meta.fv>_DocumentReference.fileFormatVersion){this.logger__.accident("migrateContext__","store_version_incompatible",this.context__.meta);throw new Error("store_version_incompatible",{cause:this.context__.meta})}if(this.context__.meta.fv===1){this.context__.meta.fv=2}if(this.context__.meta.fv===2){if(this.context__.meta.schemaVer===void 0||this.context__.meta.schemaVer===0){this.context__.meta.schemaVer=1}delete this.context__.meta["ver"];this.context__.meta.extra??={};this.context__.meta.fv=3}this.updated__()}get schemaVer(){return this.context__.meta.schemaVer??1}set schemaVer(ver){this.logger__.logMethodArgs?.("set schemaVer",{old:this.context__.meta.schemaVer,new:ver});this.context__.meta.schemaVer=ver;this.updated__()}get freeze(){return this._freeze}set freeze(value){this.logger__.logMethodArgs?.("freeze changed",{value});this._freeze=value}getData(){this.logger__.logMethod?.("getData");return this.context__.data}getStoreMeta(){this.logger__.logMethod?.("getStoreMeta");return this.context__.meta}replaceData(data){this.logger__.logMethodArgs?.("replaceData",data);this.context__.data=data;this.updated__()}mergeData(data){this.logger__.logMethodArgs?.("mergeData",data);Object.assign(this.context__.data,data);this.updated__()}save(){this.logger__.logMethod?.("save");this.updated__()}saveImmediate(){this.logger__.logMethod?.("saveImmediate");this.updated__(true)}getFullContext_(){this.logger__.logMethod?.("getFullContext_");return this.context__}async updated__(immediate=false){this.logger__.logMethodArgs?.("updated__",{immediate,delayed:this.updateDelayed_});this.hasUnprocessedChanges_=true;if(immediate!==true&&this.updateDelayed_===true)return;this.updateDelayed_=true;if(immediate===true||this.context__.meta.changeDebounce===void 0){await import_delay2.delay.nextMacrotask()}else{await import_delay2.delay.by(this.context__.meta.changeDebounce)}if(this.updateDelayed_!==true)return;this.updateDelayed_=false;this.refreshMetadata_();if(this._freeze===true)return;this.updatedCallback__(this)}refreshMetadata_(){this.logger__.logMethod?.("refreshMetadata_");this.context__.meta.updated=Date.now();this.context__.meta.rev++}getExtraMeta(){this.logger__.logMethod?.("getExtraMeta");return this.context__.meta.extra}replaceExtraMeta(extraMeta){this.logger__.logMethodArgs?.("replaceExtraMeta",extraMeta);this.context__.meta.extra=extraMeta;this.updated__()}mergeExtraMeta(extraMeta){this.logger__.logMethodArgs?.("mergeExtraMeta",extraMeta);Object.assign(this.context__.meta.extra,extraMeta);this.updated__()}};0&&(module.exports={CollectionReference,DocumentReference});
|
|
4
|
-
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts", "../src/collection-reference.ts", "../src/logger.ts", "../src/document-reference.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './collection-reference.js';\nexport * from './document-reference.js';\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\nimport {getStoreId, getStorePath} from '@alwatr/nitrobase-helper';\nimport {\n StoreFileType,\n StoreFileExtension,\n type StoreFileId,\n type CollectionContext,\n type CollectionItem,\n type CollectionItemMeta,\n type StoreFileMeta,\n} from '@alwatr/nitrobase-types';\n\nimport {logger} from './logger.js';\n\n__dev_mode__: logger.logFileModule?.('collection-reference');\n\n/**\n * Represents a reference to a collection of the AlwatrNitrobase.\n * Provides methods to interact with the collection, such as retrieving, creating, updating, and deleting items.\n *\n * @template TItem - The data type of the collection items.\n */\nexport class CollectionReference<TItem extends JsonObject = JsonObject> {\n /**\n * Alwatr nitrobase engine version string.\n */\n public static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n public static readonly fileFormatVersion = 3;\n\n /**\n * Creates new CollectionReference instance from stat.\n *\n * @param stat the collection stat.\n * @param initialData the collection data.\n * @param updatedCallback the callback to invoke when the collection changed.\n * @template TItem The collection item data type.\n * @returns A new collection reference class.\n */\n public static newRefFromData<TItem extends JsonObject>(\n stat: StoreFileId,\n updatedCallback: (from: CollectionReference<TItem>) => void,\n debugDomain?: string,\n ): CollectionReference<TItem> {\n logger.logMethodArgs?.('col.newRefFromData', stat);\n\n const now = Date.now();\n const initialContext: CollectionContext<TItem> = {\n ok: true,\n meta: {\n ...stat,\n rev: 1,\n updated: now,\n created: now,\n lastAutoId: 0,\n type: StoreFileType.Collection,\n extension: StoreFileExtension.Json,\n fv: CollectionReference.fileFormatVersion,\n extra: {},\n },\n data: {},\n };\n\n return new CollectionReference(initialContext, updatedCallback, debugDomain);\n }\n\n /**\n * Creates new CollectionReference instance from CollectionContext.\n *\n * @param context the collection context.\n * @param updatedCallback the callback to invoke when the collection changed.\n * @template TItem The collection item data type.\n * @returns A new collection reference class.\n */\n public static newRefFromContext<TItem extends JsonObject>(\n context: CollectionContext<TItem>,\n updatedCallback: (from: CollectionReference<TItem>) => void,\n debugDomain?: string,\n ): CollectionReference<TItem> {\n logger.logMethodArgs?.('col.newRefFromContext', context.meta);\n return new CollectionReference(context, updatedCallback, debugDomain);\n }\n\n /**\n * Validates the collection context and try to migrate it to the latest version.\n */\n private validateContext__(): void {\n this.logger__.logMethod?.('validateContext__');\n\n if (this.context__.ok !== true) {\n this.logger__.accident?.('validateContext__', 'store_not_ok');\n throw new Error('store_not_ok', {cause: {context: this.context__}});\n }\n\n if (this.context__.meta === undefined) {\n this.logger__.accident?.('validateContext__', 'store_meta_undefined');\n throw new Error('store_meta_undefined', {cause: {context: this.context__}});\n }\n\n if (this.context__.meta.type !== StoreFileType.Collection) {\n this.logger__.accident?.('validateContext__', 'collection_type_invalid', this.context__.meta);\n throw new Error('collection_type_invalid', {cause: this.context__.meta});\n }\n\n if (this.context__.meta.fv !== CollectionReference.fileFormatVersion) {\n this.logger__.incident?.('validateContext__', 'store_file_version_incompatible', {\n old: this.context__.meta.fv,\n new: CollectionReference.fileFormatVersion,\n });\n this.migrateContext__();\n }\n }\n\n /**\n * Migrate the collection context to the latest.\n */\n private migrateContext__(): void {\n if (this.context__.meta.fv === CollectionReference.fileFormatVersion) return;\n\n this.logger__.logMethod?.('migrateContext__');\n\n if (this.context__.meta.fv > CollectionReference.fileFormatVersion) {\n this.logger__.accident('migrateContext__', 'store_version_incompatible', this.context__.meta);\n throw new Error('store_version_incompatible', {cause: this.context__.meta});\n }\n\n if (this.context__.meta.fv === 1) {\n // migrate from v1 to v2\n // this.context__.meta.schemaVer = 0\n this.context__.meta.fv = 2;\n }\n\n if (this.context__.meta.fv === 2) {\n // migrate from v1 to v3\n if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {\n this.context__.meta.schemaVer = 1;\n }\n delete (this.context__.meta as DictionaryOpt)['ver'];\n this.context__.meta.extra ??= {};\n this.context__.meta.fv = 3;\n }\n\n this.updated__();\n }\n\n /**\n * The ID of the collection nitrobase file.\n */\n public readonly id: string;\n\n /**\n * The location path of the collection nitrobase file.\n */\n public readonly path: string;\n\n /**\n * Indicates whether the collection has unsaved changes.\n */\n public hasUnprocessedChanges_ = false;\n\n /**\n * Logger instance for this collection.\n */\n private logger__;\n\n /**\n * Collection reference have methods to get, set, update and save the Alwatr Nitrobase Collection.\n * This class is dummy in saving and loading the collection from file.\n * It's the responsibility of the Alwatr Nitrobase to save and load the collection.\n *\n * @param context__ Collection's context filled from the Alwatr Nitrobase (parent).\n * @param updatedCallback__ updated callback to invoke when the collection is updated from the Alwatr Nitrobase (parent).\n * @template TItem - Items data type.\n * @example\n * ```typescript\n * const collectionRef = alwatrStore.col('blog/posts');\n * ```\n */\n constructor(\n private context__: CollectionContext<TItem>,\n private updatedCallback__: (from: CollectionReference<TItem>) => void,\n debugDomain?: string,\n ) {\n this.id = getStoreId(this.context__.meta);\n this.path = getStorePath(this.context__.meta);\n\n debugDomain ??= this.id.slice(0, 20);\n this.logger__ = createLogger(`col:${debugDomain}`);\n\n this.logger__.logMethodArgs?.('new', {id: this.id});\n\n this.validateContext__();\n }\n\n /**\n * Get nitrobase schema version\n *\n * @returns nitrobase schema version\n */\n public get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n public set schemaVer(ver: number) {\n this.logger__.logMethodArgs?.('set schemaVer', {old: this.context__.meta.schemaVer, new: ver});\n this.context__.meta.schemaVer = ver;\n this.updated__();\n }\n\n /**\n * Indicates whether the collection data is frozen and cannot be saved.\n */\n private _freeze = false;\n\n /**\n * Gets the freeze status of the collection data.\n *\n * @returns `true` if the collection data is frozen, `false` otherwise.\n *\n * @example\n * ```typescript\n * const isFrozen = collectionRef.freeze;\n * console.log(isFrozen); // Output: false\n * ```\n */\n public get freeze(): boolean {\n return this._freeze;\n }\n\n /**\n * Sets the freeze status of the collection data.\n *\n * @param value - The freeze status to set.\n *\n * @example\n * ```typescript\n * collectionRef.freeze = true;\n * console.log(collectionRef.freeze); // Output: true\n * ```\n */\n public set freeze(value: boolean) {\n this.logger__.logMethodArgs?.('freeze changed', {value});\n this._freeze = value;\n }\n\n /**\n * Checks if an item exists in the collection.\n *\n * @param itemId - The ID of the item.\n * @returns `true` if the item with the given ID exists in the collection, `false` otherwise.\n *\n * @example\n * ```typescript\n * const doesExist = collectionRef.hasItem('item1');\n *\n * if (doesExist) {\n * collectionRef.addItem('item1', { key: 'value' });\n * }\n * ```\n */\n public hasItem(itemId: string | number): boolean {\n const exists = Object.hasOwn(this.context__.data, itemId);\n this.logger__.logMethodFull?.('hasItem', itemId, exists);\n return exists;\n }\n\n /**\n * Retrieves the metadata of the nitrobase file.\n *\n * @returns The metadata of the nitrobase file.\n *\n * @example\n * ```typescript\n * const metadata = collectionRef.getStoreMeta();\n * ```\n */\n public getStoreMeta(): Readonly<StoreFileMeta> {\n this.logger__.logMethod?.('getStoreMeta');\n return this.context__.meta;\n }\n\n /**\n * Retrieves an item from the collection. If the item does not exist, an error is thrown.\n *\n * @param itemId - The ID of the item.\n * @returns The item with the given ID.\n */\n private item__(itemId: string | number): CollectionItem<TItem> {\n const item = this.context__.data[itemId];\n if (item === undefined) {\n this.logger__.accident('item__', 'collection_item_not_found', {itemId});\n throw new Error('collection_item_not_found', {cause: {itemId}});\n }\n return item;\n }\n\n /**\n * Retrieves an item's metadata from the collection. If the item does not exist, an error is thrown.\n *\n * @param itemId - The ID of the item.\n * @returns The metadata of the item with the given ID.\n * @example\n * ```typescript\n * const itemMeta = collectionRef.getItemMeta('item1');\n * ```\n */\n public getItemMeta(itemId: string | number): Readonly<CollectionItemMeta> {\n const meta = this.item__(itemId).meta;\n this.logger__.logMethodFull?.('getItemMeta', itemId, meta);\n return meta;\n }\n\n /**\n * Retrieves an item's data from the collection. If the item does not exist, an error is thrown.\n *\n * @param itemId - The ID of the item.\n * @returns The data of the item with the given ID.\n *\n * @example\n * ```typescript\n * const itemData = collectionRef.getItemData('item1');\n * ```\n */\n public getItemData(itemId: string | number): TItem {\n this.logger__.logMethodArgs?.('getItemData', itemId);\n return this.item__(itemId).data;\n }\n\n /**\n * Direct access to an item.\n * If the item does not exist, `undefined` is returned.\n * **USE WITH CAUTION!**\n *\n * @param itemId - The ID of the item.\n * @returns The data of the item with the given ID or `undefined` if the item does not exist.\n *\n * @example\n * ```typescript\n * collectionRef.getItemContext_('item1')?.data.name = 'test2';\n * ```\n */\n public getItemContext_(itemId: string | number): CollectionItem<TItem> | undefined {\n this.logger__.logMethodArgs?.('getItemContext_', itemId);\n return this.context__.data[itemId];\n }\n\n /**\n * Add a new item to the collection.\n * If an item with the given ID already exists, an error is thrown.\n *\n * @param itemId - The ID of the item to create.\n * @param data - The initial data of the item.\n *\n * @example\n * ```typescript\n * collectionRef.addItem('item1', { key: 'value' });\n * ```\n */\n public addItem(itemId: string | number, data: TItem): void {\n this.logger__.logMethodArgs?.('addItem', {itemId, data});\n if (this.hasItem(itemId)) {\n this.logger__.accident('addItem', 'collection_item_exist', {itemId});\n throw new Error('collection_item_exist', {cause: {itemId}});\n }\n\n const now = Date.now();\n\n this.context__.data[itemId] = {\n meta: {\n id: itemId,\n // other prop calc in updateMeta__\n rev: 0,\n created: now,\n updated: now,\n },\n data,\n };\n this.updated__(itemId);\n }\n\n /**\n * Appends the given data to the collection with auto increment ID.\n *\n * @param data - The data to append.\n * @returns The ID of the appended item.\n *\n * @example\n * ```typescript\n * const newId = collectionRef.appendItem({ key: 'value' });\n * ```\n */\n public appendItem(data: TItem): string | number {\n this.logger__.logMethodArgs?.('appendItem', data);\n const id = this.nextAutoIncrementId__();\n this.addItem(id, data);\n return id;\n }\n\n /**\n * Removes an item from the collection.\n *\n * @param itemId - The ID of the item to delete.\n *\n * @example\n * ```typescript\n * collectionRef.removeItem('item1');\n * collectionRef.hasItem('item1'); // Output: false\n * ```\n */\n public removeItem(itemId: string | number): void {\n this.logger__.logMethodArgs?.('removeItem', itemId);\n delete this.context__.data[itemId];\n this.updated__();\n }\n\n /**\n * Sets an item's data in the collection. Replaces the item's data with the given data.\n *\n * @param itemId - The ID of the item to set.\n * @param data - The data to set for the item.\n *\n * @example\n * ```typescript\n * collectionRef.replaceItemData('item1', { a: 1, b: 2, c: 3 });\n * ```\n */\n public replaceItemData(itemId: string | number, data: TItem): void {\n this.logger__.logMethodArgs?.('replaceItemData', {itemId, data});\n (this.item__(itemId).data as unknown) = data;\n this.updated__(itemId);\n }\n\n /**\n * Updates an item in the collection by merging a partial update into the item's data.\n *\n * @param itemId - The ID of the item to update.\n * @param data - The part of data to merge into the item's data.\n *\n * @example\n * ```typescript\n * collectionRef.mergeItemData(itemId, partialUpdate);\n * ```\n */\n public mergeItemData(itemId: string | number, data: Partial<TItem>): void {\n this.logger__.logMethodArgs?.('mergeItemData', {itemId, data});\n Object.assign(this.item__(itemId).data, data);\n this.updated__(itemId);\n }\n\n /**\n * Requests the Alwatr Nitrobase to save the collection.\n * Saving may take some time in Alwatr Nitrobase due to the use of throttling.\n *\n * @example\n * ```typescript\n * collectionRef.save();\n * ```\n */\n public save(itemId: string | number | null): void {\n this.logger__.logMethod?.('save');\n this.updated__(itemId, false);\n }\n\n /**\n * Requests the Alwatr Nitrobase to save the collection immediately.\n *\n * @example\n * ```typescript\n * collectionRef.saveImmediate();\n * ```\n */\n public saveImmediate(itemId: string | number | null): void {\n this.logger__.logMethod?.('saveImmediate');\n this.updated__(itemId, true);\n }\n\n /**\n * Retrieves the IDs of all items in the collection in array.\n * Impact performance if the collection is large, use `ids()` instead.\n *\n * @returns Array of IDs of all items in the collection.\n * @example\n * ```typescript\n * const ids = collectionRef.keys();\n * ```\n */\n public keys(): string[] {\n this.logger__.logMethod?.('keys');\n return Object.keys(this.context__.data);\n }\n\n /**\n * Retrieves all items in the collection in array.\n * Impact performance if the collection is large, use `items()` instead.\n *\n * @returns Array of all items in the collection.\n * @example\n * ```typescript\n * const items = collectionRef.values();\n * console.log('meta: %o', items[0].meta);\n * console.log('data: %o', items[0].data);\n * ```\n */\n public values(): CollectionItem<TItem>[] {\n this.logger__.logMethod?.('values');\n return Object.values(this.context__.data);\n }\n\n /**\n * Retrieves the IDs of all items in the collection.\n * Use this method instead of `keys()` if the collection is large.\n * This method is a generator and can be used in `for...of` loops.\n * @returns Generator of IDs of all items in the collection.\n * @example\n * ```typescript\n * for (const id of collectionRef.ids()) {\n * const doc = collectionRef.get(id);\n * }\n * ```\n */\n public *ids(): Generator<string, void, void> {\n this.logger__.logMethod?.('ids');\n for (const id in this.context__.data) {\n yield id;\n }\n }\n\n /**\n * Retrieves all items in the collection.\n * Use this method instead of `values()` if the collection is large.\n * This method is a generator and can be used in `for...of` loops.\n * @returns Generator of all items in the collection.\n * @example\n * ```typescript\n * for (const item of collectionRef.items()) {\n * console.log(item.data);\n * }\n */\n public *items(): Generator<CollectionItem<TItem>, void, void> {\n this.logger__.logMethod?.('items');\n for (const id in this.context__.data) {\n yield this.context__.data[id];\n }\n }\n\n /**\n * Retrieves the full context of the collection.\n *\n * @returns The full context of the collection.\n *\n * @example\n * ```typescript\n * const context = collectionRef.getFullContext_();\n * ```\n */\n public getFullContext_(): Readonly<CollectionContext<TItem>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n public updateDelayed_ = false;\n\n /**\n * Update the document metadata and invoke the updated callback.\n * This method is throttled to prevent multiple updates in a short time.\n *\n * @param itemId - The ID of the item to update.\n */\n private async updated__(itemId: string | number | null = null, immediate = false): Promise<void> {\n this.logger__.logMethodArgs?.('updated__', {id: itemId, immediate, delayed: this.updateDelayed_});\n\n this.hasUnprocessedChanges_ = true;\n if (itemId !== null) this.refreshMeta_(itemId); // meta must updated per item\n\n if (immediate === false && this.updateDelayed_ === true) return;\n // else\n\n this.updateDelayed_ = true;\n\n if (immediate === true || this.context__.meta.changeDebounce === undefined) {\n await delay.nextMacrotask();\n }\n else {\n await delay.by(this.context__.meta.changeDebounce);\n }\n\n if (this.updateDelayed_ !== true) return; // another parallel update finished!\n this.updateDelayed_ = false;\n\n if (itemId === null) this.refreshMeta_(itemId); // root meta not updated for null\n\n if (this._freeze === true) return; // prevent save if frozen\n this.updatedCallback__(this);\n }\n\n /**\n * Refresh/recalculate the collection's metadata timestamp and revision.\n *\n * @param itemId - The ID of the item to update.\n */\n protected refreshMeta_(itemId: string | number | null): void {\n this.logger__.logMethodArgs?.('refreshMeta_', {id: itemId});\n const now = Date.now();\n this.context__.meta.rev++;\n this.context__.meta.updated = now;\n if (itemId !== null) {\n const itemMeta = this.item__(itemId).meta;\n itemMeta.rev++;\n itemMeta.updated = now;\n }\n }\n\n /**\n * Generates the next auto increment ID.\n *\n * @returns The next auto increment ID.\n * @example\n * ```typescript\n * const nextId = this.nextAutoIncrementId_();\n * ```\n */\n private nextAutoIncrementId__(): number {\n this.logger__.logMethod?.('nextAutoIncrementId__');\n const meta = this.context__.meta as Required<StoreFileMeta>;\n do {\n meta.lastAutoId++;\n } while (meta.lastAutoId in this.context__.data);\n return meta.lastAutoId;\n }\n\n /**\n * Retrieves the collection's extra metadata.\n *\n * @returns The collection's extra metadata.\n *\n * @example\n * ```typescript\n * const colExtraMeta = collectionRef.getExtraMeta();\n * ```\n */\n public getExtraMeta<T extends JsonObject>(): T {\n this.logger__.logMethod?.('getExtraMeta');\n return this.context__.meta.extra as T;\n }\n\n /**\n * Sets/replace the collection's extra metadata.\n *\n * @param extraMeta The new collection's extra metadata.\n *\n * @example\n * ```typescript\n * collectionRef.replaceExtraMeta({ a: 1, b: 2, c: 3 });\n * ```\n */\n public replaceExtraMeta<T extends JsonObject>(extraMeta: T): void {\n this.logger__.logMethodArgs?.('replaceExtraMeta', extraMeta);\n this.context__.meta.extra = extraMeta;\n this.updated__();\n }\n\n /**\n * Updates collection's extra metadata by merging a partial update.\n *\n * @param extraMeta The part of extra metadata to merge into the collection's extra metadata.\n *\n * @example\n * ```typescript\n * collectionRef.mergeExtraMeta({ c: 4 });\n * ```\n */\n public mergeExtraMeta<T extends JsonObject>(extraMeta: Partial<T>): void {\n this.logger__.logMethodArgs?.('mergeExtraMeta', extraMeta);\n Object.assign(this.context__.meta.extra, extraMeta);\n this.updated__();\n }\n}\n", "import {createLogger} from '@alwatr/logger';\n\nimport type {} from '@alwatr/nanolib';\nimport type {} from '@alwatr/type-helper';\n\nexport const logger = /* #__PURE__ */ createLogger(__package_name__);\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\nimport {getStoreId, getStorePath} from '@alwatr/nitrobase-helper';\nimport {StoreFileType, StoreFileExtension, type StoreFileId, type DocumentContext, type StoreFileMeta} from '@alwatr/nitrobase-types';\n\nimport {logger} from './logger.js';\n\n__dev_mode__: logger.logFileModule?.('document-reference');\n\n/**\n * Represents a reference to a document of the AlwatrNitrobase.\n * Provides methods to interact with the document, such as get, set, update and save.\n */\nexport class DocumentReference<TDoc extends JsonObject = JsonObject> {\n /**\n * Alwatr nitrobase engine version string.\n */\n public static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n public static readonly fileFormatVersion = 3;\n\n /**\n * Creates new DocumentReference instance from stat and initial data.\n *\n * @param statId the document stat.\n * @param data the document data.\n * @param updatedCallback the callback to invoke when the document changed.\n * @template TDoc The document data type.\n * @returns A new document reference class.\n */\n public static newRefFromData<TDoc extends JsonObject>(\n statId: StoreFileId,\n data: TDoc,\n updatedCallback: (from: DocumentReference<TDoc>) => unknown,\n debugDomain?: string,\n ): DocumentReference<TDoc> {\n logger.logMethodArgs?.('doc.newRefFromData', statId);\n\n const now = Date.now();\n const initialContext: DocumentContext<TDoc> = {\n ok: true,\n meta: {\n ...statId,\n rev: 1,\n updated: now,\n created: now,\n type: StoreFileType.Document,\n extension: StoreFileExtension.Json,\n fv: DocumentReference.fileFormatVersion,\n extra: {},\n },\n data,\n };\n\n return new DocumentReference(initialContext, updatedCallback, debugDomain);\n }\n\n /**\n * Creates new DocumentReference instance from DocumentContext.\n *\n * @param context the document context.\n * @param updatedCallback the callback to invoke when the document changed.\n * @template TDoc The document data type.\n * @returns A new document reference class.\n */\n public static newRefFromContext<TDoc extends JsonObject>(\n context: DocumentContext<TDoc>,\n updatedCallback: (from: DocumentReference<TDoc>) => unknown,\n debugDomain?: string,\n ): DocumentReference<TDoc> {\n logger.logMethodArgs?.('doc.newRefFromContext', context.meta);\n return new DocumentReference(context, updatedCallback, debugDomain);\n }\n\n /**\n * Validates the document context and try to migrate it to the latest version.\n */\n private validateContext__(): void {\n this.logger__.logMethod?.('validateContext__');\n\n if (this.context__.ok !== true) {\n this.logger__.accident?.('validateContext__', 'store_not_ok');\n throw new Error('store_not_ok', {cause: {context: this.context__}});\n }\n\n if (this.context__.meta === undefined) {\n this.logger__.accident?.('validateContext__', 'store_meta_undefined');\n throw new Error('store_meta_undefined', {cause: {context: this.context__}});\n }\n\n if (this.context__.meta.type !== StoreFileType.Document) {\n this.logger__.accident?.('validateContext__', 'document_type_invalid', this.context__.meta);\n throw new Error('document_type_invalid', {cause: this.context__.meta});\n }\n\n if (this.context__.meta.fv !== DocumentReference.fileFormatVersion) {\n this.logger__.incident?.('validateContext__', 'store_file_version_incompatible', {\n old: this.context__.meta.fv,\n new: DocumentReference.fileFormatVersion,\n });\n this.migrateContext__();\n }\n }\n\n /**\n * Migrate the document context to the latest.\n */\n private migrateContext__(): void {\n if (this.context__.meta.fv === DocumentReference.fileFormatVersion) return;\n\n this.logger__.logMethod?.('migrateContext__');\n\n if (this.context__.meta.fv > DocumentReference.fileFormatVersion) {\n this.logger__.accident('migrateContext__', 'store_version_incompatible', this.context__.meta);\n throw new Error('store_version_incompatible', {cause: this.context__.meta});\n }\n\n if (this.context__.meta.fv === 1) {\n // migrate from v1 to v2\n // this.context__.meta.schemaVer = 0\n this.context__.meta.fv = 2;\n }\n\n if (this.context__.meta.fv === 2) {\n // migrate from v1 to v3\n if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {\n this.context__.meta.schemaVer = 1;\n }\n delete (this.context__.meta as DictionaryOpt)['ver'];\n this.context__.meta.extra ??= {};\n this.context__.meta.fv = 3;\n }\n\n this.updated__();\n }\n\n /**\n * The ID of the document nitrobase file.\n */\n public readonly id: string;\n\n /**\n * The location path of the document nitrobase file.\n */\n public readonly path: string;\n\n /**\n * Indicates whether the document has unsaved changes.\n */\n public hasUnprocessedChanges_ = false;\n\n /**\n * Logger instance for this document.\n */\n private logger__;\n\n /**\n * Create a new document reference.\n * Document reference have methods to get, set, update and save the AlwatrNitrobase Document.\n *\n * @param context__ Document's context filled from the Alwatr Nitrobase (parent).\n * @param updatedCallback__ updated callback to invoke when the document is updated from the Alwatr Nitrobase (parent).\n * @template TDoc The document data type.\n */\n constructor(\n private readonly context__: DocumentContext<TDoc>,\n private readonly updatedCallback__: (from: DocumentReference<TDoc>) => unknown,\n debugDomain?: string,\n ) {\n this.id = getStoreId(this.context__.meta);\n this.path = getStorePath(this.context__.meta);\n\n debugDomain ??= this.id.slice(0, 20);\n this.logger__ = createLogger(`doc:${debugDomain}`);\n\n this.logger__.logMethodArgs?.('new', {path: this.path});\n\n this.validateContext__();\n }\n\n /**\n * Get nitrobase schema version\n *\n * @returns nitrobase schema version\n */\n public get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n public set schemaVer(ver: number) {\n this.logger__.logMethodArgs?.('set schemaVer', {old: this.context__.meta.schemaVer, new: ver});\n this.context__.meta.schemaVer = ver;\n this.updated__();\n }\n\n /**\n * Indicates whether the document data is frozen and cannot be saved.\n */\n private _freeze = false;\n\n /**\n * Gets the freeze status of the document data.\n *\n * @returns `true` if the document data is frozen, `false` otherwise.\n *\n * @example\n * ```typescript\n * const isFrozen = documentRef.freeze;\n * console.log(isFrozen); // Output: false\n * ```\n */\n public get freeze(): boolean {\n return this._freeze;\n }\n\n /**\n * Sets the freeze status of the document data.\n *\n * @param value - The freeze status to set.\n *\n * @example\n * ```typescript\n * documentRef.freeze = true;\n * console.log(documentRef.freeze); // Output: true\n * ```\n */\n public set freeze(value: boolean) {\n this.logger__.logMethodArgs?.('freeze changed', {value});\n this._freeze = value;\n }\n\n /**\n * Retrieves the document's data.\n *\n * @returns The document's data.\n *\n * @example\n * ```typescript\n * const documentData = documentRef.getData();\n * ```\n */\n public getData(): TDoc {\n this.logger__.logMethod?.('getData');\n return this.context__.data;\n }\n\n /**\n * Retrieves the document's metadata.\n *\n * @returns The document's metadata.\n *\n * @example\n * ```typescript\n * const documentMeta = documentRef.getStoreMeta();\n * ```\n */\n public getStoreMeta(): Readonly<StoreFileMeta> {\n this.logger__.logMethod?.('getStoreMeta');\n return this.context__.meta;\n }\n\n /**\n * Sets the document's data. replacing the existing data.\n *\n * @param data The new document data.\n *\n * @example\n * ```typescript\n * documentRef.replaceData({ a: 1, b: 2, c: 3 });\n * ```\n */\n public replaceData(data: TDoc): void {\n this.logger__.logMethodArgs?.('replaceData', data);\n (this.context__.data as unknown) = data;\n this.updated__();\n }\n\n /**\n * Updates document's data by merging a partial update into the document's data.\n *\n * @param data The part of data to merge into the document's data.\n *\n * @example\n * ```typescript\n * documentRef.mergeData({ c: 4 });\n * ```\n */\n public mergeData(data: Partial<TDoc>): void {\n this.logger__.logMethodArgs?.('mergeData', data);\n Object.assign(this.context__.data, data);\n this.updated__();\n }\n\n /**\n * Requests the Alwatr Nitrobase to save the document.\n * Saving may take some time in Alwatr Nitrobase due to the use of throttling.\n *\n * @example\n * ```typescript\n * documentRef.save();\n * ```\n */\n public save(): void {\n this.logger__.logMethod?.('save');\n this.updated__();\n }\n\n /**\n * Requests the Alwatr Nitrobase to save the document immediately.\n *\n * @example\n * ```typescript\n * documentRef.saveImmediate();\n * ```\n */\n public saveImmediate(): void {\n this.logger__.logMethod?.('saveImmediate');\n this.updated__(/* immediate: */ true);\n }\n\n /**\n * Retrieves the full context of the document.\n *\n * @returns The full context of the document.\n *\n * @example\n * ```typescript\n * const context = documentRef.getFullContext_();\n * ```\n */\n public getFullContext_(): Readonly<DocumentContext<TDoc>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n public updateDelayed_ = false;\n\n /**\n * Update the document metadata and invoke the updated callback.\n * This method is throttled to prevent multiple updates in a short time.\n */\n private async updated__(immediate = false): Promise<void> {\n this.logger__.logMethodArgs?.('updated__', {immediate, delayed: this.updateDelayed_});\n\n this.hasUnprocessedChanges_ = true;\n\n if (immediate !== true && this.updateDelayed_ === true) return;\n // else\n\n this.updateDelayed_ = true;\n\n if (immediate === true || this.context__.meta.changeDebounce === undefined) {\n await delay.nextMacrotask();\n }\n else {\n await delay.by(this.context__.meta.changeDebounce);\n }\n\n if (this.updateDelayed_ !== true) return; // another parallel update finished!\n this.updateDelayed_ = false;\n\n this.refreshMetadata_();\n\n if (this._freeze === true) return; // prevent save if frozen\n this.updatedCallback__(this);\n }\n\n /**\n * Refresh/recalculate the document's metadata timestamp and revision.\n */\n protected refreshMetadata_(): void {\n this.logger__.logMethod?.('refreshMetadata_');\n this.context__.meta.updated = Date.now();\n this.context__.meta.rev++;\n }\n\n /**\n * Retrieves the document's extra metadata.\n *\n * @returns The document's extra metadata.\n *\n * @example\n * ```typescript\n * const colExtraMeta = documentRef.getExtraMeta();\n * ```\n */\n public getExtraMeta<T extends JsonObject>(): T {\n this.logger__.logMethod?.('getExtraMeta');\n return this.context__.meta.extra as T;\n }\n\n /**\n * Sets/replace the document's extra metadata.\n *\n * @param extraMeta The new document's extra metadata.\n *\n * @example\n * ```typescript\n * documentRef.replaceExtraMeta({ a: 1, b: 2, c: 3 });\n * ```\n */\n public replaceExtraMeta<T extends JsonObject>(extraMeta: T): void {\n this.logger__.logMethodArgs?.('replaceExtraMeta', extraMeta);\n this.context__.meta.extra = extraMeta;\n this.updated__();\n }\n\n /**\n * Updates document's extra metadata by merging a partial update.\n *\n * @param extraMeta The part of extra metadata to merge into the document's extra metadata.\n *\n * @example\n * ```typescript\n * documentRef.mergeExtraMeta({ c: 4 });\n * ```\n */\n public mergeExtraMeta<T extends JsonObject>(extraMeta: Partial<T>): void {\n this.logger__.logMethodArgs?.('mergeExtraMeta', extraMeta);\n Object.assign(this.context__.meta.extra, extraMeta);\n this.updated__();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;qqBAAA,2KCAA,iBAAoB,yBACpB,IAAAA,eAA2B,0BAC3B,4BAAuC,oCACvC,2BAQO,mCCXP,kBAA2B,0BAKpB,IAAM,UAAyB,4BAAa,6BAAgB,EDUnE,aAAc,OAAO,gBAAgB,sBAAsB,EAQpD,IAAM,oBAAN,MAAM,oBAA2D,CA+JtE,YACU,UACA,kBACR,YACA,CAHQ,yBACA,yCAtBV,KAAO,uBAAyB,MAyDhC,KAAQ,QAAU,MA4VlB,KAAO,eAAiB,MA5XtB,KAAK,MAAK,oCAAW,KAAK,UAAU,IAAI,EACxC,KAAK,QAAO,sCAAa,KAAK,UAAU,IAAI,EAE5C,cAAgB,KAAK,GAAG,MAAM,EAAG,EAAE,EACnC,KAAK,YAAW,6BAAa,OAAO,WAAW,EAAE,EAEjD,KAAK,SAAS,gBAAg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,KAEtB,GAAI,YAAc,MAAQ,KAAK,UAAU,KAAK,iBAAmB,OAAW,CAC1E,MAAM,oBAAM,cAAc,CAC5B,KACK,CACH,MAAM,oBAAM,GAAG,KAAK,UAAU,KAAK,cAAc,CACnD,CAEA,GAAI,KAAK,iBAAmB,KAAM,OAClC,KAAK,eAAiB,MAEtB,KAAK,iBAAiB,EAEtB,GAAI,KAAK,UAAY,KAAM,OAC3B,KAAK,kBAAkB,IAAI,CAC7B,CAKU,kBAAyB,CACjC,KAAK,SAAS,YAAY,kBAAkB,EAC5C,KAAK,UAAU,KAAK,QAAU,KAAK,IAAI,EACvC,KAAK,UAAU,KAAK,KACtB,CAYO,cAAwC,CAC7C,KAAK,SAAS,YAAY,cAAc,EACxC,OAAO,KAAK,UAAU,KAAK,KAC7B,CAYO,iBAAuC,UAAoB,CAChE,KAAK,SAAS,gBAAgB,mBAAoB,SAAS,EAC3D,KAAK,UAAU,KAAK,MAAQ,UAC5B,KAAK,UAAU,CACjB,CAYO,eAAqC,UAA6B,CACvE,KAAK,SAAS,gBAAgB,iBAAkB,SAAS,EACzD,OAAO,OAAO,KAAK,UAAU,KAAK,MAAO,SAAS,EAClD,KAAK,UAAU,CACjB,CACF",
|
|
6
|
-
"names": ["import_logger", "import_delay", "import_logger", "import_nitrobase_helper", "import_nitrobase_types"]
|
|
7
|
-
}
|
package/dist/main.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/nitrobase-reference v7.10.1 */
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/nitrobase-reference v7.10.1");
|
|
3
|
-
import{delay}from"@alwatr/delay";import{createLogger as createLogger2}from"@alwatr/logger";import{getStoreId,getStorePath}from"@alwatr/nitrobase-helper";import{StoreFileType,StoreFileExtension}from"@alwatr/nitrobase-types";import{createLogger}from"@alwatr/logger";var logger=createLogger("@alwatr/nitrobase-reference");__dev_mode__:logger.logFileModule?.("collection-reference");var CollectionReference=class _CollectionReference{constructor(context__,updatedCallback__,debugDomain){this.context__=context__;this.updatedCallback__=updatedCallback__;this.hasUnprocessedChanges_=false;this._freeze=false;this.updateDelayed_=false;this.id=getStoreId(this.context__.meta);this.path=getStorePath(this.context__.meta);debugDomain??=this.id.slice(0,20);this.logger__=createLogger2(`col:${debugDomain}`);this.logger__.logMethodArgs?.("new",{id:this.id});this.validateContext__()}static{this.version="7.10.1"}static{this.fileFormatVersion=3}static newRefFromData(stat,updatedCallback,debugDomain){logger.logMethodArgs?.("col.newRefFromData",stat);const now=Date.now();const initialContext={ok:true,meta:{...stat,rev:1,updated:now,created:now,lastAutoId:0,type:StoreFileType.Collection,extension:StoreFileExtension.Json,fv:_CollectionReference.fileFormatVersion,extra:{}},data:{}};return new _CollectionReference(initialContext,updatedCallback,debugDomain)}static newRefFromContext(context,updatedCallback,debugDomain){logger.logMethodArgs?.("col.newRefFromContext",context.meta);return new _CollectionReference(context,updatedCallback,debugDomain)}validateContext__(){this.logger__.logMethod?.("validateContext__");if(this.context__.ok!==true){this.logger__.accident?.("validateContext__","store_not_ok");throw new Error("store_not_ok",{cause:{context:this.context__}})}if(this.context__.meta===void 0){this.logger__.accident?.("validateContext__","store_meta_undefined");throw new Error("store_meta_undefined",{cause:{context:this.context__}})}if(this.context__.meta.type!==StoreFileType.Collection){this.logger__.accident?.("validateContext__","collection_type_invalid",this.context__.meta);throw new Error("collection_type_invalid",{cause:this.context__.meta})}if(this.context__.meta.fv!==_CollectionReference.fileFormatVersion){this.logger__.incident?.("validateContext__","store_file_version_incompatible",{old:this.context__.meta.fv,new:_CollectionReference.fileFormatVersion});this.migrateContext__()}}migrateContext__(){if(this.context__.meta.fv===_CollectionReference.fileFormatVersion)return;this.logger__.logMethod?.("migrateContext__");if(this.context__.meta.fv>_CollectionReference.fileFormatVersion){this.logger__.accident("migrateContext__","store_version_incompatible",this.context__.meta);throw new Error("store_version_incompatible",{cause:this.context__.meta})}if(this.context__.meta.fv===1){this.context__.meta.fv=2}if(this.context__.meta.fv===2){if(this.context__.meta.schemaVer===void 0||this.context__.meta.schemaVer===0){this.context__.meta.schemaVer=1}delete this.context__.meta["ver"];this.context__.meta.extra??={};this.context__.meta.fv=3}this.updated__()}get schemaVer(){return this.context__.meta.schemaVer??1}set schemaVer(ver){this.logger__.logMethodArgs?.("set schemaVer",{old:this.context__.meta.schemaVer,new:ver});this.context__.meta.schemaVer=ver;this.updated__()}get freeze(){return this._freeze}set freeze(value){this.logger__.logMethodArgs?.("freeze changed",{value});this._freeze=value}hasItem(itemId){const exists=Object.hasOwn(this.context__.data,itemId);this.logger__.logMethodFull?.("hasItem",itemId,exists);return exists}getStoreMeta(){this.logger__.logMethod?.("getStoreMeta");return this.context__.meta}item__(itemId){const item=this.context__.data[itemId];if(item===void 0){this.logger__.accident("item__","collection_item_not_found",{itemId});throw new Error("collection_item_not_found",{cause:{itemId}})}return item}getItemMeta(itemId){const meta=this.item__(itemId).meta;this.logger__.logMethodFull?.("getItemMeta",itemId,meta);return meta}getItemData(itemId){this.logger__.logMethodArgs?.("getItemData",itemId);return this.item__(itemId).data}getItemContext_(itemId){this.logger__.logMethodArgs?.("getItemContext_",itemId);return this.context__.data[itemId]}addItem(itemId,data){this.logger__.logMethodArgs?.("addItem",{itemId,data});if(this.hasItem(itemId)){this.logger__.accident("addItem","collection_item_exist",{itemId});throw new Error("collection_item_exist",{cause:{itemId}})}const now=Date.now();this.context__.data[itemId]={meta:{id:itemId,rev:0,created:now,updated:now},data};this.updated__(itemId)}appendItem(data){this.logger__.logMethodArgs?.("appendItem",data);const id=this.nextAutoIncrementId__();this.addItem(id,data);return id}removeItem(itemId){this.logger__.logMethodArgs?.("removeItem",itemId);delete this.context__.data[itemId];this.updated__()}replaceItemData(itemId,data){this.logger__.logMethodArgs?.("replaceItemData",{itemId,data});this.item__(itemId).data=data;this.updated__(itemId)}mergeItemData(itemId,data){this.logger__.logMethodArgs?.("mergeItemData",{itemId,data});Object.assign(this.item__(itemId).data,data);this.updated__(itemId)}save(itemId){this.logger__.logMethod?.("save");this.updated__(itemId,false)}saveImmediate(itemId){this.logger__.logMethod?.("saveImmediate");this.updated__(itemId,true)}keys(){this.logger__.logMethod?.("keys");return Object.keys(this.context__.data)}values(){this.logger__.logMethod?.("values");return Object.values(this.context__.data)}*ids(){this.logger__.logMethod?.("ids");for(const id in this.context__.data){yield id}}*items(){this.logger__.logMethod?.("items");for(const id in this.context__.data){yield this.context__.data[id]}}getFullContext_(){this.logger__.logMethod?.("getFullContext_");return this.context__}async updated__(itemId=null,immediate=false){this.logger__.logMethodArgs?.("updated__",{id:itemId,immediate,delayed:this.updateDelayed_});this.hasUnprocessedChanges_=true;if(itemId!==null)this.refreshMeta_(itemId);if(immediate===false&&this.updateDelayed_===true)return;this.updateDelayed_=true;if(immediate===true||this.context__.meta.changeDebounce===void 0){await delay.nextMacrotask()}else{await delay.by(this.context__.meta.changeDebounce)}if(this.updateDelayed_!==true)return;this.updateDelayed_=false;if(itemId===null)this.refreshMeta_(itemId);if(this._freeze===true)return;this.updatedCallback__(this)}refreshMeta_(itemId){this.logger__.logMethodArgs?.("refreshMeta_",{id:itemId});const now=Date.now();this.context__.meta.rev++;this.context__.meta.updated=now;if(itemId!==null){const itemMeta=this.item__(itemId).meta;itemMeta.rev++;itemMeta.updated=now}}nextAutoIncrementId__(){this.logger__.logMethod?.("nextAutoIncrementId__");const meta=this.context__.meta;do{meta.lastAutoId++}while(meta.lastAutoId in this.context__.data);return meta.lastAutoId}getExtraMeta(){this.logger__.logMethod?.("getExtraMeta");return this.context__.meta.extra}replaceExtraMeta(extraMeta){this.logger__.logMethodArgs?.("replaceExtraMeta",extraMeta);this.context__.meta.extra=extraMeta;this.updated__()}mergeExtraMeta(extraMeta){this.logger__.logMethodArgs?.("mergeExtraMeta",extraMeta);Object.assign(this.context__.meta.extra,extraMeta);this.updated__()}};import{delay as delay2}from"@alwatr/delay";import{createLogger as createLogger3}from"@alwatr/logger";import{getStoreId as getStoreId2,getStorePath as getStorePath2}from"@alwatr/nitrobase-helper";import{StoreFileType as StoreFileType2,StoreFileExtension as StoreFileExtension2}from"@alwatr/nitrobase-types";__dev_mode__:logger.logFileModule?.("document-reference");var DocumentReference=class _DocumentReference{constructor(context__,updatedCallback__,debugDomain){this.context__=context__;this.updatedCallback__=updatedCallback__;this.hasUnprocessedChanges_=false;this._freeze=false;this.updateDelayed_=false;this.id=getStoreId2(this.context__.meta);this.path=getStorePath2(this.context__.meta);debugDomain??=this.id.slice(0,20);this.logger__=createLogger3(`doc:${debugDomain}`);this.logger__.logMethodArgs?.("new",{path:this.path});this.validateContext__()}static{this.version="7.10.1"}static{this.fileFormatVersion=3}static newRefFromData(statId,data,updatedCallback,debugDomain){logger.logMethodArgs?.("doc.newRefFromData",statId);const now=Date.now();const initialContext={ok:true,meta:{...statId,rev:1,updated:now,created:now,type:StoreFileType2.Document,extension:StoreFileExtension2.Json,fv:_DocumentReference.fileFormatVersion,extra:{}},data};return new _DocumentReference(initialContext,updatedCallback,debugDomain)}static newRefFromContext(context,updatedCallback,debugDomain){logger.logMethodArgs?.("doc.newRefFromContext",context.meta);return new _DocumentReference(context,updatedCallback,debugDomain)}validateContext__(){this.logger__.logMethod?.("validateContext__");if(this.context__.ok!==true){this.logger__.accident?.("validateContext__","store_not_ok");throw new Error("store_not_ok",{cause:{context:this.context__}})}if(this.context__.meta===void 0){this.logger__.accident?.("validateContext__","store_meta_undefined");throw new Error("store_meta_undefined",{cause:{context:this.context__}})}if(this.context__.meta.type!==StoreFileType2.Document){this.logger__.accident?.("validateContext__","document_type_invalid",this.context__.meta);throw new Error("document_type_invalid",{cause:this.context__.meta})}if(this.context__.meta.fv!==_DocumentReference.fileFormatVersion){this.logger__.incident?.("validateContext__","store_file_version_incompatible",{old:this.context__.meta.fv,new:_DocumentReference.fileFormatVersion});this.migrateContext__()}}migrateContext__(){if(this.context__.meta.fv===_DocumentReference.fileFormatVersion)return;this.logger__.logMethod?.("migrateContext__");if(this.context__.meta.fv>_DocumentReference.fileFormatVersion){this.logger__.accident("migrateContext__","store_version_incompatible",this.context__.meta);throw new Error("store_version_incompatible",{cause:this.context__.meta})}if(this.context__.meta.fv===1){this.context__.meta.fv=2}if(this.context__.meta.fv===2){if(this.context__.meta.schemaVer===void 0||this.context__.meta.schemaVer===0){this.context__.meta.schemaVer=1}delete this.context__.meta["ver"];this.context__.meta.extra??={};this.context__.meta.fv=3}this.updated__()}get schemaVer(){return this.context__.meta.schemaVer??1}set schemaVer(ver){this.logger__.logMethodArgs?.("set schemaVer",{old:this.context__.meta.schemaVer,new:ver});this.context__.meta.schemaVer=ver;this.updated__()}get freeze(){return this._freeze}set freeze(value){this.logger__.logMethodArgs?.("freeze changed",{value});this._freeze=value}getData(){this.logger__.logMethod?.("getData");return this.context__.data}getStoreMeta(){this.logger__.logMethod?.("getStoreMeta");return this.context__.meta}replaceData(data){this.logger__.logMethodArgs?.("replaceData",data);this.context__.data=data;this.updated__()}mergeData(data){this.logger__.logMethodArgs?.("mergeData",data);Object.assign(this.context__.data,data);this.updated__()}save(){this.logger__.logMethod?.("save");this.updated__()}saveImmediate(){this.logger__.logMethod?.("saveImmediate");this.updated__(true)}getFullContext_(){this.logger__.logMethod?.("getFullContext_");return this.context__}async updated__(immediate=false){this.logger__.logMethodArgs?.("updated__",{immediate,delayed:this.updateDelayed_});this.hasUnprocessedChanges_=true;if(immediate!==true&&this.updateDelayed_===true)return;this.updateDelayed_=true;if(immediate===true||this.context__.meta.changeDebounce===void 0){await delay2.nextMacrotask()}else{await delay2.by(this.context__.meta.changeDebounce)}if(this.updateDelayed_!==true)return;this.updateDelayed_=false;this.refreshMetadata_();if(this._freeze===true)return;this.updatedCallback__(this)}refreshMetadata_(){this.logger__.logMethod?.("refreshMetadata_");this.context__.meta.updated=Date.now();this.context__.meta.rev++}getExtraMeta(){this.logger__.logMethod?.("getExtraMeta");return this.context__.meta.extra}replaceExtraMeta(extraMeta){this.logger__.logMethodArgs?.("replaceExtraMeta",extraMeta);this.context__.meta.extra=extraMeta;this.updated__()}mergeExtraMeta(extraMeta){this.logger__.logMethodArgs?.("mergeExtraMeta",extraMeta);Object.assign(this.context__.meta.extra,extraMeta);this.updated__()}};export{CollectionReference,DocumentReference};
|
|
4
|
-
//# sourceMappingURL=main.mjs.map
|