first commit
This commit is contained in:
commit
45361e277d
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
dist
|
||||
node_modules
|
||||
package-lock.json
|
9
.prettierrc
Normal file
9
.prettierrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"trailingComma": "none",
|
||||
"arrowParens": "avoid",
|
||||
"printWidth": 79
|
||||
}
|
43
package.json
Normal file
43
package.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "directus-helpers",
|
||||
"version": "1.0.0",
|
||||
"description": "Helpers Directus Extensions",
|
||||
"author": "AntoXa PRO <info@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"
|
||||
}
|
2
src/index.ts
Normal file
2
src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './services'
|
||||
export * from './operations'
|
1
src/operations/index.ts
Normal file
1
src/operations/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './trigger'
|
7
src/operations/trigger.ts
Normal file
7
src/operations/trigger.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export type TTreggerData<TName extends string = string> = {
|
||||
$trigger: {
|
||||
body: {
|
||||
collection: TName
|
||||
}
|
||||
}
|
||||
}
|
47
src/services/factory.ts
Normal file
47
src/services/factory.ts
Normal file
@ -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<K extends keyof any> = { [P in K]: any }
|
||||
export type TFactoryTypes = Record<string, any>
|
||||
|
||||
export class FactoryServices<
|
||||
TTypes extends TFactoryTypes = any,
|
||||
> {
|
||||
private opts: TFactoryServicesOpts
|
||||
|
||||
private _items: Partial<TServices<keyof TTypes>> = {}
|
||||
private _files: FilesService | null = null
|
||||
|
||||
constructor(opts: TFactoryServicesOpts) {
|
||||
this.opts = opts
|
||||
}
|
||||
|
||||
items<TName extends keyof TTypes, TService extends TTypes[TName]>(
|
||||
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<TService>
|
||||
}
|
||||
|
||||
files() {
|
||||
if (!this._files) {
|
||||
this._files = new this.opts.services.FilesService({
|
||||
schema: this.opts.schema,
|
||||
accountability: this.opts.accountability
|
||||
})
|
||||
}
|
||||
return this._files as FilesService
|
||||
}
|
||||
}
|
||||
|
1
src/services/index.ts
Normal file
1
src/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './factory'
|
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@ -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"]
|
||||
}
|
13
vite.config.ts
Normal file
13
vite.config.ts
Normal file
@ -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'
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user