@osdk/typescript-sdk-docs 0.0.0

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.
@@ -0,0 +1,847 @@
1
+ 'use strict';
2
+
3
+ var outdent = require('outdent');
4
+
5
+ // src/docs.ts
6
+
7
+ // src/generatedNoCheck/docsNoComputedVariables.ts
8
+ var snippets = {
9
+ "kind": "sdk",
10
+ "versions": {
11
+ "1.0.0": {
12
+ "snippets": {
13
+ "loadSingleObjectGuide": [{
14
+ "template": 'import { type GetObjectError, isOk, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst result: Result<{{objectType}}, GetObjectError> = await client.ontology.objects.{{objectType}}.get("primaryKey");\nif (isOk(result)) {\n const object: {{objectType}} = result.value;\n} else {\n console.error(result.error.errorType);\n}'
15
+ }],
16
+ "loadObjectPageGuide": [{
17
+ "template": 'import { isOk, type LoadObjectSetError, Page, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst firstPage: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}.page({ pageSize: 30 });\n\nif (isOk(firstPage)) {\n const secondPage: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .page({ pageSize: 30, pageToken: firstPage.value.nextPageToken });\n\n const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;\n const object = objects[0];\n}'
18
+ }],
19
+ "orderObjectsGuide": [{
20
+ "template": 'import { isOk, Page, type Result, type SearchObjectsError } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst page: Result<Page<{{objectType}}>, SearchObjectsError> = await client.ontology.objects.{{objectType}}\n .orderBy(sortBy => sortBy.{{titleProperty}}.asc())\n .page({ pageSize: 30 });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
21
+ }],
22
+ "searchObjectsGuide": [{
23
+ "template": 'import { isOk, type LoadObjectSetError, Page, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst page: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .where(query => query.{{titleProperty}}.isNull())\n .page({ pageSize: 30 });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
24
+ }],
25
+ "loadSingleObjectReference": [{
26
+ "template": 'import { type GetObjectError, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst response: Result<{{objectType}}, GetObjectError> = await client.ontology.objects.{{objectType}}.get("primaryKey");'
27
+ }],
28
+ "loadObjectsReference": [{
29
+ "template": 'import { type LoadObjectSetError, Page, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst response: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .page({ pageSize: 30 });'
30
+ }],
31
+ "loadAllObjectsReference": [{
32
+ "template": 'import { isOk, type LoadObjectSetError, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objects: Result<{{objectType}}[], LoadObjectSetError> = await client.ontology.objects.{{objectType}}.all();\n\nif (isOk(objects)) {\n const object = objects.value[0];\n}'
33
+ }],
34
+ "loadLinkedObjectReference": [{
35
+ "template": 'import { type GetLinkedObjectError, type Result } from "{{{packageName}}}";\nimport { {{sourceObjectType}}, {{linkedObjectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getLinked{{linkedObjectType}}(source: {{sourceObjectType}}, linkedObjectPrimaryKey: {{linkedPrimaryKeyPropertyV1.type}}) {\n return source.{{linkApiName}}.get(linkedObjectPrimaryKey);\n}',
36
+ "computedVariables": ["linkedPrimaryKeyPropertyV1"]
37
+ }],
38
+ "loadLinkedObjectsReference": [{
39
+ "template": 'import { type GetLinkedObjectError, type Result } from "{{{packageName}}}";\nimport { {{sourceObjectType}}, {{linkedObjectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getLinked{{linkedObjectType}}(source: {{sourceObjectType}}) {\n {{#isLinkManySided}}\n return source.{{linkApiName}}.page({ pageSize: 30 });\n {{/isLinkManySided}}\n {{^isLinkManySided}}\n return source.{{linkApiName}}.get();\n {{/isLinkManySided}}\n}'
40
+ }],
41
+ "aggregationTemplate": [{
42
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst num{{objectType}} = await client.ontology.objects.{{objectType}}\n .where(query => Op.not(query.{{property}}.isNull()))\n .groupBy(property => property.{{property}}.exact())\n .count()\n .compute()'
43
+ }],
44
+ "countAggregationTemplate": [{
45
+ "template": "const num{{objectType}} = await client.ontology.objects.{{objectType}}\n .count()\n .compute()"
46
+ }],
47
+ "approximateDistinctAggregationTemplate": [{
48
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nconst distinct{{objectType}} = await client.ontology.objects.{{objectType}}\n .approximateDistinct(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses metricName as the metric name instead of the default "distinctCount"\nconst distinct{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.approximateDistinct(),\n }))\n .compute()'
49
+ }],
50
+ "exactDistinctAggregationTemplate": [{
51
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nconst distinct{{objectType}} = await client.ontology.objects.{{objectType}}\n .exactDistinct(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses metricName as the metric name instead of the default "exactDistinctCount"\nconst distinct{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.exactDistinct(),\n }))\n .compute()'
52
+ }],
53
+ "numericAggregationTemplate": [{
54
+ "template": 'const {{operation}}{{objectType}} = await client.ontology.objects.{{objectType}}\n .{{operation}}(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses "metricName" as the metric name instead of the default "{{operation}}"\nconst {{operation}}{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.{{operation}}(),\n }))\n .compute()'
55
+ }],
56
+ "fixedWidthGroupByTemplate": [{
57
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.fixedWidth(10))\n .count()\n .compute()"
58
+ }],
59
+ "durationGroupByTemplate": [{
60
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.by{{duration}}({{#durationText}}{{arg}}{{/durationText}}))\n .count()\n .compute()"
61
+ }],
62
+ "exactGroupByTemplate": [{
63
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.exact())\n .count()\n .compute()"
64
+ }],
65
+ "rangeGroupByTemplate": [{
66
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.ranges([{\n startValue: {{propertyValueV1}},\n endValue: {{propertyValueIncrementedV1}}\n }]))\n .count()\n .compute()',
67
+ "computedVariables": ["propertyValueV1", "propertyValueIncrementedV1"]
68
+ }],
69
+ "applyAction": [{
70
+ "template": 'import { ActionValidationResult, ActionExecutionMode, ReturnEditsMode{{#hasAttachmentImports}}, Attachment{{/hasAttachmentImports}}{{#hasDateInputs}}, LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}, Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.actions.{{actionApiName}}({{^hasParameters}}{},{{/hasParameters}}{{#hasParameters}}{\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n},{{/hasParameters}} {\n mode: ActionExecutionMode.VALIDATE_AND_EXECUTE,\n returnEdits: ReturnEditsMode.ALL,\n }\n);\n// Check if http request was successful\nif (!isOk(result)) {\n throw result.error;\n}\n// Check if the validation was successful\nconsole.log(result.value.validation);\nif (result.value.validation.result === ActionValidationResult.VALID) {\n // If ReturnEditsMode.ALL is used, new and updated objects edits will contain the primary key of the object\n if (result.value.edits.type === "edits") {\n console.log(result.value.edits);\n }\n}',
71
+ "computedVariables": ["actionParameterSampleValuesV1"]
72
+ }],
73
+ "batchApplyAction": [{
74
+ "template": 'import { ActionExecutionMode, ReturnEditsMode{{#hasAttachmentImports}}, Attachment{{/hasAttachmentImports}}{{#hasDateInputs}}, LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}, Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.bulkActions.{{actionApiName}}(\n [\n {{^hasParameters}}{},{}{{/hasParameters}}{{#hasParameters}}{\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n },\n {\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n },{{/hasParameters}}\n ],\n {\n returnEdits: ReturnEditsMode.NONE,\n }\n);',
75
+ "computedVariables": ["actionParameterSampleValuesV1"]
76
+ }],
77
+ "uploadAttachment": [{
78
+ "template": 'import { type Result, isOk, Attachment, type AttachmentsError } from "{{{packageName}}}";\n\nasync function uploadMyFile() {\n const file = await fetch("file.json");\n const blob = await file.blob();\n return client.ontology.attachments.upload("myFile", blob);\n}\n\nconst result: Result<Attachment, AttachmentsError> = await uploadMyFile();\n\nif (isOk(result)) {\n const attachment = result.value;\n console.log(attachment);\n} else {\n console.error(result.error.errorType);\n}'
79
+ }],
80
+ "executeFunction": [{
81
+ "template": '{{#needsImports}}\nimport { {{#hasAttachmentImports}}Attachment{{#hasDateInputs}},{{/hasDateInputs}}{{^hasDateInputs}}{{#hasTimestampInputs}},{{/hasTimestampInputs}}{{/hasDateInputs}}{{/hasAttachmentImports}}{{#hasDateInputs}}LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{/needsImports}}\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.queries.{{funcApiName}}({{{functionInputValuesV1}}});',
82
+ "computedVariables": ["functionInputValuesV1"]
83
+ }],
84
+ "stringStartsWithTemplate": [{
85
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.startsWith("foo"));'
86
+ }],
87
+ "containsAllTermsInOrderTemplate": [{
88
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAllTermsInOrder("foo bar"));'
89
+ }],
90
+ "containsAnyTermTemplate": [{
91
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAnyTerm("foo bar"));'
92
+ }],
93
+ "containsAllTermsTemplate": [{
94
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAllTerms("foo bar"));'
95
+ }],
96
+ "equalityTemplate": [{
97
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.eq({{{propertyValueV1}}}));',
98
+ "computedVariables": ["propertyValueV1"]
99
+ }],
100
+ "inFilterTemplate": [{
101
+ "template": "// Not supported"
102
+ }],
103
+ "nullTemplate": [{
104
+ "template": "const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.isNull());"
105
+ }],
106
+ "rangeTemplate": [{
107
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{operation}}({{{propertyValueV1}}}));',
108
+ "computedVariables": ["propertyValueV1"]
109
+ }],
110
+ "withinDistanceTemplate": [{
111
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.within{{distanceUnitText}}(\n // New York City\n GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n 100.0,\n ));'
112
+ }],
113
+ "withinBoundingBoxTemplate": [{
114
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.withinBoundingBox({\n topLeft: GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n bottomRight: GeoPoint.fromCoordinates({ latitude: 25.123, longitude: 80.4231 }),\n });'
115
+ }],
116
+ "withinPolygonTemplate": [{
117
+ "template": 'import { Polygon } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.withinPolygon(Polygon.fromGeoJson({\n type: "Polygon",\n coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]],\n }));'
118
+ }],
119
+ "intersectsPolygonTemplate": [{
120
+ "template": 'import { Polygon } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{intersects}}Polygon(Polygon.fromGeoJson({\n type: "Polygon",\n coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]],\n }));'
121
+ }],
122
+ "intersectsBboxTemplate": [{
123
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{intersects}}BoundingBox({\n topLeft: GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n bottomRight: GeoPoint.fromCoordinates({ latitude: 25.123, longitude: 80.4231 }),\n });'
124
+ }],
125
+ "notTemplate": [{
126
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.not(query.{{primaryKeyPropertyV1.apiName}}.isNull()));',
127
+ "computedVariables": ["primaryKeyPropertyV1"]
128
+ }],
129
+ "andTemplate": [{
130
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.and(\n Op.not(query.{{primaryKeyPropertyV1.apiName}}.isNull()),\n query.{{primaryKeyPropertyV1.apiName}}.eq("primaryKey"),\n ));',
131
+ "computedVariables": ["primaryKeyPropertyV1"]
132
+ }],
133
+ "orTemplate": [{
134
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.or(\n query.{{primaryKeyPropertyV1.apiName}}.isNull(),\n query.{{primaryKeyPropertyV1.apiName}}.eq("primaryKey"),\n ));',
135
+ "computedVariables": ["primaryKeyPropertyV1"]
136
+ }],
137
+ "loadTimeSeriesPointsSnippet": [{
138
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.points.all();\n}'
139
+ }],
140
+ "loadRelativeTimeSeriesPointsSnippet": [{
141
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\n// Only supports ranges in the past\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.from{{timeUnitValue}}Ago(1).all();\n}'
142
+ }],
143
+ "loadAbsoluteTimeSeriesPointsSnippet": [{
144
+ "template": 'import { Timestamp } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.range({\n startTime: Timestamp.fromISOString("2022-08-13T12:34:56Z"),\n endTime: Timestamp.fromISOString("2022-08-14T12:34:56Z"),\n });\n}'
145
+ }],
146
+ "loadTimeSeriesFirstPointSnippet": [{
147
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getFirstPoint();\n}'
148
+ }],
149
+ "loadTimeSeriesLastPointSnippet": [{
150
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getLastPoint();\n}'
151
+ }],
152
+ "loadObjectMetadataSnippet": [{
153
+ "template": "// Not supported."
154
+ }],
155
+ "subscribeToObjectSetInstructions": [{
156
+ "template": "// Subscribing to object sets is only supported in 2.x versions of the SDK."
157
+ }]
158
+ }
159
+ },
160
+ "1.1.0": {
161
+ "snippets": {
162
+ "loadSingleObjectGuide": [{
163
+ "template": 'import { type GetObjectError, isOk, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst result: Result<{{objectType}}, GetObjectError> = await client.ontology.objects.{{objectType}}.fetchOneWithErrors("primaryKey");\nif (isOk(result)) {\n const object: {{objectType}} = result.value;\n} else {\n console.error(result.error.errorType);\n}\n// You can also fetch a single object without the Result wrapper\ntry {\n const object: {{objectType}} = await client.ontology.objects.{{objectType}}.fetchOne("primaryKey");\n}\ncatch(e) {\n console.error(e);\n}'
164
+ }],
165
+ "loadObjectPageGuide": [{
166
+ "template": 'import { isOk, type LoadObjectSetError, Page, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst firstPage: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}.fetchPageWithErrors({ pageSize: 30 });\n\nif (isOk(firstPage)) {\n const secondPage: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .fetchPageWithErrors({ pageSize: 30, pageToken: firstPage.value.nextPageToken });\n\n const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;\n const object = objects[0];\n}\n\n// To fetch a page without a result wrapper, use fetchPage with a try/catch instead\ntry {\n const firstPage: Page<{{objectType}}> = await client.ontology.objects.{{objectType}}.fetchPage({ pageSize: 30 });\n const secondPage: Page<{{objectType}}> = await client.ontology.objects.{{objectType}}\n .fetchPage({ pageSize: 30, pageToken: firstPage.value.nextPageToken });\n const objects = [...firstPage.data, ...secondPage.data];\n const object = objects[0];\n}\ncatch (e) {\n console.error(e);\n}'
167
+ }],
168
+ "orderObjectsGuide": [{
169
+ "template": 'import { isOk, Page, type Result, type SearchObjectsError } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst page: Result<Page<{{objectType}}>, SearchObjectsError> = await client.ontology.objects.{{objectType}}\n .orderBy(sortBy => sortBy.{{titleProperty}}.asc())\n .fetchPageWithErrors({ pageSize: 30 });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
170
+ }],
171
+ "searchObjectsGuide": [{
172
+ "template": 'import { isOk, type LoadObjectSetError, Page, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst page: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .where(query => query.{{titleProperty}}.isNull())\n .fetchPageWithErrors({ pageSize: 30 });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
173
+ }],
174
+ "loadSingleObjectReference": [{
175
+ "template": 'import { type GetObjectError, type Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst response: Result<{{objectType}}, GetObjectError> = await client.ontology.objects.{{objectType}}.fetchOneWithErrors("primaryKey");\n\n// You can also fetch a single object without the result wrapper\nconst responseNoWrapper: {{objectType}} = await client.ontology.objects.{{objectType}}.fetchOne("primaryKey");\n'
176
+ }],
177
+ "loadObjectsReference": [{
178
+ "template": 'import type { LoadObjectSetError, Page, Result } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst response: Result<Page<{{objectType}}>, LoadObjectSetError> = await client.ontology.objects.{{objectType}}\n .fetchPageWithErrors({ pageSize: 30 });\n\n// To fetch a page without a result wrapper, use fetchPage instead\nconst responseNoErrorWrapper: Page<{{objectType}}> = await client.ontology.objects.{{objectType}}\n .fetchPage({ pageSize: 30 });'
179
+ }],
180
+ "loadAllObjectsReference": [{
181
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objects: {{objectType}}[]= [];\n\nfor await(const obj of client.ontology.objects.{{objectType}}.asyncIter()) {\n objects.push(obj);\n}\nconst object = objects.value[0];'
182
+ }],
183
+ "loadLinkedObjectReference": [{
184
+ "template": 'import type { GetLinkedObjectError, Result } from "{{{packageName}}}";\nimport { {{sourceObjectType}}, {{linkedObjectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getLinked{{linkedObjectType}}(source: {{sourceObjectType}}, linkedObjectPrimaryKey: {{linkedPrimaryKeyPropertyV1.type}}): Result<{{linkedObjectType}}, GetLinkedObjectError>\n{\n return source.{{linkApiName}}.fetchOneWithErrors(linkedObjectPrimaryKey);\n}\n\n// You can also get a linked object without the result wrapper\nfunction getLinkedNoWrapper{{linkedObjectType}}(source: {{sourceObjectType}}, linkedObjectPrimaryKey: {{linkedPrimaryKeyPropertyV1.type}}): {{linkedObjectType}} {\n return source.{{linkApiName}}.fetchOne(linkedObjectPrimaryKey);\n}',
185
+ "computedVariables": ["linkedPrimaryKeyPropertyV1"]
186
+ }],
187
+ "loadLinkedObjectsReference": [{
188
+ "template": 'import type { GetLinkedObjectError, Result } from "{{{packageName}}}";\nimport { {{sourceObjectType}}, {{linkedObjectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getLinked{{linkedObjectType}}(source: {{sourceObjectType}}) {\n {{#isLinkManySided}}\n return source.{{linkApiName}}.fetchPageWithErrors({ pageSize: 30 });\n {{/isLinkManySided}}\n {{^isLinkManySided}}\n return source.{{linkApiName}}.fetchOneWithErrors();\n {{/isLinkManySided}}\n}'
189
+ }],
190
+ "aggregationTemplate": [{
191
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst num{{objectType}} = await client.ontology.objects.{{objectType}}\n .where(query => Op.not(query.{{property}}.isNull()))\n .groupBy(property => property.{{property}}.exact())\n .count()\n .compute()'
192
+ }],
193
+ "countAggregationTemplate": [{
194
+ "template": "const num{{objectType}} = await client.ontology.objects.{{objectType}}\n .count()\n .compute()"
195
+ }],
196
+ "approximateDistinctAggregationTemplate": [{
197
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nconst distinct{{objectType}} = await client.ontology.objects.{{objectType}}\n .approximateDistinct(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses metricName as the metric name instead of the default "distinctCount"\nconst distinct{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.approximateDistinct(),\n }))\n .compute()'
198
+ }],
199
+ "exactDistinctAggregationTemplate": [{
200
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nconst distinct{{objectType}} = await client.ontology.objects.{{objectType}}\n .exactDistinct(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses metricName as the metric name instead of the default "exactDistinctCount"\nconst distinct{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.exactDistinct(),\n }))\n .compute()'
201
+ }],
202
+ "numericAggregationTemplate": [{
203
+ "template": 'const {{operation}}{{objectType}} = await client.ontology.objects.{{objectType}}\n .{{operation}}(obj => obj.{{property}})\n .compute()\n\n// This is equivalent to the above, but uses "metricName" as the metric name instead of the default "{{operation}}"\nconst {{operation}}{{objectType}}CustomName = await client.ontology.objects.{{objectType}}\n .aggregate(obj => ({\n metricName: obj.{{property}}.{{operation}}(),\n }))\n .compute()'
204
+ }],
205
+ "fixedWidthGroupByTemplate": [{
206
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.fixedWidth(10))\n .count()\n .compute()"
207
+ }],
208
+ "durationGroupByTemplate": [{
209
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.by{{duration}}({{#durationText}}{{arg}}{{/durationText}}))\n .count()\n .compute()"
210
+ }],
211
+ "exactGroupByTemplate": [{
212
+ "template": "const grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.exact())\n .count()\n .compute()"
213
+ }],
214
+ "rangeGroupByTemplate": [{
215
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst grouped{{objectType}} = await client.ontology.objects.{{objectType}}\n .groupBy(obj => obj.{{property}}.ranges([{\n startValue: {{propertyValueV1}},\n endValue: {{propertyValueIncrementedV1}}\n }]))\n .count()\n .compute()',
216
+ "computedVariables": ["propertyValueV1", "propertyValueIncrementedV1"]
217
+ }],
218
+ "applyAction": [{
219
+ "template": 'import { ActionValidationResult, ActionExecutionMode, ReturnEditsMode{{#hasAttachmentImports}}, Attachment{{/hasAttachmentImports}}{{#hasDateInputs}}, LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}, Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.actions.{{actionApiName}}({{^hasParameters}}{},{{/hasParameters}}{{#hasParameters}}{\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n},{{/hasParameters}} {\n mode: ActionExecutionMode.VALIDATE_AND_EXECUTE,\n returnEdits: ReturnEditsMode.ALL,\n }\n);\n// Check if http request was successful\nif (!isOk(result)) {\n throw result.error;\n}\n// Check if the validation was successful\nconsole.log(result.value.validation);\nif (result.value.validation.result === ActionValidationResult.VALID) {\n // If ReturnEditsMode.ALL is used, new and updated objects edits will contain the primary key of the object\n if (result.value.edits.type === "edits") {\n console.log(result.value.edits);\n }\n}',
220
+ "computedVariables": ["actionParameterSampleValuesV1"]
221
+ }],
222
+ "batchApplyAction": [{
223
+ "template": 'import { ActionExecutionMode, ReturnEditsMode{{#hasAttachmentImports}}, Attachment{{/hasAttachmentImports}}{{#hasDateInputs}}, LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}, Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.batchActions.{{actionApiName}}(\n [\n {{^hasParameters}}{},{}{{/hasParameters}}{{#hasParameters}}{\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n },\n {\n {{#actionParameterSampleValuesV1}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV1}}\n },{{/hasParameters}}\n ],\n {\n returnEdits: ReturnEditsMode.NONE,\n }\n);',
224
+ "computedVariables": ["actionParameterSampleValuesV1"]
225
+ }],
226
+ "uploadAttachment": [{
227
+ "template": 'import { type Result, isOk, type Attachment, type AttachmentsError } from "{{{packageName}}}";\n\nasync function uploadMyFile() {\n const file = await fetch("file.json");\n const blob = await file.blob();\n return client.ontology.attachments.upload("myFile", blob);\n}\n\nconst result: Result<Attachment, AttachmentsError> = await uploadMyFile();\n\nif (isOk(result)) {\n const attachment = result.value;\n console.log(attachment);\n} else {\n console.error(result.error.errorType);\n}'
228
+ }],
229
+ "executeFunction": [{
230
+ "template": '{{#needsImports}}\nimport { {{#hasAttachmentImports}}Attachment{{#hasDateInputs}},{{/hasDateInputs}}{{^hasDateInputs}}{{#hasTimestampInputs}},{{/hasTimestampInputs}}{{/hasDateInputs}}{{/hasAttachmentImports}}{{#hasDateInputs}}LocalDate{{#hasTimestampInputs}}, {{/hasTimestampInputs}}{{/hasDateInputs}}{{#hasTimestampInputs}}Timestamp{{/hasTimestampInputs}} } from "{{{packageName}}}";\n\n{{/needsImports}}\n{{#hasAttachmentUpload}}\nconst attachment: Attachment = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client.ontology.queries.{{funcApiName}}({{{functionInputValuesV1}}});',
231
+ "computedVariables": ["functionInputValuesV1"]
232
+ }],
233
+ "stringStartsWithTemplate": [{
234
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.startsWith("foo"));'
235
+ }],
236
+ "containsAllTermsInOrderTemplate": [{
237
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAllTermsInOrder("foo bar"));'
238
+ }],
239
+ "containsAnyTermTemplate": [{
240
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAnyTerm("foo bar"));'
241
+ }],
242
+ "containsAllTermsTemplate": [{
243
+ "template": 'const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.containsAllTerms("foo bar"));'
244
+ }],
245
+ "equalityTemplate": [{
246
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.eq({{{propertyValueV1}}}));',
247
+ "computedVariables": ["propertyValueV1"]
248
+ }],
249
+ "inFilterTemplate": [{
250
+ "template": "// Not supported"
251
+ }],
252
+ "nullTemplate": [{
253
+ "template": "const {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.isNull());"
254
+ }],
255
+ "rangeTemplate": [{
256
+ "template": '{{#isDateProperty}}\nimport { LocalDate } from "{{{packageName}}}";\n\n{{/isDateProperty}}\n{{#isTimestampProperty}}\nimport { Timestamp } from "{{{packageName}}}";\n\n{{/isTimestampProperty}}\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{operation}}({{{propertyValueV1}}}));',
257
+ "computedVariables": ["propertyValueV1"]
258
+ }],
259
+ "withinDistanceTemplate": [{
260
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.within{{distanceUnitText}}(\n // New York City\n GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n 100.0,\n ));'
261
+ }],
262
+ "withinBoundingBoxTemplate": [{
263
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.withinBoundingBox({\n topLeft: GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n bottomRight: GeoPoint.fromCoordinates({ latitude: 25.123, longitude: 80.4231 }),\n });'
264
+ }],
265
+ "withinPolygonTemplate": [{
266
+ "template": 'import { Polygon } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.withinPolygon(Polygon.fromGeoJson({\n type: "Polygon",\n coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]],\n }));'
267
+ }],
268
+ "intersectsPolygonTemplate": [{
269
+ "template": 'import { Polygon } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{intersects}}Polygon(Polygon.fromGeoJson({\n type: "Polygon",\n coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]],\n }));'
270
+ }],
271
+ "intersectsBboxTemplate": [{
272
+ "template": 'import { GeoPoint } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => query.{{property}}.{{intersects}}BoundingBox({\n topLeft: GeoPoint.fromCoordinates({ latitude: 40.7128, longitude: -74.0060 }),\n bottomRight: GeoPoint.fromCoordinates({ latitude: 25.123, longitude: 80.4231 }),\n });'
273
+ }],
274
+ "notTemplate": [{
275
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.not(query.{{primaryKeyPropertyV1.apiName}}.isNull()));',
276
+ "computedVariables": ["primaryKeyPropertyV1"]
277
+ }],
278
+ "andTemplate": [{
279
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.and(\n Op.not(query.{{primaryKeyPropertyV1.apiName}}.isNull()),\n query.{{primaryKeyPropertyV1.apiName}}.eq("primaryKey"),\n ));',
280
+ "computedVariables": ["primaryKeyPropertyV1"]
281
+ }],
282
+ "orTemplate": [{
283
+ "template": 'import { Op } from "{{{packageName}}}";\n\nconst {{objectType}}ObjectSet = client.ontology.objects.{{objectType}}\n .where(query => Op.or(\n query.{{primaryKeyPropertyV1.apiName}}.isNull(),\n query.{{primaryKeyPropertyV1.apiName}}.eq("primaryKey"),\n ));',
284
+ "computedVariables": ["primaryKeyPropertyV1"]
285
+ }],
286
+ "loadTimeSeriesPointsSnippet": [{
287
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.points.all();\n}'
288
+ }],
289
+ "loadRelativeTimeSeriesPointsSnippet": [{
290
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\n// Only supports ranges in the past\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.from{{timeUnitValue}}Ago(1).all();\n}'
291
+ }],
292
+ "loadAbsoluteTimeSeriesPointsSnippet": [{
293
+ "template": 'import { Timestamp } from "{{{packageName}}}";\nimport { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.range({\n startTime: Timestamp.fromISOString("2022-08-13T12:34:56Z"),\n endTime: Timestamp.fromISOString("2022-08-14T12:34:56Z"),\n });\n}'
294
+ }],
295
+ "loadTimeSeriesFirstPointSnippet": [{
296
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getFirstPoint();\n}'
297
+ }],
298
+ "loadTimeSeriesLastPointSnippet": [{
299
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getLastPoint();\n}'
300
+ }],
301
+ "loadObjectMetadataSnippet": [{
302
+ "template": "// Not supported."
303
+ }],
304
+ "subscribeToObjectSetInstructions": [{
305
+ "template": "// Subscribing to object sets is only supported in 2.x versions of the SDK."
306
+ }]
307
+ }
308
+ },
309
+ "2.0.0": {
310
+ "snippets": {
311
+ "loadSingleObjectGuide": [{
312
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type Result } from "@osdk/client";\n\nconst result: Result<Osdk.Instance<{{objectType}}>> = await client({{objectType}}).fetchOneWithErrors("<primaryKey>");\nif (isOk(result)) {\n const object: Osdk.Instance<{{objectType}}> = result.value;\n} else {\n console.error(result.error.message);\n}\n// You can also fetch a single object without the Result wrapper\ntry {\n const object: Osdk.Instance<{{objectType}}> = await client({{objectType}}).fetchOne("<primaryKey>");\n}\ncatch(e) {\n console.error(e);\n}'
313
+ }],
314
+ "loadObjectPageGuide": [{
315
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst firstPage: Result<PageResult<Osdk.Instance<{{objectType}}>>>\n = await client({{objectType}}).fetchPageWithErrors({ $pageSize: 30 });\n\nif (isOk(firstPage)) {\n const secondPage: Result<PageResult<Osdk.Instance<{{objectType}}, never, "{{titleProperty}}">>>\n // You can also down select properties to only get the properties you need from the object\n = await client({{objectType}}).fetchPageWithErrors({ $select: ["{{titleProperty}}"], $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });\n\n const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;\n const object = objects[0];\n}\n\n // If you want to get rids, you need to add a flag to specifically request for it. Note how the return type now includes $rid rather than never\nconst secondPageWithRids: Result<PageResult<Osdk.Instance<{{objectType}}, "$rid", "{{titleProperty}}">>>\n = await client({{objectType}}).fetchPageWithErrors({ $select: ["{{titleProperty}}"], $includeRid:true, $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });\n\n// To fetch a page without a result wrapper, use fetchPage with a try/catch instead\ntry {\n const firstPage: PageResult<Osdk.Instance<{{objectType}}>>\n = await client({{objectType}}).fetchPage({ $pageSize: 30 });\n const secondPage: PageResult<Osdk.Instance<{{objectType}}>>\n = await client({{objectType}}).fetchPage({ $pageSize: 30, $nextPageToken: firstPage.nextPageToken });\n const objects = [...firstPage.data, ...secondPage.data];\n const object = objects[0];\n}\ncatch (e) {\n console.error(e);\n}'
316
+ }],
317
+ "orderObjectsGuide": [{
318
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst page: Result<PageResult<Osdk.Instance<{{objectType}}>>> = await client({{objectType}})\n .fetchPageWithErrors({\n $orderBy: {"{{titleProperty}}": "asc"},\n $pageSize: 30\n });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
319
+ }],
320
+ "searchObjectsGuide": [{
321
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst page: Result<PageResult<Osdk.Instance<{{objectType}}>>> = await client({{objectType}})\n .where({\n {{titleProperty}}: {$isNull: true}\n })\n .fetchPageWithErrors({\n $pageSize: 30\n });\n\nif (isOk(page)) {\n const objects = page.value.data;\n const object = objects[0];\n}'
322
+ }],
323
+ "loadSingleObjectReference": [{
324
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport type { Osdk, Result } from "@osdk/client";\n\nconst response: Result<Osdk.Instance<{{objectType}}>> = await client({{objectType}}).fetchOneWithErrors("<primaryKey>");\n\n// You can also fetch a single object without the Result wrapper\n\nconst responseNoErrorWrapper: Osdk.Instance<{{objectType}}> = await client({{objectType}}).fetchOne("<primaryKey>");\n\n'
325
+ }],
326
+ "loadObjectsReference": [{
327
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport type { Osdk, PageResult, Result } from "@osdk/client";\n\nconst response: Result<PageResult<Osdk.Instance<{{objectType}}>>>\n = await client({{objectType}}).fetchPageWithErrors({ $pageSize: 30 });\n\n// To fetch a page without a result wrapper, use fetchPage instead\nconst responseNoErrorWrapper: PageResult<Osdk.Instance<{{objectType}}>>\n = await client({{objectType}}).fetchPage({ $pageSize: 30 });\n'
328
+ }],
329
+ "loadAllObjectsReference": [{
330
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport type { Osdk } from "@osdk/client";\n\nconst objects: Osdk.Instance<{{objectType}}>[]= [];\n\nfor await(const obj of client({{objectType}}).asyncIter()) {\n objects.push(obj);\n}\nconst object = objects[0];'
331
+ }],
332
+ "loadLinkedObjectReference": [{
333
+ "template": 'import { {{sourceObjectType}}, {{linkedObjectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { type Osdk, type Result } from "@osdk/client";\n\nfunction getLinked{{linkedObjectType}}(source: Osdk.Instance<{{sourceObjectType}}>, linkedObjectPrimaryKey: {{linkedPrimaryKeyPropertyV2.type}}): Result<Osdk.Instance<{{linkedObjectType}}>>\n{\n return source.$link.{{linkApiName}}.fetchOneWithErrors(linkedObjectPrimaryKey);\n}\n\n// You can also get a linked object without the result wrapper\nfunction getLinkedNoWrapper{{linkedObjectType}}(source: Osdk.Instance<{{sourceObjectType}}>, linkedObjectPrimaryKey: {{linkedPrimaryKeyPropertyV2.type}}): Osdk.Instance<{{linkedObjectType}}> {\n return source.$link.{{linkApiName}}.fetchOne(linkedObjectPrimaryKey);\n}',
334
+ "computedVariables": ["linkedPrimaryKeyPropertyV2"]
335
+ }],
336
+ "loadLinkedObjectsReference": [{
337
+ "template": 'import { {{linkedObjectType}} } from "{{{packageName}}}";\n\nfunction getLinked{{linkedObjectType}}(source: Osdk.Instance<{{sourceObjectType}}>) {\n {{#isLinkManySided}}\n return source.$link.{{linkApiName}}.fetchPageWithErrors({ $pageSize: 30 });\n {{/isLinkManySided}}\n {{^isLinkManySided}}\n return source.$link.{{linkApiName}}.fetchOneWithErrors();\n {{/isLinkManySided}}\n}'
338
+ }],
339
+ "aggregationTemplate": [{
340
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst num{{objectType}} = await client({{objectType}})\n .where({{property}}: { $isNull : false })\n .aggregate({\n $select: { $count: "unordered" },\n $groupBy: { name: "exact" },\n });'
341
+ }],
342
+ "countAggregationTemplate": [{
343
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst num{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: {$count: "unordered"},\n });'
344
+ }],
345
+ "approximateDistinctAggregationTemplate": [{
346
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst distinct{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { "{{property}}:approximateDistinct" : "unordered" },\n });'
347
+ }],
348
+ "exactDistinctAggregationTemplate": [{
349
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst distinct{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { "{{property}}:exactDistinct" : "unordered" },\n });'
350
+ }],
351
+ "numericAggregationTemplate": [{
352
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{operation}}{{objectType}} = await client({{objectType}})\n .aggregation({\n $select: { "{{property}}:{{operation}}" : "unordered" }\n });'
353
+ }],
354
+ "fixedWidthGroupByTemplate": [{
355
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst grouped{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { $count: "unordered" },\n $groupBy: { {{property}} : { $fixedWidth: 10 } }\n });'
356
+ }],
357
+ "durationGroupByTemplate": [{
358
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst grouped{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { $count: "unordered" },\n $groupBy: { {{property}} : $duration: [ {{#durationText}}{{arg}}{{/durationText}}, "{{#durationText}}{{unit}}{{/durationText}}"] }\n })'
359
+ }],
360
+ "exactGroupByTemplate": [{
361
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst grouped{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { $count: "unordered" },\n $groupBy: { {{property}} : "exact" }\n })'
362
+ }],
363
+ "rangeGroupByTemplate": [{
364
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst grouped{{objectType}} = await client({{objectType}})\n .aggregate({\n $select: { $count: "unordered" },\n $groupBy: { {{property}} : { $ranges: [[{{{propertyValueV2}}}, {{{propertyValueIncrementedV2}}} ]]} }\n });',
365
+ "computedVariables": ["propertyValueV2", "propertyValueIncrementedV2"]
366
+ }],
367
+ "applyAction": [{
368
+ "template": 'import { {{actionApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n{{#hasAttachmentImports}}import type { AttachmentUpload } from "@osdk/api";{{/hasAttachmentImports}}{{#hasMediaParameter}}import type { MediaReference } from "@osdk/api";{{/hasMediaParameter}}\n\n\n{{#hasAttachmentUpload}}\nconst attachment: AttachmentUpload = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\n{{#hasMediaParameter}}\nconst mediaReference: MediaReference = uploadMedia();\n{{/hasMediaParameter}}\nconst result = await client({{actionApiName}}).applyAction(\n{{^hasParameters}}{},\n{{/hasParameters}}{{#hasParameters}}\n {\n {{#actionParameterSampleValuesV2}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV2}}\n },{{/hasParameters}}\n {\n $returnEdits: true,\n }\n);\n\nif (result.type === "edits") {\n // for new objects and updated objects edits will contain the primary key of the object\n const updatedObject = result.editedObjectTypes[0];\n console.log("Updated object", updatedObject);\n}',
369
+ "computedVariables": ["actionParameterSampleValuesV2"]
370
+ }],
371
+ "batchApplyAction": [{
372
+ "template": 'import { {{actionApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n{{#hasAttachmentImports}}\nimport type { AttachmentUpload } from "@osdk/api";\n{{/hasAttachmentImports}}{{#hasMediaParameter}}import type { MediaReference } from "@osdk/api";{{/hasMediaParameter}}\n\n\n{{#hasAttachmentUpload}}\nconst attachment: AttachmentUpload = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\n{{#hasMediaParameter}}\nconst mediaReference: MediaReference = uploadMedia();\n{{/hasMediaParameter}}\nconst result = await client({{actionApiName}}).batchApplyAction(\n [\n {{^hasParameters}}{},{}{{/hasParameters}}{{#hasParameters}}\n {\n {{#actionParameterSampleValuesV2}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV2}}\n },\n {\n {{#actionParameterSampleValuesV2}}\n "{{key}}": {{{value}}}{{^last}}, {{/last}}\n {{/actionParameterSampleValuesV2}}\n },{{/hasParameters}}\n ],\n {\n $returnEdits: false,\n }\n);',
373
+ "computedVariables": ["actionParameterSampleValuesV2"]
374
+ }],
375
+ "uploadAttachment": [{
376
+ "template": '// Edit this import if your client location differs\nimport { client } from "./client";\nimport { type Result, isOk } from "@osdk/client";\nimport type { AttachmentUpload } from "@osdk/api";\n\n// To upload an attachment with 2.0, it has to be linked to an action call\n\nasync function uploadMyFile() {\n const file = await fetch("file.json");\n const blob = await file.blob();\n return createAttachmentUpload(blob, "myFile");\n}\n\nconst myAttachmentUpload: AttachmentUpload = await uploadMyFile();\n\nconst actionResult = client(attachmentUploadingAction).applyAction({ attachment: myAttachmentUpload });\n'
377
+ }],
378
+ "castInterfaceToObjectReference": [{
379
+ "template": 'import { {{objectTypeApiName}}, {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk } from "@osdk/client";\n\nconst page = await client({{interfaceApiName}}).fetchPageWithErrors();\n\nif (isOk(page)) {\n const interfaces = page.value.data;\n const {{interfaceApiNameCamelCase}}: Osdk<{{interfaceApiName}}> = interfaces[0];\n\n // Cast from interface to object type\n const {{objectTypeApiNameCamelCase}}: Osdk<{{objectTypeApiName}}> = {{interfaceApiNameCamelCase}}.$as({{objectTypeApiName}});\n // Or from object type back to interface\n const {{interfaceApiNameCamelCase}}2: Osdk<{{interfaceApiName}}> = {{objectTypeApiNameCamelCase}}.$as({{interfaceApiName}});\n}'
380
+ }],
381
+ "executeFunction": [{
382
+ "template": '{{#needsImports}}\nimport { {{funcApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n{{#hasAttachmentImports}}import type { AttachmentUpload } from "@osdk/api";{{/hasAttachmentImports}}\n\n{{/needsImports}}\n{{#hasAttachmentUpload}}\nconst attachment: AttachmentUpload = uploadMyFile();\n{{/hasAttachmentUpload}}\n{{#attachmentProperty}}\nconst attachment: Attachment = {{{attachmentProperty}}};\n{{/attachmentProperty}}\nconst result = await client({{funcApiName}}).executeFunction({{{functionInputValuesV2}}});',
383
+ "computedVariables": ["functionInputValuesV2"]
384
+ }],
385
+ "stringStartsWithTemplate": [{
386
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $startsWith: "foo" }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}} : { $startsWith: "foo" }\n {{/structSubPropertyApiName}}\n })'
387
+ }],
388
+ "containsAllTermsInOrderTemplate": [{
389
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $containsAllTermsInOrder: "foo bar" }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}} : { $containsAllTermsInOrder: "foo bar" }\n {{/structSubPropertyApiName}}\n })'
390
+ }],
391
+ "containsAnyTermTemplate": [{
392
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $containsAnyTerm: "foo bar" }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}} : { $containsAnyTerm: "foo bar" }\n {{/structSubPropertyApiName}}\n })'
393
+ }],
394
+ "containsAllTermsTemplate": [{
395
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $containsAllTerms: "foo bar" }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}} : { $containsAllTerms: "foo bar" }\n {{/structSubPropertyApiName}}\n })'
396
+ }],
397
+ "equalityTemplate": [{
398
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $eq: {{{propertyValueV2}}} }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $eq: {{{propertyValueV2}}} }\n {{/structSubPropertyApiName}}\n });',
399
+ "computedVariables": ["propertyValueV2"]
400
+ }],
401
+ "inFilterTemplate": [{
402
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $in: [{{{propertyValueV2}}}] }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $in: [{{{propertyValueV2}}}] }\n {{/structSubPropertyApiName}}\n });',
403
+ "computedVariables": ["propertyValueV2"]
404
+ }],
405
+ "nullTemplate": [{
406
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $isNull: true }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $isNull: true }\n {{/structSubPropertyApiName}}\n });'
407
+ }],
408
+ "rangeTemplate": [{
409
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { ${{operation}}: {{{propertyValueV2}}} }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { ${{operation}}: {{{propertyValueV2}}} }\n {{/structSubPropertyApiName}}\n });',
410
+ "computedVariables": ["propertyValueV2"]
411
+ }],
412
+ "withinDistanceTemplate": [{
413
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $within: { $distance: [100, "{{distanceUnit}}"], $of: [-74.0060, 40.7128]} }}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $within: { $distance: [100, "{{distanceUnit}}"], $of: [-74.0060, 40.7128]}}\n {{/structSubPropertyApiName}}\n })'
414
+ }],
415
+ "withinBoundingBoxTemplate": [{
416
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $within: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128]}}}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $within: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128]}}\n {{/structSubPropertyApiName}}\n\n });'
417
+ }],
418
+ "withinPolygonTemplate": [{
419
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $within: { type: "Polygon", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]]}}}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $within: { type: "Polygon", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]]}}\n {{/structSubPropertyApiName}}\n });'
420
+ }],
421
+ "intersectsPolygonTemplate": [{
422
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}}: { $intersects: { type: "Polygon", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]}}}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}}: { $intersects: { type: "Polygon", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]}}\n {{/structSubPropertyApiName}}\n });'
423
+ }],
424
+ "intersectsBboxTemplate": [{
425
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({\n {{#structSubPropertyApiName}}\n {{property}}: { {{structSubPropertyApiName}} : { $intersects: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128]}}}\n {{/structSubPropertyApiName}}\n {{^structSubPropertyApiName}}\n {{property}} : { $intersects: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128]}}\n {{/structSubPropertyApiName}}\n });'
426
+ }],
427
+ "notTemplate": [{
428
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({ $not: { {{primaryKeyPropertyV2.apiName}}: { $isNull: true }}});',
429
+ "computedVariables": ["primaryKeyPropertyV2"]
430
+ }],
431
+ "andTemplate": [{
432
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({ $and:[\n { $not: { {{primaryKeyPropertyV2.apiName}}: { $isNull: true }}},\n { {{primaryKeyPropertyV2.apiName}}: { $eq: "<primaryKey>" }}\n ]});',
433
+ "computedVariables": ["primaryKeyPropertyV2"]
434
+ }],
435
+ "orTemplate": [{
436
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst {{objectType}}ObjectSet = client({{objectType}})\n .where({ $or:[\n { $not: { {{primaryKeyPropertyV2.apiName}}: { $isNull: true }}},\n { {{primaryKeyPropertyV2.apiName}}: { $eq: "<primaryKey>" }}\n ]});',
437
+ "computedVariables": ["primaryKeyPropertyV2"]
438
+ }],
439
+ "loadInterfacesReference": [{
440
+ "template": 'import { {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst response: Result<PageResult<Osdk<{{interfaceApiName}}>>>\n = await client({{interfaceApiName}}).fetchPageWithErrors({ $pageSize: 30 });\n\n// To fetch a page without a result wrapper, use fetchPage instead\nconst responseNoErrorWrapper: PageResult<Osdk<{{interfaceApiName}}>>\n = await client({{interfaceApiName}}).fetchPage({ $pageSize: 30 });'
441
+ }],
442
+ "loadAllInterfacesReference": [{
443
+ "template": 'import { {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport type { Osdk } from "@osdk/client";\n\nconst interfaces: Osdk<{{interfaceApiName}}>[] = [];\n\nfor await(const int of client({{interfaceApiName}}).asyncIter()) {\n interfaces.push(int);\n}\nconst interface1 = interfaces[0];'
444
+ }],
445
+ "loadOrderedInterfacesReference": [{
446
+ "template": 'import { {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst page: Result<PageResult<Osdk<{{interfaceApiName}}>>> = await client({{interfaceApiName}})\n .fetchPageWithErrors({\n $orderBy: {"someProperty": "asc"},\n $pageSize: 30\n });\n\nif (isOk(page)) {\n const interfaces = page.value.data;\n const interface1 = interfaces[0];\n}'
447
+ }],
448
+ "searchInterfacesReference": [{
449
+ "template": 'import { {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { isOk, type Osdk, type PageResult, type Result } from "@osdk/client";\n\nconst page: Result<PageResult<Osdk<{{interfaceApiName}}>>> = await client({{interfaceApiName}})\n .where({\n $and:[\n { $not: { someProperty: { $isNull: true }}},\n { someProperty: { $eq: "foo" }}\n ]\n })\n .fetchPageWithErrors({\n $pageSize: 30\n });\n\nif (isOk(page)) {\n const interfaces = page.value.data;\n const interface1 = interfaces[0];\n}'
450
+ }],
451
+ "loadTimeSeriesPointsSnippet": [{
452
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllPoints();\n}'
453
+ }],
454
+ "loadRelativeTimeSeriesPointsSnippet": [{
455
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\n// Only supports ranges in the past\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllPoints({\n $before: 1,\n $unit: "{{timeUnit}}",\n })\n}'
456
+ }],
457
+ "loadAbsoluteTimeSeriesPointsSnippet": [{
458
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getAbsoluteTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllPoints({\n $startTime: "2022-08-13T12:34:56Z",\n $endTime: "2022-08-14T12:34:56Z",\n });\n}'
459
+ }],
460
+ "loadTimeSeriesFirstPointSnippet": [{
461
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getFirstTimeSeriesPoint(obj: {{objectType}}) {\n return obj.{{property}}.getFirstPoint();\n}'
462
+ }],
463
+ "loadTimeSeriesLastPointSnippet": [{
464
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getLastTimeSeriesPoint(obj: {{objectType}}) {\n return obj.{{property}}.getLastPoint();\n}'
465
+ }],
466
+ "loadGeotimeSeriesPointsSnippet": [{
467
+ "template": "// Upgrade to 2.1 for official support"
468
+ }],
469
+ "loadRelativeGeotimeSeriesPointsSnippet": [{
470
+ "template": "// Upgrade to 2.1 for official support"
471
+ }],
472
+ "loadAbsoluteGeotimeSeriesPointsSnippet": [{
473
+ "template": "// Upgrade to 2.1 for official support"
474
+ }],
475
+ "loadGeotimeSeriesLastPointSnippet": [{
476
+ "template": "// Upgrade to 2.1 for official support"
477
+ }],
478
+ "loadObjectMetadataSnippet": [{
479
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst objectTypeMetadata = await client.fetchMetadata({{objectType}});\n\nif (objectTypeMetadata.icon.type === "blueprint") {\n const blueprintIconName = objectTypeMetadata.icon.name;\n}\nconst currentVisibility = objectTypeMetadata.visibility;\nconst currentDescription = objectTypeMetadata.description;'
480
+ }],
481
+ "loadInterfaceMetadataSnippet": [{
482
+ "template": 'import { {{interfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst interfaceTypeMetadata = await client.fetchMetadata({{interfaceApiName}});\n\nconst implementingObjectTypes = interfaceTypeMetadata.implementedBy;\nconst interfaceRid = interfaceTypeMetadata.rid;'
483
+ }],
484
+ "subscribeToObjectSetInstructions": [{
485
+ "template": "// Upgrade to 2.1 for official support"
486
+ }],
487
+ "uploadMedia": [{
488
+ "template": "// Upgrade to 2.1 for official support"
489
+ }],
490
+ "readMedia": [{
491
+ "template": "// Upgrade to 2.1 for official support"
492
+ }],
493
+ "derivedPropertyBaseExample": [{
494
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("fooLink").pivotTo("barLink").selectProperty("foo")\n })\n .where({\n "newPropertyName": { $gt: 10 }\n })\n .aggregate({\n $select: { "newPropertyName:max": "unordered" }\n });'
495
+ }],
496
+ "derivedPropertyApproximateDistinctAggregation": [{
497
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:approximateDistinct")\n })'
498
+ }],
499
+ "derivedPropertyExactDistinctAggregation": [{
500
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:exactDistinct")\n })'
501
+ }],
502
+ "derivedPropertyCollectToListAggregation": [{
503
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:collectToList", 75)\n })'
504
+ }],
505
+ "derivedPropertyCollectToSetAggregation": [{
506
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:collectToSet", 75)\n })'
507
+ }],
508
+ "derivedPropertyCountAggregation": [{
509
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("$count")\n })'
510
+ }],
511
+ "derivedPropertySelectPropertyAggregation": [{
512
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").selectProperty("{{property}}")\n })'
513
+ }],
514
+ "derivedPropertyApproximatePercentileAggregation": [{
515
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:approximatePercentile", 0.5)\n })'
516
+ }],
517
+ "derivedPropertyNumericAggregation": [{
518
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\nconst sum{{objectType}} = await client({{objectType}})\n .withProperties({\n "newPropertyName": (baseObjectSet) =>\n baseObjectSet.pivotTo("{{linkName}}").aggregate("{{property}}:{{operation}}")\n })'
519
+ }],
520
+ "objectSetOperationsGuide": [{
521
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objectSetA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "a"}})\nconst objectSetB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "b"}})\nconst objectSetC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "c"}})\n\n// Object set operations can be chained. e.g. To find all objects in objectSetA \n// that are present in objectSetB but do not exist in objectSetC:\nconst result: {{objectType}}.ObjectSet = objectSetA\n .intersect(objectSetB)\n .subtract(objectSetC);'
522
+ }],
523
+ "objectSetOperationsUnion": [{
524
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objectSetA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "a"}})\nconst objectSetB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "b"}})\nconst objectSetC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "c"}})\n\n// Combine objectSetA, objectSetB and objectSetC\nconst result: {{objectType}}.ObjectSet = objectSetA\n .union(objectSetB)\n .union(objectSetC); // alternatively: objectSetA.union(objectSetB, objectSetC)'
525
+ }],
526
+ "objectSetOperationsSubtract": [{
527
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objectSetA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "a"}})\nconst objectSetB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "b"}})\nconst objectSetC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "c"}})\n\n\n// Return objects in objectSetA that are not present in either objectSetB or objectSetC\nconst result: {{objectType}}.ObjectSet = objectSetA\n .subtract(objectSetB)\n .subtract(objectSetC); // alternatively: objectSetA.subtract(objectSetB, objectSetC)'
528
+ }],
529
+ "objectSetOperationsIntersect": [{
530
+ "template": 'import { {{objectType}} } from "{{{packageName}}}/ontology/objects";\n\nconst objectSetA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "a"}})\nconst objectSetB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "b"}})\nconst objectSetC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: "c"}})\n\n\n// Return all objects common to objectSetA, objectSetB and objectSetC\nconst result: {{objectType}}.ObjectSet = objectSetA\n .intersect(objectSetB)\n .intersect(objectSetC); // alternatively: objectSetA.intersect(objectSetB, objectSetC)'
531
+ }]
532
+ }
533
+ },
534
+ "2.1.0": {
535
+ "snippets": {
536
+ "loadGeotimeSeriesPointsSnippet": [{
537
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getAllTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllValues();\n}'
538
+ }],
539
+ "loadRelativeGeotimeSeriesPointsSnippet": [{
540
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\n// Only supports ranges in the past\nfunction getRelativeTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllValues({\n $before: 1,\n $unit: "{{timeUnit}}",\n })\n}'
541
+ }],
542
+ "loadAbsoluteGeotimeSeriesPointsSnippet": [{
543
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getAbsoluteTimeSeriesPoints(obj: {{objectType}}) {\n return obj.{{property}}.getAllValues({\n $startTime: "2022-08-13T12:34:56Z",\n $endTime: "2022-08-14T12:34:56Z",\n });\n}'
544
+ }],
545
+ "loadGeotimeSeriesLastPointSnippet": [{
546
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n\nfunction getLastTimeSeriesPoint(obj: {{objectType}}) {\n return obj.{{property}}.getLatestValue();\n}'
547
+ }],
548
+ "subscribeToObjectSetInstructions": [{
549
+ "template": 'import { {{objectOrInterfaceApiName}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\n\n// A map of primary keys to objects loaded through the SDK\nconst objects: { [key: string]: {{objectOrInterfaceApiName}}.OsdkInstance } = ...\n\nconst subscription = client({{objectOrInterfaceApiName}}).subscribe( {\n onChange(update) {\n if (update.state === "ADDED_OR_UPDATED") {\n // An object has received an update or an object was added to the object set\n const currentObject = objects[update.object.$primaryKey];\n if (currentObject !== undefined) {\n currentObject["<propertyName>"] = update.object["<propertyName>"] ?? currentObject["<propertyName>"];\n }\n }\n else if (update.state === "DELETED") {\n // The object has been deleted\n delete objects[update.object.$primaryKey];\n }\n },\n onSuccessfulSubscription() {\n // The subscription was successful and you can expect to receive updates\n },\n onError(err) {\n // There was an error with the subscription and you will not receive any more updates\n console.error(err);\n },\n onOutOfDate() {\n // We could not keep track of all changes. Please reload the objects in your set.\n },\n },\n { properties: [ {{#propertyNames}}"{{.}}", {{/propertyNames}}\b\b]}\n );\n\nsubscription.unsubscribe();'
550
+ }],
551
+ "uploadMedia": [{
552
+ "template": 'import { __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference } from "@osdk/api/unstable";\nimport { {{objectType}} } from "{{{packageName}}}"\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport { Result, isOk } from "@osdk/client";\nimport type { MediaReference } from "@osdk/api";\n\n// To upload media with 2.x, it has to be linked to an Action call\nasync function uploadMedia() {\n const file = await fetch("file.json");\n const data = await file.blob();\n\n // Upload media to an object type with a media property. This returns a media reference that can passed to\n // a media parameter in an Action.\n return await client(\n __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference,\n ).createMediaReference({\n data,\n fileName: "myFile",\n objectType: {{objectType}},\n propertyType: "MediaPropertyApi",\n });\n}\n\nconst mediaReference: MediaReference = await uploadMedia();\nconst actionResult = client(mediaUploadingAction).applyAction({ media_parameter: mediaReference });'
553
+ }],
554
+ "readMedia": [{
555
+ "template": 'import { {{objectType}} } from "{{{packageName}}}";\n// Edit this import if your client location differs\nimport { client } from "./client";\nimport type { MediaMetadata, MediaReference } from "@osdk/api";\nimport { Osdk, Result } from "@osdk/client";\n\nconst result = await client({{objectType}}).fetchOne("<primaryKey>");\n\n// Fetch metadata of a media property\nconst mediaMetadata = await result.{{property}}?.fetchMetadata();\n\n// Fetch contents of a media property\nconst response = await result.{{property}}?.fetchContents();\n\nif (response.ok) {\n const data = await response.blob();\n ...\n}'
556
+ }]
557
+ }
558
+ }
559
+ }
560
+ };
561
+
562
+ // src/docs.ts
563
+ var indentedNewLine = (spacesCount) => `
564
+ ${" ".repeat(spacesCount)}`;
565
+ var TYPESCRIPT_OSDK_SNIPPETS = {
566
+ ...snippets,
567
+ computedVariables: {
568
+ functionInputValuesV1: handleFunctionInputValuesV1,
569
+ functionInputValuesV2: handleFunctionInputValuesV2,
570
+ actionParameterSampleValuesV1: handleActionParameterSampleValuesV1,
571
+ actionParameterSampleValuesV2: handleActionParameterSampleValuesV2,
572
+ propertyValueV1: handlePropertyValueV1,
573
+ propertyValueV2: handlePropertyValueV2,
574
+ propertyValueIncrementedV1: handlePropertyValueIncrementedV1,
575
+ propertyValueIncrementedV2: handlePropertyValueIncrementedV2,
576
+ propertiesV1: handlePropertiesV1,
577
+ propertiesV2: handlePropertiesV2,
578
+ primaryKeyPropertyV1: handlePrimaryKeyPropertyV1,
579
+ primaryKeyPropertyV2: handlePrimaryKeyPropertyV2,
580
+ linkedPropertiesV1: handleLinkedPropertiesV1,
581
+ linkedPropertiesV2: handleLinkedPropertiesV2,
582
+ linkedPrimaryKeyPropertyV1: handleLinkedPrimaryKeyPropertyV1,
583
+ linkedPrimaryKeyPropertyV2: handleLinkedPrimaryKeyPropertyV2
584
+ }
585
+ };
586
+ var SdkMajorVersion = /* @__PURE__ */ function(SdkMajorVersion2) {
587
+ SdkMajorVersion2[SdkMajorVersion2["V1"] = 1] = "V1";
588
+ SdkMajorVersion2[SdkMajorVersion2["V2"] = 2] = "V2";
589
+ return SdkMajorVersion2;
590
+ }(SdkMajorVersion || {});
591
+ function handleFunctionInputValuesV1({
592
+ rawFunctionInputValues
593
+ }) {
594
+ return renderFunctionInputValues(rawFunctionInputValues, SdkMajorVersion.V1);
595
+ }
596
+ function handleFunctionInputValuesV2({
597
+ rawFunctionInputValues
598
+ }) {
599
+ return renderFunctionInputValues(rawFunctionInputValues, SdkMajorVersion.V2);
600
+ }
601
+ function handleActionParameterSampleValuesV1({
602
+ rawActionTypeParameterValues
603
+ }) {
604
+ return renderActionParameterValues(rawActionTypeParameterValues, SdkMajorVersion.V1);
605
+ }
606
+ function handleActionParameterSampleValuesV2({
607
+ rawActionTypeParameterValues
608
+ }) {
609
+ return renderActionParameterValues(rawActionTypeParameterValues, SdkMajorVersion.V2);
610
+ }
611
+ function handlePropertyValueV1({
612
+ rawPropertyValue
613
+ }) {
614
+ return renderPropertyValue(rawPropertyValue, SdkMajorVersion.V1);
615
+ }
616
+ function handlePropertyValueV2({
617
+ rawPropertyValue
618
+ }) {
619
+ return renderPropertyValue(rawPropertyValue, SdkMajorVersion.V2);
620
+ }
621
+ function handlePropertyValueIncrementedV1({
622
+ rawPropertyValueIncremented
623
+ }) {
624
+ return renderPropertyValue(rawPropertyValueIncremented, SdkMajorVersion.V1);
625
+ }
626
+ function handlePropertyValueIncrementedV2({
627
+ rawPropertyValueIncremented
628
+ }) {
629
+ return renderPropertyValue(rawPropertyValueIncremented, SdkMajorVersion.V2);
630
+ }
631
+ function handlePropertiesV1({
632
+ rawProperties
633
+ }) {
634
+ if (rawProperties == null) {
635
+ throw new Error("Cannot render with null rawProperties");
636
+ }
637
+ return rawProperties.map((prop) => ({
638
+ apiName: prop.apiName,
639
+ value: renderPropertyValue(prop.value, SdkMajorVersion.V1)
640
+ }));
641
+ }
642
+ function handlePropertiesV2({
643
+ rawProperties
644
+ }) {
645
+ if (rawProperties == null) {
646
+ throw new Error("Cannot render with null rawProperties");
647
+ }
648
+ return rawProperties.map((prop) => ({
649
+ apiName: prop.apiName,
650
+ value: renderPropertyValue(prop.value, SdkMajorVersion.V2)
651
+ }));
652
+ }
653
+ function handlePrimaryKeyPropertyV1({
654
+ rawPrimaryKeyProperty
655
+ }) {
656
+ if (rawPrimaryKeyProperty == null) {
657
+ throw new Error("Cannot render with null rawPrimaryKeyProperty");
658
+ }
659
+ return {
660
+ apiName: rawPrimaryKeyProperty.apiName,
661
+ value: renderPropertyValue(rawPrimaryKeyProperty.value, SdkMajorVersion.V1)
662
+ };
663
+ }
664
+ function handlePrimaryKeyPropertyV2({
665
+ rawPrimaryKeyProperty
666
+ }) {
667
+ if (rawPrimaryKeyProperty == null) {
668
+ throw new Error("Cannot render with null rawPrimaryKeyProperty");
669
+ }
670
+ return {
671
+ apiName: rawPrimaryKeyProperty.apiName,
672
+ value: renderPropertyValue(rawPrimaryKeyProperty.value, SdkMajorVersion.V2)
673
+ };
674
+ }
675
+ function handleLinkedPropertiesV1({
676
+ rawLinkedProperties
677
+ }) {
678
+ if (rawLinkedProperties == null) {
679
+ throw new Error("Cannot render with null rawLinkedProperties");
680
+ }
681
+ return rawLinkedProperties.map((prop) => ({
682
+ apiName: prop.apiName,
683
+ value: renderPropertyValue(prop.value, SdkMajorVersion.V1)
684
+ }));
685
+ }
686
+ function handleLinkedPropertiesV2({
687
+ rawLinkedProperties
688
+ }) {
689
+ if (rawLinkedProperties == null) {
690
+ throw new Error("Cannot render with null rawLinkedProperties");
691
+ }
692
+ return rawLinkedProperties.map((prop) => ({
693
+ apiName: prop.apiName,
694
+ value: renderPropertyValue(prop.value, SdkMajorVersion.V2)
695
+ }));
696
+ }
697
+ function handleLinkedPrimaryKeyPropertyV1({
698
+ rawLinkedPrimaryKeyProperty
699
+ }) {
700
+ if (rawLinkedPrimaryKeyProperty == null) {
701
+ throw new Error("Cannot render with null rawLinkedPrimaryKeyProperty");
702
+ }
703
+ return {
704
+ apiName: rawLinkedPrimaryKeyProperty.apiName,
705
+ value: renderPropertyValue(rawLinkedPrimaryKeyProperty.value, SdkMajorVersion.V1),
706
+ type: rawLinkedPrimaryKeyProperty.type
707
+ };
708
+ }
709
+ function handleLinkedPrimaryKeyPropertyV2({
710
+ rawLinkedPrimaryKeyProperty
711
+ }) {
712
+ if (rawLinkedPrimaryKeyProperty == null) {
713
+ throw new Error("Cannot render with null rawLinkedPrimaryKeyProperty");
714
+ }
715
+ return {
716
+ apiName: rawLinkedPrimaryKeyProperty.apiName,
717
+ value: renderPropertyValue(rawLinkedPrimaryKeyProperty.value, SdkMajorVersion.V2),
718
+ type: rawLinkedPrimaryKeyProperty.type
719
+ };
720
+ }
721
+ function renderFunctionInputValues(rawFunctionInputValues, majorVersion) {
722
+ if (rawFunctionInputValues == null) {
723
+ throw new Error("Cannot render a null rawFunctionInputValues");
724
+ }
725
+ if (Object.keys(rawFunctionInputValues.parameters).length === 0) {
726
+ return "";
727
+ }
728
+ return outdent.outdent`
729
+ {
730
+ ${Object.entries(rawFunctionInputValues.parameters).map(([key, value]) => `"${key}": ${renderType(value, majorVersion, "functionInput")}`).join(`,${indentedNewLine(4)}`)}
731
+ }`;
732
+ }
733
+ function renderActionParameterValues(rawActionTypeParameterValues, majorVersion) {
734
+ if (rawActionTypeParameterValues == null) {
735
+ throw new Error("Cannot render a null rawActionTypeParameterValues");
736
+ }
737
+ return rawActionTypeParameterValues.map((param, index, array) => ({
738
+ key: param.key,
739
+ value: renderType(param.value, majorVersion, "actionParameter"),
740
+ last: index === array.length - 1
741
+ }));
742
+ }
743
+ function renderPropertyValue(propertyValue, majorVersion) {
744
+ if (propertyValue == null) {
745
+ throw new Error("Cannot render a null property value");
746
+ }
747
+ return renderType(propertyValue, majorVersion, "property");
748
+ }
749
+ function renderType(type, majorVersion, context) {
750
+ if (type == null) {
751
+ throw new Error("Cannot render a null type value");
752
+ }
753
+ switch (type.type) {
754
+ case "array":
755
+ case "set":
756
+ case "list":
757
+ return `[${renderType(type.subtype, majorVersion, context)}]`;
758
+ case "boolean":
759
+ return type.value ? "true" : "false";
760
+ case "byte":
761
+ case "integer":
762
+ case "long":
763
+ case "short":
764
+ return type.value.toString();
765
+ case "decimal":
766
+ case "double":
767
+ case "float":
768
+ if (context === "actionParameter") {
769
+ return `"${type.value.toString()}"`;
770
+ }
771
+ return type.value.toString();
772
+ case "date":
773
+ return getDateParameter(majorVersion, type.daysOffset);
774
+ case "timestamp":
775
+ return getTimestampParameter(majorVersion, type.daysOffset);
776
+ case "object":
777
+ const primaryKeyValue = type.primaryKeyType === "string" ? '"primaryKeyValue"' : "primaryKeyValue";
778
+ if (context === "actionParameter") {
779
+ return majorVersion >= SdkMajorVersion.V2 ? `{ $primaryKey: ${primaryKeyValue}, /* other properties */ }` : `{ __primaryKey: ${primaryKeyValue}, /* other properties */ }`;
780
+ }
781
+ return primaryKeyValue;
782
+ case "anonymousCustomType":
783
+ case "customType":
784
+ return "{}";
785
+ case "attachment":
786
+ return type.hasAttachments ? "attachment" : "{}";
787
+ case "interface":
788
+ case "marking":
789
+ return "{}";
790
+ case "mediaReference":
791
+ return context === "actionParameter" ? "mediaReference" : "mediaReferenceRid";
792
+ case "objectType":
793
+ return `"${type.objectTypeApiName}"`;
794
+ case "map":
795
+ if (type.keyType.type === "object") {
796
+ return `{[${getMapKeyObjectName(type.keyType.apiName)}.$objectSpecifier]: ${renderType(type.valueType, majorVersion, context)}}`;
797
+ }
798
+ return `{${renderType(type.valueType, majorVersion, context)}: ${renderType(type.valueType, majorVersion, context)}}`;
799
+ case "string":
800
+ case "unknown":
801
+ default:
802
+ return `"${type.value ?? "value"}"`;
803
+ }
804
+ }
805
+ function getMapKeyObjectName(apiName) {
806
+ if (apiName == null) {
807
+ return "osdkObject";
808
+ }
809
+ return `${getDisplayName(processObjectApiName(apiName))}OsdkObject`;
810
+ }
811
+ function getDisplayName(input) {
812
+ const tokens = input.split(/[_-]|(?<=[a-z])(?=[A-Z])/);
813
+ const result = tokens.map((token) => titleCase(token.toLowerCase())).join("");
814
+ return result.charAt(0).toLowerCase() + result.slice(1);
815
+ }
816
+ function titleCase(token) {
817
+ return (token[0] ?? "").toUpperCase() + token.slice(1);
818
+ }
819
+ function processObjectApiName(objectApiName) {
820
+ const last = objectApiName.lastIndexOf(".");
821
+ if (last === -1) {
822
+ return objectApiName;
823
+ }
824
+ return objectApiName.slice(last + 1);
825
+ }
826
+ function getDateParameter(majorVersion, daysOffset = 0) {
827
+ const offsetDate = /* @__PURE__ */ new Date();
828
+ offsetDate.setDate(offsetDate.getDate() + daysOffset);
829
+ const hasOffset = daysOffset !== 0;
830
+ if (majorVersion >= SdkMajorVersion.V2) {
831
+ return `"${offsetDate.toISOString().split("T")[0]}"`;
832
+ }
833
+ return hasOffset ? `LocalDate.now().plusDays(${daysOffset})` : "LocalDate.now()";
834
+ }
835
+ function getTimestampParameter(majorVersion, daysOffset = 0) {
836
+ const offsetDate = /* @__PURE__ */ new Date();
837
+ offsetDate.setDate(offsetDate.getDate() + daysOffset);
838
+ const hasOffset = daysOffset !== 0;
839
+ if (majorVersion >= SdkMajorVersion.V2) {
840
+ return `"${offsetDate.toISOString()}"`;
841
+ }
842
+ return hasOffset ? `Timestamp.now().plusDays(${daysOffset})` : "Timestamp.now()";
843
+ }
844
+
845
+ exports.TYPESCRIPT_OSDK_SNIPPETS = TYPESCRIPT_OSDK_SNIPPETS;
846
+ //# sourceMappingURL=index.cjs.map
847
+ //# sourceMappingURL=index.cjs.map