8000 Added type definitions for hook-less service methods. by deskoh · Pull Request #1288 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

Added type definitions for hook-less service methods.#1288

Closed
deskoh wants to merge 3 commits intofeathersjs:masterfrom
deskoh:master
Closed

Added type definitions for hook-less service methods.#1288
deskoh wants to merge 3 commits intofeathersjs:masterfrom
deskoh:master

Conversation

@deskoh
Copy link
Contributor
@deskoh deskoh commented Apr 15, 2019

Related to #1269 to support Calling the hook-less service methods of the database adapters.

Hook-less service methods is also useful for in unit tests for creating / updating multiple items if multi flag is not set as the hook-less methods does not check for multi flag,

@daffl
Copy link
Member
daffl commented Apr 18, 2019

Thank you! I think it makes sense to add them. Can we put them into a separate interface though since it's only implemented by the service adapters?

@jordanbtucker
Copy link
Contributor
jordanbtucker commented Apr 18, 2019

I think this needs to go into adapter-commons instead. For example, the following code won't work because it just uses an object based service instead of using adapter-commons.

const feathers = require('@feathersjs/feathers')

const app = feathers()

const items = []

app.use('items', {
	async create (data) {
		data.id = items.length
		items.push(data)
		return data
	},
})

const itemsService = app.service('items')

itemsService.hooks({
	before: {
		create: [
			() => { console.log('Before hook') },
		],
	},
})

async function run () {
	await itemsService.create({text: 'Hello, World!'})
	await itemsService._create({text: 'No hooks'})
	// throws TypeError: itemsService._create is not a function
}

run()

If we put it into adapter-commons, then we might be able to use namespace merging, type intersection, module augmentation or some combination to ensure the type definition works properly.

@deskoh
Copy link
Contributor Author
deskoh commented Apr 28, 2019

@jordanbtucker Existing type definitions have similar problems for object-based service. For example, referencing the code above, the snippet below also exhibits similar problems:

async function run () {
	await itemsService.create({text: 'Hello, World!'})
	await await itemsService.get(1);
	// throws TypeError: itemsService.get is not a function even though there is no type error using current type definitions.
}

The type resolution need to be able to distinguish object-based service and service using the Database Common API. Not sure how to achieve this at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0