first commit

This commit is contained in:
2024-03-06 16:08:27 +03:00
commit 45361e277d
10 changed files with 141 additions and 0 deletions

2
src/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './services'
export * from './operations'

1
src/operations/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './trigger'

View File

@@ -0,0 +1,7 @@
export type TTreggerData<TName extends string = string> = {
$trigger: {
body: {
collection: TName
}
}
}

47
src/services/factory.ts Normal file
View 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
View File

@@ -0,0 +1 @@
export * from './factory'