@zapier/kitcore 0.16.0 → 0.17.1
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 +133 -0
- package/README.md +9 -7
- package/dist/index.cjs +500 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +447 -93
- package/dist/index.d.ts +447 -93
- package/dist/index.mjs +496 -179
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -29,6 +29,30 @@ function canonicalInputSchema(schema) {
|
|
|
29
29
|
}
|
|
30
30
|
return schema;
|
|
31
31
|
}
|
|
32
|
+
function unwrapSchema(schema) {
|
|
33
|
+
let inner = schema;
|
|
34
|
+
let required = true;
|
|
35
|
+
for (; ; ) {
|
|
36
|
+
if (inner instanceof z.ZodOptional || inner instanceof z.ZodDefault) {
|
|
37
|
+
required = false;
|
|
38
|
+
inner = inner.unwrap();
|
|
39
|
+
} else if (inner instanceof z.ZodNullable) {
|
|
40
|
+
inner = inner.unwrap();
|
|
41
|
+
} else {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { inner, required };
|
|
46
|
+
}
|
|
47
|
+
function objectShapeOf(schema) {
|
|
48
|
+
const canonical = canonicalInputSchema(schema);
|
|
49
|
+
if (!canonical) return void 0;
|
|
50
|
+
const { inner } = unwrapSchema(canonical);
|
|
51
|
+
if (inner instanceof z.ZodObject) {
|
|
52
|
+
return inner.shape;
|
|
53
|
+
}
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
32
56
|
function getOutputSchema(inputSchema) {
|
|
33
57
|
return inputSchema._zod.def.outputSchema;
|
|
34
58
|
}
|
|
@@ -649,6 +673,120 @@ function createValidator(schema, { adaptError } = {}) {
|
|
|
649
673
|
}
|
|
650
674
|
var validateOptions = (schema, options, { adaptError } = {}) => parseOrThrow(schema, options, { adaptError });
|
|
651
675
|
|
|
676
|
+
// src/utils/call-options.ts
|
|
677
|
+
import { z as z2 } from "zod";
|
|
678
|
+
var CallFrameworkOptionsSchema = z2.object({
|
|
679
|
+
/** Page to fetch. Opaque to kitcore: the head's API defines the format. */
|
|
680
|
+
cursor: z2.string().optional(),
|
|
681
|
+
/** Items per page. */
|
|
682
|
+
pageSize: z2.number().int().min(1).optional(),
|
|
683
|
+
/** Stop after this many items, across pages. */
|
|
684
|
+
maxItems: z2.number().int().min(0).optional(),
|
|
685
|
+
/** Bypass output validation for this one call. */
|
|
686
|
+
skipOutputDataValidation: z2.boolean().optional()
|
|
687
|
+
});
|
|
688
|
+
var ITEM_FRAMEWORK_OPTIONS = {
|
|
689
|
+
claims: ["skipOutputDataValidation"],
|
|
690
|
+
injects: []
|
|
691
|
+
};
|
|
692
|
+
var LIST_FRAMEWORK_OPTIONS = {
|
|
693
|
+
claims: ["cursor", "pageSize", "maxItems", "skipOutputDataValidation"],
|
|
694
|
+
injects: ["cursor", "pageSize"]
|
|
695
|
+
};
|
|
696
|
+
var PAGE_FRAMEWORK_OPTIONS = {
|
|
697
|
+
claims: ["cursor", "pageSize", "maxItems"],
|
|
698
|
+
injects: ["cursor", "pageSize", "maxItems"]
|
|
699
|
+
};
|
|
700
|
+
var NO_FRAMEWORK_OPTIONS = {
|
|
701
|
+
claims: [],
|
|
702
|
+
injects: []
|
|
703
|
+
};
|
|
704
|
+
function isRecord(value) {
|
|
705
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
706
|
+
}
|
|
707
|
+
function strictlyRefused(error, claims) {
|
|
708
|
+
const refused = /* @__PURE__ */ new Set();
|
|
709
|
+
for (const issue of error.issues) {
|
|
710
|
+
if (issue.code !== "unrecognized_keys" || issue.path.length > 0) continue;
|
|
711
|
+
for (const key of issue.keys) {
|
|
712
|
+
if (claims.includes(key)) refused.add(key);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return [...refused];
|
|
716
|
+
}
|
|
717
|
+
function withoutKeys(options, keys) {
|
|
718
|
+
const next = {};
|
|
719
|
+
for (const [key, value] of Object.entries(options)) {
|
|
720
|
+
if (!keys.includes(key)) next[key] = value;
|
|
721
|
+
}
|
|
722
|
+
return next;
|
|
723
|
+
}
|
|
724
|
+
function parseCallOptions(options, {
|
|
725
|
+
schema,
|
|
726
|
+
policy = NO_FRAMEWORK_OPTIONS,
|
|
727
|
+
adaptError
|
|
728
|
+
} = {}) {
|
|
729
|
+
const claims = policy.claims;
|
|
730
|
+
const call = isRecord(options) ? options : void 0;
|
|
731
|
+
let framework = {};
|
|
732
|
+
if (call && claims.length > 0) {
|
|
733
|
+
const present = {};
|
|
734
|
+
for (const key of claims) {
|
|
735
|
+
if (key in call) present[key] = call[key];
|
|
736
|
+
}
|
|
737
|
+
framework = parseOrThrow2(CallFrameworkOptionsSchema, present, adaptError);
|
|
738
|
+
}
|
|
739
|
+
if (!schema) return { framework, domain: options, supplied: /* @__PURE__ */ new Set() };
|
|
740
|
+
const first = schema.safeParse(options);
|
|
741
|
+
if (first.success) {
|
|
742
|
+
return { framework, domain: first.data, supplied: /* @__PURE__ */ new Set() };
|
|
743
|
+
}
|
|
744
|
+
const refused = call ? strictlyRefused(first.error, claims) : [];
|
|
745
|
+
if (refused.length === 0) throw toCoreError(first.error, options, adaptError);
|
|
746
|
+
const retry = schema.safeParse(withoutKeys(call, refused));
|
|
747
|
+
if (!retry.success) {
|
|
748
|
+
throw toCoreError(retry.error, options, adaptError);
|
|
749
|
+
}
|
|
750
|
+
return { framework, domain: retry.data, supplied: new Set(refused) };
|
|
751
|
+
}
|
|
752
|
+
function mergeCallOptions({
|
|
753
|
+
framework,
|
|
754
|
+
domain
|
|
755
|
+
}) {
|
|
756
|
+
const claimed = Object.entries(framework);
|
|
757
|
+
if (!isRecord(domain) || claimed.length === 0) return domain;
|
|
758
|
+
return { ...domain, ...Object.fromEntries(claimed) };
|
|
759
|
+
}
|
|
760
|
+
function withheldFromRun(policy) {
|
|
761
|
+
return new Set(policy.claims.filter((key) => !policy.injects.includes(key)));
|
|
762
|
+
}
|
|
763
|
+
function stripFrameworkOnlyOptions(options, withheld) {
|
|
764
|
+
if (withheld.size === 0 || !isRecord(options)) return options;
|
|
765
|
+
const entries = Object.entries(options);
|
|
766
|
+
if (!entries.some(([key]) => withheld.has(key))) return options;
|
|
767
|
+
return Object.fromEntries(entries.filter(([key]) => !withheld.has(key)));
|
|
768
|
+
}
|
|
769
|
+
function parseOrThrow2(schema, input, adaptError) {
|
|
770
|
+
const result = schema.safeParse(input);
|
|
771
|
+
if (result.success) return result.data;
|
|
772
|
+
throw toCoreError(result.error, input, adaptError);
|
|
773
|
+
}
|
|
774
|
+
function toCoreError(error, input, adaptError) {
|
|
775
|
+
const messages = error.issues.map((issue) => {
|
|
776
|
+
const path = issue.path.length > 0 ? issue.path.join(".") : "input";
|
|
777
|
+
return `${path}: ${issue.message}`;
|
|
778
|
+
});
|
|
779
|
+
return createCoreError(
|
|
780
|
+
{
|
|
781
|
+
code: CoreErrorCode.Validation,
|
|
782
|
+
message: `Validation failed:
|
|
783
|
+
${messages.join("\n ")}`,
|
|
784
|
+
details: { zodErrors: error.issues, input }
|
|
785
|
+
},
|
|
786
|
+
adaptError
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
|
|
652
790
|
// src/utils/async-context.ts
|
|
653
791
|
import {
|
|
654
792
|
AsyncLocalStorage
|
|
@@ -848,7 +986,15 @@ function normalizeError(error, adaptError) {
|
|
|
848
986
|
);
|
|
849
987
|
}
|
|
850
988
|
function createFunction(coreFn, options) {
|
|
851
|
-
const {
|
|
989
|
+
const {
|
|
990
|
+
sdk,
|
|
991
|
+
schema,
|
|
992
|
+
name,
|
|
993
|
+
annotator,
|
|
994
|
+
frameworkOptions,
|
|
995
|
+
getDeprecation,
|
|
996
|
+
getStability
|
|
997
|
+
} = options;
|
|
852
998
|
const functionName = name || coreFn.name;
|
|
853
999
|
const namedFunctions = {
|
|
854
1000
|
[functionName]: async function(callOptions) {
|
|
@@ -884,25 +1030,15 @@ function createFunction(coreFn, options) {
|
|
|
884
1030
|
};
|
|
885
1031
|
hooks?.onMethodStart?.({ ...hookBase });
|
|
886
1032
|
try {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
result = await coreFn(
|
|
897
|
-
{
|
|
898
|
-
...normalizedOptions,
|
|
899
|
-
...validatedOptions
|
|
900
|
-
},
|
|
901
|
-
context
|
|
902
|
-
);
|
|
903
|
-
} else {
|
|
904
|
-
result = await coreFn(normalizedOptions, context);
|
|
905
|
-
}
|
|
1033
|
+
const parsed = parseCallOptions(normalizedOptions, {
|
|
1034
|
+
schema,
|
|
1035
|
+
policy: frameworkOptions,
|
|
1036
|
+
adaptError
|
|
1037
|
+
});
|
|
1038
|
+
const result = await coreFn(
|
|
1039
|
+
mergeCallOptions(parsed),
|
|
1040
|
+
context
|
|
1041
|
+
);
|
|
906
1042
|
hooks?.onMethodEnd?.({
|
|
907
1043
|
...hookBase,
|
|
908
1044
|
durationMs: Date.now() - startTime
|
|
@@ -1023,7 +1159,7 @@ function createPageFunction(coreFn, {
|
|
|
1023
1159
|
`${functionName}: paginated result must be exactly { data: TItem[], nextCursor? } (produced by the handler or its \`adaptPage\`); got keys [${page && typeof page === "object" ? Object.keys(page).join(", ") : typeof page}]. If the handler returns a raw shape, set \`adaptPage\` to translate it; if \`adaptPage\` already runs, it must return only \`data\`/\`nextCursor\`.`
|
|
1024
1160
|
);
|
|
1025
1161
|
}
|
|
1026
|
-
return finalizePage ? finalizePage(page) : page;
|
|
1162
|
+
return finalizePage ? finalizePage(page, options) : page;
|
|
1027
1163
|
} catch (error) {
|
|
1028
1164
|
throw normalizeError(
|
|
1029
1165
|
error,
|
|
@@ -1043,6 +1179,7 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
1043
1179
|
adaptPage,
|
|
1044
1180
|
annotator,
|
|
1045
1181
|
finalizePage,
|
|
1182
|
+
frameworkOptions,
|
|
1046
1183
|
getDeprecation,
|
|
1047
1184
|
getStability
|
|
1048
1185
|
} = options;
|
|
@@ -1086,10 +1223,13 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
1086
1223
|
};
|
|
1087
1224
|
hooks?.onMethodStart?.({ ...hookBase });
|
|
1088
1225
|
try {
|
|
1089
|
-
const validatedOptions =
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1226
|
+
const validatedOptions = mergeCallOptions(
|
|
1227
|
+
parseCallOptions(normalizedOptions, {
|
|
1228
|
+
schema,
|
|
1229
|
+
policy: frameworkOptions,
|
|
1230
|
+
adaptError
|
|
1231
|
+
})
|
|
1232
|
+
);
|
|
1093
1233
|
const pageSize = validatedOptions.pageSize ?? defaultPageSize;
|
|
1094
1234
|
const optimizedOptions = {
|
|
1095
1235
|
...validatedOptions,
|
|
@@ -1215,6 +1355,10 @@ function createPaginatedPluginMethod(sdk, config) {
|
|
|
1215
1355
|
sdk,
|
|
1216
1356
|
schema: inputSchema,
|
|
1217
1357
|
name,
|
|
1358
|
+
// The page loop reads the page controls out of the call object, so a
|
|
1359
|
+
// handler's schema does not have to declare them. It reads nothing else:
|
|
1360
|
+
// no legacy handler honors the caller's output skip.
|
|
1361
|
+
frameworkOptions: PAGE_FRAMEWORK_OPTIONS,
|
|
1218
1362
|
defaultPageSize,
|
|
1219
1363
|
adaptPage
|
|
1220
1364
|
});
|
|
@@ -1458,6 +1602,7 @@ function buildPluginStack(head, callerLabel) {
|
|
|
1458
1602
|
}
|
|
1459
1603
|
|
|
1460
1604
|
// src/model/shared.ts
|
|
1605
|
+
var CONTEXT = Symbol.for("kitcore.context");
|
|
1461
1606
|
function parseId(id) {
|
|
1462
1607
|
const at = id.lastIndexOf("/");
|
|
1463
1608
|
return at === -1 ? { name: id, namespace: void 0 } : { name: id.slice(at + 1), namespace: id.slice(0, at) };
|
|
@@ -1567,7 +1712,12 @@ function collectDynamicMembers(members) {
|
|
|
1567
1712
|
};
|
|
1568
1713
|
});
|
|
1569
1714
|
}
|
|
1570
|
-
function defineMethod(
|
|
1715
|
+
function defineMethod(configOrRef, refConfig) {
|
|
1716
|
+
const config = refConfig === void 0 ? configOrRef : {
|
|
1717
|
+
...refConfig,
|
|
1718
|
+
name: configOrRef.name,
|
|
1719
|
+
namespace: configOrRef.namespace
|
|
1720
|
+
};
|
|
1571
1721
|
const deps = normalizeImports(config.imports);
|
|
1572
1722
|
return {
|
|
1573
1723
|
pluginType: "method",
|
|
@@ -1590,8 +1740,27 @@ function defineMethod(config) {
|
|
|
1590
1740
|
run: config.run
|
|
1591
1741
|
};
|
|
1592
1742
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1743
|
+
var OVERRIDABLE = [
|
|
1744
|
+
"description",
|
|
1745
|
+
"categories",
|
|
1746
|
+
"itemType",
|
|
1747
|
+
"returnType",
|
|
1748
|
+
"packages",
|
|
1749
|
+
"experimental",
|
|
1750
|
+
"deprecation",
|
|
1751
|
+
"supportsJsonOutput"
|
|
1752
|
+
];
|
|
1753
|
+
function assertOverridable(target, fields) {
|
|
1754
|
+
const offered = Object.keys(fields).filter(
|
|
1755
|
+
(key) => !OVERRIDABLE.includes(key)
|
|
1756
|
+
);
|
|
1757
|
+
if (offered.length === 0) return;
|
|
1758
|
+
throw new Error(
|
|
1759
|
+
`defineOverride("${target}"): cannot override ${offered.join(", ")}. An override changes how a surface presents a method, never what it does. The method's declared type is fixed at \`defineMethod\` and nothing re-checks it afterwards, so patching behavior here would let a call fail against a contract its own return type says it satisfies. Overridable: ${OVERRIDABLE.join(", ")}.`
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
function buildOverride(target, namespace, fields) {
|
|
1763
|
+
assertOverridable(target, fields);
|
|
1595
1764
|
return {
|
|
1596
1765
|
pluginType: "method-override",
|
|
1597
1766
|
name: `override:${target}`,
|
|
@@ -1599,12 +1768,34 @@ function defineMethodOverride(config) {
|
|
|
1599
1768
|
target,
|
|
1600
1769
|
imports: [],
|
|
1601
1770
|
importBindings: [],
|
|
1602
|
-
meta: collectLeafMeta(
|
|
1771
|
+
meta: collectLeafMeta(fields)
|
|
1603
1772
|
};
|
|
1604
1773
|
}
|
|
1774
|
+
function defineOverride(ref, config = {}) {
|
|
1775
|
+
const { namespace, ...fields } = config;
|
|
1776
|
+
return buildOverride(ref.id, namespace, fields);
|
|
1777
|
+
}
|
|
1778
|
+
function defineMethodOverride(config) {
|
|
1779
|
+
logDeprecation(
|
|
1780
|
+
"defineMethodOverride({ target }) is deprecated. Use defineOverride(method, { ... }), which takes the method or its declareMethod stand-in."
|
|
1781
|
+
);
|
|
1782
|
+
const { target, namespace, ...fields } = config;
|
|
1783
|
+
return buildOverride(target, namespace, fields);
|
|
1784
|
+
}
|
|
1785
|
+
function assertRequirementPaths(requirements) {
|
|
1786
|
+
if (!requirements) return;
|
|
1787
|
+
for (const requirement of requirements) {
|
|
1788
|
+
if (typeof requirement !== "string" && requirement.length === 0) {
|
|
1789
|
+
throw new Error(
|
|
1790
|
+
"defineResolver: a requireParameters path must name at least one segment. An empty path names no parameter, and the engine would read it as already satisfied."
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1605
1795
|
function defineResolver(config) {
|
|
1606
1796
|
const deps = normalizeImports(config.imports);
|
|
1607
1797
|
const base = { imports: deps.plugins, importBindings: deps.bindings };
|
|
1798
|
+
assertRequirementPaths(config.requireParameters);
|
|
1608
1799
|
const gates = {
|
|
1609
1800
|
requireParameters: config.requireParameters
|
|
1610
1801
|
};
|
|
@@ -1708,21 +1899,26 @@ function declareOptionalMethod(config) {
|
|
|
1708
1899
|
// `| undefined`.
|
|
1709
1900
|
};
|
|
1710
1901
|
}
|
|
1711
|
-
function defineProperty(config) {
|
|
1712
|
-
const
|
|
1902
|
+
function defineProperty(config, refConfig) {
|
|
1903
|
+
const cfg = refConfig === void 0 ? config : {
|
|
1904
|
+
...refConfig,
|
|
1905
|
+
name: config.name,
|
|
1906
|
+
namespace: config.namespace
|
|
1907
|
+
};
|
|
1908
|
+
const deps = normalizeImports(cfg.imports);
|
|
1713
1909
|
return {
|
|
1714
1910
|
pluginType: "property",
|
|
1715
|
-
name:
|
|
1716
|
-
namespace:
|
|
1717
|
-
id: makeId(
|
|
1911
|
+
name: cfg.name,
|
|
1912
|
+
namespace: cfg.namespace,
|
|
1913
|
+
id: makeId(cfg.name, cfg.namespace),
|
|
1718
1914
|
imports: deps.plugins,
|
|
1719
1915
|
importBindings: deps.bindings,
|
|
1720
|
-
setup:
|
|
1721
|
-
dispose:
|
|
1722
|
-
value:
|
|
1723
|
-
get:
|
|
1724
|
-
meta: collectLeafMeta(
|
|
1725
|
-
dynamicMembers: collectDynamicMembers(
|
|
1916
|
+
setup: cfg.setup,
|
|
1917
|
+
dispose: cfg.dispose,
|
|
1918
|
+
value: cfg.value,
|
|
1919
|
+
get: cfg.get,
|
|
1920
|
+
meta: collectLeafMeta(cfg),
|
|
1921
|
+
dynamicMembers: collectDynamicMembers(cfg.dynamicMembers)
|
|
1726
1922
|
};
|
|
1727
1923
|
}
|
|
1728
1924
|
function declareProperty(config) {
|
|
@@ -1948,7 +2144,7 @@ function legacyGraphEntry(name, value, pluginMeta) {
|
|
|
1948
2144
|
}
|
|
1949
2145
|
|
|
1950
2146
|
// src/model/builtins.ts
|
|
1951
|
-
import { z as
|
|
2147
|
+
import { z as z3 } from "zod";
|
|
1952
2148
|
|
|
1953
2149
|
// src/model/registry-support.ts
|
|
1954
2150
|
function adaptLegacyFormatter(legacy, sdk) {
|
|
@@ -2026,6 +2222,34 @@ function collectSurfaceProjection(context, formatterSdk) {
|
|
|
2026
2222
|
}
|
|
2027
2223
|
return { meta, formatters, resolvers, positional, skipInputValidation };
|
|
2028
2224
|
}
|
|
2225
|
+
var REGISTRY_CACHE = Symbol.for("kitcore.registryCache");
|
|
2226
|
+
function freezeContainers(registry) {
|
|
2227
|
+
Object.freeze(registry.functions);
|
|
2228
|
+
for (const category of registry.categories) {
|
|
2229
|
+
Object.freeze(category.functions);
|
|
2230
|
+
Object.freeze(category);
|
|
2231
|
+
}
|
|
2232
|
+
Object.freeze(registry.categories);
|
|
2233
|
+
return Object.freeze(registry);
|
|
2234
|
+
}
|
|
2235
|
+
function getCachedRegistry(context, packageFilter) {
|
|
2236
|
+
const key = packageFilter ?? "";
|
|
2237
|
+
const caching = context;
|
|
2238
|
+
let byFilter = caching[REGISTRY_CACHE];
|
|
2239
|
+
if (!byFilter) {
|
|
2240
|
+
byFilter = /* @__PURE__ */ new Map();
|
|
2241
|
+
caching[REGISTRY_CACHE] = byFilter;
|
|
2242
|
+
}
|
|
2243
|
+
let registry = byFilter.get(key);
|
|
2244
|
+
if (!registry) {
|
|
2245
|
+
registry = freezeContainers(buildSurfaceRegistry(context, packageFilter));
|
|
2246
|
+
byFilter.set(key, registry);
|
|
2247
|
+
}
|
|
2248
|
+
return registry;
|
|
2249
|
+
}
|
|
2250
|
+
function invalidateRegistryCache(context) {
|
|
2251
|
+
delete context[REGISTRY_CACHE];
|
|
2252
|
+
}
|
|
2029
2253
|
function buildSurfaceRegistry(context, packageFilter) {
|
|
2030
2254
|
const surface = {};
|
|
2031
2255
|
for (const [binding, id] of Object.entries(context.surface)) {
|
|
@@ -2033,9 +2257,11 @@ function buildSurfaceRegistry(context, packageFilter) {
|
|
|
2033
2257
|
if (!entry || entry.pluginType === "aggregate") continue;
|
|
2034
2258
|
surface[binding] = entry.pluginType === "property" && entry.getValue ? entry.getValue() : entry.value;
|
|
2035
2259
|
}
|
|
2260
|
+
const projection = collectSurfaceProjection(context, surface);
|
|
2261
|
+
Object.assign(projection.meta, context.meta);
|
|
2036
2262
|
return buildRegistry({
|
|
2037
2263
|
sdk: surface,
|
|
2038
|
-
...
|
|
2264
|
+
...projection,
|
|
2039
2265
|
packageFilter
|
|
2040
2266
|
});
|
|
2041
2267
|
}
|
|
@@ -2055,12 +2281,12 @@ var getRegistryPlugin = defineMethod({
|
|
|
2055
2281
|
name: "getRegistry",
|
|
2056
2282
|
namespace: "kitcore",
|
|
2057
2283
|
imports: [dangerousContextPlugin],
|
|
2058
|
-
inputSchema:
|
|
2059
|
-
run: ({ imports, input }) =>
|
|
2284
|
+
inputSchema: z3.object({ package: z3.string().optional() }).optional(),
|
|
2285
|
+
run: ({ imports, input }) => getCachedRegistry(imports.context, input?.package)
|
|
2060
2286
|
});
|
|
2061
2287
|
|
|
2062
2288
|
// src/utils/output-policy.ts
|
|
2063
|
-
function
|
|
2289
|
+
function isRecord2(value) {
|
|
2064
2290
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2065
2291
|
}
|
|
2066
2292
|
function diffDroppedPaths(raw, parsed, prefix = "") {
|
|
@@ -2083,7 +2309,7 @@ function walkDroppedPaths(raw, parsed, prefix, out) {
|
|
|
2083
2309
|
}
|
|
2084
2310
|
return;
|
|
2085
2311
|
}
|
|
2086
|
-
if (
|
|
2312
|
+
if (isRecord2(raw) && isRecord2(parsed)) {
|
|
2087
2313
|
for (const key of Object.keys(raw)) {
|
|
2088
2314
|
const path = prefix ? `${prefix}.${key}` : key;
|
|
2089
2315
|
if (!(key in parsed)) {
|
|
@@ -2095,7 +2321,22 @@ function walkDroppedPaths(raw, parsed, prefix, out) {
|
|
|
2095
2321
|
return;
|
|
2096
2322
|
}
|
|
2097
2323
|
}
|
|
2098
|
-
|
|
2324
|
+
var SKIP_OUTPUT_DATA_VALIDATION = "skipOutputDataValidation";
|
|
2325
|
+
function readSkipOutputDataValidation(options) {
|
|
2326
|
+
return isRecord2(options) && options[SKIP_OUTPUT_DATA_VALIDATION] === true;
|
|
2327
|
+
}
|
|
2328
|
+
function resolveValidatingSchema(policy) {
|
|
2329
|
+
if (policy.skipOutputValidation || policy.skippedByCaller) return void 0;
|
|
2330
|
+
return policy.outputSchema;
|
|
2331
|
+
}
|
|
2332
|
+
function shouldReport(policy) {
|
|
2333
|
+
return policy.skippedByCaller === true && policy.outputSchema !== void 0 && !policy.skipOutputValidation;
|
|
2334
|
+
}
|
|
2335
|
+
function parseOutput(schema, value, policy, {
|
|
2336
|
+
locator,
|
|
2337
|
+
hint,
|
|
2338
|
+
callerCanSkip = true
|
|
2339
|
+
} = {}) {
|
|
2099
2340
|
const result = schema.safeParse(value);
|
|
2100
2341
|
if (result.success) return result.data;
|
|
2101
2342
|
const issues = result.error.issues.map((issue) => {
|
|
@@ -2110,43 +2351,91 @@ function parseOutput(schema, value, policy, locator) {
|
|
|
2110
2351
|
message: `Output validation failed${subject}${at}:
|
|
2111
2352
|
${issues.join("\n ")}
|
|
2112
2353
|
|
|
2113
|
-
|
|
2354
|
+
` + (hint ? `${hint}
|
|
2355
|
+
|
|
2356
|
+
` : "") + `The response does not match the method's \`outputSchema\`. Correct the schema, or set \`skipOutputValidation: true\` on the method to pass the response through unvalidated.` + (callerCanSkip ? ` A caller who cannot change the method can pass \`skipOutputDataValidation: true\` with the input to bypass this one call.` : ``),
|
|
2114
2357
|
details: { zodErrors: result.error.issues, output: value }
|
|
2115
2358
|
},
|
|
2116
2359
|
policy.adaptError
|
|
2117
2360
|
);
|
|
2118
2361
|
}
|
|
2119
2362
|
function applyItemOutputPolicy(result, policy) {
|
|
2120
|
-
const schema = policy
|
|
2121
|
-
|
|
2122
|
-
if (!
|
|
2363
|
+
const schema = resolveValidatingSchema(policy);
|
|
2364
|
+
const report = shouldReport(policy);
|
|
2365
|
+
if (!schema && !report) return result;
|
|
2366
|
+
if (!isRecord2(result) || !("data" in result)) return result;
|
|
2367
|
+
if (!schema) {
|
|
2368
|
+
return {
|
|
2369
|
+
...result,
|
|
2370
|
+
meta: withOutputValidation(result.meta, { skipped: true })
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2123
2373
|
const data = parseOutput(schema, result.data, policy);
|
|
2374
|
+
const validation = buildValidatedReport({
|
|
2375
|
+
policy,
|
|
2376
|
+
before: result.data,
|
|
2377
|
+
after: data
|
|
2378
|
+
});
|
|
2124
2379
|
const next = { ...result, data };
|
|
2125
|
-
if (
|
|
2126
|
-
const droppedPaths = diffDroppedPaths(result.data, data);
|
|
2127
|
-
if (droppedPaths.length > 0) {
|
|
2128
|
-
next.meta = withOutputValidation(result.meta, droppedPaths);
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2380
|
+
if (validation) next.meta = withOutputValidation(result.meta, validation);
|
|
2131
2381
|
return next;
|
|
2132
2382
|
}
|
|
2133
|
-
function
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2383
|
+
function applyRawOutputPolicy(result, policy) {
|
|
2384
|
+
const schema = resolveValidatingSchema(policy);
|
|
2385
|
+
if (!schema) return result;
|
|
2386
|
+
const looksLikeEnvelope = isRecord2(result) && "data" in result;
|
|
2387
|
+
parseOutput(schema, result, policy, {
|
|
2388
|
+
hint: looksLikeEnvelope ? 'This returned a `{ data }` envelope, and with no `output` mode the schema is matched against the WHOLE return. Did you mean `output: "item"` (or `"list"`)?' : void 0,
|
|
2389
|
+
// Raw reserves nothing in the caller's call object, so there is no per-call
|
|
2390
|
+
// skip to point at. Offering one would be advice that does nothing.
|
|
2391
|
+
callerCanSkip: false
|
|
2392
|
+
});
|
|
2393
|
+
return result;
|
|
2394
|
+
}
|
|
2395
|
+
function withOutputValidation(existing, outputDataValidation) {
|
|
2396
|
+
const base = isRecord2(existing) ? existing : {};
|
|
2397
|
+
const deprecated = outputDataValidation.skipped === false && outputDataValidation.droppedPaths ? {
|
|
2398
|
+
outputValidation: { droppedPaths: outputDataValidation.droppedPaths }
|
|
2399
|
+
} : {};
|
|
2400
|
+
return { ...base, outputDataValidation, ...deprecated };
|
|
2401
|
+
}
|
|
2402
|
+
function buildValidatedReport({
|
|
2403
|
+
policy,
|
|
2404
|
+
before,
|
|
2405
|
+
after
|
|
2406
|
+
}) {
|
|
2407
|
+
const droppedPaths = policy.includeOutputValidationDroppedPaths ? diffDroppedPaths(before, after) : [];
|
|
2408
|
+
if (droppedPaths.length === 0) return void 0;
|
|
2409
|
+
return {
|
|
2410
|
+
skipped: false,
|
|
2411
|
+
droppedPaths,
|
|
2412
|
+
instruction: `Some fields were removed from \`data\` by output validation. To receive the raw, unvalidated result instead, set \`${SKIP_OUTPUT_DATA_VALIDATION}\`.`
|
|
2413
|
+
};
|
|
2136
2414
|
}
|
|
2137
2415
|
function applyListOutputPolicy(page, policy) {
|
|
2138
|
-
const schema = policy
|
|
2139
|
-
|
|
2416
|
+
const schema = resolveValidatingSchema(policy);
|
|
2417
|
+
const report = shouldReport(policy);
|
|
2418
|
+
if (!schema && !report) return page;
|
|
2419
|
+
if (!schema) {
|
|
2420
|
+
return {
|
|
2421
|
+
...page,
|
|
2422
|
+
meta: withOutputValidation(page.meta, { skipped: true })
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2140
2425
|
const data = page.data.map(
|
|
2141
|
-
(item, index) => parseOutput(schema, item, policy, `data[${index}]`)
|
|
2426
|
+
(item, index) => parseOutput(schema, item, policy, { locator: `data[${index}]` })
|
|
2142
2427
|
);
|
|
2428
|
+
const validation = buildValidatedReport({
|
|
2429
|
+
policy,
|
|
2430
|
+
before: page.data,
|
|
2431
|
+
after: data
|
|
2432
|
+
});
|
|
2143
2433
|
const next = { ...page, data };
|
|
2144
|
-
if (
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
}
|
|
2434
|
+
if (validation)
|
|
2435
|
+
next.meta = withOutputValidation(
|
|
2436
|
+
page.meta,
|
|
2437
|
+
validation
|
|
2438
|
+
);
|
|
2150
2439
|
return next;
|
|
2151
2440
|
}
|
|
2152
2441
|
|
|
@@ -2154,15 +2443,44 @@ function applyListOutputPolicy(page, policy) {
|
|
|
2154
2443
|
var FRAMEWORK_CONFIGURATION_IDS = /* @__PURE__ */ new Set([
|
|
2155
2444
|
CORE_OPTIONS_ID
|
|
2156
2445
|
]);
|
|
2446
|
+
function isPromiseLike(value) {
|
|
2447
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
2448
|
+
}
|
|
2157
2449
|
function normalizeOutput(output) {
|
|
2158
2450
|
if (output === void 0) return { type: "raw" };
|
|
2159
2451
|
if (typeof output === "string") return { type: output };
|
|
2160
2452
|
return output;
|
|
2161
2453
|
}
|
|
2162
|
-
var CONTEXT = Symbol.for("kitcore.context");
|
|
2163
2454
|
function getContext(sdk) {
|
|
2164
2455
|
return sdk[CONTEXT];
|
|
2165
2456
|
}
|
|
2457
|
+
function assertDynamicMemberRoot(entry) {
|
|
2458
|
+
if (!entry.dynamicMembers?.length) return;
|
|
2459
|
+
const value = entry.getValue ? entry.getValue() : entry.value;
|
|
2460
|
+
if (typeof value === "object" && value !== null) return;
|
|
2461
|
+
throw new Error(
|
|
2462
|
+
`Property "${entry.name}" declares dynamicMembers, so its value must be an object when the SDK is built; got ${value === null ? "null" : typeof value}. Build the root in \`setup\` and return it from \`get\`, so members like "${entry.dynamicMembers[0].name}" are reportable from the first registry read.`
|
|
2463
|
+
);
|
|
2464
|
+
}
|
|
2465
|
+
function getRegistry(sdk, packageFilter) {
|
|
2466
|
+
if (typeof sdk !== "object" && typeof sdk !== "function" || sdk === null)
|
|
2467
|
+
throw createNoRegistryError();
|
|
2468
|
+
const context = getContext(sdk);
|
|
2469
|
+
if (context?.surface) return getCachedRegistry(context, packageFilter);
|
|
2470
|
+
const surfaced = sdk.getRegistry;
|
|
2471
|
+
if (typeof surfaced === "function") {
|
|
2472
|
+
return surfaced.call(
|
|
2473
|
+
sdk,
|
|
2474
|
+
packageFilter ? { package: packageFilter } : void 0
|
|
2475
|
+
);
|
|
2476
|
+
}
|
|
2477
|
+
throw createNoRegistryError();
|
|
2478
|
+
}
|
|
2479
|
+
function createNoRegistryError() {
|
|
2480
|
+
return new Error(
|
|
2481
|
+
"getRegistry: sdk has no kitcore context and no surfaced getRegistry()."
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2166
2484
|
function isResolverRef(value) {
|
|
2167
2485
|
return "ref" in value;
|
|
2168
2486
|
}
|
|
@@ -2668,23 +2986,17 @@ function runLegacyPass(descriptors, context) {
|
|
|
2668
2986
|
Object.assign(context, contextRest);
|
|
2669
2987
|
context.hooks = buildHooks(context.hooks, hooks);
|
|
2670
2988
|
const exports = mirrorLegacyRootKeys(context, rootKeys, meta);
|
|
2989
|
+
for (const name of Object.keys(rootKeys)) context.surface[name] = name;
|
|
2671
2990
|
if (!("getRegistry" in exports)) {
|
|
2672
|
-
let
|
|
2673
|
-
|
|
2674
|
-
const projection = collectSurfaceProjection(context, sdk);
|
|
2675
|
-
Object.assign(projection.meta, context.meta);
|
|
2676
|
-
return buildRegistry({
|
|
2677
|
-
sdk,
|
|
2678
|
-
...projection,
|
|
2679
|
-
packageFilter: options?.package
|
|
2680
|
-
});
|
|
2991
|
+
let getRegistry3 = function(options) {
|
|
2992
|
+
return getCachedRegistry(context, options?.package);
|
|
2681
2993
|
};
|
|
2682
|
-
var
|
|
2683
|
-
exports.getRegistry =
|
|
2994
|
+
var getRegistry2 = getRegistry3;
|
|
2995
|
+
exports.getRegistry = getRegistry3;
|
|
2684
2996
|
plugins.getRegistry = {
|
|
2685
2997
|
pluginType: "method",
|
|
2686
2998
|
name: "getRegistry",
|
|
2687
|
-
value:
|
|
2999
|
+
value: getRegistry3,
|
|
2688
3000
|
chain: []
|
|
2689
3001
|
};
|
|
2690
3002
|
}
|
|
@@ -2748,50 +3060,73 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2748
3060
|
const sdk = { context };
|
|
2749
3061
|
const methodAnnotator = descriptor.annotator;
|
|
2750
3062
|
const boundAnnotator = methodAnnotator ? (input) => methodAnnotator({ input }) : void 0;
|
|
2751
|
-
const outputPolicy = () => {
|
|
3063
|
+
const outputPolicy = (callOptions) => {
|
|
2752
3064
|
const core = resolveCoreOptions(context);
|
|
2753
3065
|
return {
|
|
2754
3066
|
outputSchema: descriptor.meta?.outputSchema,
|
|
2755
3067
|
skipOutputValidation: descriptor.skipOutputValidation,
|
|
3068
|
+
skippedByCaller: readSkipOutputDataValidation(callOptions),
|
|
2756
3069
|
includeOutputValidationDroppedPaths: core?.includeOutputValidationDroppedPaths,
|
|
2757
3070
|
methodName: descriptor.name,
|
|
2758
3071
|
adaptError: core?.adaptError
|
|
2759
3072
|
};
|
|
2760
3073
|
};
|
|
3074
|
+
const frameworkOptions = out.type === "list" ? LIST_FRAMEWORK_OPTIONS : ITEM_FRAMEWORK_OPTIONS;
|
|
3075
|
+
const withheld = withheldFromRun(frameworkOptions);
|
|
2761
3076
|
if (out.type === "list") {
|
|
2762
3077
|
entry.value = createPaginatedFunction(
|
|
2763
|
-
fold(
|
|
3078
|
+
fold(
|
|
3079
|
+
(input, ctx) => callRun(stripFrameworkOnlyOptions(input, withheld), ctx)
|
|
3080
|
+
),
|
|
2764
3081
|
{
|
|
2765
3082
|
sdk,
|
|
2766
3083
|
schema: descriptor.inputSchema,
|
|
2767
3084
|
name: descriptor.name,
|
|
3085
|
+
frameworkOptions,
|
|
2768
3086
|
defaultPageSize: out.defaultPageSize,
|
|
2769
3087
|
adaptPage: out.adaptPage,
|
|
2770
3088
|
annotator: boundAnnotator,
|
|
2771
3089
|
// Validate + strip each item against the item `outputSchema`
|
|
2772
3090
|
// (item mode's sibling); dropped paths surface as `[].x` in the page's
|
|
2773
3091
|
// `meta`, unioned across items.
|
|
2774
|
-
finalizePage: (page) => applyListOutputPolicy(page, outputPolicy()),
|
|
3092
|
+
finalizePage: (page, callOptions) => applyListOutputPolicy(page, outputPolicy(callOptions)),
|
|
2775
3093
|
getDeprecation: () => entry.meta?.deprecation,
|
|
2776
3094
|
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2777
3095
|
}
|
|
2778
3096
|
);
|
|
2779
3097
|
} else if (out.type === "item") {
|
|
2780
|
-
const itemCore = async (input, ctx) => applyItemOutputPolicy(
|
|
3098
|
+
const itemCore = async (input, ctx) => applyItemOutputPolicy(
|
|
3099
|
+
await callRun(stripFrameworkOnlyOptions(input, withheld), ctx),
|
|
3100
|
+
outputPolicy(input)
|
|
3101
|
+
);
|
|
2781
3102
|
entry.value = createFunction(
|
|
2782
3103
|
fold(itemCore),
|
|
2783
3104
|
{
|
|
2784
3105
|
sdk,
|
|
2785
3106
|
schema: descriptor.inputSchema,
|
|
2786
3107
|
name: descriptor.name,
|
|
3108
|
+
frameworkOptions,
|
|
2787
3109
|
annotator: boundAnnotator,
|
|
2788
3110
|
getDeprecation: () => entry.meta?.deprecation,
|
|
2789
3111
|
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2790
3112
|
}
|
|
2791
3113
|
);
|
|
2792
3114
|
} else {
|
|
3115
|
+
const rawValidates = descriptor.meta?.outputSchema !== void 0 && !descriptor.skipOutputValidation;
|
|
3116
|
+
const validateRaw = (out2) => {
|
|
3117
|
+
const policy = outputPolicy(void 0);
|
|
3118
|
+
if (isPromiseLike(out2)) {
|
|
3119
|
+
return Promise.resolve(out2).then(
|
|
3120
|
+
(value) => applyRawOutputPolicy(value, policy)
|
|
3121
|
+
);
|
|
3122
|
+
}
|
|
3123
|
+
return applyRawOutputPolicy(out2, policy);
|
|
3124
|
+
};
|
|
2793
3125
|
entry.value = createRawFunction(
|
|
2794
|
-
(input, ctx) =>
|
|
3126
|
+
(input, ctx) => {
|
|
3127
|
+
const out2 = fold(callRun)(input, ctx);
|
|
3128
|
+
return rawValidates ? validateRaw(out2) : out2;
|
|
3129
|
+
},
|
|
2795
3130
|
{
|
|
2796
3131
|
sdk,
|
|
2797
3132
|
name: descriptor.name,
|
|
@@ -2944,6 +3279,7 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2944
3279
|
dynamicMembers: descriptor.dynamicMembers
|
|
2945
3280
|
};
|
|
2946
3281
|
}
|
|
3282
|
+
assertDynamicMemberRoot(plugins[id]);
|
|
2947
3283
|
}
|
|
2948
3284
|
recordDisposer();
|
|
2949
3285
|
building.delete(id);
|
|
@@ -3167,38 +3503,33 @@ function addModelPlugin(sdk, plugin, options = {}) {
|
|
|
3167
3503
|
}
|
|
3168
3504
|
}
|
|
3169
3505
|
function addPlugin(sdk, plugin, options) {
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3506
|
+
const record = sdk;
|
|
3507
|
+
const context = getContext(record);
|
|
3508
|
+
try {
|
|
3509
|
+
if (typeof plugin === "function") {
|
|
3510
|
+
const contribution = applyPluginToSdk(
|
|
3511
|
+
record,
|
|
3512
|
+
plugin,
|
|
3513
|
+
options ?? {}
|
|
3514
|
+
);
|
|
3515
|
+
if (context) {
|
|
3516
|
+
mirrorLegacyRootKeys(context, contribution.rootKeys, contribution.meta);
|
|
3517
|
+
for (const name of Object.keys(contribution.rootKeys)) {
|
|
3518
|
+
context.surface[name] = name;
|
|
3519
|
+
}
|
|
3182
3520
|
}
|
|
3521
|
+
} else if (plugin.pluginType === "method-override") {
|
|
3522
|
+
applyMethodOverride(context, plugin);
|
|
3523
|
+
} else {
|
|
3524
|
+
addModelPlugin(record, plugin, options ?? {});
|
|
3183
3525
|
}
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
if (plugin.pluginType === "method-override") {
|
|
3187
|
-
applyMethodOverride(
|
|
3188
|
-
getContext(sdk),
|
|
3189
|
-
plugin
|
|
3190
|
-
);
|
|
3191
|
-
return;
|
|
3526
|
+
} finally {
|
|
3527
|
+
if (context) invalidateRegistryCache(context);
|
|
3192
3528
|
}
|
|
3193
|
-
addModelPlugin(
|
|
3194
|
-
sdk,
|
|
3195
|
-
plugin,
|
|
3196
|
-
options ?? {}
|
|
3197
|
-
);
|
|
3198
3529
|
}
|
|
3199
3530
|
|
|
3200
3531
|
// src/model/resolution/controller.ts
|
|
3201
|
-
import { z as
|
|
3532
|
+
import { z as z5 } from "zod";
|
|
3202
3533
|
|
|
3203
3534
|
// src/types/signals.ts
|
|
3204
3535
|
var CORE_SIGNAL_SYMBOL = Symbol.for("kitcore.signal");
|
|
@@ -3231,55 +3562,33 @@ function isCoreCancelledSignal(value) {
|
|
|
3231
3562
|
}
|
|
3232
3563
|
|
|
3233
3564
|
// src/model/resolution/plan.ts
|
|
3234
|
-
import { z as
|
|
3235
|
-
function unwrap(schema) {
|
|
3236
|
-
let inner = schema;
|
|
3237
|
-
let required = true;
|
|
3238
|
-
for (; ; ) {
|
|
3239
|
-
if (inner instanceof z3.ZodOptional) {
|
|
3240
|
-
required = false;
|
|
3241
|
-
inner = inner._zod.def.innerType;
|
|
3242
|
-
} else if (inner instanceof z3.ZodDefault) {
|
|
3243
|
-
required = false;
|
|
3244
|
-
inner = inner._zod.def.innerType;
|
|
3245
|
-
} else if (inner instanceof z3.ZodNullable) {
|
|
3246
|
-
inner = inner._zod.def.innerType;
|
|
3247
|
-
} else {
|
|
3248
|
-
break;
|
|
3249
|
-
}
|
|
3250
|
-
}
|
|
3251
|
-
return { inner, required };
|
|
3252
|
-
}
|
|
3565
|
+
import { z as z4 } from "zod";
|
|
3253
3566
|
function valueTypeOf(inner) {
|
|
3254
|
-
if (inner instanceof
|
|
3255
|
-
if (inner instanceof
|
|
3256
|
-
if (inner instanceof
|
|
3257
|
-
if (inner instanceof
|
|
3258
|
-
if (inner instanceof
|
|
3259
|
-
if (inner instanceof
|
|
3260
|
-
if (inner instanceof
|
|
3567
|
+
if (inner instanceof z4.ZodString) return "string";
|
|
3568
|
+
if (inner instanceof z4.ZodNumber) return "number";
|
|
3569
|
+
if (inner instanceof z4.ZodBoolean) return "boolean";
|
|
3570
|
+
if (inner instanceof z4.ZodEnum) return "string";
|
|
3571
|
+
if (inner instanceof z4.ZodArray) return "array";
|
|
3572
|
+
if (inner instanceof z4.ZodObject) return "object";
|
|
3573
|
+
if (inner instanceof z4.ZodRecord) return "object";
|
|
3261
3574
|
return void 0;
|
|
3262
3575
|
}
|
|
3263
3576
|
function staticChoicesOf(inner) {
|
|
3264
|
-
if (inner instanceof
|
|
3577
|
+
if (inner instanceof z4.ZodEnum) {
|
|
3265
3578
|
const values = inner.options;
|
|
3266
3579
|
return values.map((value) => ({ label: value, value }));
|
|
3267
3580
|
}
|
|
3268
3581
|
return void 0;
|
|
3269
3582
|
}
|
|
3270
|
-
function objectShape(schema) {
|
|
3271
|
-
const canonical = canonicalInputSchema(schema);
|
|
3272
|
-
const { inner } = canonical ? unwrap(canonical) : { inner: void 0 };
|
|
3273
|
-
if (inner instanceof z3.ZodObject) {
|
|
3274
|
-
return inner.shape;
|
|
3275
|
-
}
|
|
3276
|
-
return void 0;
|
|
3277
|
-
}
|
|
3278
3583
|
function topoOrder2(specs) {
|
|
3279
3584
|
const byName = new Map(specs.map((s) => [s.name, s]));
|
|
3280
3585
|
const placed = /* @__PURE__ */ new Set();
|
|
3281
3586
|
const ordered = [];
|
|
3282
|
-
const
|
|
3587
|
+
const topLevelNameOf = (r) => typeof r === "string" ? r : r.length === 1 && typeof r[0] === "string" ? r[0] : void 0;
|
|
3588
|
+
const isReady = (spec) => spec.requires.every((r) => {
|
|
3589
|
+
const name = topLevelNameOf(r);
|
|
3590
|
+
return name === void 0 || !byName.has(name) || placed.has(name);
|
|
3591
|
+
});
|
|
3283
3592
|
for (; ; ) {
|
|
3284
3593
|
const next = specs.find((s) => !placed.has(s.name) && isReady(s));
|
|
3285
3594
|
if (!next) break;
|
|
@@ -3290,7 +3599,7 @@ function topoOrder2(specs) {
|
|
|
3290
3599
|
return ordered;
|
|
3291
3600
|
}
|
|
3292
3601
|
function planParameters(entry) {
|
|
3293
|
-
const shape =
|
|
3602
|
+
const shape = objectShapeOf(entry.inputSchema);
|
|
3294
3603
|
const resolvers = entry.resolvers ?? {};
|
|
3295
3604
|
const names = shape ? [
|
|
3296
3605
|
...Object.keys(shape),
|
|
@@ -3300,7 +3609,7 @@ function planParameters(entry) {
|
|
|
3300
3609
|
] : Object.keys(resolvers);
|
|
3301
3610
|
const specs = names.map((name) => {
|
|
3302
3611
|
const field = shape?.[name];
|
|
3303
|
-
const { inner, required } = field ?
|
|
3612
|
+
const { inner, required } = field ? unwrapSchema(field) : { inner: void 0, required: false };
|
|
3304
3613
|
const resolver = resolvers[name];
|
|
3305
3614
|
return {
|
|
3306
3615
|
name,
|
|
@@ -3949,9 +4258,13 @@ async function findNext(ctx, state, path = []) {
|
|
|
3949
4258
|
const hasAskableRequired = children.some((c) => c.required && asksUser(c));
|
|
3950
4259
|
for (const leaf of ordered) {
|
|
3951
4260
|
const childPath = [...path, leaf.name];
|
|
3952
|
-
if (!leaf.requires.every(
|
|
3953
|
-
|
|
3954
|
-
|
|
4261
|
+
if (!leaf.requires.every((r) => {
|
|
4262
|
+
if (typeof r !== "string") {
|
|
4263
|
+
if (getAtPath(state.resolved, [...r]) !== void 0) return true;
|
|
4264
|
+
return r.some((_, index) => isSettled(state, r.slice(0, index + 1)));
|
|
4265
|
+
}
|
|
4266
|
+
return container[r] !== void 0 || getAtPath(state.resolved, [r]) !== void 0 || isSettled(state, [...path, r]) || isSettled(state, [r]);
|
|
4267
|
+
})) {
|
|
3955
4268
|
continue;
|
|
3956
4269
|
}
|
|
3957
4270
|
const inArrayItem = path.some((segment) => typeof segment === "number");
|
|
@@ -4355,7 +4668,7 @@ function positionAfter(pagination, action) {
|
|
|
4355
4668
|
function toJsonSchema(schema) {
|
|
4356
4669
|
if (!schema) return void 0;
|
|
4357
4670
|
try {
|
|
4358
|
-
return
|
|
4671
|
+
return z5.toJSONSchema(schema);
|
|
4359
4672
|
} catch {
|
|
4360
4673
|
return void 0;
|
|
4361
4674
|
}
|
|
@@ -4393,7 +4706,7 @@ function projectMethod(entry) {
|
|
|
4393
4706
|
}
|
|
4394
4707
|
function createController(sdk) {
|
|
4395
4708
|
function entryFor(method) {
|
|
4396
|
-
const entry =
|
|
4709
|
+
const entry = getRegistry(sdk).functions.find((f) => f.name === method);
|
|
4397
4710
|
if (!entry) throw new Error(`unknown method "${method}"`);
|
|
4398
4711
|
return entry;
|
|
4399
4712
|
}
|
|
@@ -4432,7 +4745,7 @@ function createController(sdk) {
|
|
|
4432
4745
|
throw new Error(`invalid input for "${method}": ${detail}`);
|
|
4433
4746
|
};
|
|
4434
4747
|
const listMethods = () => ({
|
|
4435
|
-
data:
|
|
4748
|
+
data: getRegistry(sdk).functions.map(projectSummary)
|
|
4436
4749
|
});
|
|
4437
4750
|
const getMethod = ({ method }) => ({
|
|
4438
4751
|
data: projectMethod(entryFor(method))
|
|
@@ -4473,10 +4786,10 @@ function createCorePlugin(options) {
|
|
|
4473
4786
|
}
|
|
4474
4787
|
|
|
4475
4788
|
// src/transport/attempt-http-request.ts
|
|
4476
|
-
import { z as
|
|
4789
|
+
import { z as z10 } from "zod";
|
|
4477
4790
|
|
|
4478
4791
|
// src/transport/authorize-http-request.ts
|
|
4479
|
-
import { z as
|
|
4792
|
+
import { z as z6 } from "zod";
|
|
4480
4793
|
function describeUnclaimedConnection(connection) {
|
|
4481
4794
|
const delimiterIndex = connection.indexOf(":");
|
|
4482
4795
|
if (delimiterIndex === -1) {
|
|
@@ -4487,7 +4800,7 @@ function describeUnclaimedConnection(connection) {
|
|
|
4487
4800
|
var authorizeHttpRequestPlugin = defineMethod({
|
|
4488
4801
|
name: "authorizeHttpRequest",
|
|
4489
4802
|
namespace: "kitcore",
|
|
4490
|
-
inputSchema:
|
|
4803
|
+
inputSchema: z6.custom(),
|
|
4491
4804
|
skipInputValidation: true,
|
|
4492
4805
|
run: async ({ input }) => {
|
|
4493
4806
|
const { connection } = input.request;
|
|
@@ -4502,7 +4815,7 @@ var authorizeHttpRequestPlugin = defineMethod({
|
|
|
4502
4815
|
});
|
|
4503
4816
|
|
|
4504
4817
|
// src/transport/dispatch-http-request.ts
|
|
4505
|
-
import { z as
|
|
4818
|
+
import { z as z7 } from "zod";
|
|
4506
4819
|
function toFetchInput(request) {
|
|
4507
4820
|
const init = { ...request };
|
|
4508
4821
|
const { url } = request;
|
|
@@ -4513,7 +4826,7 @@ function toFetchInput(request) {
|
|
|
4513
4826
|
var dispatchHttpRequestPlugin = defineMethod({
|
|
4514
4827
|
name: "dispatchHttpRequest",
|
|
4515
4828
|
namespace: "kitcore",
|
|
4516
|
-
inputSchema:
|
|
4829
|
+
inputSchema: z7.custom(),
|
|
4517
4830
|
skipInputValidation: true,
|
|
4518
4831
|
run: async ({ input }) => {
|
|
4519
4832
|
const { url, init } = toFetchInput(input.request);
|
|
@@ -4522,21 +4835,21 @@ var dispatchHttpRequestPlugin = defineMethod({
|
|
|
4522
4835
|
});
|
|
4523
4836
|
|
|
4524
4837
|
// src/transport/prepare-http-request.ts
|
|
4525
|
-
import { z as
|
|
4838
|
+
import { z as z8 } from "zod";
|
|
4526
4839
|
var prepareHttpRequestPlugin = defineMethod({
|
|
4527
4840
|
name: "prepareHttpRequest",
|
|
4528
4841
|
namespace: "kitcore",
|
|
4529
|
-
inputSchema:
|
|
4842
|
+
inputSchema: z8.custom(),
|
|
4530
4843
|
skipInputValidation: true,
|
|
4531
4844
|
run: async ({ input }) => input.request
|
|
4532
4845
|
});
|
|
4533
4846
|
|
|
4534
4847
|
// src/transport/receive-http-response.ts
|
|
4535
|
-
import { z as
|
|
4848
|
+
import { z as z9 } from "zod";
|
|
4536
4849
|
var receiveHttpResponsePlugin = defineMethod({
|
|
4537
4850
|
name: "receiveHttpResponse",
|
|
4538
4851
|
namespace: "kitcore",
|
|
4539
|
-
inputSchema:
|
|
4852
|
+
inputSchema: z9.custom(),
|
|
4540
4853
|
skipInputValidation: true,
|
|
4541
4854
|
run: async ({ input }) => input.response
|
|
4542
4855
|
});
|
|
@@ -4551,7 +4864,7 @@ var attemptHttpRequestPlugin = defineMethod({
|
|
|
4551
4864
|
declareDefault({ plugin: dispatchHttpRequestPlugin }),
|
|
4552
4865
|
declareDefault({ plugin: receiveHttpResponsePlugin })
|
|
4553
4866
|
],
|
|
4554
|
-
inputSchema:
|
|
4867
|
+
inputSchema: z10.custom(),
|
|
4555
4868
|
skipInputValidation: true,
|
|
4556
4869
|
run: async ({ input, imports }) => {
|
|
4557
4870
|
const { attempt } = input;
|
|
@@ -4576,7 +4889,7 @@ var attemptHttpRequestPlugin = defineMethod({
|
|
|
4576
4889
|
});
|
|
4577
4890
|
|
|
4578
4891
|
// src/transport/initialize-http-request.ts
|
|
4579
|
-
import { z as
|
|
4892
|
+
import { z as z11 } from "zod";
|
|
4580
4893
|
function isReplayableBody(body) {
|
|
4581
4894
|
if (body == null || typeof body !== "object") return true;
|
|
4582
4895
|
return typeof Blob !== "undefined" && body instanceof Blob || // File extends Blob
|
|
@@ -4588,7 +4901,7 @@ function withStringUrl(request) {
|
|
|
4588
4901
|
var initializeHttpRequestPlugin = defineMethod({
|
|
4589
4902
|
name: "initializeHttpRequest",
|
|
4590
4903
|
namespace: "kitcore",
|
|
4591
|
-
inputSchema:
|
|
4904
|
+
inputSchema: z11.custom(),
|
|
4592
4905
|
skipInputValidation: true,
|
|
4593
4906
|
run: async ({ input }) => {
|
|
4594
4907
|
const request = withStringUrl(input.request);
|
|
@@ -4725,7 +5038,7 @@ function canRetry(attemptNumber, maxAttempts, replayable) {
|
|
|
4725
5038
|
}
|
|
4726
5039
|
|
|
4727
5040
|
// src/transport/send-http-request.ts
|
|
4728
|
-
import { z as
|
|
5041
|
+
import { z as z12 } from "zod";
|
|
4729
5042
|
function createOperationId() {
|
|
4730
5043
|
return globalThis.crypto?.randomUUID?.() ?? `http-${Date.now()}`;
|
|
4731
5044
|
}
|
|
@@ -4736,7 +5049,7 @@ var sendHttpRequestPlugin = defineMethod({
|
|
|
4736
5049
|
declareDefault({ plugin: initializeHttpRequestPlugin }),
|
|
4737
5050
|
declareDefault({ plugin: attemptHttpRequestPlugin })
|
|
4738
5051
|
],
|
|
4739
|
-
inputSchema:
|
|
5052
|
+
inputSchema: z12.custom(),
|
|
4740
5053
|
skipInputValidation: true,
|
|
4741
5054
|
run: async ({ input, imports }) => {
|
|
4742
5055
|
const start2 = {
|
|
@@ -4760,13 +5073,13 @@ var sendHttpRequestPlugin = defineMethod({
|
|
|
4760
5073
|
});
|
|
4761
5074
|
|
|
4762
5075
|
// src/transport/fetch.ts
|
|
4763
|
-
import { z as
|
|
5076
|
+
import { z as z13 } from "zod";
|
|
4764
5077
|
var fetchPlugin = defineMethod({
|
|
4765
5078
|
name: "fetch",
|
|
4766
5079
|
namespace: "kitcore",
|
|
4767
5080
|
imports: [declareDefault({ plugin: sendHttpRequestPlugin })],
|
|
4768
5081
|
positional: ["url", "init"],
|
|
4769
|
-
inputSchema:
|
|
5082
|
+
inputSchema: z13.custom(),
|
|
4770
5083
|
skipInputValidation: true,
|
|
4771
5084
|
run: ({ input, imports }) => {
|
|
4772
5085
|
const { url, init } = input;
|
|
@@ -4809,22 +5122,22 @@ function redactHttpRequest(request) {
|
|
|
4809
5122
|
}
|
|
4810
5123
|
|
|
4811
5124
|
// src/connections/default-connection-scheme.ts
|
|
4812
|
-
import { z as
|
|
5125
|
+
import { z as z14 } from "zod";
|
|
4813
5126
|
var defaultConnectionSchemePlugin = defineMethod({
|
|
4814
5127
|
name: "defaultConnectionScheme",
|
|
4815
5128
|
namespace: "kitcore",
|
|
4816
|
-
inputSchema:
|
|
5129
|
+
inputSchema: z14.custom(),
|
|
4817
5130
|
skipInputValidation: true,
|
|
4818
5131
|
run: () => void 0
|
|
4819
5132
|
});
|
|
4820
5133
|
|
|
4821
5134
|
// src/connections/normalize-connection.ts
|
|
4822
|
-
import { z as
|
|
5135
|
+
import { z as z15 } from "zod";
|
|
4823
5136
|
var normalizeConnectionPlugin = defineMethod({
|
|
4824
5137
|
name: "normalizeConnection",
|
|
4825
5138
|
namespace: "kitcore",
|
|
4826
5139
|
imports: [declareDefault({ plugin: defaultConnectionSchemePlugin })],
|
|
4827
|
-
inputSchema:
|
|
5140
|
+
inputSchema: z15.custom(),
|
|
4828
5141
|
skipInputValidation: true,
|
|
4829
5142
|
run: ({ input, imports }) => {
|
|
4830
5143
|
const { connection } = input;
|
|
@@ -4849,11 +5162,11 @@ var normalizeConnectionPlugin = defineMethod({
|
|
|
4849
5162
|
});
|
|
4850
5163
|
|
|
4851
5164
|
// src/connections/resolve-connection.ts
|
|
4852
|
-
import { z as
|
|
5165
|
+
import { z as z16 } from "zod";
|
|
4853
5166
|
var resolveConnectionPlugin = defineMethod({
|
|
4854
5167
|
name: "resolveConnection",
|
|
4855
5168
|
namespace: "kitcore",
|
|
4856
|
-
inputSchema:
|
|
5169
|
+
inputSchema: z16.custom(),
|
|
4857
5170
|
skipInputValidation: true,
|
|
4858
5171
|
run: ({ input }) => input.connection
|
|
4859
5172
|
});
|
|
@@ -4908,6 +5221,7 @@ export {
|
|
|
4908
5221
|
defineLegacyMerge,
|
|
4909
5222
|
defineMethod,
|
|
4910
5223
|
defineMethodOverride,
|
|
5224
|
+
defineOverride,
|
|
4911
5225
|
definePlugin,
|
|
4912
5226
|
defineProperty,
|
|
4913
5227
|
defineResolver,
|
|
@@ -4923,6 +5237,7 @@ export {
|
|
|
4923
5237
|
getFieldDescriptions,
|
|
4924
5238
|
getNegatable,
|
|
4925
5239
|
getOutputSchema,
|
|
5240
|
+
getRegistry,
|
|
4926
5241
|
getRegistryPlugin,
|
|
4927
5242
|
getSchemaDescription,
|
|
4928
5243
|
initializeHttpRequestPlugin,
|
|
@@ -4934,6 +5249,7 @@ export {
|
|
|
4934
5249
|
isTelemetryNested,
|
|
4935
5250
|
normalizeConnectionPlugin,
|
|
4936
5251
|
normalizeStability,
|
|
5252
|
+
objectShapeOf,
|
|
4937
5253
|
omitExports,
|
|
4938
5254
|
openEnum,
|
|
4939
5255
|
paginate,
|
|
@@ -4955,6 +5271,7 @@ export {
|
|
|
4955
5271
|
toIterable,
|
|
4956
5272
|
toSnakeCase,
|
|
4957
5273
|
toTitleCase,
|
|
5274
|
+
unwrapSchema,
|
|
4958
5275
|
validateOptions,
|
|
4959
5276
|
withOutputSchema,
|
|
4960
5277
|
withPositional,
|