@zapier/kitcore 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +34 -3
- package/dist/index.cjs +287 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +155 -23
- package/dist/index.d.ts +155 -23
- package/dist/index.mjs +287 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -168,13 +168,39 @@ function buildRegistry({
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// src/utils/build-hooks.ts
|
|
171
|
+
var isolated = /* @__PURE__ */ new WeakSet();
|
|
172
|
+
function isolate(observer) {
|
|
173
|
+
if (!observer) return void 0;
|
|
174
|
+
if (isolated.has(observer)) return observer;
|
|
175
|
+
const wrapped = (ctx) => {
|
|
176
|
+
try {
|
|
177
|
+
observer(ctx);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error(
|
|
180
|
+
"[core] A method-lifecycle observer threw and was ignored. Observers are fire-and-forget and must not throw.",
|
|
181
|
+
error
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
isolated.add(wrapped);
|
|
186
|
+
return wrapped;
|
|
187
|
+
}
|
|
171
188
|
function composeVoid(existing, added) {
|
|
189
|
+
const wrappedExisting = isolate(existing);
|
|
190
|
+
const wrappedAdded = isolate(added);
|
|
191
|
+
if (!wrappedExisting) return wrappedAdded;
|
|
192
|
+
if (!wrappedAdded) return wrappedExisting;
|
|
193
|
+
const composed = (ctx) => {
|
|
194
|
+
wrappedExisting(ctx);
|
|
195
|
+
wrappedAdded(ctx);
|
|
196
|
+
};
|
|
197
|
+
isolated.add(composed);
|
|
198
|
+
return composed;
|
|
199
|
+
}
|
|
200
|
+
function composeAnnotators(existing, added) {
|
|
172
201
|
if (!existing) return added;
|
|
173
202
|
if (!added) return existing;
|
|
174
|
-
return (ctx) => {
|
|
175
|
-
existing(ctx);
|
|
176
|
-
added(ctx);
|
|
177
|
-
};
|
|
203
|
+
return (ctx) => ({ ...existing(ctx), ...added(ctx) });
|
|
178
204
|
}
|
|
179
205
|
function buildHooks(existing, added) {
|
|
180
206
|
const result = {};
|
|
@@ -182,6 +208,8 @@ function buildHooks(existing, added) {
|
|
|
182
208
|
if (start2) result.onMethodStart = start2;
|
|
183
209
|
const end = composeVoid(existing.onMethodEnd, added.onMethodEnd);
|
|
184
210
|
if (end) result.onMethodEnd = end;
|
|
211
|
+
const annotator = composeAnnotators(existing.annotator, added.annotator);
|
|
212
|
+
if (annotator) result.annotator = annotator;
|
|
185
213
|
return result;
|
|
186
214
|
}
|
|
187
215
|
|
|
@@ -656,11 +684,14 @@ function generateCallId() {
|
|
|
656
684
|
}
|
|
657
685
|
return null;
|
|
658
686
|
}
|
|
659
|
-
function rootCallContext(
|
|
687
|
+
function rootCallContext({
|
|
688
|
+
callOrigin = "surface"
|
|
689
|
+
} = {}) {
|
|
660
690
|
return {
|
|
661
691
|
callId: generateCallId(),
|
|
662
692
|
depth: 0,
|
|
663
693
|
annotations: {},
|
|
694
|
+
callOrigin,
|
|
664
695
|
[CALL_CONTEXT_BRAND]: true
|
|
665
696
|
};
|
|
666
697
|
}
|
|
@@ -669,6 +700,7 @@ function childCallContext(parent) {
|
|
|
669
700
|
callId: parent.callId,
|
|
670
701
|
depth: parent.depth + 1,
|
|
671
702
|
annotations: {},
|
|
703
|
+
callOrigin: parent.callOrigin,
|
|
672
704
|
[CALL_CONTEXT_BRAND]: true
|
|
673
705
|
};
|
|
674
706
|
}
|
|
@@ -694,6 +726,28 @@ var INTERNAL_CALL = Symbol("kitcore.internalCall");
|
|
|
694
726
|
function resolveCallContext(secondArg) {
|
|
695
727
|
return isCallContext(secondArg) ? secondArg : rootCallContext();
|
|
696
728
|
}
|
|
729
|
+
var hookAnnotatorReentrancy = 0;
|
|
730
|
+
function applyAnnotations({
|
|
731
|
+
context,
|
|
732
|
+
methodName,
|
|
733
|
+
input,
|
|
734
|
+
hookAnnotator,
|
|
735
|
+
methodAnnotator
|
|
736
|
+
}) {
|
|
737
|
+
if (hookAnnotator && !isInsideObserver() && context.depth === 0 && context.callOrigin !== "internal" && hookAnnotatorReentrancy === 0) {
|
|
738
|
+
hookAnnotatorReentrancy++;
|
|
739
|
+
try {
|
|
740
|
+
Object.assign(context.annotations, hookAnnotator({ methodName, input }));
|
|
741
|
+
} catch {
|
|
742
|
+
} finally {
|
|
743
|
+
hookAnnotatorReentrancy--;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
try {
|
|
747
|
+
Object.assign(context.annotations, methodAnnotator?.(input));
|
|
748
|
+
} catch {
|
|
749
|
+
}
|
|
750
|
+
}
|
|
697
751
|
function signalDeprecation(context, methodName, getDeprecation) {
|
|
698
752
|
if (isInsideObserver()) return;
|
|
699
753
|
const deprecation = getDeprecation?.();
|
|
@@ -719,7 +773,7 @@ function normalizeError(error, adaptError) {
|
|
|
719
773
|
);
|
|
720
774
|
}
|
|
721
775
|
function createFunction(coreFn, options) {
|
|
722
|
-
const { sdk, schema, name, getDeprecation } = options;
|
|
776
|
+
const { sdk, schema, name, annotator, getDeprecation } = options;
|
|
723
777
|
const functionName = name || coreFn.name;
|
|
724
778
|
const namedFunctions = {
|
|
725
779
|
[functionName]: async function(callOptions) {
|
|
@@ -733,14 +787,26 @@ function createFunction(coreFn, options) {
|
|
|
733
787
|
const normalizedOptions = callOptions ?? {};
|
|
734
788
|
const args = [normalizedOptions];
|
|
735
789
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
736
|
-
const
|
|
790
|
+
const insideObserver = isInsideObserver();
|
|
791
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
737
792
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
738
|
-
|
|
793
|
+
applyAnnotations({
|
|
794
|
+
context,
|
|
795
|
+
methodName: functionName,
|
|
796
|
+
input: normalizedOptions,
|
|
797
|
+
hookAnnotator: hooks?.annotator,
|
|
798
|
+
methodAnnotator: annotator
|
|
799
|
+
});
|
|
800
|
+
const hookBase = {
|
|
739
801
|
methodName: functionName,
|
|
740
802
|
args,
|
|
741
803
|
isPaginated: false,
|
|
742
|
-
depth
|
|
743
|
-
|
|
804
|
+
depth,
|
|
805
|
+
callId: context.callId,
|
|
806
|
+
callOrigin: context.callOrigin,
|
|
807
|
+
annotations: context.annotations
|
|
808
|
+
};
|
|
809
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
744
810
|
try {
|
|
745
811
|
let result;
|
|
746
812
|
if (schema) {
|
|
@@ -762,20 +828,14 @@ function createFunction(coreFn, options) {
|
|
|
762
828
|
result = await coreFn(normalizedOptions, context);
|
|
763
829
|
}
|
|
764
830
|
hooks?.onMethodEnd?.({
|
|
765
|
-
|
|
766
|
-
args,
|
|
767
|
-
isPaginated: false,
|
|
768
|
-
depth,
|
|
831
|
+
...hookBase,
|
|
769
832
|
durationMs: Date.now() - startTime
|
|
770
833
|
});
|
|
771
834
|
return result;
|
|
772
835
|
} catch (error) {
|
|
773
836
|
const normalizedError = normalizeError(error, adaptError);
|
|
774
837
|
hooks?.onMethodEnd?.({
|
|
775
|
-
|
|
776
|
-
args,
|
|
777
|
-
isPaginated: false,
|
|
778
|
-
depth,
|
|
838
|
+
...hookBase,
|
|
779
839
|
durationMs: Date.now() - startTime,
|
|
780
840
|
error: normalizedError
|
|
781
841
|
});
|
|
@@ -787,7 +847,7 @@ function createFunction(coreFn, options) {
|
|
|
787
847
|
return namedFunctions[functionName];
|
|
788
848
|
}
|
|
789
849
|
function createRawFunction(coreFn, options) {
|
|
790
|
-
const { sdk, name, schema, positional, getDeprecation } = options;
|
|
850
|
+
const { sdk, name, schema, positional, annotator, getDeprecation } = options;
|
|
791
851
|
return function(rawInput) {
|
|
792
852
|
const internal = arguments[1];
|
|
793
853
|
const context = resolveCallContext(internal);
|
|
@@ -797,23 +857,32 @@ function createRawFunction(coreFn, options) {
|
|
|
797
857
|
return runInMethodScope(() => {
|
|
798
858
|
const startTime = Date.now();
|
|
799
859
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
800
|
-
const
|
|
860
|
+
const insideObserver = isInsideObserver();
|
|
861
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
801
862
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
802
863
|
const input = schema ? rawInput ?? {} : rawInput;
|
|
864
|
+
applyAnnotations({
|
|
865
|
+
context,
|
|
866
|
+
methodName: name,
|
|
867
|
+
input,
|
|
868
|
+
hookAnnotator: hooks?.annotator,
|
|
869
|
+
methodAnnotator: annotator
|
|
870
|
+
});
|
|
803
871
|
const record = input;
|
|
804
872
|
const args = positional ? positional.filter((key) => record?.[key] !== void 0).map((key) => record?.[key]) : [input];
|
|
805
|
-
|
|
873
|
+
const hookBase = {
|
|
806
874
|
methodName: name,
|
|
807
875
|
args,
|
|
808
876
|
isPaginated: false,
|
|
809
|
-
depth
|
|
810
|
-
|
|
877
|
+
depth,
|
|
878
|
+
callId: context.callId,
|
|
879
|
+
callOrigin: context.callOrigin,
|
|
880
|
+
annotations: context.annotations
|
|
881
|
+
};
|
|
882
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
811
883
|
const fireEnd = (error) => {
|
|
812
884
|
hooks?.onMethodEnd?.({
|
|
813
|
-
|
|
814
|
-
args,
|
|
815
|
-
isPaginated: false,
|
|
816
|
-
depth,
|
|
885
|
+
...hookBase,
|
|
817
886
|
durationMs: Date.now() - startTime,
|
|
818
887
|
...error ? { error } : {}
|
|
819
888
|
});
|
|
@@ -880,7 +949,15 @@ function createPageFunction(coreFn, {
|
|
|
880
949
|
return namedFunctions[functionName];
|
|
881
950
|
}
|
|
882
951
|
function createPaginatedFunction(coreFn, options) {
|
|
883
|
-
const {
|
|
952
|
+
const {
|
|
953
|
+
sdk,
|
|
954
|
+
schema,
|
|
955
|
+
name,
|
|
956
|
+
defaultPageSize,
|
|
957
|
+
adaptPage,
|
|
958
|
+
annotator,
|
|
959
|
+
getDeprecation
|
|
960
|
+
} = options;
|
|
884
961
|
const pageFunction = createPageFunction(coreFn, { sdk, adaptPage });
|
|
885
962
|
const functionName = name || coreFn.name;
|
|
886
963
|
const namedFunctions = {
|
|
@@ -895,14 +972,26 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
895
972
|
const normalizedOptions = callOptions ?? {};
|
|
896
973
|
const args = [normalizedOptions];
|
|
897
974
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
898
|
-
const
|
|
975
|
+
const insideObserver = isInsideObserver();
|
|
976
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
899
977
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
900
|
-
|
|
978
|
+
applyAnnotations({
|
|
979
|
+
context,
|
|
980
|
+
methodName: functionName,
|
|
981
|
+
input: normalizedOptions,
|
|
982
|
+
hookAnnotator: hooks?.annotator,
|
|
983
|
+
methodAnnotator: annotator
|
|
984
|
+
});
|
|
985
|
+
const hookBase = {
|
|
901
986
|
methodName: functionName,
|
|
902
987
|
args,
|
|
903
988
|
isPaginated: true,
|
|
904
|
-
depth
|
|
905
|
-
|
|
989
|
+
depth,
|
|
990
|
+
callId: context.callId,
|
|
991
|
+
callOrigin: context.callOrigin,
|
|
992
|
+
annotations: context.annotations
|
|
993
|
+
};
|
|
994
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
906
995
|
try {
|
|
907
996
|
const validatedOptions = {
|
|
908
997
|
...normalizedOptions,
|
|
@@ -925,24 +1014,21 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
925
1014
|
return result.value;
|
|
926
1015
|
});
|
|
927
1016
|
if (hooks?.onMethodEnd) {
|
|
928
|
-
firstPagePromise.then(
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
944
|
-
});
|
|
945
|
-
});
|
|
1017
|
+
firstPagePromise.then(
|
|
1018
|
+
() => {
|
|
1019
|
+
hooks.onMethodEnd({
|
|
1020
|
+
...hookBase,
|
|
1021
|
+
durationMs: Date.now() - startTime
|
|
1022
|
+
});
|
|
1023
|
+
},
|
|
1024
|
+
(error) => {
|
|
1025
|
+
hooks.onMethodEnd({
|
|
1026
|
+
...hookBase,
|
|
1027
|
+
durationMs: Date.now() - startTime,
|
|
1028
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
);
|
|
946
1032
|
}
|
|
947
1033
|
const pageStream = async function* () {
|
|
948
1034
|
yield await firstPagePromise;
|
|
@@ -976,10 +1062,7 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
976
1062
|
} catch (error) {
|
|
977
1063
|
const normalizedError = normalizeError(error, adaptError);
|
|
978
1064
|
hooks?.onMethodEnd?.({
|
|
979
|
-
|
|
980
|
-
args,
|
|
981
|
-
isPaginated: true,
|
|
982
|
-
depth,
|
|
1065
|
+
...hookBase,
|
|
983
1066
|
durationMs: Date.now() - startTime,
|
|
984
1067
|
error: normalizedError
|
|
985
1068
|
});
|
|
@@ -1404,6 +1487,7 @@ function defineMethod(config) {
|
|
|
1404
1487
|
meta: collectLeafMeta(config),
|
|
1405
1488
|
resolvers: config.resolvers,
|
|
1406
1489
|
formatter: config.formatter,
|
|
1490
|
+
annotator: config.annotator,
|
|
1407
1491
|
output: config.output,
|
|
1408
1492
|
positional: config.positional,
|
|
1409
1493
|
setup: config.setup,
|
|
@@ -1563,7 +1647,8 @@ function defineHook(config) {
|
|
|
1563
1647
|
setup: config.setup,
|
|
1564
1648
|
dispose: config.dispose,
|
|
1565
1649
|
wrap: config.wrap,
|
|
1566
|
-
observe: config.observe
|
|
1650
|
+
observe: config.observe,
|
|
1651
|
+
annotator: config.annotator
|
|
1567
1652
|
};
|
|
1568
1653
|
}
|
|
1569
1654
|
function declarePlugin(config) {
|
|
@@ -2002,7 +2087,14 @@ function collectPlugins(root, materialized = /* @__PURE__ */ new Set(), configur
|
|
|
2002
2087
|
}
|
|
2003
2088
|
return byId;
|
|
2004
2089
|
}
|
|
2005
|
-
function bindValue(
|
|
2090
|
+
function bindValue({
|
|
2091
|
+
target,
|
|
2092
|
+
key,
|
|
2093
|
+
entry,
|
|
2094
|
+
bindMode = "surface",
|
|
2095
|
+
ctx,
|
|
2096
|
+
frameworkOrigin = false
|
|
2097
|
+
}) {
|
|
2006
2098
|
if (entry.pluginType === "property" && entry.getValue) {
|
|
2007
2099
|
Object.defineProperty(target, key, {
|
|
2008
2100
|
get: entry.getValue,
|
|
@@ -2010,7 +2102,7 @@ function bindValue(target, key, entry, callType = "surface", ctx) {
|
|
|
2010
2102
|
configurable: true
|
|
2011
2103
|
});
|
|
2012
2104
|
} else {
|
|
2013
|
-
const value =
|
|
2105
|
+
const value = bindMode === "internal" && entry.pluginType === "method" ? entry.bindInternal?.({ ctx, frameworkOrigin }) ?? entry.internalValue ?? entry.value : entry.value;
|
|
2014
2106
|
Object.defineProperty(target, key, {
|
|
2015
2107
|
value,
|
|
2016
2108
|
writable: true,
|
|
@@ -2028,7 +2120,12 @@ function buildSurface(context, ...maps) {
|
|
|
2028
2120
|
sdk[CONTEXT] = context;
|
|
2029
2121
|
return sdk;
|
|
2030
2122
|
}
|
|
2031
|
-
function buildImports(
|
|
2123
|
+
function buildImports({
|
|
2124
|
+
plugins,
|
|
2125
|
+
importBindings,
|
|
2126
|
+
ctx,
|
|
2127
|
+
frameworkOrigin = false
|
|
2128
|
+
}) {
|
|
2032
2129
|
const imports = {};
|
|
2033
2130
|
for (const { binding, id, optional } of importBindings) {
|
|
2034
2131
|
const entry = plugins[id];
|
|
@@ -2041,10 +2138,31 @@ function buildImports(plugins, importBindings, ctx) {
|
|
|
2041
2138
|
});
|
|
2042
2139
|
continue;
|
|
2043
2140
|
}
|
|
2044
|
-
bindValue(
|
|
2141
|
+
bindValue({
|
|
2142
|
+
target: imports,
|
|
2143
|
+
key: binding,
|
|
2144
|
+
entry,
|
|
2145
|
+
bindMode: "internal",
|
|
2146
|
+
ctx,
|
|
2147
|
+
frameworkOrigin
|
|
2148
|
+
});
|
|
2045
2149
|
}
|
|
2046
2150
|
return imports;
|
|
2047
2151
|
}
|
|
2152
|
+
function bindInternalTwin({
|
|
2153
|
+
ctx,
|
|
2154
|
+
frameworkOrigin,
|
|
2155
|
+
withContext,
|
|
2156
|
+
internalValue
|
|
2157
|
+
}) {
|
|
2158
|
+
if (ctx) {
|
|
2159
|
+
return (...args) => withContext(childCallContext(ctx))(...args);
|
|
2160
|
+
}
|
|
2161
|
+
if (frameworkOrigin) {
|
|
2162
|
+
return (...args) => withContext(rootCallContext({ callOrigin: "internal" }))(...args);
|
|
2163
|
+
}
|
|
2164
|
+
return internalValue;
|
|
2165
|
+
}
|
|
2048
2166
|
function mirrorLegacyRootKeys(context, rootKeys, meta) {
|
|
2049
2167
|
const exports = {};
|
|
2050
2168
|
for (const [name, value] of Object.entries(rootKeys)) {
|
|
@@ -2108,7 +2226,11 @@ function bindResolver(resolver, plugins) {
|
|
|
2108
2226
|
case "info":
|
|
2109
2227
|
return { type: "info", text: resolver.text };
|
|
2110
2228
|
case "object": {
|
|
2111
|
-
const imports = buildImports(
|
|
2229
|
+
const imports = buildImports({
|
|
2230
|
+
plugins,
|
|
2231
|
+
importBindings: resolver.importBindings,
|
|
2232
|
+
frameworkOrigin: true
|
|
2233
|
+
});
|
|
2112
2234
|
const bound = {
|
|
2113
2235
|
type: "object",
|
|
2114
2236
|
requireParameters: resolver.requireParameters
|
|
@@ -2149,7 +2271,11 @@ function bindResolver(resolver, plugins) {
|
|
|
2149
2271
|
return bound;
|
|
2150
2272
|
}
|
|
2151
2273
|
case "dynamic": {
|
|
2152
|
-
const imports = buildImports(
|
|
2274
|
+
const imports = buildImports({
|
|
2275
|
+
plugins,
|
|
2276
|
+
importBindings: resolver.importBindings,
|
|
2277
|
+
frameworkOrigin: true
|
|
2278
|
+
});
|
|
2153
2279
|
const {
|
|
2154
2280
|
getContext: getContext2,
|
|
2155
2281
|
listItems,
|
|
@@ -2204,7 +2330,11 @@ function bindDefinitions(definitions, plugins) {
|
|
|
2204
2330
|
return out;
|
|
2205
2331
|
}
|
|
2206
2332
|
function bindFormatter(formatter, plugins) {
|
|
2207
|
-
const imports = buildImports(
|
|
2333
|
+
const imports = buildImports({
|
|
2334
|
+
plugins,
|
|
2335
|
+
importBindings: formatter.importBindings,
|
|
2336
|
+
frameworkOrigin: true
|
|
2337
|
+
});
|
|
2208
2338
|
const bound = { format: formatter.format };
|
|
2209
2339
|
const { getContext: getContext2 } = formatter;
|
|
2210
2340
|
if (getContext2)
|
|
@@ -2292,17 +2422,32 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2292
2422
|
// Replaced below; never called.
|
|
2293
2423
|
value: () => void 0
|
|
2294
2424
|
};
|
|
2295
|
-
const callRun = (input, ctx) =>
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2425
|
+
const callRun = (input, ctx) => {
|
|
2426
|
+
const callContext = ctx ?? rootCallContext();
|
|
2427
|
+
return descriptor.run({
|
|
2428
|
+
imports: buildImports({
|
|
2429
|
+
plugins,
|
|
2430
|
+
importBindings: descriptor.importBindings,
|
|
2431
|
+
ctx: callContext
|
|
2432
|
+
}),
|
|
2433
|
+
state: states.get(id),
|
|
2434
|
+
input,
|
|
2435
|
+
callContext,
|
|
2436
|
+
annotate: (metadata) => {
|
|
2437
|
+
Object.assign(callContext.annotations, metadata);
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
};
|
|
2300
2441
|
const fold = (coreFn) => (input, ctx) => {
|
|
2301
2442
|
let next = (i) => coreFn(i, ctx);
|
|
2302
2443
|
for (const wrap of entry.chain) {
|
|
2303
2444
|
const inner = next;
|
|
2304
2445
|
next = (i) => wrap.run({
|
|
2305
|
-
imports: buildImports(
|
|
2446
|
+
imports: buildImports({
|
|
2447
|
+
plugins,
|
|
2448
|
+
importBindings: wrap.owner.importBindings,
|
|
2449
|
+
ctx
|
|
2450
|
+
}),
|
|
2306
2451
|
next: inner,
|
|
2307
2452
|
input: i,
|
|
2308
2453
|
// Overwritten by the chain item's own closure with the owning
|
|
@@ -2313,6 +2458,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2313
2458
|
return next(input);
|
|
2314
2459
|
};
|
|
2315
2460
|
const sdk = { context };
|
|
2461
|
+
const methodAnnotator = descriptor.annotator;
|
|
2462
|
+
const boundAnnotator = methodAnnotator ? (input) => methodAnnotator({ input }) : void 0;
|
|
2316
2463
|
if (out.type === "list") {
|
|
2317
2464
|
entry.value = createPaginatedFunction(
|
|
2318
2465
|
fold(callRun),
|
|
@@ -2322,6 +2469,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2322
2469
|
name: descriptor.name,
|
|
2323
2470
|
defaultPageSize: out.defaultPageSize,
|
|
2324
2471
|
adaptPage: out.adaptPage,
|
|
2472
|
+
annotator: boundAnnotator,
|
|
2325
2473
|
getDeprecation: () => entry.meta?.deprecation
|
|
2326
2474
|
}
|
|
2327
2475
|
);
|
|
@@ -2333,6 +2481,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2333
2481
|
sdk,
|
|
2334
2482
|
schema: descriptor.inputSchema,
|
|
2335
2483
|
name: descriptor.name,
|
|
2484
|
+
annotator: boundAnnotator,
|
|
2336
2485
|
getDeprecation: () => entry.meta?.deprecation
|
|
2337
2486
|
}
|
|
2338
2487
|
);
|
|
@@ -2344,6 +2493,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2344
2493
|
name: descriptor.name,
|
|
2345
2494
|
schema: descriptor.skipInputValidation ? void 0 : descriptor.inputSchema,
|
|
2346
2495
|
positional: descriptor.positional,
|
|
2496
|
+
annotator: boundAnnotator,
|
|
2347
2497
|
// The boundary reads the deprecation LIVE off the entry, so a
|
|
2348
2498
|
// deprecation merged after build (defineMethodOverride, addPlugin)
|
|
2349
2499
|
// fires too.
|
|
@@ -2364,12 +2514,22 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2364
2514
|
const internalValue = (...args) => canonicalValue(pack(args), INTERNAL_CALL);
|
|
2365
2515
|
entry.value = (...args) => canonicalValue(pack(args));
|
|
2366
2516
|
entry.internalValue = internalValue;
|
|
2367
|
-
entry.bindInternal = (
|
|
2517
|
+
entry.bindInternal = (opts) => bindInternalTwin({
|
|
2518
|
+
...opts,
|
|
2519
|
+
withContext: (context2) => {
|
|
2520
|
+
return (...args) => canonicalValue(pack(args), context2);
|
|
2521
|
+
},
|
|
2522
|
+
internalValue
|
|
2523
|
+
});
|
|
2368
2524
|
entry.positional = names;
|
|
2369
2525
|
} else {
|
|
2370
2526
|
const internalValue = (input) => canonicalValue(input, INTERNAL_CALL);
|
|
2371
2527
|
entry.internalValue = internalValue;
|
|
2372
|
-
entry.bindInternal = (
|
|
2528
|
+
entry.bindInternal = (opts) => bindInternalTwin({
|
|
2529
|
+
...opts,
|
|
2530
|
+
withContext: (context2) => (input) => canonicalValue(input, context2),
|
|
2531
|
+
internalValue
|
|
2532
|
+
});
|
|
2373
2533
|
}
|
|
2374
2534
|
plugins[id] = entry;
|
|
2375
2535
|
}
|
|
@@ -2395,8 +2555,14 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2395
2555
|
if (!dispose) return;
|
|
2396
2556
|
context.disposers?.push({
|
|
2397
2557
|
id,
|
|
2558
|
+
// Teardown is framework-internal: an SDK method a `dispose` calls runs
|
|
2559
|
+
// on an internal-origin root (dropped from telemetry).
|
|
2398
2560
|
dispose: (input) => dispose({
|
|
2399
|
-
imports: buildImports(
|
|
2561
|
+
imports: buildImports({
|
|
2562
|
+
plugins,
|
|
2563
|
+
importBindings: descriptor.importBindings,
|
|
2564
|
+
frameworkOrigin: true
|
|
2565
|
+
}),
|
|
2400
2566
|
state: states.get(id),
|
|
2401
2567
|
input
|
|
2402
2568
|
})
|
|
@@ -2406,7 +2572,10 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2406
2572
|
states.set(
|
|
2407
2573
|
id,
|
|
2408
2574
|
descriptor.setup ? descriptor.setup({
|
|
2409
|
-
imports: buildImports(
|
|
2575
|
+
imports: buildImports({
|
|
2576
|
+
plugins,
|
|
2577
|
+
importBindings: descriptor.importBindings
|
|
2578
|
+
})
|
|
2410
2579
|
}) : void 0
|
|
2411
2580
|
);
|
|
2412
2581
|
recordDisposer();
|
|
@@ -2418,14 +2587,20 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2418
2587
|
states.set(
|
|
2419
2588
|
id,
|
|
2420
2589
|
descriptor.setup ? descriptor.setup({
|
|
2421
|
-
imports: buildImports(
|
|
2590
|
+
imports: buildImports({
|
|
2591
|
+
plugins,
|
|
2592
|
+
importBindings: descriptor.importBindings
|
|
2593
|
+
})
|
|
2422
2594
|
}) : void 0
|
|
2423
2595
|
);
|
|
2424
2596
|
} else {
|
|
2425
2597
|
states.set(
|
|
2426
2598
|
id,
|
|
2427
2599
|
descriptor.setup ? descriptor.setup({
|
|
2428
|
-
imports: buildImports(
|
|
2600
|
+
imports: buildImports({
|
|
2601
|
+
plugins,
|
|
2602
|
+
importBindings: descriptor.importBindings
|
|
2603
|
+
})
|
|
2429
2604
|
}) : void 0
|
|
2430
2605
|
);
|
|
2431
2606
|
if (descriptor.privileged) {
|
|
@@ -2443,7 +2618,7 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2443
2618
|
pluginType: "property",
|
|
2444
2619
|
name: descriptor.name,
|
|
2445
2620
|
getValue: () => get({
|
|
2446
|
-
imports: buildImports(plugins, importBindings),
|
|
2621
|
+
imports: buildImports({ plugins, importBindings }),
|
|
2447
2622
|
state: states.get(id)
|
|
2448
2623
|
}),
|
|
2449
2624
|
meta: descriptor.meta,
|
|
@@ -2479,7 +2654,7 @@ function resolvePlugin(sdk, ref) {
|
|
|
2479
2654
|
return entry.getValue();
|
|
2480
2655
|
}
|
|
2481
2656
|
if (entry.pluginType === "method" && entry.internalValue) {
|
|
2482
|
-
return entry.internalValue;
|
|
2657
|
+
return entry.bindInternal?.({ frameworkOrigin: true }) ?? entry.internalValue;
|
|
2483
2658
|
}
|
|
2484
2659
|
return entry.value;
|
|
2485
2660
|
}
|
|
@@ -2514,7 +2689,7 @@ function resolveAggregates(descriptors, context) {
|
|
|
2514
2689
|
if (descriptor.pluginType !== "aggregate") continue;
|
|
2515
2690
|
const exports = {};
|
|
2516
2691
|
for (const [binding, child] of Object.entries(descriptor.exports)) {
|
|
2517
|
-
bindValue(exports, binding, plugins[child.id]);
|
|
2692
|
+
bindValue({ target: exports, key: binding, entry: plugins[child.id] });
|
|
2518
2693
|
}
|
|
2519
2694
|
plugins[id] = { pluginType: "aggregate", name: descriptor.name, exports };
|
|
2520
2695
|
}
|
|
@@ -2557,23 +2732,39 @@ function assembleHooks(descriptors, context, states) {
|
|
|
2557
2732
|
const plugins = context.plugins;
|
|
2558
2733
|
for (const id of topoOrder(descriptors)) {
|
|
2559
2734
|
const descriptor = descriptors.get(id);
|
|
2560
|
-
if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe) {
|
|
2735
|
+
if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe && !descriptor.annotator) {
|
|
2561
2736
|
continue;
|
|
2562
2737
|
}
|
|
2563
|
-
const { observe } = descriptor;
|
|
2564
|
-
const imports = buildImports(plugins, descriptor.importBindings);
|
|
2738
|
+
const { observe, annotator } = descriptor;
|
|
2565
2739
|
const state = states.get(id);
|
|
2566
2740
|
const contributed = {};
|
|
2567
|
-
if (observe
|
|
2568
|
-
const
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2741
|
+
if (observe?.onMethodStart || observe?.onMethodEnd) {
|
|
2742
|
+
const imports = buildImports({
|
|
2743
|
+
plugins,
|
|
2744
|
+
importBindings: descriptor.importBindings,
|
|
2745
|
+
frameworkOrigin: true
|
|
2746
|
+
});
|
|
2747
|
+
if (observe.onMethodStart) {
|
|
2748
|
+
const onStart = observe.onMethodStart;
|
|
2749
|
+
contributed.onMethodStart = (input) => {
|
|
2750
|
+
runIsolatedObserver(() => onStart({ imports, input, state }));
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
if (observe.onMethodEnd) {
|
|
2754
|
+
const onEnd = observe.onMethodEnd;
|
|
2755
|
+
contributed.onMethodEnd = (input) => {
|
|
2756
|
+
runIsolatedObserver(() => onEnd({ imports, input, state }));
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2572
2759
|
}
|
|
2573
|
-
if (
|
|
2574
|
-
const
|
|
2575
|
-
contributed.
|
|
2576
|
-
|
|
2760
|
+
if (annotator) {
|
|
2761
|
+
const annotatorFn = annotator;
|
|
2762
|
+
contributed.annotator = ({ methodName, input }) => {
|
|
2763
|
+
try {
|
|
2764
|
+
return annotatorFn({ methodName, input, state });
|
|
2765
|
+
} catch {
|
|
2766
|
+
return {};
|
|
2767
|
+
}
|
|
2577
2768
|
};
|
|
2578
2769
|
}
|
|
2579
2770
|
context.hooks = buildHooks(context.hooks, contributed);
|
|
@@ -2607,7 +2798,11 @@ function createSdk(root, options) {
|
|
|
2607
2798
|
pluginSurface = plugins2[plugin.id].exports;
|
|
2608
2799
|
} else {
|
|
2609
2800
|
pluginSurface = {};
|
|
2610
|
-
bindValue(
|
|
2801
|
+
bindValue({
|
|
2802
|
+
target: pluginSurface,
|
|
2803
|
+
key: plugin.name,
|
|
2804
|
+
entry: plugins2[plugin.id]
|
|
2805
|
+
});
|
|
2611
2806
|
}
|
|
2612
2807
|
for (const key of Object.keys(legacyExports)) context.surface[key] = key;
|
|
2613
2808
|
if (plugin.pluginType === "aggregate") {
|
|
@@ -2624,7 +2819,7 @@ function createSdk(root, options) {
|
|
|
2624
2819
|
if (root.pluginType === "method" || root.pluginType === "property") {
|
|
2625
2820
|
context.surface[root.name] = root.id;
|
|
2626
2821
|
const sdk = buildSurface(context);
|
|
2627
|
-
bindValue(sdk, root.name, plugins[root.id]);
|
|
2822
|
+
bindValue({ target: sdk, key: root.name, entry: plugins[root.id] });
|
|
2628
2823
|
return sdk;
|
|
2629
2824
|
}
|
|
2630
2825
|
if (root.pluginType === "aggregate")
|
|
@@ -2656,7 +2851,7 @@ function addModelPlugin(sdk, plugin, options = {}) {
|
|
|
2656
2851
|
context.surface[binding] = child.id;
|
|
2657
2852
|
}
|
|
2658
2853
|
} else {
|
|
2659
|
-
bindValue(sdk, plugin.name, entry);
|
|
2854
|
+
bindValue({ target: sdk, key: plugin.name, entry });
|
|
2660
2855
|
context.surface[plugin.name] = plugin.id;
|
|
2661
2856
|
}
|
|
2662
2857
|
}
|