@osdk/maker 0.10.1 → 0.11.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -85
- package/README.md +748 -0
- package/build/browser/api/addDependency.js +40 -0
- package/build/browser/api/addDependency.js.map +1 -0
- package/build/browser/api/defineAction.js +74 -12
- package/build/browser/api/defineAction.js.map +1 -1
- package/build/browser/api/defineImportSpt.js +9 -9
- package/build/browser/api/defineImportSpt.js.map +1 -1
- package/build/browser/api/defineInterface.js +2 -13
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineLink.js +38 -8
- package/build/browser/api/defineLink.js.map +1 -1
- package/build/browser/api/defineObject.js +10 -1
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +91 -176
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/defineSpt.js +3 -16
- package/build/browser/api/defineSpt.js.map +1 -1
- package/build/browser/api/overall.test.js +4454 -2559
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/propertyConversionUtils.js +271 -0
- package/build/browser/api/propertyConversionUtils.js.map +1 -0
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +23 -5
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/index.js +1 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +515 -237
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +52 -13
- package/build/esm/api/addDependency.js +40 -0
- package/build/esm/api/addDependency.js.map +1 -0
- package/build/esm/api/defineAction.js +74 -12
- package/build/esm/api/defineAction.js.map +1 -1
- package/build/esm/api/defineImportSpt.js +9 -9
- package/build/esm/api/defineImportSpt.js.map +1 -1
- package/build/esm/api/defineInterface.js +2 -13
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineLink.js +38 -8
- package/build/esm/api/defineLink.js.map +1 -1
- package/build/esm/api/defineObject.js +10 -1
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +91 -176
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/defineSpt.js +3 -16
- package/build/esm/api/defineSpt.js.map +1 -1
- package/build/esm/api/overall.test.js +4454 -2559
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/propertyConversionUtils.js +271 -0
- package/build/esm/api/propertyConversionUtils.js.map +1 -0
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +23 -5
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/types/api/addDependency.d.ts +1 -0
- package/build/types/api/addDependency.d.ts.map +1 -0
- package/build/types/api/defineAction.d.ts +6 -6
- package/build/types/api/defineAction.d.ts.map +1 -1
- package/build/types/api/defineImportSpt.d.ts +1 -0
- package/build/types/api/defineImportSpt.d.ts.map +1 -1
- package/build/types/api/defineInterface.d.ts +1 -1
- package/build/types/api/defineLink.d.ts.map +1 -1
- package/build/types/api/defineObject.d.ts +2 -0
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/build/types/api/defineOntology.d.ts +1 -1
- package/build/types/api/defineOntology.d.ts.map +1 -1
- package/build/types/api/defineSpt.d.ts.map +1 -1
- package/build/types/api/propertyConversionUtils.d.ts +24 -0
- package/build/types/api/propertyConversionUtils.d.ts.map +1 -0
- package/build/types/api/types.d.ts +43 -6
- package/build/types/api/types.d.ts.map +1 -1
- package/build/types/cli/main.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/package.json +7 -6
package/README.md
ADDED
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
# OSDK Maker Package
|
|
2
|
+
|
|
3
|
+
The Maker package provides a type-safe, programmatic way to define ontologies, which are the foundation for structured data in Palantir Foundry. This document provides examples of how to use the maker API to define various ontology entities.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Getting Started](#getting-started)
|
|
8
|
+
- [Key Concepts](#key-concepts)
|
|
9
|
+
- [Defining an Ontology](#defining-an-ontology)
|
|
10
|
+
- [Defining Shared Property Types](#defining-shared-property-types)
|
|
11
|
+
- [Defining Value Types](#defining-value-types)
|
|
12
|
+
- [Defining Interfaces](#defining-interfaces)
|
|
13
|
+
- [Defining Objects](#defining-objects)
|
|
14
|
+
- [Defining Links](#defining-links)
|
|
15
|
+
- [Interface Link Constraints](#interface-link-constraints)
|
|
16
|
+
- [Defining Actions](#defining-actions)
|
|
17
|
+
- [Importing Ontology Entities](#importing-ontology-entities)
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
To get started with the maker package, install it as a dependency in your project:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @osdk/maker
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Defining an Ontology
|
|
28
|
+
|
|
29
|
+
An ontology serves as a container for all your type definitions. You define an ontology using the `defineOntology` function:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { defineOntology } from "@osdk/maker";
|
|
33
|
+
|
|
34
|
+
await defineOntology("com.example.", async () => {
|
|
35
|
+
// Define your ontology entities here
|
|
36
|
+
}, "path/to/output/directory");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The namespace parameter (`"com.example."` in this example) prefixes all entity names to avoid naming conflicts.
|
|
40
|
+
|
|
41
|
+
## Defining Shared Property Types
|
|
42
|
+
|
|
43
|
+
Shared Property Types (SPTs) are reusable property definitions that can be used across different object types and interfaces.
|
|
44
|
+
|
|
45
|
+
### Basic SPT
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { defineSharedPropertyType } from "@osdk/maker";
|
|
49
|
+
|
|
50
|
+
// Define a simple string SPT
|
|
51
|
+
const nameProperty = defineSharedPropertyType({
|
|
52
|
+
apiName: "name",
|
|
53
|
+
type: "string",
|
|
54
|
+
displayName: "Name",
|
|
55
|
+
description: "The name of an entity",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Define a numeric SPT
|
|
59
|
+
const ageProperty = defineSharedPropertyType({
|
|
60
|
+
apiName: "age",
|
|
61
|
+
type: "integer",
|
|
62
|
+
displayName: "Age",
|
|
63
|
+
description: "The age in years",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Define a boolean SPT
|
|
67
|
+
const activeProperty = defineSharedPropertyType({
|
|
68
|
+
apiName: "active",
|
|
69
|
+
type: "boolean",
|
|
70
|
+
displayName: "Active",
|
|
71
|
+
description: "Whether the entity is active",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Define a date SPT
|
|
75
|
+
const birthdateProperty = defineSharedPropertyType({
|
|
76
|
+
apiName: "birthdate",
|
|
77
|
+
type: "date",
|
|
78
|
+
displayName: "Birth Date",
|
|
79
|
+
description: "Date of birth",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Define a timestamp SPT
|
|
83
|
+
const updatedAtProperty = defineSharedPropertyType({
|
|
84
|
+
apiName: "updatedAt",
|
|
85
|
+
type: "timestamp",
|
|
86
|
+
displayName: "Last Updated",
|
|
87
|
+
description: "When the entity was last updated",
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Array SPT
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const tagsProperty = defineSharedPropertyType({
|
|
95
|
+
apiName: "tags",
|
|
96
|
+
type: "string",
|
|
97
|
+
array: true,
|
|
98
|
+
displayName: "Tags",
|
|
99
|
+
description: "List of tags",
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Struct SPT
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const addressProperty = defineSharedPropertyType({
|
|
107
|
+
apiName: "address",
|
|
108
|
+
type: {
|
|
109
|
+
type: "struct",
|
|
110
|
+
structDefinition: {
|
|
111
|
+
street: "string",
|
|
112
|
+
city: "string",
|
|
113
|
+
state: "string",
|
|
114
|
+
zipCode: {
|
|
115
|
+
fieldType: "string",
|
|
116
|
+
displayMetadata: {
|
|
117
|
+
displayName: "ZIP Code",
|
|
118
|
+
description: "The postal code",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
country: "string",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
displayName: "Address",
|
|
125
|
+
description: "Physical address information",
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Specialized String SPT
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const descriptionProperty = defineSharedPropertyType({
|
|
133
|
+
apiName: "description",
|
|
134
|
+
type: {
|
|
135
|
+
type: "string",
|
|
136
|
+
isLongText: true,
|
|
137
|
+
supportsEfficientLeadingWildcard: true,
|
|
138
|
+
supportsExactMatching: false,
|
|
139
|
+
},
|
|
140
|
+
displayName: "Description",
|
|
141
|
+
description: "Detailed description text",
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Marking Property
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const securityMarkingProperty = defineSharedPropertyType({
|
|
149
|
+
apiName: "securityMarking",
|
|
150
|
+
type: {
|
|
151
|
+
type: "marking",
|
|
152
|
+
markingType: "CBAC",
|
|
153
|
+
},
|
|
154
|
+
displayName: "Security Marking",
|
|
155
|
+
description: "Security classification",
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Media Reference
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
const imageProperty = defineSharedPropertyType({
|
|
163
|
+
apiName: "image",
|
|
164
|
+
type: "mediaReference",
|
|
165
|
+
displayName: "Image",
|
|
166
|
+
description: "Reference to an image file",
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Geographic Data
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const locationProperty = defineSharedPropertyType({
|
|
174
|
+
apiName: "location",
|
|
175
|
+
type: "geopoint",
|
|
176
|
+
displayName: "Location",
|
|
177
|
+
description: "Geographic coordinates",
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const areaProperty = defineSharedPropertyType({
|
|
181
|
+
apiName: "area",
|
|
182
|
+
type: "geoshape",
|
|
183
|
+
displayName: "Area",
|
|
184
|
+
description: "Geographic area or region",
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Defining Value Types
|
|
189
|
+
|
|
190
|
+
Value types allow you to define custom data types with specific constraints and validation rules.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { defineValueType } from "@osdk/maker";
|
|
194
|
+
|
|
195
|
+
// Define a string value type with constraints
|
|
196
|
+
defineValueType({
|
|
197
|
+
apiName: "emailAddress",
|
|
198
|
+
displayName: "Email Address",
|
|
199
|
+
type: {
|
|
200
|
+
type: "string",
|
|
201
|
+
constraints: [{
|
|
202
|
+
constraint: {
|
|
203
|
+
regex: "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
|
|
204
|
+
},
|
|
205
|
+
failureMessage: "Must be a valid email address",
|
|
206
|
+
}],
|
|
207
|
+
},
|
|
208
|
+
version: "1.0.0",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Define a boolean value type with allowed values
|
|
212
|
+
defineValueType({
|
|
213
|
+
apiName: "trueFalseValue",
|
|
214
|
+
displayName: "True/False Value",
|
|
215
|
+
type: {
|
|
216
|
+
type: "boolean",
|
|
217
|
+
constraints: [{
|
|
218
|
+
constraint: {
|
|
219
|
+
allowedValues: ["TRUE_VALUE"],
|
|
220
|
+
},
|
|
221
|
+
}],
|
|
222
|
+
},
|
|
223
|
+
version: "0.1.0",
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Defining Interfaces
|
|
228
|
+
|
|
229
|
+
Interfaces define a contract that objects can implement, specifying a set of properties that must be present.
|
|
230
|
+
|
|
231
|
+
### Basic Interface
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { defineInterface } from "@osdk/maker";
|
|
235
|
+
|
|
236
|
+
// Define an interface with inline properties
|
|
237
|
+
const personInterface = defineInterface({
|
|
238
|
+
apiName: "Person",
|
|
239
|
+
displayName: "Person",
|
|
240
|
+
description: "Represents a person",
|
|
241
|
+
properties: {
|
|
242
|
+
firstName: "string",
|
|
243
|
+
lastName: "string",
|
|
244
|
+
email: "string",
|
|
245
|
+
age: "integer",
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Define an interface with existing property types
|
|
250
|
+
const employeeInterface = defineInterface({
|
|
251
|
+
apiName: "Employee",
|
|
252
|
+
displayName: "Employee",
|
|
253
|
+
description: "Represents an employee",
|
|
254
|
+
properties: {
|
|
255
|
+
firstName: nameProperty, // Using previously defined SPT
|
|
256
|
+
lastName: nameProperty, // Using previously defined SPT
|
|
257
|
+
employeeId: "string",
|
|
258
|
+
department: "string",
|
|
259
|
+
hireDate: "date",
|
|
260
|
+
isActive: "boolean",
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Interface with Optional Properties
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const customerInterface = defineInterface({
|
|
269
|
+
apiName: "Customer",
|
|
270
|
+
displayName: "Customer",
|
|
271
|
+
properties: {
|
|
272
|
+
name: "string",
|
|
273
|
+
email: "string",
|
|
274
|
+
// Define an optional property
|
|
275
|
+
phoneNumber: {
|
|
276
|
+
required: false,
|
|
277
|
+
propertyDefinition: "string",
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Interface Extension
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// Define an interface that extends another interface
|
|
287
|
+
const managerInterface = defineInterface({
|
|
288
|
+
apiName: "Manager",
|
|
289
|
+
displayName: "Manager",
|
|
290
|
+
properties: {
|
|
291
|
+
managementLevel: "string",
|
|
292
|
+
directReports: "integer",
|
|
293
|
+
},
|
|
294
|
+
extends: [employeeInterface], // Extends the Employee interface
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Alternative approach using apiNames
|
|
298
|
+
const executiveInterface = defineInterface({
|
|
299
|
+
apiName: "Executive",
|
|
300
|
+
displayName: "Executive",
|
|
301
|
+
properties: {
|
|
302
|
+
stockOptions: "boolean",
|
|
303
|
+
},
|
|
304
|
+
extends: ["Manager"], // Extends using apiName
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Interface with Icon
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const productInterface = defineInterface({
|
|
312
|
+
apiName: "Product",
|
|
313
|
+
displayName: "Product",
|
|
314
|
+
icon: {
|
|
315
|
+
locator: "cube",
|
|
316
|
+
color: "#007bff",
|
|
317
|
+
},
|
|
318
|
+
properties: {
|
|
319
|
+
name: "string",
|
|
320
|
+
sku: "string",
|
|
321
|
+
price: "decimal",
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Interface with Status
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
const legacyInterface = defineInterface({
|
|
330
|
+
apiName: "LegacySystem",
|
|
331
|
+
displayName: "Legacy System",
|
|
332
|
+
properties: {
|
|
333
|
+
systemName: "string",
|
|
334
|
+
version: "string",
|
|
335
|
+
},
|
|
336
|
+
status: {
|
|
337
|
+
type: "deprecated",
|
|
338
|
+
message: "This interface is being phased out",
|
|
339
|
+
deadline: "2026-01-01T00:00:00.000Z",
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const experimentalInterface = defineInterface({
|
|
344
|
+
apiName: "ExperimentalFeature",
|
|
345
|
+
displayName: "Experimental Feature",
|
|
346
|
+
properties: {
|
|
347
|
+
featureName: "string",
|
|
348
|
+
enabled: "boolean",
|
|
349
|
+
},
|
|
350
|
+
status: {
|
|
351
|
+
type: "experimental",
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Defining Objects
|
|
357
|
+
|
|
358
|
+
Objects represent the core data entities in your ontology.
|
|
359
|
+
|
|
360
|
+
### Basic Object
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { defineObject } from "@osdk/maker";
|
|
364
|
+
|
|
365
|
+
// Define an object type
|
|
366
|
+
const personObject = defineObject({
|
|
367
|
+
apiName: "person",
|
|
368
|
+
displayName: "Person",
|
|
369
|
+
pluralDisplayName: "People",
|
|
370
|
+
titlePropertyApiName: "name", // Property to use as the title
|
|
371
|
+
primaryKeyPropertyApiName: "id", // Property to use as the primary key
|
|
372
|
+
properties: [
|
|
373
|
+
{
|
|
374
|
+
apiName: "id",
|
|
375
|
+
type: "string",
|
|
376
|
+
displayName: "ID",
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
apiName: "name",
|
|
380
|
+
type: "string",
|
|
381
|
+
displayName: "Name",
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
apiName: "email",
|
|
385
|
+
type: "string",
|
|
386
|
+
displayName: "Email",
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
apiName: "age",
|
|
390
|
+
type: "integer",
|
|
391
|
+
displayName: "Age",
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Object Implementing Interface
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
// Define an object that implements an interface
|
|
401
|
+
const employeeObject = defineObject({
|
|
402
|
+
apiName: "employee",
|
|
403
|
+
displayName: "Employee",
|
|
404
|
+
pluralDisplayName: "Employees",
|
|
405
|
+
titlePropertyApiName: "name",
|
|
406
|
+
primaryKeyPropertyApiName: "id",
|
|
407
|
+
properties: [
|
|
408
|
+
{
|
|
409
|
+
apiName: "id",
|
|
410
|
+
type: "string",
|
|
411
|
+
displayName: "ID",
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
apiName: "name",
|
|
415
|
+
type: "string",
|
|
416
|
+
displayName: "Name",
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
apiName: "email",
|
|
420
|
+
type: "string",
|
|
421
|
+
displayName: "Email",
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
apiName: "department",
|
|
425
|
+
type: "string",
|
|
426
|
+
displayName: "Department",
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
apiName: "hireDate",
|
|
430
|
+
type: "date",
|
|
431
|
+
displayName: "Hire Date",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
apiName: "isActive",
|
|
435
|
+
type: "boolean",
|
|
436
|
+
displayName: "Active",
|
|
437
|
+
},
|
|
438
|
+
],
|
|
439
|
+
implementsInterfaces: [
|
|
440
|
+
{
|
|
441
|
+
implements: employeeInterface,
|
|
442
|
+
propertyMapping: [
|
|
443
|
+
{ interfaceProperty: "firstName", mapsTo: "name" },
|
|
444
|
+
{ interfaceProperty: "lastName", mapsTo: "name" },
|
|
445
|
+
{ interfaceProperty: "employeeId", mapsTo: "id" },
|
|
446
|
+
{ interfaceProperty: "department", mapsTo: "department" },
|
|
447
|
+
{ interfaceProperty: "hireDate", mapsTo: "hireDate" },
|
|
448
|
+
{ interfaceProperty: "isActive", mapsTo: "isActive" },
|
|
449
|
+
],
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Object with Struct Property
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
const customerObject = defineObject({
|
|
459
|
+
apiName: "customer",
|
|
460
|
+
displayName: "Customer",
|
|
461
|
+
pluralDisplayName: "Customers",
|
|
462
|
+
titlePropertyApiName: "name",
|
|
463
|
+
primaryKeyPropertyApiName: "id",
|
|
464
|
+
properties: [
|
|
465
|
+
{
|
|
466
|
+
apiName: "id",
|
|
467
|
+
type: "string",
|
|
468
|
+
displayName: "ID",
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
apiName: "name",
|
|
472
|
+
type: "string",
|
|
473
|
+
displayName: "Name",
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
apiName: "address",
|
|
477
|
+
type: {
|
|
478
|
+
type: "struct",
|
|
479
|
+
structDefinition: {
|
|
480
|
+
street: "string",
|
|
481
|
+
city: "string",
|
|
482
|
+
state: "string",
|
|
483
|
+
zipCode: "string",
|
|
484
|
+
country: "string",
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
displayName: "Address",
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
});
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
### Object with Datasource
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
// Stream-backed object with retention period
|
|
497
|
+
const eventObject = defineObject({
|
|
498
|
+
apiName: "event",
|
|
499
|
+
displayName: "Event",
|
|
500
|
+
pluralDisplayName: "Events",
|
|
501
|
+
titlePropertyApiName: "eventName",
|
|
502
|
+
primaryKeyPropertyApiName: "eventId",
|
|
503
|
+
properties: [
|
|
504
|
+
{
|
|
505
|
+
apiName: "eventId",
|
|
506
|
+
type: "string",
|
|
507
|
+
displayName: "Event ID",
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
apiName: "eventName",
|
|
511
|
+
type: "string",
|
|
512
|
+
displayName: "Event Name",
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
apiName: "timestamp",
|
|
516
|
+
type: "timestamp",
|
|
517
|
+
displayName: "Timestamp",
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
datasource: {
|
|
521
|
+
type: "stream",
|
|
522
|
+
retentionPeriod: "P90D", // 90 days retention (ISO 8601 duration format)
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// Dataset-backed object
|
|
527
|
+
const productObject = defineObject({
|
|
528
|
+
apiName: "product",
|
|
529
|
+
displayName: "Product",
|
|
530
|
+
pluralDisplayName: "Products",
|
|
531
|
+
titlePropertyApiName: "name",
|
|
532
|
+
primaryKeyPropertyApiName: "id",
|
|
533
|
+
properties: [
|
|
534
|
+
{
|
|
535
|
+
apiName: "id",
|
|
536
|
+
type: "string",
|
|
537
|
+
displayName: "ID",
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
apiName: "name",
|
|
541
|
+
type: "string",
|
|
542
|
+
displayName: "Name",
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
apiName: "price",
|
|
546
|
+
type: "decimal",
|
|
547
|
+
displayName: "Price",
|
|
548
|
+
},
|
|
549
|
+
],
|
|
550
|
+
datasource: {
|
|
551
|
+
type: "dataset",
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
## Defining Links
|
|
557
|
+
|
|
558
|
+
Links define relationships between objects.
|
|
559
|
+
|
|
560
|
+
### One-to-Many Link
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
import { defineLink } from "@osdk/maker";
|
|
564
|
+
|
|
565
|
+
// Define a one-to-many link between departments and employees
|
|
566
|
+
const departmentToEmployeesLink = defineLink({
|
|
567
|
+
apiName: "departmentToEmployees",
|
|
568
|
+
one: {
|
|
569
|
+
object: departmentObject, // The "one" side of the relationship
|
|
570
|
+
metadata: {
|
|
571
|
+
apiName: "department",
|
|
572
|
+
displayName: "Department",
|
|
573
|
+
pluralDisplayName: "Departments",
|
|
574
|
+
visibility: "NORMAL",
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
toMany: {
|
|
578
|
+
object: employeeObject, // The "many" side of the relationship
|
|
579
|
+
metadata: {
|
|
580
|
+
apiName: "employees",
|
|
581
|
+
displayName: "Employee",
|
|
582
|
+
pluralDisplayName: "Employees",
|
|
583
|
+
visibility: "NORMAL",
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
manyForeignKeyProperty: "departmentId", // Property on employeeObject that refers to departmentObject
|
|
587
|
+
});
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### Many-to-Many Link
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
// Define a many-to-many link between products and categories
|
|
594
|
+
const productToCategoriesLink = defineLink({
|
|
595
|
+
apiName: "productToCategories",
|
|
596
|
+
many: {
|
|
597
|
+
object: productObject, // One side of the many-to-many relationship
|
|
598
|
+
metadata: {
|
|
599
|
+
apiName: "products",
|
|
600
|
+
displayName: "Product",
|
|
601
|
+
pluralDisplayName: "Products",
|
|
602
|
+
visibility: "NORMAL",
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
toMany: {
|
|
606
|
+
object: categoryObject, // Other side of the many-to-many relationship
|
|
607
|
+
metadata: {
|
|
608
|
+
apiName: "categories",
|
|
609
|
+
displayName: "Category",
|
|
610
|
+
pluralDisplayName: "Categories",
|
|
611
|
+
visibility: "NORMAL",
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
## Interface Link Constraints
|
|
618
|
+
|
|
619
|
+
Interface Link Constraints define relationships between interfaces.
|
|
620
|
+
|
|
621
|
+
```typescript
|
|
622
|
+
import { defineInterfaceLinkConstraint } from "@osdk/maker";
|
|
623
|
+
|
|
624
|
+
// Define a single link constraint between Manager and Employee interfaces
|
|
625
|
+
const managerToEmployeesLink = defineInterfaceLinkConstraint({
|
|
626
|
+
apiName: "managerToEmployees",
|
|
627
|
+
from: managerInterface,
|
|
628
|
+
toMany: employeeInterface,
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
// Define a one-to-one link constraint
|
|
632
|
+
const personToAddressLink = defineInterfaceLinkConstraint({
|
|
633
|
+
apiName: "personToAddress",
|
|
634
|
+
from: personInterface,
|
|
635
|
+
toOne: addressInterface,
|
|
636
|
+
});
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
## Defining Actions
|
|
640
|
+
|
|
641
|
+
Actions define operations that can be performed on objects and interfaces.
|
|
642
|
+
|
|
643
|
+
### Custom Action
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
import { defineAction } from "@osdk/maker";
|
|
647
|
+
|
|
648
|
+
// Define a custom action
|
|
649
|
+
const markAsInactiveAction = defineAction({
|
|
650
|
+
apiName: "mark-as-inactive",
|
|
651
|
+
displayName: "Mark as Inactive",
|
|
652
|
+
parameters: [
|
|
653
|
+
{
|
|
654
|
+
id: "reason",
|
|
655
|
+
displayName: "Reason",
|
|
656
|
+
type: "string",
|
|
657
|
+
validation: {
|
|
658
|
+
required: true,
|
|
659
|
+
allowedValues: { type: "text" },
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
id: "effectiveDate",
|
|
664
|
+
displayName: "Effective Date",
|
|
665
|
+
type: "date",
|
|
666
|
+
validation: {
|
|
667
|
+
required: true,
|
|
668
|
+
allowedValues: { type: "datetime" },
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
status: "active",
|
|
673
|
+
rules: [
|
|
674
|
+
{
|
|
675
|
+
type: "addOrModifyObjectRuleV2",
|
|
676
|
+
addOrModifyObjectRuleV2: {
|
|
677
|
+
objectToModify: "objectToModifyParameter",
|
|
678
|
+
propertyValues: {
|
|
679
|
+
"isActive": {
|
|
680
|
+
type: "staticValue",
|
|
681
|
+
staticValue: {
|
|
682
|
+
type: "boolean",
|
|
683
|
+
boolean: false,
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
"inactiveReason": {
|
|
687
|
+
type: "parameterId",
|
|
688
|
+
parameterId: "reason",
|
|
689
|
+
},
|
|
690
|
+
"inactiveDate": {
|
|
691
|
+
type: "parameterId",
|
|
692
|
+
parameterId: "effectiveDate",
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
structFieldValues: {},
|
|
696
|
+
},
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
});
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
### Create Object Action
|
|
703
|
+
|
|
704
|
+
```typescript
|
|
705
|
+
import { defineCreateObjectAction } from "@osdk/maker";
|
|
706
|
+
|
|
707
|
+
// Define an action to create an employee
|
|
708
|
+
const createEmployeeAction = defineCreateObjectAction(employeeObject);
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
### Modify Object Action
|
|
712
|
+
|
|
713
|
+
```typescript
|
|
714
|
+
import { defineModifyObjectAction } from "@osdk/maker";
|
|
715
|
+
|
|
716
|
+
// Define an action to modify an employee
|
|
717
|
+
const modifyEmployeeAction = defineModifyObjectAction(employeeObject);
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
### Delete Object Action
|
|
721
|
+
|
|
722
|
+
```typescript
|
|
723
|
+
import { defineDeleteObjectAction } from "@osdk/maker";
|
|
724
|
+
|
|
725
|
+
// Define an action to delete an employee
|
|
726
|
+
const deleteEmployeeAction = defineDeleteObjectAction(employeeObject);
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
### Interface Actions
|
|
730
|
+
|
|
731
|
+
```typescript
|
|
732
|
+
import {
|
|
733
|
+
defineCreateInterfaceObjectAction,
|
|
734
|
+
defineModifyInterfaceObjectAction,
|
|
735
|
+
} from "@osdk/maker";
|
|
736
|
+
|
|
737
|
+
// Define an action to create objects implementing an interface
|
|
738
|
+
const createPersonAction = defineCreateInterfaceObjectAction(personInterface);
|
|
739
|
+
|
|
740
|
+
// Define an action for a specific object type that implements an interface
|
|
741
|
+
const createEmployeePersonAction = defineCreateInterfaceObjectAction(
|
|
742
|
+
personInterface,
|
|
743
|
+
employeeObject,
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
// Define an action to modify objects implementing an interface
|
|
747
|
+
const modifyPersonAction = defineModifyInterfaceObjectAction(personInterface);
|
|
748
|
+
```
|