@osdk/react-sdk-docs 0.4.0 → 0.4.1-main-d15d3cfbd6062435cd1ed0fd47e94c3ecbc79d82
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 +6 -0
- package/build/browser/generatedNoCheck/docsNoComputedVariables.js +79 -79
- package/build/browser/generatedNoCheck/docsNoComputedVariables.js.map +1 -1
- package/build/cjs/index.cjs +79 -79
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/generatedNoCheck/docsNoComputedVariables.js +79 -79
- package/build/esm/generatedNoCheck/docsNoComputedVariables.js.map +1 -1
- package/package.json +5 -5
|
@@ -7,227 +7,227 @@ export const snippets = {
|
|
|
7
7
|
"2.0.0": {
|
|
8
8
|
"snippets": {
|
|
9
9
|
"reactProviderSetup": [{
|
|
10
|
-
"template": "import {
|
|
10
|
+
"template": "import { OsdkProvider } from \"@osdk/react\";\nimport { createClient } from \"@osdk/client\";\n\nconst client = createClient(\n \"https://your-stack.palantirfoundry.com\",\n \"{{{packageName}}}\",\n async () => \"your-token\"\n);\n\nfunction App() {\n return (\n <OsdkProvider client={client}>\n <YourApp />\n </OsdkProvider>\n );\n}"
|
|
11
11
|
}],
|
|
12
12
|
"reactUseOsdkObjectsBasic": [{
|
|
13
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
13
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{objectType}});\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && !data && <div className=\"skeleton\">Loading...</div>}\n <ul>\n {data?.map(obj => (\n <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>\n ))}\n </ul>\n {isLoading && data && <span className=\"refresh-indicator\">Refreshing...</span>}\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
14
14
|
}],
|
|
15
15
|
"reactUseOsdkObjectsFilter": [{
|
|
16
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
16
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Filtered{{objectType}}List() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{titleProperty}}: { $isNotNull: true }\n }\n });\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && !data && <div className=\"skeleton\">Loading...</div>}\n <ul>\n {data?.map(obj => (\n <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>\n ))}\n </ul>\n </div>\n );\n}"
|
|
17
17
|
}],
|
|
18
18
|
"reactUseOsdkObjectByPrimaryKey": [{
|
|
19
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react
|
|
19
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react\";\n\nfunction {{objectType}}Detail({ primaryKey }: { primaryKey: string }) {\n const { object, isLoading, error } = useOsdkObject({{objectType}}, primaryKey);\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && !object && <div className=\"skeleton\">Loading...</div>}\n {object && (\n <div>\n <h2>{object.{{titleProperty}}}</h2>\n </div>\n )}\n </div>\n );\n}"
|
|
20
20
|
}],
|
|
21
21
|
"reactUseLinksBasic": [{
|
|
22
|
-
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react
|
|
22
|
+
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react\";\n\nfunction Linked{{linkedObjectType}}({ source }: { source: {{sourceObjectType}}.OsdkInstance }) {\n const { links, isLoading, error } = useLinks(source, \"{{linkApiName}}\");\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && !links && <div className=\"skeleton\">Loading...</div>}\n <ul>\n {links?.map(linked => (\n <li key={linked.$primaryKey}>{linked.$primaryKey}</li>\n ))}\n </ul>\n </div>\n );\n}"
|
|
23
23
|
}],
|
|
24
24
|
"reactUseOsdkActionBasic": [{
|
|
25
|
-
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react
|
|
25
|
+
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react\";\n\nfunction {{actionApiName}}Button() {\n const { applyAction, isPending, error } = useOsdkAction({{actionApiName}});\n\n const handleClick = async () => {\n await applyAction({\n {{#actionParameterSampleValuesV2}}\n {{key}}: {{value}}{{^last}},{{/last}}\n {{/actionParameterSampleValuesV2}}\n });\n };\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {String(error.unknown ?? error.actionValidation)}</div>}\n <button onClick={handleClick} disabled={isPending}>\n {isPending ? \"Applying...\" : \"Apply {{actionApiName}}\"}\n </button>\n </div>\n );\n}",
|
|
26
26
|
"computedVariables": ["actionParameterSampleValuesV2"]
|
|
27
27
|
}],
|
|
28
28
|
"reactUseOsdkAggregationBasic": [{
|
|
29
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
29
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}Count() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: { $select: { $count: \"unordered\" } }\n });\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && data == null && <div className=\"skeleton\">Loading...</div>}\n {data != null && <span>Total: {data}</span>}\n </div>\n );\n}"
|
|
30
30
|
}],
|
|
31
31
|
"reactUseOsdkObjectsEnabled": [{
|
|
32
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
32
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Conditional{{objectType}}List({ shouldFetch }: { shouldFetch: boolean }) {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n enabled: shouldFetch\n });\n\n return (\n <div>\n {!shouldFetch && <div>Select criteria to load data</div>}\n {error && <div className=\"error-banner\">Error: {error.message}</div>}\n {isLoading && !data && <div className=\"skeleton\">Loading...</div>}\n <ul>\n {data?.map(obj => (\n <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>\n ))}\n </ul>\n </div>\n );\n}"
|
|
33
33
|
}],
|
|
34
34
|
"loadSingleObjectGuide": [{
|
|
35
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react
|
|
35
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react\";\n\nfunction {{objectType}}Detail({ primaryKey }: { primaryKey: string }) {\n const { object, isLoading, error } = useOsdkObject({{objectType}}, primaryKey);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !object && <div>Loading...</div>}\n {object && <div>{object.{{titleProperty}}}</div>}\n </div>\n );\n}"
|
|
36
36
|
}],
|
|
37
37
|
"loadObjectPageGuide": [{
|
|
38
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
38
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{objectType}}, {\n pageSize: 30\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
39
39
|
}],
|
|
40
40
|
"orderObjectsGuide": [{
|
|
41
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
41
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Sorted{{objectType}}List() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n orderBy: { {{titleProperty}}: \"asc\" }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
42
42
|
}],
|
|
43
43
|
"searchObjectsGuide": [{
|
|
44
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
44
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Filtered{{objectType}}List() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{titleProperty}}: { $isNotNull: true }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
45
45
|
}],
|
|
46
46
|
"loadSingleObjectReference": [{
|
|
47
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react
|
|
47
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObject } from \"@osdk/react\";\n\nfunction {{objectType}}Detail({ primaryKey }: { primaryKey: string }) {\n const { object, isLoading, error } = useOsdkObject({{objectType}}, primaryKey);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !object && <div>Loading...</div>}\n {object && <div>{object.{{titleProperty}}}</div>}\n </div>\n );\n}"
|
|
48
48
|
}],
|
|
49
49
|
"loadObjectsReference": [{
|
|
50
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
50
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{objectType}}, {\n pageSize: 30\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
51
51
|
}],
|
|
52
52
|
"loadAllObjectsReference": [{
|
|
53
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
53
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\n// Note: For large datasets, consider using pagination with fetchMore\nfunction All{{objectType}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{objectType}});\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
54
54
|
}],
|
|
55
55
|
"loadLinkedObjectReference": [{
|
|
56
|
-
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react
|
|
56
|
+
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react\";\n\nfunction {{linkedObjectType}}Detail({ source }: { source: {{sourceObjectType}}.OsdkInstance }) {\n const { links, isLoading, error } = useLinks(source, \"{{linkApiName}}\");\n const linkedObject = links?.[0];\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !links && <div>Loading...</div>}\n {linkedObject && <div>{linkedObject.$primaryKey}</div>}\n </div>\n );\n}"
|
|
57
57
|
}],
|
|
58
58
|
"loadLinkedObjectsReference": [{
|
|
59
|
-
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react
|
|
59
|
+
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useLinks } from \"@osdk/react\";\n\nfunction Linked{{linkedObjectType}}List({ source }: { source: {{sourceObjectType}}.OsdkInstance }) {\n const { links, isLoading, error, fetchMore } = useLinks(source, \"{{linkApiName}}\");\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !links && <div>Loading...</div>}\n <ul>\n {links?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
60
60
|
}],
|
|
61
61
|
"aggregationTemplate": [{
|
|
62
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
62
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}Aggregation() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n where: { {{property}}: { $isNull: false } },\n aggregate: {\n $select: { $count: \"unordered\" },\n $groupBy: { {{property}}: \"exact\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <pre>{JSON.stringify(data, null, 2)}</pre>}\n </div>\n );\n}"
|
|
63
63
|
}],
|
|
64
64
|
"countAggregationTemplate": [{
|
|
65
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
65
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}Count() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: { $select: { $count: \"unordered\" } }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <span>Total: {data}</span>}\n </div>\n );\n}"
|
|
66
66
|
}],
|
|
67
67
|
"approximateDistinctAggregationTemplate": [{
|
|
68
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
68
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}DistinctCount() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: { $select: { \"{{property}}:approximateDistinct\": \"unordered\" } }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <span>Distinct count: {data}</span>}\n </div>\n );\n}"
|
|
69
69
|
}],
|
|
70
70
|
"exactDistinctAggregationTemplate": [{
|
|
71
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
71
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}ExactDistinctCount() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: { $select: { \"{{property}}:exactDistinct\": \"unordered\" } }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <span>Exact distinct count: {data}</span>}\n </div>\n );\n}"
|
|
72
72
|
}],
|
|
73
73
|
"numericAggregationTemplate": [{
|
|
74
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
74
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}{{operation}}() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: { $select: { \"{{property}}:{{operation}}\": \"unordered\" } }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <span>{{operation}}: {data}</span>}\n </div>\n );\n}"
|
|
75
75
|
}],
|
|
76
76
|
"fixedWidthGroupByTemplate": [{
|
|
77
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
77
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}GroupedByFixedWidth() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: {\n $select: { $count: \"unordered\" },\n $groupBy: { {{property}}: { $fixedWidth: 10 } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <pre>{JSON.stringify(data, null, 2)}</pre>}\n </div>\n );\n}"
|
|
78
78
|
}],
|
|
79
79
|
"durationGroupByTemplate": [{
|
|
80
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
80
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}GroupedByDuration() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: {\n $select: { $count: \"unordered\" },\n $groupBy: { {{property}}: { $duration: [{{#durationText}}{{arg}}{{/durationText}}, \"{{#durationText}}{{unit}}{{/durationText}}\"] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <pre>{JSON.stringify(data, null, 2)}</pre>}\n </div>\n );\n}"
|
|
81
81
|
}],
|
|
82
82
|
"exactGroupByTemplate": [{
|
|
83
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
83
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}GroupedByExact() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: {\n $select: { $count: \"unordered\" },\n $groupBy: { {{property}}: \"exact\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <pre>{JSON.stringify(data, null, 2)}</pre>}\n </div>\n );\n}"
|
|
84
84
|
}],
|
|
85
85
|
"rangeGroupByTemplate": [{
|
|
86
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react
|
|
86
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkAggregation } from \"@osdk/react\";\n\nfunction {{objectType}}GroupedByRange() {\n const { data, isLoading, error } = useOsdkAggregation({{objectType}}, {\n aggregate: {\n $select: { $count: \"unordered\" },\n $groupBy: { {{property}}: { $ranges: [[{{{propertyValueV2}}}, {{{propertyValueV2}}}]] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && data == null && <div>Loading...</div>}\n {data != null && <pre>{JSON.stringify(data, null, 2)}</pre>}\n </div>\n );\n}",
|
|
87
87
|
"computedVariables": ["propertyValueV2"]
|
|
88
88
|
}],
|
|
89
89
|
"applyAction": [{
|
|
90
|
-
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react
|
|
90
|
+
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react\";\n\nfunction {{actionApiName}}Button() {\n const { applyAction, isPending, error } = useOsdkAction({{actionApiName}});\n\n const handleClick = async () => {\n await applyAction({\n {{#actionParameterSampleValuesV2}}\n {{key}}: {{value}}{{^last}},{{/last}}\n {{/actionParameterSampleValuesV2}}\n });\n };\n\n return (\n <div>\n {error && <div>Error: {String(error.unknown ?? error.actionValidation)}</div>}\n <button onClick={handleClick} disabled={isPending}>\n {isPending ? \"Applying...\" : \"Apply\"}\n </button>\n </div>\n );\n}",
|
|
91
91
|
"computedVariables": ["actionParameterSampleValuesV2"]
|
|
92
92
|
}],
|
|
93
93
|
"applyActionResponse": [{
|
|
94
|
-
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react
|
|
94
|
+
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react\";\n\nfunction {{actionApiName}}WithResult() {\n const { applyAction, isPending, error, data } = useOsdkAction({{actionApiName}});\n\n const handleClick = async () => {\n await applyAction({\n {{#actionParameterSampleValuesV2}}\n {{key}}: {{value}}{{^last}},{{/last}}\n {{/actionParameterSampleValuesV2}}\n });\n };\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {String(error.unknown ?? error.actionValidation)}</div>}\n {data && <div>Action completed successfully</div>}\n <button onClick={handleClick} disabled={isPending}>\n {isPending ? \"Applying...\" : \"Apply {{actionApiName}}\"}\n </button>\n </div>\n );\n}",
|
|
95
95
|
"computedVariables": ["actionParameterSampleValuesV2"]
|
|
96
96
|
}],
|
|
97
97
|
"validateAction": [{
|
|
98
|
-
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction, useDebouncedCallback } from \"@osdk/react
|
|
98
|
+
"template": "import { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction, useDebouncedCallback } from \"@osdk/react\";\nimport { useState } from \"react\";\n\nfunction {{actionApiName}}WithValidation() {\n const { validateAction, applyAction, isPending, validationResult } = useOsdkAction({{actionApiName}});\n const [params, setParams] = useState<Record<string, string>>({});\n\n const debouncedValidate = useDebouncedCallback(\n (nextParams: Record<string, string>) => { validateAction(nextParams); },\n 300\n );\n\n const handleParamChange = (key: string, value: string) => {\n const nextParams = { ...params, [key]: value };\n setParams(nextParams);\n debouncedValidate(nextParams);\n };\n\n return (\n <div>\n <input\n placeholder=\"Parameter value\"\n onChange={(e) => handleParamChange(\"paramName\", e.target.value)}\n />\n {validationResult?.result === \"INVALID\" && (\n <div>Validation errors present</div>\n )}\n <button\n onClick={() => applyAction(params)}\n disabled={isPending || validationResult?.result === \"INVALID\"}\n >\n {isPending ? \"Applying...\" : \"Apply\"}\n </button>\n </div>\n );\n}"
|
|
99
99
|
}],
|
|
100
100
|
"batchApplyAction": [{
|
|
101
|
-
"template": "// Batch actions in React should be handled with multiple hook calls\n// or by using the client directly for batch operations\nimport { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react
|
|
101
|
+
"template": "// Batch actions in React should be handled with multiple hook calls\n// or by using the client directly for batch operations\nimport { {{actionApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkAction } from \"@osdk/react\";\n\nfunction Batch{{actionApiName}}() {\n const { applyAction, isPending } = useOsdkAction({{actionApiName}});\n\n const handleBatchApply = async (items: Array<Parameters<typeof applyAction>[0]>) => {\n await Promise.all(items.map(item => applyAction(item)));\n };\n\n return (\n <button onClick={() => handleBatchApply([])} disabled={isPending}>\n Apply Batch\n </button>\n );\n}"
|
|
102
102
|
}],
|
|
103
103
|
"clientSetup": [{
|
|
104
|
-
"template": "import {
|
|
104
|
+
"template": "import { OsdkProvider } from \"@osdk/react\";\nimport { createClient } from \"@osdk/client\";\n\nconst client = createClient(\n \"https://your-stack.palantirfoundry.com\",\n \"{{{packageName}}}\",\n async () => \"your-token\"\n);\n\nfunction App() {\n return (\n <OsdkProvider client={client}>\n <YourApp />\n </OsdkProvider>\n );\n}"
|
|
105
105
|
}],
|
|
106
106
|
"callFunction": [{
|
|
107
|
-
"template": "import { {{funcApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkFunction } from \"@osdk/react
|
|
107
|
+
"template": "import { {{funcApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkFunction } from \"@osdk/react\";\n\nfunction {{funcApiName}}Caller() {\n const { data, isLoading, error, refetch } = useOsdkFunction({{funcApiName}}, {\n params: { /* function parameters */ }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n {data && <pre>{JSON.stringify(data, null, 2)}</pre>}\n <button onClick={refetch}>Refresh</button>\n </div>\n );\n}"
|
|
108
108
|
}],
|
|
109
109
|
"executeFunction": [{
|
|
110
|
-
"template": "import { {{funcApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkFunction } from \"@osdk/react
|
|
110
|
+
"template": "import { {{funcApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkFunction } from \"@osdk/react\";\n\nfunction {{funcApiName}}Executor() {\n const { data, isLoading, error, refetch } = useOsdkFunction({{funcApiName}}, {\n params: { /* function parameters */ }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n {data && <pre>{JSON.stringify(data, null, 2)}</pre>}\n <button onClick={refetch}>Refresh</button>\n </div>\n );\n}"
|
|
111
111
|
}],
|
|
112
112
|
"stringStartsWithTemplate": [{
|
|
113
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
113
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}StartsWith() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $startsWith: \"foo\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
114
114
|
}],
|
|
115
115
|
"containsAnyTermTemplate": [{
|
|
116
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
116
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}ContainsAnyTerm() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $containsAnyTerm: \"foo bar\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
117
117
|
}],
|
|
118
118
|
"containsAllTermsTemplate": [{
|
|
119
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
119
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}ContainsAllTerms() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $containsAllTerms: \"foo bar\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
120
120
|
}],
|
|
121
121
|
"containsAllTermsInOrderTemplate": [{
|
|
122
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
122
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}ContainsAllTermsInOrder() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $containsAllTermsInOrder: \"foo bar\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
123
123
|
}],
|
|
124
124
|
"containsTemplate": [{
|
|
125
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
125
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}Contains() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $contains: \"value\" }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
126
126
|
}],
|
|
127
127
|
"equalityTemplate": [{
|
|
128
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
128
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}Equality() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $eq: {{{propertyValueV2}}} }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
129
129
|
"computedVariables": ["propertyValueV2"]
|
|
130
130
|
}],
|
|
131
131
|
"inFilterTemplate": [{
|
|
132
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
132
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}InFilter() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $in: [{{{propertyValueV2}}}] }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
133
133
|
"computedVariables": ["propertyValueV2"]
|
|
134
134
|
}],
|
|
135
135
|
"rangeTemplate": [{
|
|
136
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
136
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}Range() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { ${{operation}}: {{{propertyValueV2}}} }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
137
137
|
"computedVariables": ["propertyValueV2"]
|
|
138
138
|
}],
|
|
139
139
|
"nullTemplate": [{
|
|
140
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
140
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}NullFilter() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $isNull: true }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
141
141
|
}],
|
|
142
142
|
"andTemplate": [{
|
|
143
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
143
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}AndFilter() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n $and: [\n { $not: { {{primaryKeyPropertyV2.apiName}}: { $isNull: true } } },\n { {{property}}: { $eq: {{{propertyValueV2}}} } }\n ]\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
144
144
|
"computedVariables": ["primaryKeyPropertyV2", "propertyValueV2"]
|
|
145
145
|
}],
|
|
146
146
|
"orTemplate": [{
|
|
147
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
147
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}OrFilter() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n $or: [\n { $not: { {{primaryKeyPropertyV2.apiName}}: { $isNull: true } } },\n { {{property}}: { $eq: {{{propertyValueV2}}} } }\n ]\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
148
148
|
"computedVariables": ["primaryKeyPropertyV2", "propertyValueV2"]
|
|
149
149
|
}],
|
|
150
150
|
"notTemplate": [{
|
|
151
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
151
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}NotFilter() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n $not: { {{property}}: { $eq: {{{propertyValueV2}}} } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}",
|
|
152
152
|
"computedVariables": ["propertyValueV2"]
|
|
153
153
|
}],
|
|
154
154
|
"withinDistanceTemplate": [{
|
|
155
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
155
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}WithinDistance() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $within: { $distance: [100, \"{{distanceUnit}}\"], $of: [-74.0060, 40.7128] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
156
156
|
}],
|
|
157
157
|
"withinBoundingBoxTemplate": [{
|
|
158
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
158
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}WithinBoundingBox() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $within: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
159
159
|
}],
|
|
160
160
|
"withinPolygonTemplate": [{
|
|
161
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
161
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}WithinPolygon() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $within: { type: \"Polygon\", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
162
162
|
}],
|
|
163
163
|
"intersectsPolygonTemplate": [{
|
|
164
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
164
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}IntersectsPolygon() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $intersects: { type: \"Polygon\", coordinates: [[[10.0, 40.0], [20.0, 50.0], [20.0, 30.0], [10.0, 40.0]]] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
165
165
|
}],
|
|
166
166
|
"intersectsBboxTemplate": [{
|
|
167
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
167
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectType}}IntersectsBbox() {\n const { data, isLoading, error } = useOsdkObjects({{objectType}}, {\n where: {\n {{property}}: { $intersects: { $bbox: [-74.0060, 25.123, 80.4231, 40.7128] } }\n }\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
168
168
|
}],
|
|
169
169
|
"objectSetOperationsGuide": [{
|
|
170
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
170
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}SetOperations() {\n const client = useOsdkClient();\n const combinedSet = useMemo(() => {\n const setA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"a\" } });\n const setB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"b\" } });\n const setC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"c\" } });\n return setA.intersect(setB).subtract(setC);\n }, [client]);\n\n const { data, isLoading, error } = useObjectSet(combinedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
171
171
|
}],
|
|
172
172
|
"objectSetOperationsUnion": [{
|
|
173
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
173
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}Union() {\n const client = useOsdkClient();\n const unionSet = useMemo(() => {\n const setA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"a\" } });\n const setB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"b\" } });\n const setC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"c\" } });\n return setA.union(setB).union(setC);\n }, [client]);\n\n const { data, isLoading, error } = useObjectSet(unionSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
174
174
|
}],
|
|
175
175
|
"objectSetOperationsSubtract": [{
|
|
176
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
176
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}Subtract() {\n const client = useOsdkClient();\n const subtractedSet = useMemo(() => {\n const setA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"a\" } });\n const setB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"b\" } });\n const setC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"c\" } });\n return setA.subtract(setB).subtract(setC);\n }, [client]);\n\n const { data, isLoading, error } = useObjectSet(subtractedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
177
177
|
}],
|
|
178
178
|
"objectSetOperationsIntersect": [{
|
|
179
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
179
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}Intersect() {\n const client = useOsdkClient();\n const intersectedSet = useMemo(() => {\n const setA = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"a\" } });\n const setB = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"b\" } });\n const setC = client({{objectType}}).where({ {{titleProperty}}: { $containsAnyTerm: \"c\" } });\n return setA.intersect(setB).intersect(setC);\n }, [client]);\n\n const { data, isLoading, error } = useObjectSet(intersectedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.{{titleProperty}}}</li>)}\n </ul>\n </div>\n );\n}"
|
|
180
180
|
}],
|
|
181
181
|
"derivedPropertyBaseExample": [{
|
|
182
|
-
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
182
|
+
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{sourceObjectType}}DerivedProperty() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{sourceObjectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"$count\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
183
183
|
}],
|
|
184
184
|
"derivedPropertyCountAggregation": [{
|
|
185
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
185
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedCount() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"$count\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
186
186
|
}],
|
|
187
187
|
"derivedPropertyNumericAggregation": [{
|
|
188
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
188
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedNumeric() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:{{operation}}\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
189
189
|
}],
|
|
190
190
|
"derivedPropertySelectPropertyAggregation": [{
|
|
191
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
191
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedSelectProperty() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").selectProperty(\"{{property}}\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
192
192
|
}],
|
|
193
193
|
"derivedPropertyApproximateDistinctAggregation": [{
|
|
194
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
194
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedApproxDistinct() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:approximateDistinct\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
195
195
|
}],
|
|
196
196
|
"derivedPropertyExactDistinctAggregation": [{
|
|
197
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
197
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedExactDistinct() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:exactDistinct\")\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
198
198
|
}],
|
|
199
199
|
"derivedPropertyApproximatePercentileAggregation": [{
|
|
200
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
200
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedPercentile() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:approximatePercentile\", { percentile: 95 })\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
201
201
|
}],
|
|
202
202
|
"derivedPropertyCollectToListAggregation": [{
|
|
203
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
203
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedCollectList() {\n const client = useOsdkClient();\n const maxObjectsInList = 75;\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:collectList\", { limit: maxObjectsInList })\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
204
204
|
}],
|
|
205
205
|
"derivedPropertyCollectToSetAggregation": [{
|
|
206
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
206
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedCollectSet() {\n const client = useOsdkClient();\n const maxObjectsInSet = 75;\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"{{property}}:collectSet\", { limit: maxObjectsInSet })\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
207
207
|
}],
|
|
208
208
|
"loadObjectMetadataSnippet": [{
|
|
209
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkMetadata } from \"@osdk/react
|
|
209
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkMetadata } from \"@osdk/react\";\n\nfunction {{objectType}}Metadata() {\n const { loading, metadata, error } = useOsdkMetadata({{objectType}});\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error}</div>}\n {loading && !metadata && <div className=\"skeleton\">Loading...</div>}\n {metadata && (\n <div>\n <div>Description: {metadata.description}</div>\n <div>Visibility: {metadata.visibility}</div>\n </div>\n )}\n </div>\n );\n}"
|
|
210
210
|
}],
|
|
211
211
|
"loadInterfaceMetadataSnippet": [{
|
|
212
|
-
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkMetadata } from \"@osdk/react
|
|
212
|
+
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkMetadata } from \"@osdk/react\";\n\nfunction {{interfaceApiName}}Metadata() {\n const { loading, metadata, error } = useOsdkMetadata({{interfaceApiName}});\n\n return (\n <div>\n {error && <div className=\"error-banner\">Error: {error}</div>}\n {loading && !metadata && <div className=\"skeleton\">Loading...</div>}\n {metadata && (\n <div>\n <div>RID: {metadata.rid}</div>\n <div>Implemented by: {metadata.implementedBy?.join(\", \")}</div>\n </div>\n )}\n </div>\n );\n}"
|
|
213
213
|
}],
|
|
214
214
|
"loadInterfacesReference": [{
|
|
215
|
-
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
215
|
+
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{interfaceApiName}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{interfaceApiName}}, {\n pageSize: 30\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
216
216
|
}],
|
|
217
217
|
"loadAllInterfacesReference": [{
|
|
218
|
-
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
218
|
+
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction All{{interfaceApiName}}List() {\n const { data, isLoading, error, fetchMore } = useOsdkObjects({{interfaceApiName}});\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n {fetchMore && <button onClick={fetchMore}>Load more</button>}\n </div>\n );\n}"
|
|
219
219
|
}],
|
|
220
220
|
"loadOrderedInterfacesReference": [{
|
|
221
|
-
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
221
|
+
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Ordered{{interfaceApiName}}List() {\n const { data, isLoading, error } = useOsdkObjects({{interfaceApiName}}, {\n orderBy: { {{property}}: \"asc\" },\n pageSize: 30\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
222
222
|
}],
|
|
223
223
|
"searchInterfacesReference": [{
|
|
224
|
-
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
224
|
+
"template": "import { {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction Search{{interfaceApiName}}() {\n const { data, isLoading, error } = useOsdkObjects({{interfaceApiName}}, {\n where: {\n {{property}}: { $startsWith: \"foo\" }\n },\n pageSize: 30\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
225
225
|
}],
|
|
226
226
|
"castInterfaceToObjectReference": [{
|
|
227
|
-
"template": "import { {{objectTypeApiName}}, {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
227
|
+
"template": "import { {{objectTypeApiName}}, {{interfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction CastInterface() {\n const { data, isLoading, error } = useOsdkObjects({{interfaceApiName}}, {\n pageSize: 10\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => {\n const casted = obj.$as({{objectTypeApiName}});\n return <li key={casted.$primaryKey}>{casted.$primaryKey}</li>;\n })}\n </ul>\n </div>\n );\n}"
|
|
228
228
|
}],
|
|
229
229
|
"subscribeToObjectSetInstructions": [{
|
|
230
|
-
"template": "import { {{objectOrInterfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react
|
|
230
|
+
"template": "import { {{objectOrInterfaceApiName}} } from \"{{{packageName}}}\";\nimport { useOsdkObjects } from \"@osdk/react\";\n\nfunction {{objectOrInterfaceApiName}}LiveList() {\n const { data, isLoading, error } = useOsdkObjects({{objectOrInterfaceApiName}}, {\n streamUpdates: true\n });\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
231
231
|
}],
|
|
232
232
|
"loadTimeSeriesPointsSnippet": [{
|
|
233
233
|
"template": "// Timeseries does not have a dedicated React hook yet.\n// Use the client API directly with a loaded OSDK object.\nimport type { Osdk } from \"@osdk/client\";\nimport type { {{objectType}} } from \"{{{packageName}}}\";\n\nasync function getAllTimeSeriesPoints(obj: Osdk.Instance<typeof {{objectType}}>) {\n return obj.{{property}}?.getAllPoints();\n}"
|
|
@@ -257,35 +257,35 @@ export const snippets = {
|
|
|
257
257
|
"template": "// Geo-time series does not have a dedicated React hook yet.\n// Use the client API directly with a loaded OSDK object.\nimport type { Osdk } from \"@osdk/client\";\nimport type { {{objectType}} } from \"{{{packageName}}}\";\n\nasync function getRelativeGeotimeSeriesPoints(obj: Osdk.Instance<typeof {{objectType}}>) {\n return obj.{{property}}?.getAllValues({\n $before: 1,\n $unit: \"{{timeUnit}}\",\n });\n}"
|
|
258
258
|
}],
|
|
259
259
|
"uploadAttachment": [{
|
|
260
|
-
"template": "import { useOsdkClient } from \"@osdk/react
|
|
260
|
+
"template": "import { useOsdkClient } from \"@osdk/react\";\nimport { createAttachmentUpload } from \"@osdk/client\";\nimport { {{actionApiName}} } from \"{{{packageName}}}\";\n\nfunction AttachmentUploader() {\n const client = useOsdkClient();\n\n const handleUpload = async (file: File) => {\n const attachment = createAttachmentUpload(file, file.name);\n await client({{actionApiName}}).applyAction({\n {{primaryKeyPropertyV2.apiName}}: {{{propertyValueV2}}},\n {{property}}: attachment\n });\n };\n\n return (\n <input type=\"file\" onChange={e => {\n const file = e.target.files?.[0];\n if (file) {\n handleUpload(file);\n }\n }} />\n );\n}",
|
|
261
261
|
"computedVariables": ["propertyValueV2", "primaryKeyPropertyV2"]
|
|
262
262
|
}],
|
|
263
263
|
"readMedia": [{
|
|
264
264
|
"template": "// Media does not have a dedicated React hook yet.\n// Use the client API directly with a loaded OSDK object.\nimport type { Osdk } from \"@osdk/client\";\nimport type { {{objectType}} } from \"{{{packageName}}}\";\n\nasync function readMediaContent(obj: Osdk.Instance<typeof {{objectType}}>) {\n const contents = await obj.{{property}}?.fetchContents();\n if (contents?.ok) {\n return contents.blob();\n }\n}"
|
|
265
265
|
}],
|
|
266
266
|
"uploadMedia": [{
|
|
267
|
-
"template": "import { useOsdkClient } from \"@osdk/react
|
|
267
|
+
"template": "import { useOsdkClient } from \"@osdk/react\";\nimport { __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference } from \"@osdk/api/unstable\";\nimport type { MediaReference } from \"@osdk/api\";\nimport { {{actionApiName}}, {{objectType}} } from \"{{{packageName}}}\";\n\nfunction MediaUploader() {\n const client = useOsdkClient();\n\n const handleUpload = async (file: File) => {\n const mediaReference: MediaReference = await client(\n __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference,\n ).createMediaReference({\n data: file,\n fileName: file.name,\n objectType: {{objectType}},\n propertyType: \"{{property}}\",\n });\n await client({{actionApiName}}).applyAction({\n // Pass the required action parameters including the primary key\n {{mediaParameter}}: mediaReference\n });\n };\n\n return (\n <input type=\"file\" onChange={e => {\n const file = e.target.files?.[0];\n if (file) {\n handleUpload(file);\n }\n }} />\n );\n}"
|
|
268
268
|
}],
|
|
269
269
|
"uploadMediaOntologyEdits": [{
|
|
270
|
-
"template": "import { useOsdkClient } from \"@osdk/react
|
|
270
|
+
"template": "import { useOsdkClient } from \"@osdk/react\";\nimport { {{objectType}} } from \"{{{packageName}}}\";\nimport { createEditBatch, uploadMedia } from \"@osdk/functions\";\n\nfunction MediaOntologyEditsUploader() {\n const client = useOsdkClient();\n\n const handleUpload = async (file: File) => {\n const batch = createEditBatch(client);\n const mediaReference = await uploadMedia(client, { data: file, fileName: file.name });\n // @ts-expect-error - batch.create types don't support media references yet\n batch.create({{objectType}}, { {{property}}: mediaReference });\n return batch.getEdits();\n };\n\n return (\n <input type=\"file\" onChange={e => {\n const file = e.target.files?.[0];\n if (file) {\n handleUpload(file);\n }\n }} />\n );\n}"
|
|
271
271
|
}],
|
|
272
272
|
"uploadMediaEphemeral": [{
|
|
273
273
|
"template": "// Ephemeral media upload is not yet supported in the React SDK"
|
|
274
274
|
}],
|
|
275
275
|
"derivedPropertyNumericExpression": [{
|
|
276
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
276
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedNumericExpression() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n {{^isUnary}}\n \"newPropertyName\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\")\n .aggregate(\"{{property}}\").{{operation}}(\n baseObjectSet.pivotTo(\"{{linkApiName}}\").aggregate(\"$count\"))\n {{/isUnary}}\n {{#isUnary}}\n \"{{operation}}_{{property}}\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\")\n .selectProperty(\"{{property}}\").{{operation}}()\n {{/isUnary}}\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
277
277
|
}],
|
|
278
278
|
"derivedPropertyDatetimeExpression": [{
|
|
279
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
279
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}DerivedDatetimeExpression() {\n const client = useOsdkClient();\n const derivedSet = useMemo(() =>\n client({{objectType}}).withProperties({\n {{^isExtractPart}}\n \"derivedPropertyDatetime_{{operation}}\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\")\n .selectProperty(\"{{property}}\")\n .{{operation}}(baseObjectSet.pivotTo(\"{{linkApiName}}\").selectProperty(\"{{property}}\"))\n {{/isExtractPart}}\n {{#isExtractPart}}\n \"YEARS_part_of_{{property}}_of_{{linkApiName}}\": (baseObjectSet) =>\n baseObjectSet.pivotTo(\"{{linkApiName}}\")\n .selectProperty(\"{{property}}\").extractPart(\"YEARS\")\n {{/isExtractPart}}\n }), [client]);\n\n const { data, isLoading, error } = useObjectSet(derivedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
280
280
|
}],
|
|
281
281
|
"nearestNeighborsTextQuery": [{
|
|
282
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
282
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}NearestNeighborsText() {\n const client = useOsdkClient();\n const resultSet = useMemo(() =>\n client({{objectType}}).nearestNeighbors(\"coffee\", 5, \"{{property}}\"),\n [client]);\n\n const { data, isLoading, error } = useObjectSet(resultSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
283
283
|
}],
|
|
284
284
|
"nearestNeighborsVectorQuery": [{
|
|
285
|
-
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
285
|
+
"template": "import { {{objectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction {{objectType}}NearestNeighborsVector() {\n const client = useOsdkClient();\n // Note that this vector maps to an arbitrary string\n // It must match the dimension of the \"{{property}}\" property: {{vectorDimensionSize}}\n const vectorQuery = useMemo(() =>\n Array.from({ length: {{vectorDimensionSize}} }, () => 0.3),\n []);\n const resultSet = useMemo(() =>\n client({{objectType}}).nearestNeighbors(vectorQuery, 5, \"{{property}}\"),\n [client, vectorQuery]);\n\n const { data, isLoading, error } = useObjectSet(resultSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
286
286
|
}],
|
|
287
287
|
"searchAround": [{
|
|
288
|
-
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react
|
|
288
|
+
"template": "import { {{sourceObjectType}} } from \"{{{packageName}}}\";\nimport { useOsdkClient, useObjectSet } from \"@osdk/react\";\nimport { useMemo } from \"react\";\n\nfunction SearchAround{{linkedObjectType}}() {\n const client = useOsdkClient();\n const linkedSet = useMemo(() =>\n client({{sourceObjectType}})\n .where({ {{rawLinkedPrimaryKeyProperty.apiName}}: { $in: [\"a\", \"b\", \"c\"] } })\n .pivotTo(\"{{linkApiName}}\"),\n [client]);\n\n const { data, isLoading, error } = useObjectSet(linkedSet);\n\n return (\n <div>\n {error && <div>Error: {error.message}</div>}\n {isLoading && !data && <div>Loading...</div>}\n <ul>\n {data?.map(obj => <li key={obj.$primaryKey}>{obj.$primaryKey}</li>)}\n </ul>\n </div>\n );\n}"
|
|
289
289
|
}]
|
|
290
290
|
}
|
|
291
291
|
}
|