@topolo/sdk 0.10.1 → 0.10.3
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/dist/index.cjs +12 -10
- package/dist/index.js +12 -10
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4299,7 +4299,7 @@ function sampleString(schema, hint) {
|
|
|
4299
4299
|
if (schema.format === "uri" || schema.format === "url") return "https://topolo.app";
|
|
4300
4300
|
if (schema.format === "date-time") return patternedString(schema.pattern || "", hint) || "2026-01-15T12:00:00Z";
|
|
4301
4301
|
const words = String(hint || "value").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
4302
|
-
let value = typeof schema.pattern === "string" ? patternedString(schema.pattern, hint) : /(^|\s)id$/.test(words) ? `${slugify(words.replace(/\sid$/, "") || "resource")}_01` : words.includes("date") ? "2026-01-15" : words.includes("period") || words.includes("month") ? "2026-01" : words.includes("year") ? "2026" : `Sample ${words}`;
|
|
4302
|
+
let value = typeof schema.pattern === "string" ? patternedString(schema.pattern, hint) : words === "workspace" ? "ws_example" : /(^|\s)id$/.test(words) ? `${slugify(words.replace(/\sid$/, "") || "resource")}_01` : words.includes("date") ? "2026-01-15" : words.includes("period") || words.includes("month") ? "2026-01" : words.includes("year") ? "2026" : `Sample ${words}`;
|
|
4303
4303
|
const minimum = Number.isInteger(schema.minLength) ? schema.minLength : 0;
|
|
4304
4304
|
const maximum = Number.isInteger(schema.maxLength) ? schema.maxLength : null;
|
|
4305
4305
|
if (value.length < minimum) value = value.padEnd(minimum, "x");
|
|
@@ -4313,6 +4313,16 @@ function localReference(rootSchema, reference) {
|
|
|
4313
4313
|
return isRecord4(value) ? value[key] : void 0;
|
|
4314
4314
|
}, rootSchema);
|
|
4315
4315
|
}
|
|
4316
|
+
function representativeNumber(schema, hint) {
|
|
4317
|
+
const integer = schema.type === "integer";
|
|
4318
|
+
const words = String(hint || "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
4319
|
+
const preferred = /\b(?:percent|percentage|ratio|rate)\b/.test(words) ? 0.5 : /\b(?:amount|balance|cent|cents|minor)\b/.test(words) ? 1e3 : words.includes("year") ? 2026 : 1;
|
|
4320
|
+
const exclusiveOffset = (value2) => Math.max(Number.EPSILON * Math.max(1, Math.abs(value2)) * 2, Number.MIN_VALUE);
|
|
4321
|
+
const lower = typeof schema.exclusiveMinimum === "number" ? integer ? Math.floor(schema.exclusiveMinimum) + 1 : schema.exclusiveMinimum + exclusiveOffset(schema.exclusiveMinimum) : typeof schema.minimum === "number" ? integer ? Math.ceil(schema.minimum) : schema.minimum : -Infinity;
|
|
4322
|
+
const upper = typeof schema.exclusiveMaximum === "number" ? integer ? Math.ceil(schema.exclusiveMaximum) - 1 : schema.exclusiveMaximum - exclusiveOffset(schema.exclusiveMaximum) : typeof schema.maximum === "number" ? integer ? Math.floor(schema.maximum) : schema.maximum : Infinity;
|
|
4323
|
+
const value = Math.min(Math.max(preferred, lower), upper);
|
|
4324
|
+
return integer ? Math.round(value) : value;
|
|
4325
|
+
}
|
|
4316
4326
|
function sampleForSchema(schema, depth = 0, hint = "value", rootSchema = schema) {
|
|
4317
4327
|
if (!isRecord4(schema) || depth > 20) return null;
|
|
4318
4328
|
const referenced = localReference(rootSchema, schema.$ref);
|
|
@@ -4332,15 +4342,7 @@ function sampleForSchema(schema, depth = 0, hint = "value", rootSchema = schema)
|
|
|
4332
4342
|
}
|
|
4333
4343
|
if (schema.type === "boolean") return false;
|
|
4334
4344
|
if (schema.type === "integer" || schema.type === "number") {
|
|
4335
|
-
|
|
4336
|
-
if (typeof schema.exclusiveMinimum === "number" && value <= schema.exclusiveMinimum) {
|
|
4337
|
-
value = schema.type === "integer" ? Math.floor(schema.exclusiveMinimum) + 1 : schema.exclusiveMinimum + 0.1;
|
|
4338
|
-
}
|
|
4339
|
-
if (typeof schema.maximum === "number") value = Math.min(value, schema.maximum);
|
|
4340
|
-
if (typeof schema.exclusiveMaximum === "number" && value >= schema.exclusiveMaximum) {
|
|
4341
|
-
value = schema.type === "integer" ? Math.ceil(schema.exclusiveMaximum) - 1 : schema.exclusiveMaximum - 0.1;
|
|
4342
|
-
}
|
|
4343
|
-
return value;
|
|
4345
|
+
return representativeNumber(schema, hint);
|
|
4344
4346
|
}
|
|
4345
4347
|
if (schema.type === "string") return sampleString(schema, hint);
|
|
4346
4348
|
if (schema.type === "null") return null;
|
package/dist/index.js
CHANGED
|
@@ -4223,7 +4223,7 @@ function sampleString(schema, hint) {
|
|
|
4223
4223
|
if (schema.format === "uri" || schema.format === "url") return "https://topolo.app";
|
|
4224
4224
|
if (schema.format === "date-time") return patternedString(schema.pattern || "", hint) || "2026-01-15T12:00:00Z";
|
|
4225
4225
|
const words = String(hint || "value").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
4226
|
-
let value = typeof schema.pattern === "string" ? patternedString(schema.pattern, hint) : /(^|\s)id$/.test(words) ? `${slugify(words.replace(/\sid$/, "") || "resource")}_01` : words.includes("date") ? "2026-01-15" : words.includes("period") || words.includes("month") ? "2026-01" : words.includes("year") ? "2026" : `Sample ${words}`;
|
|
4226
|
+
let value = typeof schema.pattern === "string" ? patternedString(schema.pattern, hint) : words === "workspace" ? "ws_example" : /(^|\s)id$/.test(words) ? `${slugify(words.replace(/\sid$/, "") || "resource")}_01` : words.includes("date") ? "2026-01-15" : words.includes("period") || words.includes("month") ? "2026-01" : words.includes("year") ? "2026" : `Sample ${words}`;
|
|
4227
4227
|
const minimum = Number.isInteger(schema.minLength) ? schema.minLength : 0;
|
|
4228
4228
|
const maximum = Number.isInteger(schema.maxLength) ? schema.maxLength : null;
|
|
4229
4229
|
if (value.length < minimum) value = value.padEnd(minimum, "x");
|
|
@@ -4237,6 +4237,16 @@ function localReference(rootSchema, reference) {
|
|
|
4237
4237
|
return isRecord4(value) ? value[key] : void 0;
|
|
4238
4238
|
}, rootSchema);
|
|
4239
4239
|
}
|
|
4240
|
+
function representativeNumber(schema, hint) {
|
|
4241
|
+
const integer = schema.type === "integer";
|
|
4242
|
+
const words = String(hint || "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
4243
|
+
const preferred = /\b(?:percent|percentage|ratio|rate)\b/.test(words) ? 0.5 : /\b(?:amount|balance|cent|cents|minor)\b/.test(words) ? 1e3 : words.includes("year") ? 2026 : 1;
|
|
4244
|
+
const exclusiveOffset = (value2) => Math.max(Number.EPSILON * Math.max(1, Math.abs(value2)) * 2, Number.MIN_VALUE);
|
|
4245
|
+
const lower = typeof schema.exclusiveMinimum === "number" ? integer ? Math.floor(schema.exclusiveMinimum) + 1 : schema.exclusiveMinimum + exclusiveOffset(schema.exclusiveMinimum) : typeof schema.minimum === "number" ? integer ? Math.ceil(schema.minimum) : schema.minimum : -Infinity;
|
|
4246
|
+
const upper = typeof schema.exclusiveMaximum === "number" ? integer ? Math.ceil(schema.exclusiveMaximum) - 1 : schema.exclusiveMaximum - exclusiveOffset(schema.exclusiveMaximum) : typeof schema.maximum === "number" ? integer ? Math.floor(schema.maximum) : schema.maximum : Infinity;
|
|
4247
|
+
const value = Math.min(Math.max(preferred, lower), upper);
|
|
4248
|
+
return integer ? Math.round(value) : value;
|
|
4249
|
+
}
|
|
4240
4250
|
function sampleForSchema(schema, depth = 0, hint = "value", rootSchema = schema) {
|
|
4241
4251
|
if (!isRecord4(schema) || depth > 20) return null;
|
|
4242
4252
|
const referenced = localReference(rootSchema, schema.$ref);
|
|
@@ -4256,15 +4266,7 @@ function sampleForSchema(schema, depth = 0, hint = "value", rootSchema = schema)
|
|
|
4256
4266
|
}
|
|
4257
4267
|
if (schema.type === "boolean") return false;
|
|
4258
4268
|
if (schema.type === "integer" || schema.type === "number") {
|
|
4259
|
-
|
|
4260
|
-
if (typeof schema.exclusiveMinimum === "number" && value <= schema.exclusiveMinimum) {
|
|
4261
|
-
value = schema.type === "integer" ? Math.floor(schema.exclusiveMinimum) + 1 : schema.exclusiveMinimum + 0.1;
|
|
4262
|
-
}
|
|
4263
|
-
if (typeof schema.maximum === "number") value = Math.min(value, schema.maximum);
|
|
4264
|
-
if (typeof schema.exclusiveMaximum === "number" && value >= schema.exclusiveMaximum) {
|
|
4265
|
-
value = schema.type === "integer" ? Math.ceil(schema.exclusiveMaximum) - 1 : schema.exclusiveMaximum - 0.1;
|
|
4266
|
-
}
|
|
4267
|
-
return value;
|
|
4269
|
+
return representativeNumber(schema, hint);
|
|
4268
4270
|
}
|
|
4269
4271
|
if (schema.type === "string") return sampleString(schema, hint);
|
|
4270
4272
|
if (schema.type === "null") return null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topolo/sdk",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"topoloPublishedVersion": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
|
+
"topoloPublishedVersion": "0.10.3",
|
|
5
5
|
"description": "Typed client SDK for the Topolo platform. Used by TopoloCli, TopoloMCP, and third-party agents.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|