@osdk/client 2.6.0-beta.1 → 2.6.0-beta.2
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 +19 -0
- package/build/browser/Client.js +1 -1
- package/build/browser/Client.js.map +1 -1
- package/build/browser/fetchMetadata.test.js +11 -0
- package/build/browser/fetchMetadata.test.js.map +1 -1
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js +15 -0
- package/build/browser/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js +4 -0
- package/build/browser/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js +10 -0
- package/build/browser/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/browser/object/convertWireToOsdkObjects.test.js +12 -0
- package/build/browser/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/browser/object/formatting/applyPropertyFormatter.js +52 -0
- package/build/browser/object/formatting/applyPropertyFormatter.js.map +1 -0
- package/build/browser/object/formatting/applyPropertyFormatter.test.js +423 -0
- package/build/browser/object/formatting/applyPropertyFormatter.test.js.map +1 -0
- package/build/browser/object/formatting/formatBoolean.js +23 -0
- package/build/browser/object/formatting/formatBoolean.js.map +1 -0
- package/build/browser/object/formatting/formatNumber.js +242 -0
- package/build/browser/object/formatting/formatNumber.js.map +1 -0
- package/build/browser/object/formatting/propertyFormattingUtils.js +39 -0
- package/build/browser/object/formatting/propertyFormattingUtils.js.map +1 -0
- package/build/browser/util/UserAgent.js +2 -2
- package/build/cjs/{chunk-DCEFUXFS.cjs → chunk-6L3MX4LH.cjs} +35 -15
- package/build/cjs/chunk-6L3MX4LH.cjs.map +1 -0
- package/build/cjs/{chunk-BP7BR5FZ.cjs → chunk-X7WMWKLM.cjs} +298 -54
- package/build/cjs/chunk-X7WMWKLM.cjs.map +1 -0
- package/build/cjs/index.cjs +8 -8
- package/build/cjs/public/internal.cjs +8 -8
- package/build/cjs/public/unstable-do-not-use.cjs +31 -31
- package/build/esm/Client.js +1 -1
- package/build/esm/Client.js.map +1 -1
- package/build/esm/fetchMetadata.test.js +11 -0
- package/build/esm/fetchMetadata.test.js.map +1 -1
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js +15 -0
- package/build/esm/internal/conversions/modernToLegacyWhereClause.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/BaseHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js +4 -0
- package/build/esm/object/convertWireToOsdkObjects/createOsdkInterface.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js +10 -0
- package/build/esm/object/convertWireToOsdkObjects/createOsdkObject.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects.test.js +12 -0
- package/build/esm/object/convertWireToOsdkObjects.test.js.map +1 -1
- package/build/esm/object/formatting/applyPropertyFormatter.js +52 -0
- package/build/esm/object/formatting/applyPropertyFormatter.js.map +1 -0
- package/build/esm/object/formatting/applyPropertyFormatter.test.js +423 -0
- package/build/esm/object/formatting/applyPropertyFormatter.test.js.map +1 -0
- package/build/esm/object/formatting/formatBoolean.js +23 -0
- package/build/esm/object/formatting/formatBoolean.js.map +1 -0
- package/build/esm/object/formatting/formatNumber.js +242 -0
- package/build/esm/object/formatting/formatNumber.js.map +1 -0
- package/build/esm/object/formatting/propertyFormattingUtils.js +39 -0
- package/build/esm/object/formatting/propertyFormattingUtils.js.map +1 -0
- package/build/esm/util/UserAgent.js +2 -2
- package/build/types/Client.d.ts +1 -1
- package/build/types/object/formatting/applyPropertyFormatter.d.ts +18 -0
- package/build/types/object/formatting/applyPropertyFormatter.d.ts.map +1 -0
- package/build/types/object/formatting/applyPropertyFormatter.test.d.ts +1 -0
- package/build/types/object/formatting/applyPropertyFormatter.test.d.ts.map +1 -0
- package/build/types/object/formatting/formatBoolean.d.ts +5 -0
- package/build/types/object/formatting/formatBoolean.d.ts.map +1 -0
- package/build/types/object/formatting/formatNumber.d.ts +15 -0
- package/build/types/object/formatting/formatNumber.d.ts.map +1 -0
- package/build/types/object/formatting/propertyFormattingUtils.d.ts +10 -0
- package/build/types/object/formatting/propertyFormattingUtils.d.ts.map +1 -0
- package/package.json +7 -7
- package/build/cjs/chunk-BP7BR5FZ.cjs.map +0 -1
- package/build/cjs/chunk-DCEFUXFS.cjs.map +0 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { resolvePropertyReference } from "./propertyFormattingUtils.js";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extended NumberFormatOptions that includes rounding mode support
|
|
21
|
+
* which is available in modern browsers but not yet in TypeScript types.
|
|
22
|
+
* Only includes modes that are actually supported by Intl.NumberFormat and used in our API.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Formats a number value according to the specified formatting rule
|
|
27
|
+
*/
|
|
28
|
+
export function formatNumber(value, numberType, objectData, locale) {
|
|
29
|
+
switch (numberType.type) {
|
|
30
|
+
case "standard":
|
|
31
|
+
return formatStandardNumber(value, numberType.baseFormatOptions, locale);
|
|
32
|
+
case "fixedValues":
|
|
33
|
+
return numberType.values[value];
|
|
34
|
+
case "currency":
|
|
35
|
+
return formatCurrency(value, numberType, objectData, locale);
|
|
36
|
+
case "standardUnit":
|
|
37
|
+
return formatStandardUnit(value, numberType, objectData, locale);
|
|
38
|
+
case "customUnit":
|
|
39
|
+
return formatCustomUnit(value, numberType, objectData, locale);
|
|
40
|
+
case "affix":
|
|
41
|
+
return formatAffix(value, numberType, objectData, locale);
|
|
42
|
+
case "duration":
|
|
43
|
+
// TODO (duration is a bit more complex)
|
|
44
|
+
return undefined;
|
|
45
|
+
case "scale":
|
|
46
|
+
return formatScale(value, numberType, locale);
|
|
47
|
+
case "ratio":
|
|
48
|
+
return formatRatio(value, numberType, locale);
|
|
49
|
+
default:
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function formatStandardNumber(value, options, locale) {
|
|
54
|
+
return formatNumberWithAffixes(value, options, locale);
|
|
55
|
+
}
|
|
56
|
+
function formatCurrency(value, rule, objectData, locale) {
|
|
57
|
+
const currencyCode = resolvePropertyReference(rule.currencyCode, objectData);
|
|
58
|
+
if (currencyCode == null) {
|
|
59
|
+
return formatStandardNumber(value, rule.baseFormatOptions, locale);
|
|
60
|
+
}
|
|
61
|
+
const options = {
|
|
62
|
+
...convertToIntlOptions(rule.baseFormatOptions),
|
|
63
|
+
style: "currency",
|
|
64
|
+
currency: currencyCode,
|
|
65
|
+
currencyDisplay: rule.style === "COMPACT" ? "narrowSymbol" : "symbol"
|
|
66
|
+
};
|
|
67
|
+
return formatWithIntl(value, options, locale);
|
|
68
|
+
}
|
|
69
|
+
function formatStandardUnit(value, rule, objectData, locale) {
|
|
70
|
+
const unit = resolvePropertyReference(rule.unit, objectData);
|
|
71
|
+
if (unit == null) {
|
|
72
|
+
return formatStandardNumber(value, rule.baseFormatOptions, locale);
|
|
73
|
+
}
|
|
74
|
+
const options = {
|
|
75
|
+
...convertToIntlOptions(rule.baseFormatOptions),
|
|
76
|
+
style: "unit",
|
|
77
|
+
unit: unit
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
return formatWithIntl(value, options, locale);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return formatNumberWithAffixes(value, rule.baseFormatOptions, locale, "", ` ${unit}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function formatCustomUnit(value, rule, objectData, locale) {
|
|
86
|
+
const unit = resolvePropertyReference(rule.unit, objectData);
|
|
87
|
+
const suffix = unit != null ? ` ${unit}` : "";
|
|
88
|
+
return formatNumberWithAffixes(value, rule.baseFormatOptions, locale, "", suffix);
|
|
89
|
+
}
|
|
90
|
+
function formatAffix(value, rule, objectData, locale) {
|
|
91
|
+
const prefix = rule.affix.prefix != null ? resolvePropertyReference(rule.affix.prefix, objectData) ?? "" : "";
|
|
92
|
+
const suffix = rule.affix.postfix != null ? resolvePropertyReference(rule.affix.postfix, objectData) ?? "" : "";
|
|
93
|
+
return formatNumberWithAffixes(value, rule.baseFormatOptions, locale, prefix, suffix);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Gets the scale divisor for a given scale type
|
|
98
|
+
*/
|
|
99
|
+
function getScaleDivisor(scaleType) {
|
|
100
|
+
switch (scaleType) {
|
|
101
|
+
case "THOUSANDS":
|
|
102
|
+
return 1e3;
|
|
103
|
+
case "MILLIONS":
|
|
104
|
+
return 1e6;
|
|
105
|
+
case "BILLIONS":
|
|
106
|
+
return 1e9;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unknown scale type: ${scaleType}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the localized compact suffix for a given scale.
|
|
114
|
+
* Uses Intl.NumberFormat with compact notation to get the proper i18n suffix.
|
|
115
|
+
*/
|
|
116
|
+
function getLocalizedCompactSuffix(scaleDivisor, locale) {
|
|
117
|
+
const compactFormatter = new Intl.NumberFormat(locale, {
|
|
118
|
+
notation: "compact",
|
|
119
|
+
compactDisplay: "short"
|
|
120
|
+
});
|
|
121
|
+
const parts = compactFormatter.formatToParts(scaleDivisor);
|
|
122
|
+
const compactPart = parts.find(p => p.type === "compact");
|
|
123
|
+
return compactPart?.value ?? "";
|
|
124
|
+
}
|
|
125
|
+
function formatScale(value, rule, locale) {
|
|
126
|
+
const scaleDivisor = getScaleDivisor(rule.scaleType);
|
|
127
|
+
const suffix = getLocalizedCompactSuffix(scaleDivisor, locale);
|
|
128
|
+
return formatNumberWithAffixes(value / scaleDivisor, rule.baseFormatOptions, locale, "", suffix);
|
|
129
|
+
}
|
|
130
|
+
function getRatioScaledValue(value, ratioType) {
|
|
131
|
+
switch (ratioType) {
|
|
132
|
+
case "PERCENTAGE":
|
|
133
|
+
return value * 100;
|
|
134
|
+
case "PER_MILLE":
|
|
135
|
+
return value * 1000;
|
|
136
|
+
case "BASIS_POINTS":
|
|
137
|
+
return value * 10000;
|
|
138
|
+
default:
|
|
139
|
+
throw new Error(`Unknown ratio type: ${ratioType}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function formatRatio(value, rule, locale) {
|
|
143
|
+
// Special case: PERCENTAGE uses Intl's native percent style
|
|
144
|
+
if (rule.ratioType === "PERCENTAGE") {
|
|
145
|
+
const options = {
|
|
146
|
+
...convertToIntlOptions(rule.baseFormatOptions),
|
|
147
|
+
style: "percent"
|
|
148
|
+
};
|
|
149
|
+
return formatWithIntl(value, options, locale);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Other ratio types: scale and add suffix
|
|
153
|
+
const scaledValue = getRatioScaledValue(value, rule.ratioType);
|
|
154
|
+
let suffix;
|
|
155
|
+
switch (rule.ratioType) {
|
|
156
|
+
case "PER_MILLE":
|
|
157
|
+
suffix = "‰";
|
|
158
|
+
break;
|
|
159
|
+
case "BASIS_POINTS":
|
|
160
|
+
suffix = " bps";
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
rule.ratioType;
|
|
164
|
+
throw new Error(`Unknown ratio type: ${rule.ratioType}`);
|
|
165
|
+
}
|
|
166
|
+
return formatNumberWithAffixes(scaledValue, rule.baseFormatOptions, locale, "", suffix);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Maps notation from OSDK format to Intl format
|
|
171
|
+
*/
|
|
172
|
+
function mapNotation(notation) {
|
|
173
|
+
switch (notation) {
|
|
174
|
+
case "STANDARD":
|
|
175
|
+
return "standard";
|
|
176
|
+
case "SCIENTIFIC":
|
|
177
|
+
return "scientific";
|
|
178
|
+
case "ENGINEERING":
|
|
179
|
+
return "engineering";
|
|
180
|
+
case "COMPACT":
|
|
181
|
+
return "compact";
|
|
182
|
+
default:
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Maps rounding mode from OSDK format to Intl format
|
|
188
|
+
*/
|
|
189
|
+
function mapRoundingMode(mode) {
|
|
190
|
+
switch (mode) {
|
|
191
|
+
case "CEIL":
|
|
192
|
+
return "ceil";
|
|
193
|
+
case "FLOOR":
|
|
194
|
+
return "floor";
|
|
195
|
+
case "ROUND_CLOSEST":
|
|
196
|
+
return "halfExpand";
|
|
197
|
+
default:
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function convertToIntlOptions(options) {
|
|
202
|
+
return {
|
|
203
|
+
useGrouping: options.useGrouping,
|
|
204
|
+
minimumIntegerDigits: options.minimumIntegerDigits,
|
|
205
|
+
minimumFractionDigits: options.minimumFractionDigits,
|
|
206
|
+
maximumFractionDigits: options.maximumFractionDigits,
|
|
207
|
+
minimumSignificantDigits: options.minimumSignificantDigits,
|
|
208
|
+
maximumSignificantDigits: options.maximumSignificantDigits,
|
|
209
|
+
notation: options.notation ? mapNotation(options.notation) : undefined,
|
|
210
|
+
roundingMode: options.roundingMode ? mapRoundingMode(options.roundingMode) : undefined,
|
|
211
|
+
convertNegativeToParenthesis: options.convertNegativeToParenthesis
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Applies negative-to-parenthesis conversion if requested
|
|
217
|
+
*/
|
|
218
|
+
function maybeConvertNegativeToParenthesis(formatted, value, shouldConvert) {
|
|
219
|
+
if (shouldConvert && value < 0) {
|
|
220
|
+
return formatted.replace(/^-/, "(") + ")";
|
|
221
|
+
}
|
|
222
|
+
return formatted;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Formats a number using Intl.NumberFormat with the given options
|
|
227
|
+
*/
|
|
228
|
+
function formatWithIntl(value, options, locale) {
|
|
229
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
230
|
+
const formatted = formatter.format(value);
|
|
231
|
+
return maybeConvertNegativeToParenthesis(formatted, value, options.convertNegativeToParenthesis ?? false);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Formats a number and optionally adds prefix/suffix
|
|
236
|
+
*/
|
|
237
|
+
function formatNumberWithAffixes(value, baseOptions, locale, prefix, suffix) {
|
|
238
|
+
const intlOptions = convertToIntlOptions(baseOptions);
|
|
239
|
+
const formatted = formatWithIntl(value, intlOptions, locale);
|
|
240
|
+
return `${prefix || ""}${formatted}${suffix || ""}`;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=formatNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatNumber.js","names":["resolvePropertyReference","formatNumber","value","numberType","objectData","locale","type","formatStandardNumber","baseFormatOptions","values","formatCurrency","formatStandardUnit","formatCustomUnit","formatAffix","undefined","formatScale","formatRatio","options","formatNumberWithAffixes","rule","currencyCode","convertToIntlOptions","style","currency","currencyDisplay","formatWithIntl","unit","error","suffix","prefix","affix","postfix","getScaleDivisor","scaleType","Error","getLocalizedCompactSuffix","scaleDivisor","compactFormatter","Intl","NumberFormat","notation","compactDisplay","parts","formatToParts","compactPart","find","p","getRatioScaledValue","ratioType","scaledValue","mapNotation","mapRoundingMode","mode","useGrouping","minimumIntegerDigits","minimumFractionDigits","maximumFractionDigits","minimumSignificantDigits","maximumSignificantDigits","roundingMode","convertNegativeToParenthesis","maybeConvertNegativeToParenthesis","formatted","shouldConvert","replace","formatter","format","baseOptions","intlOptions"],"sources":["formatNumber.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n NumberFormatAffix,\n NumberFormatCurrency,\n NumberFormatCustomUnit,\n NumberFormatOptions,\n NumberFormatRatio,\n NumberFormatScale,\n NumberFormatStandardUnit,\n NumberRatioType,\n NumberScaleType,\n PropertyNumberFormattingRuleType,\n} from \"@osdk/api\";\nimport type { SimpleOsdkProperties } from \"../SimpleOsdkProperties.js\";\nimport { resolvePropertyReference } from \"./propertyFormattingUtils.js\";\n\n/**\n * Extended NumberFormatOptions that includes rounding mode support\n * which is available in modern browsers but not yet in TypeScript types.\n * Only includes modes that are actually supported by Intl.NumberFormat and used in our API.\n */\nexport interface ExtendedNumberFormatOptions extends Intl.NumberFormatOptions {\n roundingMode?: \"ceil\" | \"floor\" | \"halfExpand\";\n convertNegativeToParenthesis?: boolean;\n}\n\n/**\n * Formats a number value according to the specified formatting rule\n */\nexport function formatNumber(\n value: number,\n numberType: PropertyNumberFormattingRuleType,\n objectData: SimpleOsdkProperties,\n locale: string,\n): string | undefined {\n switch (numberType.type) {\n case \"standard\":\n return formatStandardNumber(\n value,\n numberType.baseFormatOptions,\n locale,\n );\n\n case \"fixedValues\":\n return numberType.values[value];\n\n case \"currency\":\n return formatCurrency(value, numberType, objectData, locale);\n\n case \"standardUnit\":\n return formatStandardUnit(value, numberType, objectData, locale);\n\n case \"customUnit\":\n return formatCustomUnit(value, numberType, objectData, locale);\n\n case \"affix\":\n return formatAffix(value, numberType, objectData, locale);\n\n case \"duration\":\n // TODO (duration is a bit more complex)\n return undefined;\n\n case \"scale\":\n return formatScale(value, numberType, locale);\n\n case \"ratio\":\n return formatRatio(value, numberType, locale);\n\n default:\n numberType satisfies never;\n return undefined;\n }\n}\n\nfunction formatStandardNumber(\n value: number,\n options: NumberFormatOptions,\n locale: string,\n): string {\n return formatNumberWithAffixes(value, options, locale);\n}\n\nfunction formatCurrency(\n value: number,\n rule: NumberFormatCurrency,\n objectData: SimpleOsdkProperties,\n locale: string,\n): string {\n const currencyCode = resolvePropertyReference(rule.currencyCode, objectData);\n if (currencyCode == null) {\n return formatStandardNumber(value, rule.baseFormatOptions, locale);\n }\n\n const options: ExtendedNumberFormatOptions = {\n ...convertToIntlOptions(rule.baseFormatOptions),\n style: \"currency\",\n currency: currencyCode,\n currencyDisplay: rule.style === \"COMPACT\" ? \"narrowSymbol\" : \"symbol\",\n };\n\n return formatWithIntl(value, options, locale);\n}\n\nfunction formatStandardUnit(\n value: number,\n rule: NumberFormatStandardUnit,\n objectData: SimpleOsdkProperties,\n locale: string,\n): string {\n const unit = resolvePropertyReference(rule.unit, objectData);\n if (unit == null) {\n return formatStandardNumber(value, rule.baseFormatOptions, locale);\n }\n\n const options: ExtendedNumberFormatOptions = {\n ...convertToIntlOptions(rule.baseFormatOptions),\n style: \"unit\",\n unit: unit,\n };\n\n try {\n return formatWithIntl(value, options, locale);\n } catch (error) {\n const suffix = ` ${unit}`;\n return formatNumberWithAffixes(\n value,\n rule.baseFormatOptions,\n locale,\n \"\",\n suffix,\n );\n }\n}\n\nfunction formatCustomUnit(\n value: number,\n rule: NumberFormatCustomUnit,\n objectData: SimpleOsdkProperties,\n locale: string,\n): string {\n const unit = resolvePropertyReference(rule.unit, objectData);\n const suffix = unit != null ? ` ${unit}` : \"\";\n return formatNumberWithAffixes(\n value,\n rule.baseFormatOptions,\n locale,\n \"\",\n suffix,\n );\n}\n\nfunction formatAffix(\n value: number,\n rule: NumberFormatAffix,\n objectData: SimpleOsdkProperties,\n locale: string,\n): string {\n const prefix = rule.affix.prefix != null\n ? resolvePropertyReference(rule.affix.prefix, objectData) ?? \"\"\n : \"\";\n const suffix = rule.affix.postfix != null\n ? resolvePropertyReference(rule.affix.postfix, objectData) ?? \"\"\n : \"\";\n return formatNumberWithAffixes(\n value,\n rule.baseFormatOptions,\n locale,\n prefix,\n suffix,\n );\n}\n\n/**\n * Gets the scale divisor for a given scale type\n */\nfunction getScaleDivisor(scaleType: NumberScaleType): number {\n switch (scaleType) {\n case \"THOUSANDS\":\n return 1e3;\n case \"MILLIONS\":\n return 1e6;\n case \"BILLIONS\":\n return 1e9;\n default:\n scaleType satisfies never;\n throw new Error(`Unknown scale type: ${scaleType}`);\n }\n}\n\n/**\n * Extracts the localized compact suffix for a given scale.\n * Uses Intl.NumberFormat with compact notation to get the proper i18n suffix.\n */\nfunction getLocalizedCompactSuffix(\n scaleDivisor: number,\n locale: string,\n): string {\n const compactFormatter = new Intl.NumberFormat(locale, {\n notation: \"compact\",\n compactDisplay: \"short\",\n });\n\n const parts = compactFormatter.formatToParts(scaleDivisor);\n const compactPart = parts.find(p => p.type === \"compact\");\n return compactPart?.value ?? \"\";\n}\n\nfunction formatScale(\n value: number,\n rule: NumberFormatScale,\n locale: string,\n): string {\n const scaleDivisor = getScaleDivisor(rule.scaleType);\n const scaledValue = value / scaleDivisor;\n const suffix = getLocalizedCompactSuffix(scaleDivisor, locale);\n\n return formatNumberWithAffixes(\n scaledValue,\n rule.baseFormatOptions,\n locale,\n \"\",\n suffix,\n );\n}\n\nfunction getRatioScaledValue(\n value: number,\n ratioType: NumberRatioType,\n): number {\n switch (ratioType) {\n case \"PERCENTAGE\":\n return value * 100;\n case \"PER_MILLE\":\n return value * 1000;\n case \"BASIS_POINTS\":\n return value * 10000;\n default:\n ratioType satisfies never;\n throw new Error(`Unknown ratio type: ${ratioType}`);\n }\n}\n\nfunction formatRatio(\n value: number,\n rule: NumberFormatRatio,\n locale: string,\n): string {\n // Special case: PERCENTAGE uses Intl's native percent style\n if (rule.ratioType === \"PERCENTAGE\") {\n const options: ExtendedNumberFormatOptions = {\n ...convertToIntlOptions(rule.baseFormatOptions),\n style: \"percent\",\n };\n return formatWithIntl(value, options, locale);\n }\n\n // Other ratio types: scale and add suffix\n const scaledValue = getRatioScaledValue(value, rule.ratioType);\n\n let suffix: string;\n switch (rule.ratioType) {\n case \"PER_MILLE\":\n suffix = \"‰\";\n break;\n case \"BASIS_POINTS\":\n suffix = \" bps\";\n break;\n default:\n rule.ratioType satisfies never;\n throw new Error(`Unknown ratio type: ${rule.ratioType}`);\n }\n\n return formatNumberWithAffixes(\n scaledValue,\n rule.baseFormatOptions,\n locale,\n \"\",\n suffix,\n );\n}\n\n/**\n * Maps notation from OSDK format to Intl format\n */\nfunction mapNotation(\n notation: \"STANDARD\" | \"SCIENTIFIC\" | \"ENGINEERING\" | \"COMPACT\",\n): Intl.NumberFormatOptions[\"notation\"] {\n switch (notation) {\n case \"STANDARD\":\n return \"standard\";\n case \"SCIENTIFIC\":\n return \"scientific\";\n case \"ENGINEERING\":\n return \"engineering\";\n case \"COMPACT\":\n return \"compact\";\n default:\n notation satisfies never;\n }\n}\n\n/**\n * Maps rounding mode from OSDK format to Intl format\n */\nfunction mapRoundingMode(\n mode: \"CEIL\" | \"FLOOR\" | \"ROUND_CLOSEST\",\n): ExtendedNumberFormatOptions[\"roundingMode\"] {\n switch (mode) {\n case \"CEIL\":\n return \"ceil\";\n case \"FLOOR\":\n return \"floor\";\n case \"ROUND_CLOSEST\":\n return \"halfExpand\";\n default:\n mode satisfies never;\n return undefined;\n }\n}\n\nfunction convertToIntlOptions(\n options: NumberFormatOptions,\n): ExtendedNumberFormatOptions {\n return {\n useGrouping: options.useGrouping,\n minimumIntegerDigits: options.minimumIntegerDigits,\n minimumFractionDigits: options.minimumFractionDigits,\n maximumFractionDigits: options.maximumFractionDigits,\n minimumSignificantDigits: options.minimumSignificantDigits,\n maximumSignificantDigits: options.maximumSignificantDigits,\n notation: options.notation ? mapNotation(options.notation) : undefined,\n roundingMode: options.roundingMode\n ? mapRoundingMode(options.roundingMode)\n : undefined,\n convertNegativeToParenthesis: options.convertNegativeToParenthesis,\n };\n}\n\n/**\n * Applies negative-to-parenthesis conversion if requested\n */\nfunction maybeConvertNegativeToParenthesis(\n formatted: string,\n value: number,\n shouldConvert: boolean,\n): string {\n if (shouldConvert && value < 0) {\n return formatted.replace(/^-/, \"(\") + \")\";\n }\n return formatted;\n}\n\n/**\n * Formats a number using Intl.NumberFormat with the given options\n */\nfunction formatWithIntl(\n value: number,\n options: ExtendedNumberFormatOptions,\n locale: string,\n): string {\n const formatter = new Intl.NumberFormat(locale, options);\n const formatted = formatter.format(value);\n return maybeConvertNegativeToParenthesis(\n formatted,\n value,\n options.convertNegativeToParenthesis ?? false,\n );\n}\n\n/**\n * Formats a number and optionally adds prefix/suffix\n */\nfunction formatNumberWithAffixes(\n value: number,\n baseOptions: NumberFormatOptions,\n locale: string,\n prefix?: string,\n suffix?: string,\n): string {\n const intlOptions = convertToIntlOptions(baseOptions);\n const formatted = formatWithIntl(value, intlOptions, locale);\n return `${prefix || \"\"}${formatted}${suffix || \"\"}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA,SAASA,wBAAwB,QAAQ,8BAA8B;;AAEvE;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC1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EAAE1C,OAAO,CAAC0C,YAAY,GAC9BR,eAAe,CAAClC,OAAO,CAAC0C,YAAY,CAAC,GACrC7C,SAAS;IACb8C,4BAA4B,EAAE3C,OAAO,CAAC2C;EACxC,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAASC,iCAAiCA,CACxCC,SAAiB,EACjB5D,KAAa,EACb6D,aAAsB,EACd;EACR,IAAIA,aAAa,IAAI7D,KAAK,GAAG,CAAC,EAAE;IAC9B,OAAO4D,SAAS,CAACE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG;EAC3C;EACA,OAAOF,SAAS;AAClB;;AAEA;AACA;AACA;AACA,SAASrC,cAAcA,CACrBvB,KAAa,EACbe,OAAoC,EACpCZ,MAAc,EACN;EACR,MAAM4D,SAAS,GAAG,IAAI3B,IAAI,CAACC,YAAY,CAAClC,MAAM,EAAEY,OAAO,CAAC;EACxD,MAAM6C,SAAS,GAAGG,SAAS,CAACC,MAAM,CAAChE,KAAK,CAAC;EACzC,OAAO2D,iCAAiC,CACtCC,SAAS,EACT5D,KAAK,EACLe,OAAO,CAAC2C,4BAA4B,IAAI,KAC1C,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAAS1C,uBAAuBA,CAC9BhB,KAAa,EACbiE,WAAgC,EAChC9D,MAAc,EACdwB,MAAe,EACfD,MAAe,EACP;EACR,MAAMwC,WAAW,GAAG/C,oBAAoB,CAAC8C,WAAW,CAAC;EACrD,MAAML,SAAS,GAAGrC,cAAc,CAACvB,KAAK,EAAEkE,WAAW,EAAE/D,MAAM,CAAC;EAC5D,OAAO,GAAGwB,MAAM,IAAI,EAAE,GAAGiC,SAAS,GAAGlC,MAAM,IAAI,EAAE,EAAE;AACrD","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a property reference or string constant to its actual value
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function resolvePropertyReference(ref, objectData) {
|
|
22
|
+
if (ref.type === "constant") {
|
|
23
|
+
return ref.value;
|
|
24
|
+
} else if (ref.type === "propertyType") {
|
|
25
|
+
const value = objectData[ref.propertyApiName];
|
|
26
|
+
return value != null ? String(value) : undefined;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the browser's current locale
|
|
32
|
+
*/
|
|
33
|
+
export function getBrowserLocale() {
|
|
34
|
+
if (typeof navigator !== "undefined" && navigator.language != null) {
|
|
35
|
+
return navigator.language;
|
|
36
|
+
}
|
|
37
|
+
return "en-US";
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=propertyFormattingUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyFormattingUtils.js","names":["resolvePropertyReference","ref","objectData","type","value","propertyApiName","String","undefined","getBrowserLocale","navigator","language"],"sources":["propertyFormattingUtils.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PropertyTypeReferenceOrStringConstant } from \"@osdk/api\";\nimport type { SimpleOsdkProperties } from \"../SimpleOsdkProperties.js\";\n\n/**\n * Resolves a property reference or string constant to its actual value\n */\n\nexport function resolvePropertyReference(\n ref: PropertyTypeReferenceOrStringConstant,\n objectData: SimpleOsdkProperties,\n): string | undefined {\n if (ref.type === \"constant\") {\n return ref.value;\n } else if (ref.type === \"propertyType\") {\n const value = objectData[ref.propertyApiName];\n return value != null ? String(value) : undefined;\n }\n return undefined;\n}\n/**\n * Gets the browser's current locale\n */\nexport function getBrowserLocale(): string {\n if (typeof navigator !== \"undefined\" && navigator.language != null) {\n return navigator.language;\n }\n return \"en-US\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;;AAEA,OAAO,SAASA,wBAAwBA,CACtCC,GAA0C,EAC1CC,UAAgC,EACZ;EACpB,IAAID,GAAG,CAACE,IAAI,KAAK,UAAU,EAAE;IAC3B,OAAOF,GAAG,CAACG,KAAK;EAClB,CAAC,MAAM,IAAIH,GAAG,CAACE,IAAI,KAAK,cAAc,EAAE;IACtC,MAAMC,KAAK,GAAGF,UAAU,CAACD,GAAG,CAACI,eAAe,CAAC;IAC7C,OAAOD,KAAK,IAAI,IAAI,GAAGE,MAAM,CAACF,KAAK,CAAC,GAAGG,SAAS;EAClD;EACA,OAAOA,SAAS;AAClB;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAA,EAAW;EACzC,IAAI,OAAOC,SAAS,KAAK,WAAW,IAAIA,SAAS,CAACC,QAAQ,IAAI,IAAI,EAAE;IAClE,OAAOD,SAAS,CAACC,QAAQ;EAC3B;EACA,OAAO,OAAO;AAChB","ignoreList":[]}
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
export const USER_AGENT = `osdk-client/${"2.6.0-beta.
|
|
18
|
-
export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.
|
|
17
|
+
export const USER_AGENT = `osdk-client/${"2.6.0-beta.2"}`;
|
|
18
|
+
export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.6.0-beta.2"}`;
|
|
19
19
|
//# sourceMappingURL=UserAgent.js.map
|
package/build/types/Client.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface Client extends SharedClient, OldSharedClient {
|
|
|
16
16
|
<Q extends Experiment<"2.0.8"> | Experiment<"2.1.0"> | Experiment<"2.2.0">>(experiment: Q): ExperimentFns<Q>;
|
|
17
17
|
fetchMetadata<Q extends (ObjectTypeDefinition | InterfaceDefinition | ActionDefinition<any> | QueryDefinition<any>)>(o: Q): Promise<Q extends ObjectTypeDefinition ? ObjectMetadata : Q extends InterfaceDefinition ? InterfaceMetadata : Q extends ActionDefinition<any> ? ActionMetadata : Q extends QueryDefinition<any> ? QueryMetadata : never>;
|
|
18
18
|
}
|
|
19
|
-
declare const MaxOsdkVersion = "2.
|
|
19
|
+
declare const MaxOsdkVersion = "2.6.0";
|
|
20
20
|
export type MaxOsdkVersion = typeof MaxOsdkVersion;
|
|
21
21
|
declare const ErrorMessage: unique symbol;
|
|
22
22
|
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ObjectMetadata } from "@osdk/api";
|
|
2
|
+
import type { SimpleOsdkProperties } from "../SimpleOsdkProperties.js";
|
|
3
|
+
export interface FormatPropertyOptions {
|
|
4
|
+
locale?: string;
|
|
5
|
+
timezoneId?: string;
|
|
6
|
+
}
|
|
7
|
+
type PropertyValue = string | Array<string> | number | Array<number> | boolean | Array<boolean> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Applies formatting rules to a property value and returns the formatted string value.
|
|
10
|
+
*
|
|
11
|
+
* @param propertyValue - The value of the property to format
|
|
12
|
+
* @returns The formatted string value, or undefined if the property cannot be formatted
|
|
13
|
+
*
|
|
14
|
+
* @experimental This is a stub implementation that returns undefined.
|
|
15
|
+
* The actual formatting logic will be implemented later.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyPropertyFormatter(propertyValue: PropertyValue, propertyDefinition: ObjectMetadata.Property | undefined, objectData: SimpleOsdkProperties, options?: FormatPropertyOptions): string | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,sBAAmD,WAAY;AAC7E,cAAc,4BAA4B,4BAA6B;AAKvE,iBAAiB,sBAAsB;CACrC;CACA;AACD;KAEI,yBAED,yBAEA,0BAEA;;;;;;;;;;AAcJ,OAAO,iBAAS,uBACdA,eAAe,eACfC,oBAAoB,eAAe,sBACnCC,YAAY,sBACZC,UAAS","names":["propertyValue: PropertyValue","propertyDefinition: ObjectMetadata.Property | undefined","objectData: SimpleOsdkProperties","options: FormatPropertyOptions"],"sources":["../../../../src/object/formatting/applyPropertyFormatter.ts"],"version":3,"file":"applyPropertyFormatter.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../../src/object/formatting/applyPropertyFormatter.test.ts"],"version":3,"file":"applyPropertyFormatter.test.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,qCAAqC,WAAY;;;;AAK/D,OAAO,iBAAS,cACdA,gBACAC,MAAM","names":["value: boolean","rule: PropertyBooleanFormattingRule"],"sources":["../../../../src/object/formatting/formatBoolean.ts"],"version":3,"file":"formatBoolean.d.ts"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PropertyNumberFormattingRuleType } from "@osdk/api";
|
|
2
|
+
import type { SimpleOsdkProperties } from "../SimpleOsdkProperties.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extended NumberFormatOptions that includes rounding mode support
|
|
5
|
+
* which is available in modern browsers but not yet in TypeScript types.
|
|
6
|
+
* Only includes modes that are actually supported by Intl.NumberFormat and used in our API.
|
|
7
|
+
*/
|
|
8
|
+
export interface ExtendedNumberFormatOptions extends Intl.NumberFormatOptions {
|
|
9
|
+
roundingMode?: "ceil" | "floor" | "halfExpand";
|
|
10
|
+
convertNegativeToParenthesis?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Formats a number value according to the specified formatting rule
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatNumber(value: number, numberType: PropertyNumberFormattingRuleType, objectData: SimpleOsdkProperties, locale: string): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAUE,wCACK,WAAY;AACnB,cAAc,4BAA4B,4BAA6B;;;;;;AAQvE,iBAAiB,oCAAoC,KAAK,oBAAoB;CAC5E,eAAe,SAAS,UAAU;CAClC;AACD;;;;AAKD,OAAO,iBAAS,aACdA,eACAC,YAAY,kCACZC,YAAY,sBACZC","names":["value: number","numberType: PropertyNumberFormattingRuleType","objectData: SimpleOsdkProperties","locale: string"],"sources":["../../../../src/object/formatting/formatNumber.ts"],"version":3,"file":"formatNumber.d.ts"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropertyTypeReferenceOrStringConstant } from "@osdk/api";
|
|
2
|
+
import type { SimpleOsdkProperties } from "../SimpleOsdkProperties.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a property reference or string constant to its actual value
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolvePropertyReference(ref: PropertyTypeReferenceOrStringConstant, objectData: SimpleOsdkProperties): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the browser's current locale
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBrowserLocale(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,6CAA6C,WAAY;AACvE,cAAc,4BAA4B,4BAA6B;;;;AAMvE,OAAO,iBAAS,yBACdA,KAAK,uCACLC,YAAY;;;;AAad,OAAO,iBAAS","names":["ref: PropertyTypeReferenceOrStringConstant","objectData: SimpleOsdkProperties"],"sources":["../../../../src/object/formatting/propertyFormattingUtils.ts"],"version":3,"file":"propertyFormattingUtils.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/client",
|
|
3
|
-
"version": "2.6.0-beta.
|
|
3
|
+
"version": "2.6.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"access": "public",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@osdk/foundry.core": "2.30.0",
|
|
51
|
-
"@osdk/foundry.ontologies": "2.
|
|
51
|
+
"@osdk/foundry.ontologies": "2.35.0",
|
|
52
52
|
"@osdk/shared.client": "^1.0.1",
|
|
53
53
|
"@osdk/shared.client2": "^1.0.0",
|
|
54
54
|
"@types/geojson": "^7946.0.16",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"tiny-invariant": "^1.3.3",
|
|
66
66
|
"type-fest": "^4.41.0",
|
|
67
67
|
"ws": "^8.18.3",
|
|
68
|
-
"@osdk/client.unstable": "2.6.0-beta.
|
|
69
|
-
"@osdk/
|
|
70
|
-
"@osdk/api": "2.6.0-beta.1",
|
|
68
|
+
"@osdk/client.unstable": "2.6.0-beta.2",
|
|
69
|
+
"@osdk/api": "2.6.0-beta.2",
|
|
71
70
|
"@osdk/shared.client.impl": "~1.6.0-beta.1",
|
|
72
71
|
"@osdk/shared.net.errors": "~2.6.0-beta.1",
|
|
72
|
+
"@osdk/generator-converters": "2.6.0-beta.2",
|
|
73
73
|
"@osdk/shared.net.fetch": "~1.6.0-beta.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
@@ -91,10 +91,10 @@
|
|
|
91
91
|
"ts-expect": "^1.3.0",
|
|
92
92
|
"typescript": "~5.5.4",
|
|
93
93
|
"zod": "^3.25.76",
|
|
94
|
+
"@osdk/client.test.ontology": "~2.6.0-beta.2",
|
|
94
95
|
"@osdk/monorepo.api-extractor": "~0.5.0-beta.1",
|
|
95
96
|
"@osdk/monorepo.tsconfig": "~0.5.0-beta.1",
|
|
96
|
-
"@osdk/shared.test": "~2.6.0-beta.
|
|
97
|
-
"@osdk/client.test.ontology": "~2.6.0-beta.1"
|
|
97
|
+
"@osdk/shared.test": "~2.6.0-beta.2"
|
|
98
98
|
},
|
|
99
99
|
"publishConfig": {
|
|
100
100
|
"access": "public"
|