Просмотр исходного кода

refactor: removes declaration files

e22m4u 4 дней назад
Родитель
Сommit
e2bb6be20c

+ 2 - 0
dist/cjs/index.cjs

@@ -236,6 +236,8 @@ var import_js_format3 = require("@e22m4u/js-format");
 var _ProjectionSchemaRegistry = class _ProjectionSchemaRegistry extends import_js_service.Service {
   /**
    * Schema map.
+   *
+   * @type {Map.<string, object>}
    */
   _schemas = /* @__PURE__ */ new Map();
   /**

+ 3 - 0
eslint.config.js

@@ -2,6 +2,7 @@ import globals from 'globals';
 import eslintJs from '@eslint/js';
 import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
+import eslintImportPlugin from 'eslint-plugin-import';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 
@@ -16,11 +17,13 @@ export default [{
   plugins: {
     'jsdoc': eslintJsdocPlugin,
     'mocha': eslintMochaPlugin,
+    'import': eslintImportPlugin,
     'chai-expect': eslintChaiExpectPlugin,
   },
   rules: {
     ...eslintJs.configs.recommended.rules,
     ...eslintPrettierConfig.rules,
+    ...eslintImportPlugin.flatConfigs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
     ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,

+ 7 - 0
jsconfig.json

@@ -0,0 +1,7 @@
+{
+  "compilerOptions": {
+    "target": "es2022",
+    "module": "NodeNext",
+    "moduleResolution": "NodeNext"
+  }
+}

+ 6 - 9
package.json

@@ -11,17 +11,15 @@
     "projection",
     "filtering"
   ],
-  "homepage": "https://github.com/e22m4u/js-data-projector",
+  "homepage": "https://gitrepos.ru/e22m4u/js-data-projector",
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/e22m4u/js-data-projector.git"
+    "url": "git+https://gitrepos.ru/e22m4u/js-data-projector.git"
   },
   "type": "module",
-  "types": "./src/index.d.ts",
   "module": "./src/index.js",
   "main": "./dist/cjs/index.cjs",
   "exports": {
-    "types": "./src/index.d.ts",
     "import": "./src/index.js",
     "require": "./dist/cjs/index.cjs"
   },
@@ -29,8 +27,8 @@
     "node": ">=12"
   },
   "scripts": {
-    "lint": "tsc && eslint ./src",
-    "lint:fix": "tsc && eslint ./src --fix",
+    "lint": "eslint ./src",
+    "lint:fix": "eslint ./src --fix",
     "format": "prettier --write \"./src/**/*.js\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha --bail",
     "test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
@@ -45,20 +43,19 @@
     "@commitlint/cli": "~20.1.0",
     "@commitlint/config-conventional": "~20.0.0",
     "@eslint/js": "~9.39.1",
-    "@types/mocha": "~10.0.10",
     "c8": "~10.1.3",
     "chai": "~6.2.1",
     "esbuild": "~0.27.0",
     "eslint": "~9.39.1",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",
+    "eslint-plugin-import": "^2.32.0",
     "eslint-plugin-jsdoc": "~61.4.1",
     "eslint-plugin-mocha": "~11.2.0",
     "globals": "~16.5.0",
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
     "prettier": "~3.7.2",
-    "rimraf": "~6.1.2",
-    "typescript": "~5.9.3"
+    "rimraf": "~6.1.2"
   }
 }

+ 0 - 55
src/data-projector.d.ts

@@ -1,55 +0,0 @@
-import {Service} from '@e22m4u/js-service';
-import {ProjectDataOptions} from './project-data.js';
-import {ProjectionSchema} from './projection-schema.js';
-
-/**
- * Data projector.
- */
-export declare class DataProjector extends Service {
-  /**
-   * Define schema.
-   *
-   * @param name
-   * @param schema
-   */
-  defineSchema(name: string, schema: ProjectionSchema): this;
-
-  /**
-   * Project.
-   *
-   * @param schemaOrName
-   * @param data
-   * @param options
-   */
-  project<T>(
-    schemaOrName: string | ProjectionSchema,
-    data: T,
-    options?: Omit<ProjectDataOptions, 'resolver'>,
-  ): T;
-
-  /**
-   * Project with "input" scope.
-   *
-   * @param schemaOrName
-   * @param data
-   * @param options
-   */
-  projectInput<T>(
-    schemaOrName: string | ProjectionSchema,
-    data: T,
-    options?: Omit<ProjectDataOptions, 'resolver' | 'scope'>,
-  ): T;
-
-  /**
-   * Project with "output" scope.
-   *
-   * @param schemaOrName
-   * @param data
-   * @param options
-   */
-  projectOutput<T>(
-    schemaOrName: string | ProjectionSchema,
-    data: T,
-    options?: Omit<ProjectDataOptions, 'resolver' | 'scope'>,
-  ): T;
-}

+ 0 - 2
src/data-projector.spec.js

@@ -142,7 +142,6 @@ describe('DataProjector', function () {
 
     it('should throw an error when the resolver option is provided', function () {
       const S = new DataProjector();
-      // @ts-ignore
       const throwable = v => () => S.project({}, {}, {resolver: v});
       const error = 'Option "resolver" is not supported for the DataProjector.';
       expect(throwable('str')).to.throw(error);
@@ -159,7 +158,6 @@ describe('DataProjector', function () {
 
     it('should validate the given schema object', function () {
       const S = new DataProjector();
-      // @ts-ignore
       const throwable = () => S.project({foo: 10}, {foo: 'bar'});
       expect(throwable).to.throw(
         'Property options must be a Boolean or an Object, but 10 was given.',

+ 0 - 6
src/index.d.ts

@@ -1,6 +0,0 @@
-export * from './project-data.js';
-export * from './data-projector.js';
-export * from './projection-scope.js';
-export * from './projection-schema.js';
-export * from './projection-schema-registry.js';
-export * from './validate-projection-schema.js';

+ 0 - 1
src/index.js

@@ -1,6 +1,5 @@
 export * from './project-data.js';
 export * from './data-projector.js';
 export * from './projection-scope.js';
-export * from './projection-schema.js';
 export * from './projection-schema-registry.js';
 export * from './validate-projection-schema.js';

+ 0 - 30
src/project-data.d.ts

@@ -1,30 +0,0 @@
-import {ProjectionSchema} from './projection-schema.js';
-
-/**
- * Projection schema resolver.
- */
-export type ProjectionSchemaResolver = (
-  schemaName: string,
-) => ProjectionSchema;
-
-/**
- * Project data options.
- */
-export type ProjectDataOptions = {
-  strict?: boolean;
-  scope?: string;
-  resolver?: ProjectionSchemaResolver;
-};
-
-/**
- * Project data.
- *
- * @param schemaOrName
- * @param data
- * @param options
- */
-export declare function projectData<T>(
-  schemaOrName: string | ProjectionSchema,
-  data: T,
-  options?: ProjectDataOptions,
-): T;

+ 0 - 22
src/projection-schema-registry.d.ts

@@ -1,22 +0,0 @@
-import {Service} from '@e22m4u/js-service';
-import {ProjectionSchema} from './projection-schema.js';
-
-/**
- * Projection schema registry.
- */
-export declare class ProjectionSchemaRegistry extends Service {
-  /**
-   * Define schema.
-   *
-   * @param name
-   * @param schema
-   */
-  defineSchema(name: string, schema: ProjectionSchema): this;
-
-  /**
-   * Get schema.
-   *
-   * @param name
-   */
-  getSchema(name: string): ProjectionSchema;
-}

+ 2 - 0
src/projection-schema-registry.js

@@ -8,6 +8,8 @@ import {validateProjectionSchema} from './validate-projection-schema.js';
 export class ProjectionSchemaRegistry extends Service {
   /**
    * Schema map.
+   *
+   * @type {Map.<string, object>}
    */
   _schemas = new Map();
 

+ 0 - 29
src/projection-schema.d.ts

@@ -1,29 +0,0 @@
-/**
- * Projection schema.
- */
-export type ProjectionSchema = {
-  [property: string]: boolean | ProjectionSchemaPropertyOptions | undefined;
-}
-
-/**
- * Projection schema property options.
- */
-export type ProjectionSchemaPropertyOptions = {
-  select?: boolean;
-  scopes?: ProjectionSchemaScopes;
-  schema?: string | ProjectionSchema;
-}
-
-/**
- * Projection schema scopes.
- */
-export type ProjectionSchemaScopes = {
-  [scope: string]: boolean | ProjectionSchemaScopeOptions | undefined;
-}
-
-/**
- * Projection schema scope options.
- */
-export type ProjectionSchemaScopeOptions = {
-  select?: boolean;
-}

+ 0 - 1
src/projection-schema.js

@@ -1 +0,0 @@
-export {};

+ 0 - 13
src/projection-scope.d.ts

@@ -1,13 +0,0 @@
-/**
- * Projection scope.
- */
-export declare const ProjectionScope: {
-  INPUT: 'input',
-  OUTPUT: 'output',
-};
-
-/**
- * Projection scope.
- */
-export type ProjectionScope =
-  (typeof ProjectionScope)[keyof typeof ProjectionScope];

+ 0 - 12
src/validate-projection-schema.d.ts

@@ -1,12 +0,0 @@
-import {ProjectionSchema} from './projection-schema.js';
-
-/**
- * Validate projection schema.
- *
- * @param schema
- * @param shallowMode
- */
-export declare function validateProjectionSchema(
-  schema: ProjectionSchema,
-  shallowMode?: boolean
-): void;

+ 0 - 2
src/validate-projection-schema.spec.js

@@ -176,7 +176,6 @@ describe('validateProjectionSchema', function () {
   });
 
   it('should validate root schema in shallow mode', function () {
-    // @ts-ignore
     const throwable = () => validateProjectionSchema({foo: 10}, true);
     expect(throwable).to.throw(
       'Property options must be a Boolean or an Object, but 10 was given.',
@@ -184,7 +183,6 @@ describe('validateProjectionSchema', function () {
   });
 
   it('should skip nested schema checking in shallow mode', function () {
-    // @ts-ignore
     validateProjectionSchema({foo: {schema: {prop: 10}}}, true);
   });
 });

+ 0 - 14
tsconfig.json

@@ -1,14 +0,0 @@
-{
-  "compilerOptions": {
-    "noEmit": true,
-    "target": "es2022",
-    "module": "NodeNext",
-    "moduleResolution": "NodeNext",
-    "allowJs": true,
-    "checkJs": true
-  },
-  "include": [
-    "./src/**/*.ts",
-    "./src/**/*.js"
-  ]
-}