@alwatr/nitrobase-reference 7.6.0 → 7.8.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/CHANGELOG.md +19 -0
- package/dist/collection-reference.d.ts +2 -2
- package/dist/collection-reference.d.ts.map +1 -1
- package/dist/document-reference.d.ts.map +1 -1
- package/dist/main.cjs +8 -8
- package/dist/main.cjs.map +2 -2
- package/dist/main.mjs +8 -8
- package/dist/main.mjs.map +2 -2
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [7.8.0](https://github.com/Alwatr/nitrobase/compare/v7.7.0...v7.8.0) (2025-03-06)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **reference:** update save and saveImmediate methods to accept itemId parameter ([8fe304e](https://github.com/Alwatr/nitrobase/commit/8fe304ec47a2d86a6ca78e8cbea3efe7d231bc88)) by @
|
|
11
|
+
|
|
12
|
+
### Miscellaneous Chores
|
|
13
|
+
|
|
14
|
+
* **reference:** remove unnecessary blank line in DocumentReference class ([eeb63b9](https://github.com/Alwatr/nitrobase/commit/eeb63b96e07e6638b1fcc4976de65571ed4267eb)) by @
|
|
15
|
+
|
|
16
|
+
### Dependencies update
|
|
17
|
+
|
|
18
|
+
* **deps-dev:** bump the dependencies group across 1 directory with 5 updates ([fe6ab37](https://github.com/Alwatr/nitrobase/commit/fe6ab37263f609f8bce8398462b7105b8e5a55fe)) by @dependabot[bot]
|
|
19
|
+
* update @alwatr/nanolib, @alwatr/nano-build, and @alwatr/type-helper to latest versions ([5f3f89b](https://github.com/Alwatr/nitrobase/commit/5f3f89b1236f66e9167957d60d43c8d0abff108d)) by @
|
|
20
|
+
|
|
21
|
+
## [7.7.0](https://github.com/Alwatr/nitrobase/compare/v7.6.1...v7.7.0) (2025-02-26)
|
|
22
|
+
|
|
23
|
+
**Note:** Version bump only for package @alwatr/nitrobase-reference
|
|
24
|
+
|
|
6
25
|
## [7.6.0](https://github.com/Alwatr/nitrobase/compare/v7.5.9...v7.6.0) (2025-02-26)
|
|
7
26
|
|
|
8
27
|
### Miscellaneous Chores
|
|
@@ -252,7 +252,7 @@ export declare class CollectionReference<TItem extends JsonObject = JsonObject>
|
|
|
252
252
|
* collectionRef.save();
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
|
-
save(): void;
|
|
255
|
+
save(itemId: string | number | null): void;
|
|
256
256
|
/**
|
|
257
257
|
* Requests the Alwatr Nitrobase to save the collection immediately.
|
|
258
258
|
*
|
|
@@ -261,7 +261,7 @@ export declare class CollectionReference<TItem extends JsonObject = JsonObject>
|
|
|
261
261
|
* collectionRef.saveImmediate();
|
|
262
262
|
* ```
|
|
263
263
|
*/
|
|
264
|
-
saveImmediate(): void;
|
|
264
|
+
saveImmediate(itemId: string | number | null): void;
|
|
265
265
|
/**
|
|
266
266
|
* Retrieves the IDs of all items in the collection in array.
|
|
267
267
|
* Impact performance if the collection is large, use `ids()` instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-reference.d.ts","sourceRoot":"","sources":["../src/collection-reference.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,KAAK,SAAS,UAAU,GAAG,UAAU;IAgKlE,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,iBAAiB;IAhK3B;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,SAAuB;IAE9C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,iBAAiB,KAAK;IAEtC;;;;;;;;OAQ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ACH,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAGxB;IAED;;;;;;;;;OASG;IACH,OAAO,IAAI,IAAI;IAKf;;;;;;;;;OASG;IACH,YAAY,IAAI,QAAQ,CAAC,aAAa,CAAC;IAKvC;;;;;;;;;OASG;IACH,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAM7B;;;;;;;;;OASG;IACH,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAMpC;;;;;;;;OAQG;IACH,IAAI,IAAI,IAAI;IAKZ;;;;;;;OAOG;IACH,aAAa,IAAI,IAAI;IAKrB;;;;;;;;;OASG;IACH,eAAe,IAAI,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAKlD,cAAc,UAAS;IAEvB;;;OAGG;YACW,SAAS;IA0BvB;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAMlC;;;;;;;;;OASG;IACH,YAAY,CAAC,CAAC,SAAS,UAAU,KAAK,CAAC;IAKvC;;;;;;;;;OASG;IACH,gBAAgB,CAAC,CAAC,SAAS,UAAU,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI;IAM1D;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,SAAS,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;CAKlE"}
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/nitrobase-reference v7.
|
|
1
|
+
/* @alwatr/nitrobase-reference v7.8.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -33,7 +33,7 @@ var import_nitrobase_types = require("@alwatr/nitrobase-types");
|
|
|
33
33
|
|
|
34
34
|
// src/logger.ts
|
|
35
35
|
var import_nanolib = require("@alwatr/nanolib");
|
|
36
|
-
__dev_mode__: import_nanolib.packageTracer.add("@alwatr/nitrobase-reference", "7.
|
|
36
|
+
__dev_mode__: import_nanolib.packageTracer.add("@alwatr/nitrobase-reference", "7.8.0");
|
|
37
37
|
var logger = /* @__PURE__ */ (0, import_nanolib.createLogger)("@alwatr/nitrobase-reference");
|
|
38
38
|
|
|
39
39
|
// src/collection-reference.ts
|
|
@@ -406,9 +406,9 @@ var _CollectionReference = class _CollectionReference {
|
|
|
406
406
|
* collectionRef.save();
|
|
407
407
|
* ```
|
|
408
408
|
*/
|
|
409
|
-
save() {
|
|
409
|
+
save(itemId) {
|
|
410
410
|
this.logger__.logMethod?.("save");
|
|
411
|
-
this.updated__(
|
|
411
|
+
this.updated__(itemId, false);
|
|
412
412
|
}
|
|
413
413
|
/**
|
|
414
414
|
* Requests the Alwatr Nitrobase to save the collection immediately.
|
|
@@ -418,9 +418,9 @@ var _CollectionReference = class _CollectionReference {
|
|
|
418
418
|
* collectionRef.saveImmediate();
|
|
419
419
|
* ```
|
|
420
420
|
*/
|
|
421
|
-
saveImmediate() {
|
|
421
|
+
saveImmediate(itemId) {
|
|
422
422
|
this.logger__.logMethod?.("saveImmediate");
|
|
423
|
-
this.updated__(
|
|
423
|
+
this.updated__(itemId, true);
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
426
426
|
* Retrieves the IDs of all items in the collection in array.
|
|
@@ -605,7 +605,7 @@ var _CollectionReference = class _CollectionReference {
|
|
|
605
605
|
/**
|
|
606
606
|
* Alwatr nitrobase engine version string.
|
|
607
607
|
*/
|
|
608
|
-
_CollectionReference.version = "7.
|
|
608
|
+
_CollectionReference.version = "7.8.0";
|
|
609
609
|
/**
|
|
610
610
|
* Alwatr nitrobase engine file format version number.
|
|
611
611
|
*/
|
|
@@ -955,7 +955,7 @@ var _DocumentReference = class _DocumentReference {
|
|
|
955
955
|
/**
|
|
956
956
|
* Alwatr nitrobase engine version string.
|
|
957
957
|
*/
|
|
958
|
-
_DocumentReference.version = "7.
|
|
958
|
+
_DocumentReference.version = "7.8.0";
|
|
959
959
|
/**
|
|
960
960
|
* Alwatr nitrobase engine file format version number.
|
|
961
961
|
*/
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the collection nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the collection has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 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 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 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 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 save(): void {\n this.logger__.logMethod?.('save');\n this.updated__(null, 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 saveImmediate(): void {\n this.logger__.logMethod?.('saveImmediate');\n this.updated__(null, 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 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 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 *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 *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 getFullContext_(): Readonly<CollectionContext<TItem>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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, packageTracer} from '@alwatr/nanolib';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport const logger = /* #__PURE__ */ createLogger(__package_name__);\n", "import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the document nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the document has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 getFullContext_(): Readonly<DocumentContext<TDoc>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 /**\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 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 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 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": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,kBAAkC;AAClC,8BAAuC;AACvC,6BAQO;;;ACVP,qBAA0C;AAE1C,aAAc,8BAAc,IAAI,+BAAkB,OAAmB;AAE9D,IAAM,SAAyB,iDAAa,6BAAgB;;;ADUnE,aAAc,QAAO,gBAAgB,sBAAsB;AAQpD,IAAM,uBAAN,MAAM,qBAA2D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+JtE,YACU,WACA,mBACR,aACA;AAHQ;AACA;AAtBV;AAAA;AAAA;AAAA,kCAAyB;AAyDzB;AAAA;AAAA;AAAA,SAAQ,UAAU;AA4VlB,0BAAiB;AA5Xf,SAAK,SAAK,oCAAW,KAAK,UAAU,IAAI;AACxC,SAAK,WAAO,sCAAa,KAAK,UAAU,IAAI;AAE5C,kCAAgB,KAAK,GAAG,MAAM,GAAG,EAAE;AACnC,SAAK,eAAW,8BAAa,OAAO,WAAW,EAAE;AAEjD,SAAK,SAAS,gBAAgB,OAAO,EAAC,IAAI,KAAK,GAAE,CAAC;AAElD,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAzJA,OAAO,eACL,MACA,iBACA,aAC4B;AAC5B,WAAO,gBAAgB,sBAAsB,IAAI;AAEjD,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,iBAA2C;AAAA,MAC/C,IAAI;AAAA,MACJ,MAAM;AAAA,QACJ,GAAG;AAAA,QACH,KAAK;AAAA,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AK,IAAI;AACvC,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,eAAwC;AACtC,SAAK,SAAS,YAAY,cAAc;AACxC,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,iBAAuC,WAAoB;AACzD,SAAK,SAAS,gBAAgB,oBAAoB,SAAS;AAC3D,SAAK,UAAU,KAAK,QAAQ;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,eAAqC,WAA6B;AAChE,SAAK,SAAS,gBAAgB,kBAAkB,SAAS;AACzD,WAAO,OAAO,KAAK,UAAU,KAAK,OAAO,SAAS;AAClD,SAAK,UAAU;AAAA,EACjB;AACF;AAAA;AAAA;AAAA;AAhaa,mBAIK,UAAU;AAAA;AAAA;AAAA;AAJf,mBASK,oBAAoB;AAT/B,IAAM,oBAAN;",
|
|
4
|
+
"sourcesContent": ["export * from './collection-reference.js';\nexport * from './document-reference.js';\n", "import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the collection nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the collection has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 *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 *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 getFullContext_(): Readonly<CollectionContext<TItem>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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, packageTracer} from '@alwatr/nanolib';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport const logger = /* #__PURE__ */ createLogger(__package_name__);\n", "import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the document nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the document has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 getFullContext_(): Readonly<DocumentContext<TDoc>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,kBAAkC;AAClC,8BAAuC;AACvC,6BAQO;;;ACVP,qBAA0C;AAE1C,aAAc,8BAAc,IAAI,+BAAkB,OAAmB;AAE9D,IAAM,SAAyB,iDAAa,6BAAgB;;;ADUnE,aAAc,QAAO,gBAAgB,sBAAsB;AAQpD,IAAM,uBAAN,MAAM,qBAA2D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+JtE,YACU,WACA,mBACR,aACA;AAHQ;AACA;AAtBV;AAAA;AAAA;AAAA,kCAAyB;AAyDzB;AAAA;AAAA;AAAA,SAAQ,UAAU;AA4VlB,0BAAiB;AA5Xf,SAAK,SAAK,oCAAW,KAAK,UAAU,IAAI;AACxC,SA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olib", "import_nitrobase_helper", "import_nitrobase_types"]
|
|
7
7
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/nitrobase-reference v7.
|
|
1
|
+
/* @alwatr/nitrobase-reference v7.8.0 */
|
|
2
2
|
|
|
3
3
|
// src/collection-reference.ts
|
|
4
4
|
import { createLogger as createLogger2, delay } from "@alwatr/nanolib";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
// src/logger.ts
|
|
12
12
|
import { createLogger, packageTracer } from "@alwatr/nanolib";
|
|
13
|
-
__dev_mode__: packageTracer.add("@alwatr/nitrobase-reference", "7.
|
|
13
|
+
__dev_mode__: packageTracer.add("@alwatr/nitrobase-reference", "7.8.0");
|
|
14
14
|
var logger = /* @__PURE__ */ createLogger("@alwatr/nitrobase-reference");
|
|
15
15
|
|
|
16
16
|
// src/collection-reference.ts
|
|
@@ -383,9 +383,9 @@ var _CollectionReference = class _CollectionReference {
|
|
|
383
383
|
* collectionRef.save();
|
|
384
384
|
* ```
|
|
385
385
|
*/
|
|
386
|
-
save() {
|
|
386
|
+
save(itemId) {
|
|
387
387
|
this.logger__.logMethod?.("save");
|
|
388
|
-
this.updated__(
|
|
388
|
+
this.updated__(itemId, false);
|
|
389
389
|
}
|
|
390
390
|
/**
|
|
391
391
|
* Requests the Alwatr Nitrobase to save the collection immediately.
|
|
@@ -395,9 +395,9 @@ var _CollectionReference = class _CollectionReference {
|
|
|
395
395
|
* collectionRef.saveImmediate();
|
|
396
396
|
* ```
|
|
397
397
|
*/
|
|
398
|
-
saveImmediate() {
|
|
398
|
+
saveImmediate(itemId) {
|
|
399
399
|
this.logger__.logMethod?.("saveImmediate");
|
|
400
|
-
this.updated__(
|
|
400
|
+
this.updated__(itemId, true);
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Retrieves the IDs of all items in the collection in array.
|
|
@@ -582,7 +582,7 @@ var _CollectionReference = class _CollectionReference {
|
|
|
582
582
|
/**
|
|
583
583
|
* Alwatr nitrobase engine version string.
|
|
584
584
|
*/
|
|
585
|
-
_CollectionReference.version = "7.
|
|
585
|
+
_CollectionReference.version = "7.8.0";
|
|
586
586
|
/**
|
|
587
587
|
* Alwatr nitrobase engine file format version number.
|
|
588
588
|
*/
|
|
@@ -932,7 +932,7 @@ var _DocumentReference = class _DocumentReference {
|
|
|
932
932
|
/**
|
|
933
933
|
* Alwatr nitrobase engine version string.
|
|
934
934
|
*/
|
|
935
|
-
_DocumentReference.version = "7.
|
|
935
|
+
_DocumentReference.version = "7.8.0";
|
|
936
936
|
/**
|
|
937
937
|
* Alwatr nitrobase engine file format version number.
|
|
938
938
|
*/
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/collection-reference.ts", "../src/logger.ts", "../src/document-reference.ts"],
|
|
4
|
-
"sourcesContent": ["import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the collection nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the collection has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 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 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 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 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 save(): void {\n this.logger__.logMethod?.('save');\n this.updated__(null, 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 saveImmediate(): void {\n this.logger__.logMethod?.('saveImmediate');\n this.updated__(null, 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 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 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 *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 *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 getFullContext_(): Readonly<CollectionContext<TItem>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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, packageTracer} from '@alwatr/nanolib';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport const logger = /* #__PURE__ */ createLogger(__package_name__);\n", "import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the document nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the document has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 getFullContext_(): Readonly<DocumentContext<TDoc>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 /**\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 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 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 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": ";;;AAAA,SAAQ,gBAAAA,eAAc,aAAY;AAClC,SAAQ,YAAY,oBAAmB;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAMK;;;ACVP,SAAQ,cAAc,qBAAoB;AAE1C,aAAc,eAAc,IAAI,+BAAkB,OAAmB;AAE9D,IAAM,SAAyB,6BAAa,6BAAgB;;;ADUnE,aAAc,QAAO,gBAAgB,sBAAsB;AAQpD,IAAM,uBAAN,MAAM,qBAA2D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+JtE,YACU,WACA,mBACR,aACA;AAHQ;AACA;AAtBV;AAAA;AAAA;AAAA,kCAAyB;AAyDzB;AAAA;AAAA;AAAA,SAAQ,UAAU;AA4VlB,0BAAiB;AA5Xf,SAAK,KAAK,WAAW,KAAK,UAAU,IAAI;AACxC,SAAK,OAAO,aAAa,KAAK,UAAU,IAAI;AAE5C,kCAAgB,KAAK,GAAG,MAAM,GAAG,EAAE;AACnC,SAAK,WAAWC,cAAa,OAAO,WAAW,EAAE;AAEjD,SAAK,SAAS,gBAAgB,OAAO,EAAC,IAAI,KAA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mBAAmB,QAAW;AAC1E,YAAME,OAAM,UAAU;AAAA,IACxB,OACK;AACH,YAAMA,OAAM,GAAG,KAAK,UAAU,KAAK,cAAc;AAAA,IACnD;AAEA,QAAI,KAAK,mBAAmB,KAAM;AAClC,SAAK,iBAAiB;AAEtB,SAAK,iBAAiB;AAEtB,QAAI,KAAK,YAAY,KAAM;AAC3B,SAAK,kBAAkB,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKU,mBAAyB;AACjC,SAAK,SAAS,YAAY,kBAAkB;AAC5C,SAAK,UAAU,KAAK,UAAU,KAAK,IAAI;AACvC,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,eAAwC;AACtC,SAAK,SAAS,YAAY,cAAc;AACxC,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,iBAAuC,WAAoB;AACzD,SAAK,SAAS,gBAAgB,oBAAoB,SAAS;AAC3D,SAAK,UAAU,KAAK,QAAQ;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,eAAqC,WAA6B;AAChE,SAAK,SAAS,gBAAgB,kBAAkB,SAAS;AACzD,WAAO,OAAO,KAAK,UAAU,KAAK,OAAO,SAAS;AAClD,SAAK,UAAU;AAAA,EACjB;AACF;AAAA;AAAA;AAAA;AAhaa,mBAIK,UAAU;AAAA;AAAA;AAAA;AAJf,mBASK,oBAAoB;AAT/B,IAAM,oBAAN;",
|
|
4
|
+
"sourcesContent": ["import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the collection nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the collection has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 *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 *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 getFullContext_(): Readonly<CollectionContext<TItem>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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, packageTracer} from '@alwatr/nanolib';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport const logger = /* #__PURE__ */ createLogger(__package_name__);\n", "import {createLogger, delay} from '@alwatr/nanolib';\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 static readonly version = __package_version__;\n\n /**\n * Alwatr nitrobase engine file format version number.\n */\n 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 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 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 readonly id: string;\n\n /**\n * The location path of the document nitrobase file.\n */\n readonly path: string;\n\n /**\n * Indicates whether the document has unsaved changes.\n */\n 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 get schemaVer(): number {\n return this.context__.meta.schemaVer ?? 1;\n }\n\n /**\n * Set nitrobase schema version for migrate\n */\n 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 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 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 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 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 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 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 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 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 getFullContext_(): Readonly<DocumentContext<TDoc>> {\n this.logger__.logMethod?.('getFullContext_');\n return this.context__;\n }\n\n 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.immediate();\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 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 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 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": ";;;AAAA,SAAQ,gBAAAA,eAAc,aAAY;AAClC,SAAQ,YAAY,oBAAmB;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAMK;;;ACVP,SAAQ,cAAc,qBAAoB;AAE1C,aAAc,eAAc,IAAI,+BAAkB,OAAmB;AAE9D,IAAM,SAAyB,6BAAa,6BAAgB;;;ADUn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AAU,KAAK,QAAQ;AAC5B,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,eAAqC,WAA6B;AAChE,SAAK,SAAS,gBAAgB,kBAAkB,SAAS;AACzD,WAAO,OAAO,KAAK,UAAU,KAAK,OAAO,SAAS;AAClD,SAAK,UAAU;AAAA,EACjB;AACF;AAAA;AAAA;AAAA;AA/Za,mBAIK,UAAU;AAAA;AAAA;AAAA;AAJf,mBASK,oBAAoB;AAT/B,IAAM,oBAAN;",
|
|
6
6
|
"names": ["createLogger", "createLogger", "createLogger", "delay", "getStoreId", "getStorePath", "StoreFileType", "StoreFileExtension", "getStoreId", "getStorePath", "createLogger", "StoreFileType", "StoreFileExtension", "delay"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/nitrobase-reference",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.0",
|
|
4
4
|
"description": "Nitrobase is a blazingly fast, lightweight database built on JSON. It stores data entirely in memory for lightning-quick access, while also providing a JSON file backup for persistence. You can easily serve your data over the web using our high-performance accelerated Nginx server.",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -60,17 +60,17 @@
|
|
|
60
60
|
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@alwatr/nanolib": "^5.
|
|
64
|
-
"@alwatr/nitrobase-helper": "^7.
|
|
65
|
-
"@alwatr/nitrobase-types": "^7.
|
|
63
|
+
"@alwatr/nanolib": "^5.5.0",
|
|
64
|
+
"@alwatr/nitrobase-helper": "^7.8.0",
|
|
65
|
+
"@alwatr/nitrobase-types": "^7.8.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@alwatr/nano-build": "^5.
|
|
68
|
+
"@alwatr/nano-build": "^5.5.0",
|
|
69
69
|
"@alwatr/prettier-config": "^5.0.0",
|
|
70
70
|
"@alwatr/tsconfig-base": "^5.0.0",
|
|
71
|
-
"@alwatr/type-helper": "^5.
|
|
72
|
-
"@types/node": "^22.13.
|
|
73
|
-
"typescript": "^5.
|
|
71
|
+
"@alwatr/type-helper": "^5.4.0",
|
|
72
|
+
"@types/node": "^22.13.9",
|
|
73
|
+
"typescript": "^5.8.2"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "fc40e664a2fe93d060fdbed6a05377043bbdc890"
|
|
76
76
|
}
|