-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathcreateFeatureService.ts
More file actions
201 lines (185 loc) · 5.31 KB
/
Copy pathcreateFeatureService.ts
File metadata and controls
201 lines (185 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Copyright (c) 2018-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import { request, IExtent, ISpatialReference } from "@esri/arcgis-rest-request";
import {
moveItem,
ICreateUpdateItemOptions,
determineOwner,
getPortalUrl
} from "@esri/arcgis-rest-portal";
/**
* A [`createParameters` JSON object for a new
* service](https://developers.arcgis.com/rest/users-groups-and-items/create-service.htm).
*/
export interface ICreateServiceParams {
/**
* Name of the service to be created. This name must be unique. If the name already exists, the operation will fail. ArcGIS Enterprise does not allow spaces or special characters other than underscores in a service name.
*/
name: string;
/**
* Description given to the service.
*/
serviceDescription?: string;
/**
* Indicates whether the data changes.
*/
hasStaticData?: boolean;
/**
* A double value indicating any constraints enforced on query operations.
*/
maxRecordCount?: number;
/**
* The formats in which query results are returned.
*/
supportedQueryFormats?: string;
/**
* Specify feature service editing capabilities for Create, Delete, Query, Update, and Sync.
*/
capabilities?: string;
/**
* A user-friendly description for the published dataset.
*/
description?: string;
/**
* Copyright information associated with the dataset.
*/
copyrightText?: string;
/**
* All layers added to a hosted feature service need to have the same spatial reference defined for
* the feature service. When creating a new empty service without specifying its spatial reference,
* the spatial reference of the hosted feature service is set to the first layer added to that
* feature service.
*/
spatialReference?: ISpatialReference;
/**
* The initial extent set for the service.
*/
initialExtent?: IExtent;
/**
* Indicates if updating the geometry of the service is permitted.
*/
allowGeometryUpdates?: boolean;
/**
* Units used by the feature service
*/
units?: string;
/**
* A JSON object specifying the properties of cross-site scripting prevention.
*/
xssPreventionInfo?: any;
/**
* Editor tracking info.
*/
editorTrackingInfo?: {
enableEditorTracking?: boolean;
enableOwnershipAccessControl?: boolean;
allowOthersToUpdate?: boolean;
allowOthersToDelete?: boolean;
allowOthersToQuery?: boolean;
allowAnonymousToUpdate?: boolean;
allowAnonymousToDelete?: boolean;
};
}
export interface ICreateServiceOptions extends ICreateUpdateItemOptions {
/**
* A JSON object specifying the properties of the newly-created service. See the [REST
* Documentation](https://developers.arcgis.com/rest/users-groups-and-items/working-with-users-groups-and-items.htm)
* for more information.
*/
item: ICreateServiceParams;
/**
* Alphanumeric id of folder to house moved item. If null, empty, or "/", the destination is the
* root folder.
*/
folderId?: string;
/**
* If true, the service is overwritten. The default value is false.
*/
overwrite?: boolean;
/**
* Specifies if the request is generating a location tracking view. A view can only be
* created if there is already a Location Tracking Service that has been created.
*/
isView?: boolean;
}
export interface ICreateServiceResult {
/**
* The encoded URL to the hosted service.
*/
encodedServiceURL: string;
/**
* Indicates if this feature service represents a view.
*/
isView: boolean;
/**
* The unique ID for this item.
*/
itemId: string;
/**
* Name of the service item.
*/
name: string;
/**
* The ID of the new service item.
*/
serviceItemId: string;
/**
* The URL to the hosted service.
*/
serviceurl: string;
/**
* The size of the item.
*/
size: number;
/**
* Indicates if the operation was successful.
*/
success: boolean;
/**
* The type of service created.
*/
type: string;
}
/**
* Create a new [hosted feature service](https://developers.arcgis.com/rest/users-groups-and-items/create-service.htm). After the service has been created, call {@linkcode addToServiceDefinition} if you'd like to update it's schema.
*
* ```js
* import {
* createFeatureService,
* addToServiceDefinition
* } from '@esri/arcgis-rest-feature-service';
* //
* createFeatureService({
* authentication: ArcGISIdentityManager,
* item: {
* "name": "NewEmptyService",
* "capabilities": "Create,Delete,Query,Update,Editing"
* }
* });
* ```
*
* @param requestOptions - Options for the request.
* @returns A Promise that resolves with service details once the service has been created
*/
export function createFeatureService(
requestOptions: ICreateServiceOptions
): Promise<ICreateServiceResult> {
return determineOwner(requestOptions).then((owner) => {
const options: ICreateServiceOptions = {
...requestOptions
};
const baseUrl = `${getPortalUrl(requestOptions)}/content/users/${owner}`;
const folder =
!options.folderId || options.folderId === "/"
? ""
: "/" + options.folderId;
const url = `${baseUrl}${folder}/createService`;
// Create the service
options.params = {
createParameters: options.item,
outputType: "featureService",
...options.params
};
return request(url, options);
});
}