From 45361e277de1a58aa14fdcda48541e34e58964fc Mon Sep 17 00:00:00 2001 From: AntoXa PRO Date: Wed, 6 Mar 2024 16:08:27 +0300 Subject: [PATCH] first commit --- .gitignore | 3 +++ .prettierrc | 9 ++++++++ package.json | 43 +++++++++++++++++++++++++++++++++++ src/index.ts | 2 ++ src/operations/index.ts | 1 + src/operations/trigger.ts | 7 ++++++ src/services/factory.ts | 47 +++++++++++++++++++++++++++++++++++++++ src/services/index.ts | 1 + tsconfig.json | 15 +++++++++++++ vite.config.ts | 13 +++++++++++ 10 files changed, 141 insertions(+) create mode 100644 .gitignore create mode 100644 .prettierrc create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 src/operations/index.ts create mode 100644 src/operations/trigger.ts create mode 100644 src/services/factory.ts create mode 100644 src/services/index.ts create mode 100644 tsconfig.json create mode 100644 vite.config.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91a3983 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist +node_modules +package-lock.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..cdda34f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "useTabs": true, + "tabWidth": 2, + "singleQuote": true, + "semi": false, + "trailingComma": "none", + "arrowParens": "avoid", + "printWidth": 79 +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..bb1641f --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "directus-helpers", + "version": "1.0.0", + "description": "Helpers Directus Extensions", + "author": "AntoXa PRO ", + "homepage": "https://antoxahub.ru/antoxa/directus-helpers", + "repository": { + "type": "git", + "url": "https://antoxahub.ru/antoxa/directus-helpers.git" + }, + "module": "./dist/index.mjs", + "main": "./dist/index.umd.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "requier": "./dist/index.umd.js" + }, + "./dist/*": "./dist/*", + "./package.json": "./package.json", + "./tsconfig.json": "./tsconfig.json" + }, + "files": [ + "dist", + "tsconfig.json" + ], + "scripts": { + "build": "vite build", + "prepare": "npm run build" + }, + "keywords": [ + "Directus" + ], + "devDependencies": { + "@directus/api": "^18.0.0", + "@directus/extensions-sdk": "^11.0.0", + "prettier": "^3.2.5", + "vite": "^5.1.5", + "vite-plugin-dts": "^3.7.3" + }, + "license": "ISC" +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..c87b7f3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './services' +export * from './operations' diff --git a/src/operations/index.ts b/src/operations/index.ts new file mode 100644 index 0000000..21279ad --- /dev/null +++ b/src/operations/index.ts @@ -0,0 +1 @@ +export * from './trigger' diff --git a/src/operations/trigger.ts b/src/operations/trigger.ts new file mode 100644 index 0000000..6e21b8d --- /dev/null +++ b/src/operations/trigger.ts @@ -0,0 +1,7 @@ +export type TTreggerData = { + $trigger: { + body: { + collection: TName + } + } +} diff --git a/src/services/factory.ts b/src/services/factory.ts new file mode 100644 index 0000000..910e20b --- /dev/null +++ b/src/services/factory.ts @@ -0,0 +1,47 @@ +import type { SchemaOverview, Accountability } from '@directus/types' +import type { ItemsService, FilesService } from '@directus/api/dist/services' + +export type TFactoryServicesOpts = { + services: any + schema: SchemaOverview + accountability?: Accountability +} + +type TServices = { [P in K]: any } +export type TFactoryTypes = Record + +export class FactoryServices< + TTypes extends TFactoryTypes = any, +> { + private opts: TFactoryServicesOpts + + private _items: Partial> = {} + private _files: FilesService | null = null + + constructor(opts: TFactoryServicesOpts) { + this.opts = opts + } + + items( + name: TName + ) { + if (!this._items[name]) { + this._items[name] = new this.opts.services.ItemsService(name, { + schema: this.opts.schema, + accountability: this.opts.accountability + }) + } + return this._items[name] as ItemsService + } + + files() { + if (!this._files) { + this._files = new this.opts.services.FilesService({ + schema: this.opts.schema, + accountability: this.opts.accountability + }) + } + return this._files as FilesService + } +} + diff --git a/src/services/index.ts b/src/services/index.ts new file mode 100644 index 0000000..8fd2463 --- /dev/null +++ b/src/services/index.ts @@ -0,0 +1 @@ +export * from './factory' diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..9576b77 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + + "strict": true, + "moduleResolution": "Node", + "isolatedModules": true, + "esModuleInterop": true, + "useDefineForClassFields": true, + + "declaration": true + }, + "include": ["src/**/*.ts", "src/**/*.d.ts"] +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..2f5e0af --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite' +import dts from 'vite-plugin-dts' + +export default defineConfig({ + plugins: [dts()], + build: { + lib: { + entry: 'src/index.ts', + name: 'directus-helpers', + fileName: 'index' + } + } +})