<commit_before>## Data service view
This is a special use case for a child resource that is a `view` of the parent. If a specific parent is selected, the `view` is treated as a singleton. Otherwise, it is treated as a standard resource.

See [dataService](./dataService.md) and [singletonDataService](../baseSingletonDataService/singletonDataService.md) for details on each resource type.

### Example
Data service view:
```
export let endpoint: string = '/permissions';

export interface IUserPermissions {
	financial: ICRUDPermissions;
}

export interface ICRUDPermissions {
	create: boolean;
	read: boolean;
	edit: boolean;
	delete: boolean;
}
```
Definition in the parent (see [parentDataService](../baseParentDataService/parentDataService.md) for details on how to define a parent data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import * as permissions from './permissions';

export { permissions };

export interface IChildResources {
	permissions: __dataContracts.IDataServiceView<permissions.IUserPermissions, void>;
}

export function buildChildResources(baseResourceBuilder: __dataContracts.IBaseResourceBuilder): { (): IChildResources } {
	return (): IServiceEventChildResources => {
		return {
			permissions: baseResourceBuilder.createResourceView<permissions.IUserPermissions, void>({
				endpoint: permissions.endpoint,
			}),
		};
	};
}
```
Usage (as a data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import { DataServices, serviceName as dataServiceName, user } from '../data/data.service';

export class MyConsumer {
	permissionsResource: __dataContracts.IDataService<user.permissions.IUserPermissions, void>;

	static $inject: string[] = [dataServiceName];
	constructor(dataServices: DataServices) {
		// no parent is selected
		this.permissionsResource = dataServices.user.childContract();
	}

	action(): void {
		this.permissionsResource.getList().then((permissions: user.permissions.IUserPermissions[]): void => {
			console.log(permissions);
		});
	}
}
```
Usage (as a singleton data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import { DataServices, serviceName as dataServiceName, user } from '../data/data.service';

export class MyConsumer {
	permissionsResource: __dataContracts.IDataService<user.permissions.IUserPermissions, void>;

	static $inject: string[] = [dataServiceName, 'userId'];
	constructor(dataServices: DataServices, userId: number) {
		// select a parent
		this.permissionsResource = dataServices.user.childContract(userId);
	}

	action(): void {
		this.permissionsResource.get().then((permissions: user.permissions.IUserPermissions): void => {
			console.log(permissions);
		});
	}
}
```<commit_msg>User `settings` is a better use case. Permissions could easily have a many-to-one relationship with users, which would undermine the use case.<commit_after>## Data service view
This is a special use case for a child resource that is a `view` of the parent. If a specific parent is selected, the `view` is treated as a singleton. Otherwise, it is treated as a standard resource.

See [dataService](./dataService.md) and [singletonDataService](../baseSingletonDataService/singletonDataService.md) for details on each resource type.

### Example
Data service view:
```
export let endpoint: string = '/settings';

export interface IUserSettings {
	theme: string;
}
```
Definition in the parent (see [parentDataService](../baseParentDataService/parentDataService.md) for details on how to define a parent data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import * as settings from './settings';

export { settings };

export interface IChildResources {
	settings: __dataContracts.IDataServiceView<settings.IUserSettings, void>;
}

export function buildChildResources(baseResourceBuilder: __dataContracts.IBaseResourceBuilder): { (): IChildResources } {
	return (): IServiceEventChildResources => {
		return {
			settings: baseResourceBuilder.createResourceView<settings.IUserSettings, void>({
				endpoint: settings.endpoint,
			}),
		};
	};
}
```
Usage (as a data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import { DataServices, serviceName as dataServiceName, user } from '../data/data.service';

export class MyConsumer {
	settingsResource: __dataContracts.IDataService<user.settings.IUserSettings, void>;

	static $inject: string[] = [dataServiceName];
	constructor(dataServices: DataServices) {
		// no parent is selected
		this.settingsResource = dataServices.user.childContract();
	}

	action(): void {
		this.settingsResource.getList().then((settings: user.settings.IUserSettings[]): void => {
			console.log(settings);
		});
	}
}
```
Usage (as a singleton data service):
```
import { services } from 'typescript-angular-utilities';
import __dataContracts = services.dataContracts;

import { DataServices, serviceName as dataServiceName, user } from '../data/data.service';

export class MyConsumer {
	settingsResource: __dataContracts.IDataService<user.settings.IUserSettings, void>;

	static $inject: string[] = [dataServiceName, 'userId'];
	constructor(dataServices: DataServices, userId: number) {
		// select a parent
		this.settingsResource = dataServices.user.childContract(userId).settings;
	}

	action(): void {
		this.settingsResource.get().then((settings: user.settings.IUserSettings): void => {
			console.log(settings);
		});
	}
}
```
{'fraction_non_alphanumeric': 0.11613584374450114, 'fraction_numerical': 0.0, 'mean_word_length': 5.555940023068051, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3402183', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1574, 'n_words': 444}