first commit
This commit is contained in:
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'
|
Reference in New Issue
Block a user