grafast 0.1.1-beta.2 → 0.1.1-beta.21

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.
Files changed (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyTransforms = exports.__ValueStep = exports.__TrackedValueStep = exports.__ItemStep = exports.__InputStaticLeafStep = exports.__InputObjectStep = exports.__InputListStep = exports.SetterStep = exports.setter = exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.partitionByIndex = exports.ObjectStep = exports.object = exports.specFromNodeId = exports.NodeStep = exports.node = exports.makeDecodeNodeId = exports.listTransform = exports.__ListTransformStep = exports.ListenStep = exports.listen = exports.ListStep = exports.list = exports.LastStep = exports.last = exports.LambdaStep = exports.lambda = exports.groupBy = exports.FirstStep = exports.first = exports.filter = exports.ErrorStep = exports.error = exports.each = exports.ConstantStep = exports.constant = exports.EdgeStep = exports.ConnectionStep = exports.connection = exports.assertPageInfoCapableStep = exports.assertEdgeCapableStep = exports.AccessStep = exports.access = exports.debugPlans = exports.context = exports.operationPlan = void 0;
4
- exports.ProxyStep = exports.proxy = exports.LoadStep = exports.loadOneCallback = exports.loadOne = exports.loadManyCallback = exports.loadMany = exports.LoadedRecordStep = exports.GraphQLResolverStep = exports.graphqlResolver = exports.graphqlItemHandler = exports.GraphQLItemHandler = exports.ApplyTransformsStep = void 0;
3
+ exports.setter = exports.Setter = exports.createObjectAndApplyChildren = exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.partitionByIndex = exports.ObjectStep = exports.object = exports.specFromNodeId = exports.NodeStep = exports.nodeIdFromNode = exports.node = exports.makeDecodeNodeIdRuntime = exports.makeDecodeNodeId = exports.listTransform = exports.__ListTransformStep = exports.ListenStep = exports.listen = exports.ListStep = exports.list = exports.LastStep = exports.last = exports.LambdaStep = exports.lambda = exports.groupBy = exports.FirstStep = exports.first = exports.filter = exports.ErrorStep = exports.error = exports.each = exports.ConstantStep = exports.constant = exports.EdgeStep = exports.ConnectionStep = exports.connection = exports.assertPageInfoCapableStep = exports.assertEdgeCapableStep = exports.AccessStep = exports.access = exports.TRAP_INHIBITED = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_ERROR = exports.trap = exports.inhibitOnNull = exports.assertNotNull = exports.__FlagStep = void 0;
4
+ exports.ProxyStep = exports.proxy = exports.PolymorphicBranchStep = exports.polymorphicBranch = exports.LoadStep = exports.loadOneCallback = exports.loadOne = exports.loadManyCallback = exports.loadMany = exports.LoadedRecordStep = exports.GraphQLResolverStep = exports.graphqlResolver = exports.graphqlItemHandler = exports.GraphQLItemHandler = exports.ConditionStep = exports.condition = exports.BakedInputStep = exports.bakedInputRuntime = exports.bakedInput = exports.ApplyTransformsStep = exports.applyTransforms = exports.Modifier = exports.isModifier = exports.assertModifier = exports.ApplyInputStep = exports.applyInput = exports.__ValueStep = exports.__TrackedValueStep = exports.__ItemStep = exports.__InputStaticLeafStep = exports.__InputObjectStep = exports.__InputListStep = exports.SideEffectStep = exports.sideEffect = void 0;
5
+ exports.operationPlan = operationPlan;
6
+ exports.context = context;
7
+ exports.rootValue = rootValue;
8
+ exports.trackedContext = trackedContext;
9
+ exports.trackedRootValue = trackedRootValue;
10
+ exports.debugPlans = debugPlans;
5
11
  const withGlobalLayerPlan_js_1 = require("../engine/lib/withGlobalLayerPlan.js");
6
12
  const global_js_1 = require("../global.js");
7
13
  function operationPlan() {
8
14
  return (0, withGlobalLayerPlan_js_1.currentLayerPlan)().operationPlan;
9
15
  }
10
- exports.operationPlan = operationPlan;
11
16
  function context() {
12
17
  return operationPlan().contextStep;
13
18
  }
14
- exports.context = context;
19
+ function rootValue() {
20
+ return operationPlan().rootValueStep;
21
+ }
22
+ function trackedContext() {
23
+ return operationPlan().trackedContextStep;
24
+ }
25
+ function trackedRootValue() {
26
+ return operationPlan().trackedRootValueStep;
27
+ }
15
28
  /**
16
29
  * Turns on debug mode, calls the callback, and then turns debug mode back off
17
30
  * again.
@@ -23,7 +36,14 @@ function debugPlans(callback) {
23
36
  (0, global_js_1.setDebug)(oldDebug);
24
37
  return result;
25
38
  }
26
- exports.debugPlans = debugPlans;
39
+ var __flag_js_1 = require("./__flag.js");
40
+ Object.defineProperty(exports, "__FlagStep", { enumerable: true, get: function () { return __flag_js_1.__FlagStep; } });
41
+ Object.defineProperty(exports, "assertNotNull", { enumerable: true, get: function () { return __flag_js_1.assertNotNull; } });
42
+ Object.defineProperty(exports, "inhibitOnNull", { enumerable: true, get: function () { return __flag_js_1.inhibitOnNull; } });
43
+ Object.defineProperty(exports, "trap", { enumerable: true, get: function () { return __flag_js_1.trap; } });
44
+ Object.defineProperty(exports, "TRAP_ERROR", { enumerable: true, get: function () { return __flag_js_1.TRAP_ERROR; } });
45
+ Object.defineProperty(exports, "TRAP_ERROR_OR_INHIBITED", { enumerable: true, get: function () { return __flag_js_1.TRAP_ERROR_OR_INHIBITED; } });
46
+ Object.defineProperty(exports, "TRAP_INHIBITED", { enumerable: true, get: function () { return __flag_js_1.TRAP_INHIBITED; } });
27
47
  var access_js_1 = require("./access.js");
28
48
  Object.defineProperty(exports, "access", { enumerable: true, get: function () { return access_js_1.access; } });
29
49
  Object.defineProperty(exports, "AccessStep", { enumerable: true, get: function () { return access_js_1.AccessStep; } });
@@ -65,7 +85,9 @@ Object.defineProperty(exports, "__ListTransformStep", { enumerable: true, get: f
65
85
  Object.defineProperty(exports, "listTransform", { enumerable: true, get: function () { return listTransform_js_1.listTransform; } });
66
86
  var node_js_1 = require("./node.js");
67
87
  Object.defineProperty(exports, "makeDecodeNodeId", { enumerable: true, get: function () { return node_js_1.makeDecodeNodeId; } });
88
+ Object.defineProperty(exports, "makeDecodeNodeIdRuntime", { enumerable: true, get: function () { return node_js_1.makeDecodeNodeIdRuntime; } });
68
89
  Object.defineProperty(exports, "node", { enumerable: true, get: function () { return node_js_1.node; } });
90
+ Object.defineProperty(exports, "nodeIdFromNode", { enumerable: true, get: function () { return node_js_1.nodeIdFromNode; } });
69
91
  Object.defineProperty(exports, "NodeStep", { enumerable: true, get: function () { return node_js_1.NodeStep; } });
70
92
  Object.defineProperty(exports, "specFromNodeId", { enumerable: true, get: function () { return node_js_1.specFromNodeId; } });
71
93
  var object_js_1 = require("./object.js");
@@ -81,8 +103,12 @@ Object.defineProperty(exports, "reverse", { enumerable: true, get: function () {
81
103
  Object.defineProperty(exports, "reverseArray", { enumerable: true, get: function () { return reverse_js_1.reverseArray; } });
82
104
  Object.defineProperty(exports, "ReverseStep", { enumerable: true, get: function () { return reverse_js_1.ReverseStep; } });
83
105
  var setter_js_1 = require("./setter.js");
106
+ Object.defineProperty(exports, "createObjectAndApplyChildren", { enumerable: true, get: function () { return setter_js_1.createObjectAndApplyChildren; } });
107
+ Object.defineProperty(exports, "Setter", { enumerable: true, get: function () { return setter_js_1.Setter; } });
84
108
  Object.defineProperty(exports, "setter", { enumerable: true, get: function () { return setter_js_1.setter; } });
85
- Object.defineProperty(exports, "SetterStep", { enumerable: true, get: function () { return setter_js_1.SetterStep; } });
109
+ var sideEffect_js_1 = require("./sideEffect.js");
110
+ Object.defineProperty(exports, "sideEffect", { enumerable: true, get: function () { return sideEffect_js_1.sideEffect; } });
111
+ Object.defineProperty(exports, "SideEffectStep", { enumerable: true, get: function () { return sideEffect_js_1.SideEffectStep; } });
86
112
  // Internal plans
87
113
  var __inputList_js_1 = require("./__inputList.js");
88
114
  Object.defineProperty(exports, "__InputListStep", { enumerable: true, get: function () { return __inputList_js_1.__InputListStep; } });
@@ -96,9 +122,22 @@ var __trackedValue_js_1 = require("./__trackedValue.js");
96
122
  Object.defineProperty(exports, "__TrackedValueStep", { enumerable: true, get: function () { return __trackedValue_js_1.__TrackedValueStep; } });
97
123
  var __value_js_1 = require("./__value.js");
98
124
  Object.defineProperty(exports, "__ValueStep", { enumerable: true, get: function () { return __value_js_1.__ValueStep; } });
125
+ var applyInput_js_1 = require("./applyInput.js");
126
+ Object.defineProperty(exports, "applyInput", { enumerable: true, get: function () { return applyInput_js_1.applyInput; } });
127
+ Object.defineProperty(exports, "ApplyInputStep", { enumerable: true, get: function () { return applyInput_js_1.ApplyInputStep; } });
128
+ Object.defineProperty(exports, "assertModifier", { enumerable: true, get: function () { return applyInput_js_1.assertModifier; } });
129
+ Object.defineProperty(exports, "isModifier", { enumerable: true, get: function () { return applyInput_js_1.isModifier; } });
130
+ Object.defineProperty(exports, "Modifier", { enumerable: true, get: function () { return applyInput_js_1.Modifier; } });
99
131
  var applyTransforms_js_1 = require("./applyTransforms.js");
100
132
  Object.defineProperty(exports, "applyTransforms", { enumerable: true, get: function () { return applyTransforms_js_1.applyTransforms; } });
101
133
  Object.defineProperty(exports, "ApplyTransformsStep", { enumerable: true, get: function () { return applyTransforms_js_1.ApplyTransformsStep; } });
134
+ var bakedInput_js_1 = require("./bakedInput.js");
135
+ Object.defineProperty(exports, "bakedInput", { enumerable: true, get: function () { return bakedInput_js_1.bakedInput; } });
136
+ Object.defineProperty(exports, "bakedInputRuntime", { enumerable: true, get: function () { return bakedInput_js_1.bakedInputRuntime; } });
137
+ Object.defineProperty(exports, "BakedInputStep", { enumerable: true, get: function () { return bakedInput_js_1.BakedInputStep; } });
138
+ var condition_js_1 = require("./condition.js");
139
+ Object.defineProperty(exports, "condition", { enumerable: true, get: function () { return condition_js_1.condition; } });
140
+ Object.defineProperty(exports, "ConditionStep", { enumerable: true, get: function () { return condition_js_1.ConditionStep; } });
102
141
  var graphqlResolver_js_1 = require("./graphqlResolver.js");
103
142
  Object.defineProperty(exports, "GraphQLItemHandler", { enumerable: true, get: function () { return graphqlResolver_js_1.GraphQLItemHandler; } });
104
143
  Object.defineProperty(exports, "graphqlItemHandler", { enumerable: true, get: function () { return graphqlResolver_js_1.graphqlItemHandler; } });
@@ -111,6 +150,9 @@ Object.defineProperty(exports, "loadManyCallback", { enumerable: true, get: func
111
150
  Object.defineProperty(exports, "loadOne", { enumerable: true, get: function () { return load_js_1.loadOne; } });
112
151
  Object.defineProperty(exports, "loadOneCallback", { enumerable: true, get: function () { return load_js_1.loadOneCallback; } });
113
152
  Object.defineProperty(exports, "LoadStep", { enumerable: true, get: function () { return load_js_1.LoadStep; } });
153
+ var polymorphicBranch_js_1 = require("./polymorphicBranch.js");
154
+ Object.defineProperty(exports, "polymorphicBranch", { enumerable: true, get: function () { return polymorphicBranch_js_1.polymorphicBranch; } });
155
+ Object.defineProperty(exports, "PolymorphicBranchStep", { enumerable: true, get: function () { return polymorphicBranch_js_1.PolymorphicBranchStep; } });
114
156
  var proxy_js_1 = require("./proxy.js");
115
157
  Object.defineProperty(exports, "proxy", { enumerable: true, get: function () { return proxy_js_1.proxy; } });
116
158
  Object.defineProperty(exports, "ProxyStep", { enumerable: true, get: function () { return proxy_js_1.ProxyStep; } });
@@ -1,10 +1,11 @@
1
- import type { ExecutionExtra, PromiseOrDirect, UnwrapPlanTuple } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
1
+ import type { PromiseOrDirect, UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Multistep, UnwrapMultistep } from "../multistep.js";
3
+ import type { Step } from "../step.js";
4
+ import { UnbatchedStep } from "../step.js";
4
5
  /**
5
6
  * Calls the given lambda function for each tuple
6
7
  */
7
- export declare class LambdaStep<TIn, TOut> extends UnbatchedExecutableStep<TOut> {
8
+ export declare class LambdaStep<TIn, TOut> extends UnbatchedStep<TOut> {
8
9
  private fn;
9
10
  static $$export: {
10
11
  moduleName: string;
@@ -12,18 +13,17 @@ export declare class LambdaStep<TIn, TOut> extends UnbatchedExecutableStep<TOut>
12
13
  };
13
14
  isSyncAndSafe: boolean;
14
15
  allowMultipleOptimizations: boolean;
15
- private planDep;
16
- constructor($plan: ExecutableStep<TIn> | null | undefined, fn: (value: TIn) => PromiseOrDirect<TOut>);
16
+ private depId;
17
+ constructor($plan: Step<TIn> | null | undefined, fn: (value: TIn) => PromiseOrDirect<TOut>);
17
18
  toStringMeta(): any;
18
19
  deduplicate(peers: LambdaStep<any, any>[]): LambdaStep<TIn, TOut>[];
19
- unbatchedExecute(_extra: ExecutionExtra, value: TIn): PromiseOrDirect<TOut>;
20
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, value: TIn): PromiseOrDirect<TOut>;
20
21
  }
21
22
  /**
22
23
  * A plan that takes the input `$plan` and feeds each value through the `fn`
23
24
  * callback. Note: if you need to pass more than one value, pass a `ListStep`
24
25
  * as the `$plan` argument.
25
26
  */
26
- declare function lambda<const TIn extends readonly ExecutableStep[], TOut>(plans: TIn, fn: (value: UnwrapPlanTuple<TIn>) => PromiseOrDirect<TOut>, isSyncAndSafe?: boolean): LambdaStep<UnwrapPlanTuple<TIn>, TOut>;
27
- declare function lambda<const TIn, TOut>($plan: ExecutableStep<TIn> | null | undefined, fn: (value: TIn) => PromiseOrDirect<TOut>, isSyncAndSafe?: boolean): LambdaStep<TIn, TOut>;
27
+ declare function lambda<const TInMultistep extends Multistep, TOut>(spec: TInMultistep, fn: (value: UnwrapMultistep<TInMultistep>) => PromiseOrDirect<TOut>, isSyncAndSafe?: boolean): LambdaStep<UnwrapMultistep<TInMultistep>, TOut>;
28
28
  export { lambda };
29
29
  //# sourceMappingURL=lambda.d.ts.map
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lambda = exports.LambdaStep = void 0;
3
+ exports.LambdaStep = void 0;
4
+ exports.lambda = lambda;
5
+ const multistep_js_1 = require("../multistep.js");
4
6
  const step_js_1 = require("../step.js");
5
- const list_js_1 = require("./list.js");
7
+ const sideEffect_js_1 = require("./sideEffect.js");
6
8
  /**
7
9
  * Calls the given lambda function for each tuple
8
10
  */
9
- class LambdaStep extends step_js_1.UnbatchedExecutableStep {
11
+ class LambdaStep extends step_js_1.UnbatchedStep {
10
12
  static { this.$$export = {
11
13
  moduleName: "grafast",
12
14
  exportName: "LambdaStep",
@@ -17,7 +19,7 @@ class LambdaStep extends step_js_1.UnbatchedExecutableStep {
17
19
  // Lambda is only sync and safe if the callback is; so default to false
18
20
  this.isSyncAndSafe = false;
19
21
  this.allowMultipleOptimizations = true;
20
- this.planDep = $plan != null ? this.addDependency($plan) : null;
22
+ this.depId = $plan != null ? this.addDependency($plan) : null;
21
23
  if (fn.hasSideEffects) {
22
24
  this.hasSideEffects = true;
23
25
  }
@@ -39,13 +41,21 @@ class LambdaStep extends step_js_1.UnbatchedExecutableStep {
39
41
  }
40
42
  }
41
43
  exports.LambdaStep = LambdaStep;
42
- function lambda(planOrPlans, fn, isSyncAndSafe = false) {
44
+ /**
45
+ * A plan that takes the input `$plan` and feeds each value through the `fn`
46
+ * callback. Note: if you need to pass more than one value, pass a `ListStep`
47
+ * as the `$plan` argument.
48
+ */
49
+ function lambda(spec, fn, isSyncAndSafe = false) {
43
50
  if (fn.length > 1) {
44
51
  throw new Error("lambda callback should accept one argument, perhaps you forgot to destructure the arguments?");
45
52
  }
46
- const $lambda = Array.isArray(planOrPlans)
47
- ? new LambdaStep((0, list_js_1.list)(planOrPlans), fn)
48
- : new LambdaStep(planOrPlans, fn);
53
+ const $in = (0, multistep_js_1.multistep)(spec);
54
+ const $lambda = new LambdaStep($in, fn);
55
+ if (fn.hasSideEffects) {
56
+ console.trace(`You passed a function with \`hasSideEffects = true\` to \`lambda()\`, you should use \`sideEffect()\` instead (it has the same signature). We've automatically corrected this, but you should fix it in your code so the types are correct.`);
57
+ return (0, sideEffect_js_1.sideEffect)(spec, fn);
58
+ }
49
59
  if (isSyncAndSafe) {
50
60
  if (fn.constructor.name === "AsyncFunction") {
51
61
  throw new Error(`lambda call claims to be syncAndSafe, however the callback function is asynchronous`);
@@ -54,5 +64,4 @@ function lambda(planOrPlans, fn, isSyncAndSafe = false) {
54
64
  }
55
65
  return $lambda;
56
66
  }
57
- exports.lambda = lambda;
58
67
  //# sourceMappingURL=lambda.js.map
@@ -1,21 +1,22 @@
1
- import type { ExecutionExtra } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
4
- export declare class LastStep<TData> extends UnbatchedExecutableStep<TData> {
1
+ import type { UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
4
+ import type { ConnectionCapableStep } from "./connection.js";
5
+ export declare class LastStep<TData> extends UnbatchedStep<TData> {
5
6
  static $$export: {
6
7
  moduleName: string;
7
8
  exportName: string;
8
9
  };
9
10
  isSyncAndSafe: boolean;
10
11
  allowMultipleOptimizations: boolean;
11
- constructor(parentPlan: ExecutableStep<ReadonlyArray<TData>>);
12
- unbatchedExecute: (_extra: ExecutionExtra, list: ReadonlyArray<TData>) => TData;
12
+ constructor(parentPlan: Step<ReadonlyArray<TData>> | ConnectionCapableStep<Step<TData>, any>);
13
+ unbatchedExecute: (_extra: UnbatchedExecutionExtra, list: ReadonlyArray<TData>) => TData;
13
14
  deduplicate(peers: LastStep<TData>[]): LastStep<TData>[];
14
- optimize(): ExecutableStep<any> | this;
15
+ optimize(): any;
15
16
  }
16
17
  /**
17
18
  * A plan that resolves to the last entry in the list returned by the given
18
19
  * plan.
19
20
  */
20
- export declare function last<TData>(plan: ExecutableStep<ReadonlyArray<TData>>): LastStep<TData>;
21
+ export declare function last<TData>(plan: Step<ReadonlyArray<TData>> | ConnectionCapableStep<Step<TData>, any>): LastStep<TData>;
21
22
  //# sourceMappingURL=last.d.ts.map
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.last = exports.LastStep = void 0;
3
+ exports.LastStep = void 0;
4
+ exports.last = last;
4
5
  const step_js_1 = require("../step.js");
6
+ const connection_js_1 = require("./connection.js");
5
7
  const list_js_1 = require("./list.js");
6
- class LastStep extends step_js_1.UnbatchedExecutableStep {
8
+ class LastStep extends step_js_1.UnbatchedStep {
7
9
  static { this.$$export = {
8
10
  moduleName: "grafast",
9
11
  exportName: "LastStep",
@@ -15,7 +17,7 @@ class LastStep extends step_js_1.UnbatchedExecutableStep {
15
17
  this.unbatchedExecute = (_extra, list) => {
16
18
  return list?.[list?.length - 1];
17
19
  };
18
- this.addDependency(parentPlan);
20
+ this.addDependency((0, connection_js_1.itemsOrStep)(parentPlan));
19
21
  }
20
22
  deduplicate(peers) {
21
23
  return peers;
@@ -24,7 +26,7 @@ class LastStep extends step_js_1.UnbatchedExecutableStep {
24
26
  const parent = this.getDep(0);
25
27
  // The last of a list plan is just the last dependency of the list plan.
26
28
  if (parent instanceof list_js_1.ListStep) {
27
- return parent.getDep(parent.dependencies.length - 1);
29
+ return parent.last();
28
30
  }
29
31
  return this;
30
32
  }
@@ -35,7 +37,6 @@ exports.LastStep = LastStep;
35
37
  * plan.
36
38
  */
37
39
  function last(plan) {
38
- return new LastStep(plan);
40
+ return plan.operationPlan.cacheStep(plan, "GrafastInternal:last()", "", () => new LastStep(plan));
39
41
  }
40
- exports.last = last;
41
42
  //# sourceMappingURL=last.js.map
@@ -1,8 +1,12 @@
1
- import type { ExecutionExtra, StepOptimizeOptions, UnwrapPlanTuple } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
1
+ import type { ExecutionDetails, StepOptimizeOptions, UnbatchedExecutionExtra, UnwrapPlanTuple } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
4
4
  import { ConstantStep } from "./constant.js";
5
- export declare class ListStep<const TPlanTuple extends readonly ExecutableStep[]> extends UnbatchedExecutableStep<UnwrapPlanTuple<TPlanTuple>> {
5
+ interface ListStepCacheConfig {
6
+ identifier?: string;
7
+ cacheSize?: number;
8
+ }
9
+ export declare class ListStep<const TPlanTuple extends readonly Step[]> extends UnbatchedStep<UnwrapPlanTuple<TPlanTuple>> {
6
10
  static $$export: {
7
11
  moduleName: string;
8
12
  exportName: string;
@@ -10,20 +14,27 @@ export declare class ListStep<const TPlanTuple extends readonly ExecutableStep[]
10
14
  isSyncAndSafe: boolean;
11
15
  allowMultipleOptimizations: boolean;
12
16
  optimizeMetaKey: string;
13
- constructor(list: TPlanTuple);
17
+ private cacheSize;
18
+ private valueCount;
19
+ constructor(list: TPlanTuple, cacheConfig?: ListStepCacheConfig);
14
20
  toStringMeta(): string;
15
- execute(count: number, values: any[][]): Array<UnwrapPlanTuple<TPlanTuple>>;
16
- unbatchedExecute(_extra: ExecutionExtra, ...values: any[]): UnwrapPlanTuple<TPlanTuple>;
21
+ execute({ indexMap, values }: ExecutionDetails): readonly UnwrapPlanTuple<TPlanTuple>[];
22
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, ...values: any[]): UnwrapPlanTuple<TPlanTuple>;
23
+ deduplicatedUnbatchedExecute({ meta: inMeta }: UnbatchedExecutionExtra, ...values: any[]): UnwrapPlanTuple<TPlanTuple>;
17
24
  deduplicate(peers: ListStep<TPlanTuple>[]): ListStep<TPlanTuple>[];
18
25
  optimize(opts: StepOptimizeOptions): this | ConstantStep<any[]>;
26
+ finalize(): void;
19
27
  /**
20
28
  * Get the original plan at the given index back again.
21
29
  */
22
- at<TIndex extends keyof TPlanTuple>(index: TIndex): TPlanTuple[TIndex];
30
+ at<TIndex extends keyof TPlanTuple & number>(index: TIndex): TPlanTuple[TIndex];
31
+ first(): TPlanTuple[0] | import("./__flag.js").__FlagStep<TPlanTuple[0]>;
32
+ last(): TPlanTuple[number] | import("./__flag.js").__FlagStep<TPlanTuple[number]>;
23
33
  }
24
34
  /**
25
35
  * Takes a list of plans and turns it into a single plan that represents the
26
36
  * list of their values.
27
37
  */
28
- export declare function list<const TPlanTuple extends readonly ExecutableStep[]>(list: TPlanTuple): ListStep<TPlanTuple>;
38
+ export declare function list<const TPlanTuple extends readonly Step[]>(list: TPlanTuple, cacheConfig?: ListStepCacheConfig): ListStep<TPlanTuple>;
39
+ export {};
29
40
  //# sourceMappingURL=list.d.ts.map
@@ -1,36 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.list = exports.ListStep = void 0;
3
+ exports.ListStep = void 0;
4
+ exports.list = list;
4
5
  const step_js_1 = require("../step.js");
5
6
  const constant_js_1 = require("./constant.js");
6
- class ListStep extends step_js_1.UnbatchedExecutableStep {
7
+ const DEFAULT_CACHE_SIZE = 100;
8
+ class ListStep extends step_js_1.UnbatchedStep {
7
9
  static { this.$$export = {
8
10
  moduleName: "grafast",
9
11
  exportName: "ListStep",
10
12
  }; }
11
- constructor(list) {
13
+ constructor(list, cacheConfig) {
12
14
  super();
13
15
  this.isSyncAndSafe = true;
14
16
  this.allowMultipleOptimizations = true;
15
17
  this.optimizeMetaKey = "ListStep";
18
+ this.valueCount = list.length;
19
+ this.cacheSize =
20
+ cacheConfig?.cacheSize ??
21
+ (cacheConfig?.identifier ? DEFAULT_CACHE_SIZE : 0);
22
+ this.metaKey =
23
+ this.cacheSize <= 0
24
+ ? undefined
25
+ : cacheConfig?.identifier
26
+ ? `list|${list.length}|${cacheConfig.identifier}`
27
+ : this.id;
16
28
  for (let i = 0, l = list.length; i < l; i++) {
17
- this.addDependency(list[i], true);
29
+ this.addDependency({ step: list[i], skipDeduplication: true });
18
30
  }
19
31
  }
20
32
  toStringMeta() {
21
33
  return this.dependencies.map(($dep) => $dep.id).join(",");
22
34
  }
23
- execute(count, values) {
24
- const result = [];
25
- for (let i = 0; i < count; i++) {
26
- result[i] = values.map((list) => list[i]);
27
- }
28
- return result;
35
+ execute({ indexMap, values }) {
36
+ return indexMap((i) => values.map((value) => value.at(i)));
29
37
  }
30
38
  unbatchedExecute(_extra, ...values //UnwrapPlanTuple<TPlanTuple>,
31
39
  ) {
32
40
  return values;
33
41
  }
42
+ deduplicatedUnbatchedExecute({ meta: inMeta }, ...values //UnwrapPlanTuple<TPlanTuple>,
43
+ ) {
44
+ const meta = inMeta;
45
+ if (meta.nextIndex !== undefined) {
46
+ outer: for (let i = 0, l = meta.results.length; i < l; i++) {
47
+ const cachedValues = meta.results[i];
48
+ for (let j = 0, c = this.valueCount; j < c; j++) {
49
+ if (values[j] !== cachedValues[j]) {
50
+ continue outer;
51
+ }
52
+ }
53
+ return cachedValues;
54
+ }
55
+ }
56
+ else {
57
+ meta.nextIndex = 0;
58
+ meta.results = [];
59
+ }
60
+ meta.results[meta.nextIndex] = values;
61
+ // Only cache this.cacheSize results, use a round-robin
62
+ const maxIndex = this.cacheSize - 1;
63
+ meta.nextIndex = meta.nextIndex === maxIndex ? 0 : meta.nextIndex + 1;
64
+ return values;
65
+ }
34
66
  deduplicate(peers) {
35
67
  return peers;
36
68
  }
@@ -56,20 +88,31 @@ class ListStep extends step_js_1.UnbatchedExecutableStep {
56
88
  }
57
89
  return this;
58
90
  }
91
+ finalize() {
92
+ if (this.cacheSize > 0) {
93
+ this.unbatchedExecute = this.deduplicatedUnbatchedExecute;
94
+ }
95
+ super.finalize();
96
+ }
59
97
  /**
60
98
  * Get the original plan at the given index back again.
61
99
  */
62
100
  at(index) {
63
101
  return this.getDep(index);
64
102
  }
103
+ first() {
104
+ return this.getDep(0);
105
+ }
106
+ last() {
107
+ return this.getDep(this.dependencies.length - 1);
108
+ }
65
109
  }
66
110
  exports.ListStep = ListStep;
67
111
  /**
68
112
  * Takes a list of plans and turns it into a single plan that represents the
69
113
  * list of their values.
70
114
  */
71
- function list(list) {
72
- return new ListStep(list);
115
+ function list(list, cacheConfig) {
116
+ return new ListStep(list, cacheConfig);
73
117
  }
74
- exports.list = list;
75
118
  //# sourceMappingURL=list.js.map
@@ -1,22 +1,21 @@
1
- import type { LayerPlanReasonSubroutine } from "../engine/LayerPlan.js";
2
- import { LayerPlan } from "../engine/LayerPlan.js";
3
- import type { GrafastError } from "../error.js";
4
- import type { ConnectionCapableStep } from "../index.js";
5
- import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../interfaces.js";
1
+ import type { ConnectionCapableStep, ExecutionDetails } from "../index.js";
2
+ import type { GrafastResultsList } from "../interfaces.js";
3
+ import { $$deepDepSkip } from "../interfaces.js";
6
4
  import type { ListCapableStep } from "../step.js";
7
- import { $$deepDepSkip, ExecutableStep } from "../step.js";
5
+ import { Step } from "../step.js";
8
6
  import { __ItemStep } from "./__item.js";
7
+ import type { ItemsStep } from "./connection.js";
9
8
  export type ListTransformReduce<TMemo, TItemPlanData> = (memo: TMemo, entireItemValue: unknown, itemPlanData: TItemPlanData) => TMemo;
10
- export type ListTransformItemPlanCallback<TListStep extends ExecutableStep<readonly any[]>, TDepsStep extends ExecutableStep> = (listItemPlan: TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>) => TDepsStep;
11
- export interface ListTransformOptions<TListStep extends ExecutableStep<readonly any[]>, TDepsStep extends ExecutableStep, TMemo, TItemStep extends ExecutableStep | undefined = undefined> {
9
+ export type ListTransformItemPlanCallback<TListStep extends Step<readonly any[]>, TDepsStep extends Step> = (listItemPlan: ItemsStep<TListStep> extends ListCapableStep<any, any> ? ReturnType<ItemsStep<TListStep>["listItem"]> : __ItemStep<any>) => TDepsStep;
10
+ export interface ListTransformOptions<TListStep extends Step<readonly any[]> | ConnectionCapableStep<Step<any>, any>, TDepsStep extends Step, TMemo, TItemStep extends Step | undefined = undefined> {
12
11
  listStep: TListStep;
13
- itemPlanCallback: ListTransformItemPlanCallback<TListStep, TDepsStep>;
12
+ itemPlanCallback: ListTransformItemPlanCallback<ItemsStep<TListStep>, TDepsStep>;
14
13
  initialState(): TMemo;
15
- reduceCallback: ListTransformReduce<TMemo, TDepsStep extends ExecutableStep<infer U> ? U : never>;
16
- listItem?(itemPlan: ExecutableStep): TItemStep;
14
+ reduceCallback: ListTransformReduce<TMemo, TDepsStep extends Step<infer U> ? U : never>;
15
+ listItem?(itemPlan: Step): TItemStep;
17
16
  finalizeCallback?(data: TMemo): TMemo;
18
17
  meta?: string;
19
- optimize?: (this: __ListTransformStep<TListStep, TDepsStep, TMemo, TItemStep>) => ExecutableStep;
18
+ optimize?: (this: __ListTransformStep<TListStep, TDepsStep, TMemo, TItemStep>) => Step;
20
19
  connectionClone?: ConnectionCapableStep<TListStep, any>["connectionClone"];
21
20
  }
22
21
  /**
@@ -28,34 +27,31 @@ export interface ListTransformOptions<TListStep extends ExecutableStep<readonly
28
27
  * It's recommended that you don't use this directly, please use one of the
29
28
  * functions that uses this under the hood such as `filter()`.
30
29
  */
31
- export declare class __ListTransformStep<TListStep extends ExecutableStep<readonly any[]> = ExecutableStep<readonly any[]>, TDepsStep extends ExecutableStep = ExecutableStep, TMemo = any, TItemStep extends ExecutableStep | undefined = ExecutableStep | undefined> extends ExecutableStep<TMemo> {
30
+ export declare class __ListTransformStep<TListStep extends Step<readonly any[]> | ConnectionCapableStep<any, any> = Step<readonly any[]> | ConnectionCapableStep<any, any>, TDepsStep extends Step = Step, TMemo = any, TItemStep extends Step | undefined = Step | undefined> extends Step<TMemo> {
32
31
  static $$export: {
33
32
  moduleName: string;
34
33
  exportName: string;
35
34
  };
36
35
  isSyncAndSafe: boolean;
37
36
  private listStepDepId;
38
- itemPlanCallback: ListTransformItemPlanCallback<TListStep, TDepsStep>;
37
+ private rawListStepDepId;
38
+ itemPlanCallback: ListTransformItemPlanCallback<ItemsStep<TListStep>, TDepsStep>;
39
39
  initialState: () => TMemo;
40
- reduceCallback: ListTransformReduce<TMemo, TDepsStep extends ExecutableStep<infer U> ? U : never>;
40
+ reduceCallback: ListTransformReduce<TMemo, TDepsStep extends Step<infer U> ? U : never>;
41
41
  finalizeCallback?: (data: TMemo) => TMemo;
42
42
  listItem?: (itemPlan: __ItemStep<this>) => TItemStep;
43
43
  private meta;
44
44
  connectionClone?: ConnectionCapableStep<TListStep, any>["connectionClone"];
45
45
  /** Set during query planning. */
46
46
  itemStepId: number;
47
- /**
48
- * @internal
49
- */
50
- subroutineLayer: LayerPlan<LayerPlanReasonSubroutine>;
51
47
  constructor(options: ListTransformOptions<TListStep, TDepsStep, TMemo, TItemStep>);
52
48
  toStringMeta(): string | null;
53
49
  getListStep(): TListStep;
54
50
  [$$deepDepSkip](): TListStep;
55
51
  dangerouslyGetListPlan(): TListStep;
56
52
  deduplicate(peers: __ListTransformStep<any, any, any, any>[]): __ListTransformStep<TListStep, TDepsStep, TMemo, TItemStep>[];
57
- optimize(): ExecutableStep;
58
- execute(_count: number, values: [GrafastValuesList<any[] | null | undefined | GrafastError>], extra: ExecutionExtra): Promise<GrafastResultsList<TMemo>>;
53
+ optimize(): Step;
54
+ execute({ indexForEach, indexMap, values, extra, }: ExecutionDetails<[any[] | null | undefined | Error]>): Promise<GrafastResultsList<TMemo>>;
59
55
  }
60
56
  /**
61
57
  * **Experimental.**
@@ -65,5 +61,5 @@ export declare class __ListTransformStep<TListStep extends ExecutableStep<readon
65
61
  *
66
62
  * {@page ~grafast/steps/listTransform.md}
67
63
  */
68
- export declare function listTransform<TListStep extends ExecutableStep<readonly any[]>, TDepsStep extends ExecutableStep, TMemo, TItemStep extends ExecutableStep | undefined = undefined>(options: ListTransformOptions<TListStep, TDepsStep, TMemo, TItemStep>): __ListTransformStep<TListStep, TDepsStep, TMemo, TItemStep>;
64
+ export declare function listTransform<TListStep extends Step<readonly any[]> | ConnectionCapableStep<any, any>, TDepsStep extends Step, TMemo, TItemStep extends Step | undefined = undefined>(options: ListTransformOptions<TListStep, TDepsStep, TMemo, TItemStep>): __ListTransformStep<TListStep, TDepsStep, TMemo, TItemStep>;
69
65
  //# sourceMappingURL=listTransform.d.ts.map