@zapier/kitcore 0.10.1 → 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 +12 -0
- package/README.md +34 -3
- package/dist/index.cjs +249 -78
- 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 +249 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -197,12 +197,19 @@ function composeVoid(existing, added) {
|
|
|
197
197
|
isolated.add(composed);
|
|
198
198
|
return composed;
|
|
199
199
|
}
|
|
200
|
+
function composeAnnotators(existing, added) {
|
|
201
|
+
if (!existing) return added;
|
|
202
|
+
if (!added) return existing;
|
|
203
|
+
return (ctx) => ({ ...existing(ctx), ...added(ctx) });
|
|
204
|
+
}
|
|
200
205
|
function buildHooks(existing, added) {
|
|
201
206
|
const result = {};
|
|
202
207
|
const start2 = composeVoid(existing.onMethodStart, added.onMethodStart);
|
|
203
208
|
if (start2) result.onMethodStart = start2;
|
|
204
209
|
const end = composeVoid(existing.onMethodEnd, added.onMethodEnd);
|
|
205
210
|
if (end) result.onMethodEnd = end;
|
|
211
|
+
const annotator = composeAnnotators(existing.annotator, added.annotator);
|
|
212
|
+
if (annotator) result.annotator = annotator;
|
|
206
213
|
return result;
|
|
207
214
|
}
|
|
208
215
|
|
|
@@ -677,11 +684,14 @@ function generateCallId() {
|
|
|
677
684
|
}
|
|
678
685
|
return null;
|
|
679
686
|
}
|
|
680
|
-
function rootCallContext(
|
|
687
|
+
function rootCallContext({
|
|
688
|
+
callOrigin = "surface"
|
|
689
|
+
} = {}) {
|
|
681
690
|
return {
|
|
682
691
|
callId: generateCallId(),
|
|
683
692
|
depth: 0,
|
|
684
693
|
annotations: {},
|
|
694
|
+
callOrigin,
|
|
685
695
|
[CALL_CONTEXT_BRAND]: true
|
|
686
696
|
};
|
|
687
697
|
}
|
|
@@ -690,6 +700,7 @@ function childCallContext(parent) {
|
|
|
690
700
|
callId: parent.callId,
|
|
691
701
|
depth: parent.depth + 1,
|
|
692
702
|
annotations: {},
|
|
703
|
+
callOrigin: parent.callOrigin,
|
|
693
704
|
[CALL_CONTEXT_BRAND]: true
|
|
694
705
|
};
|
|
695
706
|
}
|
|
@@ -715,6 +726,28 @@ var INTERNAL_CALL = Symbol("kitcore.internalCall");
|
|
|
715
726
|
function resolveCallContext(secondArg) {
|
|
716
727
|
return isCallContext(secondArg) ? secondArg : rootCallContext();
|
|
717
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
|
+
}
|
|
718
751
|
function signalDeprecation(context, methodName, getDeprecation) {
|
|
719
752
|
if (isInsideObserver()) return;
|
|
720
753
|
const deprecation = getDeprecation?.();
|
|
@@ -740,7 +773,7 @@ function normalizeError(error, adaptError) {
|
|
|
740
773
|
);
|
|
741
774
|
}
|
|
742
775
|
function createFunction(coreFn, options) {
|
|
743
|
-
const { sdk, schema, name, getDeprecation } = options;
|
|
776
|
+
const { sdk, schema, name, annotator, getDeprecation } = options;
|
|
744
777
|
const functionName = name || coreFn.name;
|
|
745
778
|
const namedFunctions = {
|
|
746
779
|
[functionName]: async function(callOptions) {
|
|
@@ -754,14 +787,26 @@ function createFunction(coreFn, options) {
|
|
|
754
787
|
const normalizedOptions = callOptions ?? {};
|
|
755
788
|
const args = [normalizedOptions];
|
|
756
789
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
757
|
-
const
|
|
790
|
+
const insideObserver = isInsideObserver();
|
|
791
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
758
792
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
759
|
-
|
|
793
|
+
applyAnnotations({
|
|
794
|
+
context,
|
|
795
|
+
methodName: functionName,
|
|
796
|
+
input: normalizedOptions,
|
|
797
|
+
hookAnnotator: hooks?.annotator,
|
|
798
|
+
methodAnnotator: annotator
|
|
799
|
+
});
|
|
800
|
+
const hookBase = {
|
|
760
801
|
methodName: functionName,
|
|
761
802
|
args,
|
|
762
803
|
isPaginated: false,
|
|
763
|
-
depth
|
|
764
|
-
|
|
804
|
+
depth,
|
|
805
|
+
callId: context.callId,
|
|
806
|
+
callOrigin: context.callOrigin,
|
|
807
|
+
annotations: context.annotations
|
|
808
|
+
};
|
|
809
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
765
810
|
try {
|
|
766
811
|
let result;
|
|
767
812
|
if (schema) {
|
|
@@ -783,20 +828,14 @@ function createFunction(coreFn, options) {
|
|
|
783
828
|
result = await coreFn(normalizedOptions, context);
|
|
784
829
|
}
|
|
785
830
|
hooks?.onMethodEnd?.({
|
|
786
|
-
|
|
787
|
-
args,
|
|
788
|
-
isPaginated: false,
|
|
789
|
-
depth,
|
|
831
|
+
...hookBase,
|
|
790
832
|
durationMs: Date.now() - startTime
|
|
791
833
|
});
|
|
792
834
|
return result;
|
|
793
835
|
} catch (error) {
|
|
794
836
|
const normalizedError = normalizeError(error, adaptError);
|
|
795
837
|
hooks?.onMethodEnd?.({
|
|
796
|
-
|
|
797
|
-
args,
|
|
798
|
-
isPaginated: false,
|
|
799
|
-
depth,
|
|
838
|
+
...hookBase,
|
|
800
839
|
durationMs: Date.now() - startTime,
|
|
801
840
|
error: normalizedError
|
|
802
841
|
});
|
|
@@ -808,7 +847,7 @@ function createFunction(coreFn, options) {
|
|
|
808
847
|
return namedFunctions[functionName];
|
|
809
848
|
}
|
|
810
849
|
function createRawFunction(coreFn, options) {
|
|
811
|
-
const { sdk, name, schema, positional, getDeprecation } = options;
|
|
850
|
+
const { sdk, name, schema, positional, annotator, getDeprecation } = options;
|
|
812
851
|
return function(rawInput) {
|
|
813
852
|
const internal = arguments[1];
|
|
814
853
|
const context = resolveCallContext(internal);
|
|
@@ -818,23 +857,32 @@ function createRawFunction(coreFn, options) {
|
|
|
818
857
|
return runInMethodScope(() => {
|
|
819
858
|
const startTime = Date.now();
|
|
820
859
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
821
|
-
const
|
|
860
|
+
const insideObserver = isInsideObserver();
|
|
861
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
822
862
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
823
863
|
const input = schema ? rawInput ?? {} : rawInput;
|
|
864
|
+
applyAnnotations({
|
|
865
|
+
context,
|
|
866
|
+
methodName: name,
|
|
867
|
+
input,
|
|
868
|
+
hookAnnotator: hooks?.annotator,
|
|
869
|
+
methodAnnotator: annotator
|
|
870
|
+
});
|
|
824
871
|
const record = input;
|
|
825
872
|
const args = positional ? positional.filter((key) => record?.[key] !== void 0).map((key) => record?.[key]) : [input];
|
|
826
|
-
|
|
873
|
+
const hookBase = {
|
|
827
874
|
methodName: name,
|
|
828
875
|
args,
|
|
829
876
|
isPaginated: false,
|
|
830
|
-
depth
|
|
831
|
-
|
|
877
|
+
depth,
|
|
878
|
+
callId: context.callId,
|
|
879
|
+
callOrigin: context.callOrigin,
|
|
880
|
+
annotations: context.annotations
|
|
881
|
+
};
|
|
882
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
832
883
|
const fireEnd = (error) => {
|
|
833
884
|
hooks?.onMethodEnd?.({
|
|
834
|
-
|
|
835
|
-
args,
|
|
836
|
-
isPaginated: false,
|
|
837
|
-
depth,
|
|
885
|
+
...hookBase,
|
|
838
886
|
durationMs: Date.now() - startTime,
|
|
839
887
|
...error ? { error } : {}
|
|
840
888
|
});
|
|
@@ -901,7 +949,15 @@ function createPageFunction(coreFn, {
|
|
|
901
949
|
return namedFunctions[functionName];
|
|
902
950
|
}
|
|
903
951
|
function createPaginatedFunction(coreFn, options) {
|
|
904
|
-
const {
|
|
952
|
+
const {
|
|
953
|
+
sdk,
|
|
954
|
+
schema,
|
|
955
|
+
name,
|
|
956
|
+
defaultPageSize,
|
|
957
|
+
adaptPage,
|
|
958
|
+
annotator,
|
|
959
|
+
getDeprecation
|
|
960
|
+
} = options;
|
|
905
961
|
const pageFunction = createPageFunction(coreFn, { sdk, adaptPage });
|
|
906
962
|
const functionName = name || coreFn.name;
|
|
907
963
|
const namedFunctions = {
|
|
@@ -916,14 +972,26 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
916
972
|
const normalizedOptions = callOptions ?? {};
|
|
917
973
|
const args = [normalizedOptions];
|
|
918
974
|
const depth = Math.max(context.depth, getCurrentDepth());
|
|
919
|
-
const
|
|
975
|
+
const insideObserver = isInsideObserver();
|
|
976
|
+
const hooks = insideObserver ? void 0 : sdk.context.hooks;
|
|
920
977
|
const adaptError = resolveCoreOptions(sdk.context)?.adaptError;
|
|
921
|
-
|
|
978
|
+
applyAnnotations({
|
|
979
|
+
context,
|
|
980
|
+
methodName: functionName,
|
|
981
|
+
input: normalizedOptions,
|
|
982
|
+
hookAnnotator: hooks?.annotator,
|
|
983
|
+
methodAnnotator: annotator
|
|
984
|
+
});
|
|
985
|
+
const hookBase = {
|
|
922
986
|
methodName: functionName,
|
|
923
987
|
args,
|
|
924
988
|
isPaginated: true,
|
|
925
|
-
depth
|
|
926
|
-
|
|
989
|
+
depth,
|
|
990
|
+
callId: context.callId,
|
|
991
|
+
callOrigin: context.callOrigin,
|
|
992
|
+
annotations: context.annotations
|
|
993
|
+
};
|
|
994
|
+
hooks?.onMethodStart?.({ ...hookBase });
|
|
927
995
|
try {
|
|
928
996
|
const validatedOptions = {
|
|
929
997
|
...normalizedOptions,
|
|
@@ -949,19 +1017,13 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
949
1017
|
firstPagePromise.then(
|
|
950
1018
|
() => {
|
|
951
1019
|
hooks.onMethodEnd({
|
|
952
|
-
|
|
953
|
-
args,
|
|
954
|
-
isPaginated: true,
|
|
955
|
-
depth,
|
|
1020
|
+
...hookBase,
|
|
956
1021
|
durationMs: Date.now() - startTime
|
|
957
1022
|
});
|
|
958
1023
|
},
|
|
959
1024
|
(error) => {
|
|
960
1025
|
hooks.onMethodEnd({
|
|
961
|
-
|
|
962
|
-
args,
|
|
963
|
-
isPaginated: true,
|
|
964
|
-
depth,
|
|
1026
|
+
...hookBase,
|
|
965
1027
|
durationMs: Date.now() - startTime,
|
|
966
1028
|
error: error instanceof Error ? error : new Error(String(error))
|
|
967
1029
|
});
|
|
@@ -1000,10 +1062,7 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
1000
1062
|
} catch (error) {
|
|
1001
1063
|
const normalizedError = normalizeError(error, adaptError);
|
|
1002
1064
|
hooks?.onMethodEnd?.({
|
|
1003
|
-
|
|
1004
|
-
args,
|
|
1005
|
-
isPaginated: true,
|
|
1006
|
-
depth,
|
|
1065
|
+
...hookBase,
|
|
1007
1066
|
durationMs: Date.now() - startTime,
|
|
1008
1067
|
error: normalizedError
|
|
1009
1068
|
});
|
|
@@ -1428,6 +1487,7 @@ function defineMethod(config) {
|
|
|
1428
1487
|
meta: collectLeafMeta(config),
|
|
1429
1488
|
resolvers: config.resolvers,
|
|
1430
1489
|
formatter: config.formatter,
|
|
1490
|
+
annotator: config.annotator,
|
|
1431
1491
|
output: config.output,
|
|
1432
1492
|
positional: config.positional,
|
|
1433
1493
|
setup: config.setup,
|
|
@@ -1587,7 +1647,8 @@ function defineHook(config) {
|
|
|
1587
1647
|
setup: config.setup,
|
|
1588
1648
|
dispose: config.dispose,
|
|
1589
1649
|
wrap: config.wrap,
|
|
1590
|
-
observe: config.observe
|
|
1650
|
+
observe: config.observe,
|
|
1651
|
+
annotator: config.annotator
|
|
1591
1652
|
};
|
|
1592
1653
|
}
|
|
1593
1654
|
function declarePlugin(config) {
|
|
@@ -2026,7 +2087,14 @@ function collectPlugins(root, materialized = /* @__PURE__ */ new Set(), configur
|
|
|
2026
2087
|
}
|
|
2027
2088
|
return byId;
|
|
2028
2089
|
}
|
|
2029
|
-
function bindValue(
|
|
2090
|
+
function bindValue({
|
|
2091
|
+
target,
|
|
2092
|
+
key,
|
|
2093
|
+
entry,
|
|
2094
|
+
bindMode = "surface",
|
|
2095
|
+
ctx,
|
|
2096
|
+
frameworkOrigin = false
|
|
2097
|
+
}) {
|
|
2030
2098
|
if (entry.pluginType === "property" && entry.getValue) {
|
|
2031
2099
|
Object.defineProperty(target, key, {
|
|
2032
2100
|
get: entry.getValue,
|
|
@@ -2034,7 +2102,7 @@ function bindValue(target, key, entry, callType = "surface", ctx) {
|
|
|
2034
2102
|
configurable: true
|
|
2035
2103
|
});
|
|
2036
2104
|
} else {
|
|
2037
|
-
const value =
|
|
2105
|
+
const value = bindMode === "internal" && entry.pluginType === "method" ? entry.bindInternal?.({ ctx, frameworkOrigin }) ?? entry.internalValue ?? entry.value : entry.value;
|
|
2038
2106
|
Object.defineProperty(target, key, {
|
|
2039
2107
|
value,
|
|
2040
2108
|
writable: true,
|
|
@@ -2052,7 +2120,12 @@ function buildSurface(context, ...maps) {
|
|
|
2052
2120
|
sdk[CONTEXT] = context;
|
|
2053
2121
|
return sdk;
|
|
2054
2122
|
}
|
|
2055
|
-
function buildImports(
|
|
2123
|
+
function buildImports({
|
|
2124
|
+
plugins,
|
|
2125
|
+
importBindings,
|
|
2126
|
+
ctx,
|
|
2127
|
+
frameworkOrigin = false
|
|
2128
|
+
}) {
|
|
2056
2129
|
const imports = {};
|
|
2057
2130
|
for (const { binding, id, optional } of importBindings) {
|
|
2058
2131
|
const entry = plugins[id];
|
|
@@ -2065,10 +2138,31 @@ function buildImports(plugins, importBindings, ctx) {
|
|
|
2065
2138
|
});
|
|
2066
2139
|
continue;
|
|
2067
2140
|
}
|
|
2068
|
-
bindValue(
|
|
2141
|
+
bindValue({
|
|
2142
|
+
target: imports,
|
|
2143
|
+
key: binding,
|
|
2144
|
+
entry,
|
|
2145
|
+
bindMode: "internal",
|
|
2146
|
+
ctx,
|
|
2147
|
+
frameworkOrigin
|
|
2148
|
+
});
|
|
2069
2149
|
}
|
|
2070
2150
|
return imports;
|
|
2071
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
|
+
}
|
|
2072
2166
|
function mirrorLegacyRootKeys(context, rootKeys, meta) {
|
|
2073
2167
|
const exports = {};
|
|
2074
2168
|
for (const [name, value] of Object.entries(rootKeys)) {
|
|
@@ -2132,7 +2226,11 @@ function bindResolver(resolver, plugins) {
|
|
|
2132
2226
|
case "info":
|
|
2133
2227
|
return { type: "info", text: resolver.text };
|
|
2134
2228
|
case "object": {
|
|
2135
|
-
const imports = buildImports(
|
|
2229
|
+
const imports = buildImports({
|
|
2230
|
+
plugins,
|
|
2231
|
+
importBindings: resolver.importBindings,
|
|
2232
|
+
frameworkOrigin: true
|
|
2233
|
+
});
|
|
2136
2234
|
const bound = {
|
|
2137
2235
|
type: "object",
|
|
2138
2236
|
requireParameters: resolver.requireParameters
|
|
@@ -2173,7 +2271,11 @@ function bindResolver(resolver, plugins) {
|
|
|
2173
2271
|
return bound;
|
|
2174
2272
|
}
|
|
2175
2273
|
case "dynamic": {
|
|
2176
|
-
const imports = buildImports(
|
|
2274
|
+
const imports = buildImports({
|
|
2275
|
+
plugins,
|
|
2276
|
+
importBindings: resolver.importBindings,
|
|
2277
|
+
frameworkOrigin: true
|
|
2278
|
+
});
|
|
2177
2279
|
const {
|
|
2178
2280
|
getContext: getContext2,
|
|
2179
2281
|
listItems,
|
|
@@ -2228,7 +2330,11 @@ function bindDefinitions(definitions, plugins) {
|
|
|
2228
2330
|
return out;
|
|
2229
2331
|
}
|
|
2230
2332
|
function bindFormatter(formatter, plugins) {
|
|
2231
|
-
const imports = buildImports(
|
|
2333
|
+
const imports = buildImports({
|
|
2334
|
+
plugins,
|
|
2335
|
+
importBindings: formatter.importBindings,
|
|
2336
|
+
frameworkOrigin: true
|
|
2337
|
+
});
|
|
2232
2338
|
const bound = { format: formatter.format };
|
|
2233
2339
|
const { getContext: getContext2 } = formatter;
|
|
2234
2340
|
if (getContext2)
|
|
@@ -2316,17 +2422,32 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2316
2422
|
// Replaced below; never called.
|
|
2317
2423
|
value: () => void 0
|
|
2318
2424
|
};
|
|
2319
|
-
const callRun = (input, ctx) =>
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
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
|
+
};
|
|
2324
2441
|
const fold = (coreFn) => (input, ctx) => {
|
|
2325
2442
|
let next = (i) => coreFn(i, ctx);
|
|
2326
2443
|
for (const wrap of entry.chain) {
|
|
2327
2444
|
const inner = next;
|
|
2328
2445
|
next = (i) => wrap.run({
|
|
2329
|
-
imports: buildImports(
|
|
2446
|
+
imports: buildImports({
|
|
2447
|
+
plugins,
|
|
2448
|
+
importBindings: wrap.owner.importBindings,
|
|
2449
|
+
ctx
|
|
2450
|
+
}),
|
|
2330
2451
|
next: inner,
|
|
2331
2452
|
input: i,
|
|
2332
2453
|
// Overwritten by the chain item's own closure with the owning
|
|
@@ -2337,6 +2458,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2337
2458
|
return next(input);
|
|
2338
2459
|
};
|
|
2339
2460
|
const sdk = { context };
|
|
2461
|
+
const methodAnnotator = descriptor.annotator;
|
|
2462
|
+
const boundAnnotator = methodAnnotator ? (input) => methodAnnotator({ input }) : void 0;
|
|
2340
2463
|
if (out.type === "list") {
|
|
2341
2464
|
entry.value = createPaginatedFunction(
|
|
2342
2465
|
fold(callRun),
|
|
@@ -2346,6 +2469,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2346
2469
|
name: descriptor.name,
|
|
2347
2470
|
defaultPageSize: out.defaultPageSize,
|
|
2348
2471
|
adaptPage: out.adaptPage,
|
|
2472
|
+
annotator: boundAnnotator,
|
|
2349
2473
|
getDeprecation: () => entry.meta?.deprecation
|
|
2350
2474
|
}
|
|
2351
2475
|
);
|
|
@@ -2357,6 +2481,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2357
2481
|
sdk,
|
|
2358
2482
|
schema: descriptor.inputSchema,
|
|
2359
2483
|
name: descriptor.name,
|
|
2484
|
+
annotator: boundAnnotator,
|
|
2360
2485
|
getDeprecation: () => entry.meta?.deprecation
|
|
2361
2486
|
}
|
|
2362
2487
|
);
|
|
@@ -2368,6 +2493,7 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2368
2493
|
name: descriptor.name,
|
|
2369
2494
|
schema: descriptor.skipInputValidation ? void 0 : descriptor.inputSchema,
|
|
2370
2495
|
positional: descriptor.positional,
|
|
2496
|
+
annotator: boundAnnotator,
|
|
2371
2497
|
// The boundary reads the deprecation LIVE off the entry, so a
|
|
2372
2498
|
// deprecation merged after build (defineMethodOverride, addPlugin)
|
|
2373
2499
|
// fires too.
|
|
@@ -2388,12 +2514,22 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2388
2514
|
const internalValue = (...args) => canonicalValue(pack(args), INTERNAL_CALL);
|
|
2389
2515
|
entry.value = (...args) => canonicalValue(pack(args));
|
|
2390
2516
|
entry.internalValue = internalValue;
|
|
2391
|
-
entry.bindInternal = (
|
|
2517
|
+
entry.bindInternal = (opts) => bindInternalTwin({
|
|
2518
|
+
...opts,
|
|
2519
|
+
withContext: (context2) => {
|
|
2520
|
+
return (...args) => canonicalValue(pack(args), context2);
|
|
2521
|
+
},
|
|
2522
|
+
internalValue
|
|
2523
|
+
});
|
|
2392
2524
|
entry.positional = names;
|
|
2393
2525
|
} else {
|
|
2394
2526
|
const internalValue = (input) => canonicalValue(input, INTERNAL_CALL);
|
|
2395
2527
|
entry.internalValue = internalValue;
|
|
2396
|
-
entry.bindInternal = (
|
|
2528
|
+
entry.bindInternal = (opts) => bindInternalTwin({
|
|
2529
|
+
...opts,
|
|
2530
|
+
withContext: (context2) => (input) => canonicalValue(input, context2),
|
|
2531
|
+
internalValue
|
|
2532
|
+
});
|
|
2397
2533
|
}
|
|
2398
2534
|
plugins[id] = entry;
|
|
2399
2535
|
}
|
|
@@ -2419,8 +2555,14 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2419
2555
|
if (!dispose) return;
|
|
2420
2556
|
context.disposers?.push({
|
|
2421
2557
|
id,
|
|
2558
|
+
// Teardown is framework-internal: an SDK method a `dispose` calls runs
|
|
2559
|
+
// on an internal-origin root (dropped from telemetry).
|
|
2422
2560
|
dispose: (input) => dispose({
|
|
2423
|
-
imports: buildImports(
|
|
2561
|
+
imports: buildImports({
|
|
2562
|
+
plugins,
|
|
2563
|
+
importBindings: descriptor.importBindings,
|
|
2564
|
+
frameworkOrigin: true
|
|
2565
|
+
}),
|
|
2424
2566
|
state: states.get(id),
|
|
2425
2567
|
input
|
|
2426
2568
|
})
|
|
@@ -2430,7 +2572,10 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2430
2572
|
states.set(
|
|
2431
2573
|
id,
|
|
2432
2574
|
descriptor.setup ? descriptor.setup({
|
|
2433
|
-
imports: buildImports(
|
|
2575
|
+
imports: buildImports({
|
|
2576
|
+
plugins,
|
|
2577
|
+
importBindings: descriptor.importBindings
|
|
2578
|
+
})
|
|
2434
2579
|
}) : void 0
|
|
2435
2580
|
);
|
|
2436
2581
|
recordDisposer();
|
|
@@ -2442,14 +2587,20 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2442
2587
|
states.set(
|
|
2443
2588
|
id,
|
|
2444
2589
|
descriptor.setup ? descriptor.setup({
|
|
2445
|
-
imports: buildImports(
|
|
2590
|
+
imports: buildImports({
|
|
2591
|
+
plugins,
|
|
2592
|
+
importBindings: descriptor.importBindings
|
|
2593
|
+
})
|
|
2446
2594
|
}) : void 0
|
|
2447
2595
|
);
|
|
2448
2596
|
} else {
|
|
2449
2597
|
states.set(
|
|
2450
2598
|
id,
|
|
2451
2599
|
descriptor.setup ? descriptor.setup({
|
|
2452
|
-
imports: buildImports(
|
|
2600
|
+
imports: buildImports({
|
|
2601
|
+
plugins,
|
|
2602
|
+
importBindings: descriptor.importBindings
|
|
2603
|
+
})
|
|
2453
2604
|
}) : void 0
|
|
2454
2605
|
);
|
|
2455
2606
|
if (descriptor.privileged) {
|
|
@@ -2467,7 +2618,7 @@ function buildEagerArtifacts(descriptors, context, states) {
|
|
|
2467
2618
|
pluginType: "property",
|
|
2468
2619
|
name: descriptor.name,
|
|
2469
2620
|
getValue: () => get({
|
|
2470
|
-
imports: buildImports(plugins, importBindings),
|
|
2621
|
+
imports: buildImports({ plugins, importBindings }),
|
|
2471
2622
|
state: states.get(id)
|
|
2472
2623
|
}),
|
|
2473
2624
|
meta: descriptor.meta,
|
|
@@ -2503,7 +2654,7 @@ function resolvePlugin(sdk, ref) {
|
|
|
2503
2654
|
return entry.getValue();
|
|
2504
2655
|
}
|
|
2505
2656
|
if (entry.pluginType === "method" && entry.internalValue) {
|
|
2506
|
-
return entry.internalValue;
|
|
2657
|
+
return entry.bindInternal?.({ frameworkOrigin: true }) ?? entry.internalValue;
|
|
2507
2658
|
}
|
|
2508
2659
|
return entry.value;
|
|
2509
2660
|
}
|
|
@@ -2538,7 +2689,7 @@ function resolveAggregates(descriptors, context) {
|
|
|
2538
2689
|
if (descriptor.pluginType !== "aggregate") continue;
|
|
2539
2690
|
const exports = {};
|
|
2540
2691
|
for (const [binding, child] of Object.entries(descriptor.exports)) {
|
|
2541
|
-
bindValue(exports, binding, plugins[child.id]);
|
|
2692
|
+
bindValue({ target: exports, key: binding, entry: plugins[child.id] });
|
|
2542
2693
|
}
|
|
2543
2694
|
plugins[id] = { pluginType: "aggregate", name: descriptor.name, exports };
|
|
2544
2695
|
}
|
|
@@ -2581,23 +2732,39 @@ function assembleHooks(descriptors, context, states) {
|
|
|
2581
2732
|
const plugins = context.plugins;
|
|
2582
2733
|
for (const id of topoOrder(descriptors)) {
|
|
2583
2734
|
const descriptor = descriptors.get(id);
|
|
2584
|
-
if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe) {
|
|
2735
|
+
if (!descriptor || descriptor.pluginType !== "hook" || !descriptor.observe && !descriptor.annotator) {
|
|
2585
2736
|
continue;
|
|
2586
2737
|
}
|
|
2587
|
-
const { observe } = descriptor;
|
|
2588
|
-
const imports = buildImports(plugins, descriptor.importBindings);
|
|
2738
|
+
const { observe, annotator } = descriptor;
|
|
2589
2739
|
const state = states.get(id);
|
|
2590
2740
|
const contributed = {};
|
|
2591
|
-
if (observe
|
|
2592
|
-
const
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
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
|
+
}
|
|
2596
2759
|
}
|
|
2597
|
-
if (
|
|
2598
|
-
const
|
|
2599
|
-
contributed.
|
|
2600
|
-
|
|
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
|
+
}
|
|
2601
2768
|
};
|
|
2602
2769
|
}
|
|
2603
2770
|
context.hooks = buildHooks(context.hooks, contributed);
|
|
@@ -2631,7 +2798,11 @@ function createSdk(root, options) {
|
|
|
2631
2798
|
pluginSurface = plugins2[plugin.id].exports;
|
|
2632
2799
|
} else {
|
|
2633
2800
|
pluginSurface = {};
|
|
2634
|
-
bindValue(
|
|
2801
|
+
bindValue({
|
|
2802
|
+
target: pluginSurface,
|
|
2803
|
+
key: plugin.name,
|
|
2804
|
+
entry: plugins2[plugin.id]
|
|
2805
|
+
});
|
|
2635
2806
|
}
|
|
2636
2807
|
for (const key of Object.keys(legacyExports)) context.surface[key] = key;
|
|
2637
2808
|
if (plugin.pluginType === "aggregate") {
|
|
@@ -2648,7 +2819,7 @@ function createSdk(root, options) {
|
|
|
2648
2819
|
if (root.pluginType === "method" || root.pluginType === "property") {
|
|
2649
2820
|
context.surface[root.name] = root.id;
|
|
2650
2821
|
const sdk = buildSurface(context);
|
|
2651
|
-
bindValue(sdk, root.name, plugins[root.id]);
|
|
2822
|
+
bindValue({ target: sdk, key: root.name, entry: plugins[root.id] });
|
|
2652
2823
|
return sdk;
|
|
2653
2824
|
}
|
|
2654
2825
|
if (root.pluginType === "aggregate")
|
|
@@ -2680,7 +2851,7 @@ function addModelPlugin(sdk, plugin, options = {}) {
|
|
|
2680
2851
|
context.surface[binding] = child.id;
|
|
2681
2852
|
}
|
|
2682
2853
|
} else {
|
|
2683
|
-
bindValue(sdk, plugin.name, entry);
|
|
2854
|
+
bindValue({ target: sdk, key: plugin.name, entry });
|
|
2684
2855
|
context.surface[plugin.name] = plugin.id;
|
|
2685
2856
|
}
|
|
2686
2857
|
}
|