Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update imports & packages based on the latest changes of nanolib & prevent side-effects #310

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript",
"version": "5.6.2-sdk",
"version": "5.6.3-sdk",
"main": "./lib/typescript.js",
"type": "commonjs",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"publish": "lerna publish from-package"
},
"devDependencies": {
"@alwatr/eslint-config": "^1.2.8",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/eslint-config": "^1.2.11",
"@alwatr/prettier-config": "^1.0.6",
"@lerna-lite/changed": "^3.9.3",
"@lerna-lite/cli": "^3.9.3",
"@lerna-lite/diff": "^3.9.3",
Expand Down
16 changes: 6 additions & 10 deletions packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/exit-hook": "^1.1.1",
"@alwatr/flat-string": "^1.1.1",
"@alwatr/logger": "^4.0.1",
"@alwatr/nanolib": "^1.2.0",
"@alwatr/nitrobase-helper": "workspace:^",
"@alwatr/nitrobase-reference": "workspace:^",
"@alwatr/nitrobase-types": "workspace:^",
"@alwatr/node-fs": "^1.1.1",
"@alwatr/wait": "^1.1.16"
"@alwatr/nitrobase-types": "workspace:^"
},
"devDependencies": {
"@alwatr/nano-build": "^1.5.0",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/tsconfig-base": "^1.3.0",
"@alwatr/type-helper": "^2.0.0",
"@alwatr/nano-build": "^2.0.1",
"@alwatr/prettier-config": "^1.0.6",
"@alwatr/tsconfig-base": "^1.3.2",
"@alwatr/type-helper": "^2.0.2",
"@types/node": "^22.7.5",
"typescript": "^5.6.3"
}
Expand Down
14 changes: 6 additions & 8 deletions packages/engine/src/alwatr-nitrobase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {exitHook} from '@alwatr/exit-hook';
import {delay} from '@alwatr/nanolib';
import {exitHook} from '@alwatr/nanolib/exit-hook';
import {existsSync, readJson, resolve, unlink, writeJson} from '@alwatr/nanolib/node-fs';
import {getStoreId, getStorePath} from '@alwatr/nitrobase-helper';
import {CollectionReference, DocumentReference} from '@alwatr/nitrobase-reference';
import {
Expand All @@ -12,14 +14,10 @@ import {
type StoreFileId,
type CollectionItem,
} from '@alwatr/nitrobase-types';
import {existsSync, readJson, resolve, unlink, writeJson} from '@alwatr/node-fs';
import {waitForTimeout} from '@alwatr/wait';

import {logger} from './logger.js';

import type {Dictionary, JsonObject} from '@alwatr/type-helper';

logger.logModule?.('alwatr-nitrobase');
__dev_mode__: logger.logFileModule?.('alwatr-nitrobase');

/**
* AlwatrNitrobase configuration.
Expand Down Expand Up @@ -79,7 +77,7 @@ export class AlwatrNitrobase {
/**
* Keep all loaded nitrobase file context loaded in memory.
*/
private cacheReferences__: Dictionary<DocumentReference | CollectionReference> = {};
private cacheReferences__: DictionaryReq<DocumentReference | CollectionReference> = {};

/**
* Constructs an AlwatrNitrobase instance with the provided configuration.
Expand Down Expand Up @@ -377,7 +375,7 @@ export class AlwatrNitrobase {
}
const path = getStorePath(this.rootDb__.getItemData(id_));
this.rootDb__.removeItem(id_);
await waitForTimeout(0);
await delay.by(0);
try {
await unlink(resolve(this.config__.rootPath, path));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {definePackage} from '@alwatr/logger';
import {createLogger, packageTracer} from '@alwatr/nanolib';

import type {} from '@alwatr/nano-build';
__dev_mode__: packageTracer.add(__package_name__, __package_version__);

export const logger = definePackage('@alwatr/nitrobase-engine', __package_version__);
export const logger = /* #__PURE__ */ createLogger(__package_name__);
3 changes: 2 additions & 1 deletion packages/engine/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"rootDir": "src",
"outDir": "dist",
"emitDeclarationOnly": true,
"composite": true
"composite": true,
"types": ["node", "@alwatr/nano-build", "@alwatr/type-helper"]
},
"include": ["src/**/*.ts"],
"references": [{"path": "../types"}, {"path": "../reference"}, {"path": "../helper"}]
Expand Down
10 changes: 5 additions & 5 deletions packages/helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/flat-string": "^1.1.1",
"@alwatr/nanolib": "^1.2.0",
"@alwatr/nitrobase-types": "workspace:^"
},
"devDependencies": {
"@alwatr/logger": "^4.0.1",
"@alwatr/nano-build": "^1.5.0",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/tsconfig-base": "^1.3.0",
"@alwatr/logger": "^4.0.5",
"@alwatr/nano-build": "^2.0.1",
"@alwatr/prettier-config": "^1.0.6",
"@alwatr/tsconfig-base": "^1.3.2",
"@alwatr/wait": "^1.1.16",
"@types/node": "^22.7.5",
"typescript": "^5.6.3"
Expand Down
4 changes: 3 additions & 1 deletion packages/helper/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {flatString} from '@alwatr/flat-string';
import {flatString, packageTracer} from '@alwatr/nanolib';
import {StoreFileExtension, type StoreFileId, type StoreFileStat} from '@alwatr/nitrobase-types';

__dev_mode__: packageTracer.add(__package_name__, __package_version__);

/**
* Convert StoreFileId to a string ID.
*
Expand Down
9 changes: 5 additions & 4 deletions packages/nitrobase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/nanolib": "^1.2.0",
"@alwatr/nitrobase-engine": "workspace:^",
"@alwatr/nitrobase-helper": "workspace:^",
"@alwatr/nitrobase-reference": "workspace:^",
"@alwatr/nitrobase-types": "workspace:^"
},
"devDependencies": {
"@alwatr/logger": "^4.0.1",
"@alwatr/nano-build": "^1.5.0",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/tsconfig-base": "^1.3.0",
"@alwatr/logger": "^4.0.5",
"@alwatr/nano-build": "^2.0.1",
"@alwatr/prettier-config": "^1.0.6",
"@alwatr/tsconfig-base": "^1.3.2",
"@alwatr/wait": "^1.1.16",
"@types/node": "^22.7.5",
"typescript": "^5.6.3"
Expand Down
4 changes: 4 additions & 0 deletions packages/nitrobase/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {packageTracer} from '@alwatr/nanolib';

export * from '@alwatr/nitrobase-engine';
export * from '@alwatr/nitrobase-reference';
export * from '@alwatr/nitrobase-helper';
export * from '@alwatr/nitrobase-types';

__dev_mode__: packageTracer.add(__package_name__, __package_version__);
14 changes: 6 additions & 8 deletions packages/reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/flat-string": "^1.1.1",
"@alwatr/logger": "^4.0.1",
"@alwatr/nanolib": "^1.2.0",
"@alwatr/nitrobase-helper": "workspace:^",
"@alwatr/nitrobase-types": "workspace:^",
"@alwatr/wait": "^1.1.16"
"@alwatr/nitrobase-types": "workspace:^"
},
"devDependencies": {
"@alwatr/nano-build": "^1.5.0",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/tsconfig-base": "^1.3.0",
"@alwatr/type-helper": "^2.0.0",
"@alwatr/nano-build": "^2.0.1",
"@alwatr/prettier-config": "^1.0.6",
"@alwatr/tsconfig-base": "^1.3.2",
"@alwatr/type-helper": "^2.0.2",
"@types/node": "^22.7.5",
"typescript": "^5.6.3"
}
Expand Down
13 changes: 5 additions & 8 deletions packages/reference/src/collection-reference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createLogger} from '@alwatr/logger';
import {createLogger, delay} from '@alwatr/nanolib';
import {getStoreId, getStorePath} from '@alwatr/nitrobase-helper';
import {
StoreFileType,
Expand All @@ -9,13 +9,10 @@ import {
type CollectionItemMeta,
type StoreFileMeta,
} from '@alwatr/nitrobase-types';
import {waitForImmediate, waitForTimeout} from '@alwatr/wait';

import {logger} from './logger.js';

import type {Dictionary, JsonObject} from '@alwatr/type-helper';

logger.logModule?.('collection-reference');
__dev_mode__: logger.logFileModule?.('collection-reference');

/**
* Represents a reference to a collection of the AlwatrNitrobase.
Expand Down Expand Up @@ -142,7 +139,7 @@ export class CollectionReference<TItem extends JsonObject = JsonObject> {
if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {
this.context__.meta.schemaVer = 1;
}
delete (this.context__.meta as Dictionary)['ver'];
delete (this.context__.meta as DictionaryOpt)['ver'];
this.context__.meta.extra ??= {};
this.context__.meta.fv = 3;
}
Expand Down Expand Up @@ -588,10 +585,10 @@ export class CollectionReference<TItem extends JsonObject = JsonObject> {
this.updateDelayed_ = true;

if (immediate === true || this.context__.meta.changeDebounce === undefined) {
await waitForImmediate();
await delay.immediate();
}
else {
await waitForTimeout(this.context__.meta.changeDebounce);
await delay.by(this.context__.meta.changeDebounce);
}

if (this.updateDelayed_ !== true) return; // another parallel update finished!
Expand Down
13 changes: 5 additions & 8 deletions packages/reference/src/document-reference.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {createLogger} from '@alwatr/logger';
import {createLogger, delay} from '@alwatr/nanolib';
import {getStoreId, getStorePath} from '@alwatr/nitrobase-helper';
import {StoreFileType, StoreFileExtension, type StoreFileId, type DocumentContext, type StoreFileMeta} from '@alwatr/nitrobase-types';
import {waitForImmediate, waitForTimeout} from '@alwatr/wait';

import {logger} from './logger.js';

import type {Dictionary, JsonObject} from '@alwatr/type-helper';

logger.logModule?.('document-reference');
__dev_mode__: logger.logFileModule?.('document-reference');

/**
* Represents a reference to a document of the AlwatrNitrobase.
Expand Down Expand Up @@ -131,7 +128,7 @@ export class DocumentReference<TDoc extends JsonObject = JsonObject> {
if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {
this.context__.meta.schemaVer = 1;
}
delete (this.context__.meta as Dictionary)['ver'];
delete (this.context__.meta as DictionaryOpt)['ver'];
this.context__.meta.extra ??= {};
this.context__.meta.fv = 3;
}
Expand Down Expand Up @@ -358,10 +355,10 @@ export class DocumentReference<TDoc extends JsonObject = JsonObject> {
this.updateDelayed_ = true;

if (immediate === true || this.context__.meta.changeDebounce === undefined) {
await waitForImmediate();
await delay.immediate();
}
else {
await waitForTimeout(this.context__.meta.changeDebounce);
await delay.by(this.context__.meta.changeDebounce);
}

if (this.updateDelayed_ !== true) return; // another parallel update finished!
Expand Down
6 changes: 3 additions & 3 deletions packages/reference/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {definePackage} from '@alwatr/logger';
import {createLogger, packageTracer} from '@alwatr/nanolib';

import type {} from '@alwatr/nano-build';
__dev_mode__: packageTracer.add(__package_name__, __package_version__);

export const logger = definePackage('@alwatr/nitrobase-reference', __package_version__);
export const logger = /* #__PURE__ */ createLogger(__package_name__);
3 changes: 2 additions & 1 deletion packages/reference/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"rootDir": "src",
"outDir": "dist",
"emitDeclarationOnly": true,
"composite": true
"composite": true,
"types": ["node", "@alwatr/nano-build", "@alwatr/type-helper"]
},
"include": ["src/**/*.ts", "src/util.ts"],
"references": [{"path": "../types"}, {"path": "../helper"}]
Expand Down
10 changes: 5 additions & 5 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/dedupe": "^1.1.1"
"@alwatr/nanolib": "^1.2.0"
},
"devDependencies": {
"@alwatr/nano-build": "^1.5.0",
"@alwatr/prettier-config": "^1.0.5",
"@alwatr/tsconfig-base": "^1.3.0",
"@alwatr/type-helper": "^2.0.0",
"@alwatr/nano-build": "^2.0.1",
"@alwatr/prettier-config": "^1.0.6",
"@alwatr/tsconfig-base": "^1.3.2",
"@alwatr/type-helper": "^2.0.2",
"@types/node": "^22.7.5",
"typescript": "^5.6.3"
}
Expand Down
9 changes: 3 additions & 6 deletions packages/types/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {definePackage} from '@alwatr/dedupe';
import {packageTracer} from '@alwatr/nanolib';

import type {} from '@alwatr/nano-build';
import type {Dictionary, JsonObject} from '@alwatr/type-helper';

definePackage('@alwatr/nitrobase-types', __package_version__);
__dev_mode__: packageTracer.add(__package_name__, __package_version__);

// *** Nitrobase File ***

Expand Down Expand Up @@ -265,4 +262,4 @@ export type CollectionItem<TData extends JsonObject = JsonObject> = {
/**
* Collection item context type.
*/
export type CollectionContext<T extends JsonObject = JsonObject> = StoreFileContext<Dictionary<CollectionItem<T>>>;
export type CollectionContext<T extends JsonObject = JsonObject> = StoreFileContext<DictionaryReq<CollectionItem<T>>>;
3 changes: 2 additions & 1 deletion packages/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"rootDir": "src",
"outDir": "dist",
"emitDeclarationOnly": true,
"composite": true
"composite": true,
"types": ["node", "@alwatr/nano-build", "@alwatr/type-helper"]
},
"include": ["src/**/*.ts"]
}
Loading
Loading