@voxgig/apidef 8.33.0 → 8.33.2

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.
@@ -137,6 +137,20 @@ function newFlowStep(opname: OpName, args: Record<string, any>): ModelEntityFlow
137
137
  }
138
138
 
139
139
 
140
+ // A step calls the op without an action, so it reads the point that call
141
+ // reaches: the last plain point, the most generic as points sort the most
142
+ // specific first.
143
+ function plainPoint(points: any[] | undefined): any {
144
+ const all = points ?? []
145
+ for (let i = all.length - 1; 0 <= i; i--) {
146
+ if (null == all[i]?.q?.$action) {
147
+ return all[i]
148
+ }
149
+ }
150
+ return getelem(all, -1)
151
+ }
152
+
153
+
140
154
  // Reverse-lookup: given a point with rename.param like {spaceId: 'id'} or
141
155
  // {space_id: 'id'}, return the snake_case ORIGINAL name (e.g. 'space_id') of
142
156
  // any param whose URL placeholder is now `{id}`. Returns null when no
@@ -162,8 +176,7 @@ const createStep: MakeFlowStep = (
162
176
  args: Record<string, any>
163
177
  ) => {
164
178
  if (null != opmap.create) {
165
- // Use last point as most generic
166
- const point = getelem(opmap.create.points, -1)
179
+ const point = plainPoint(opmap.create.points)
167
180
  const step = newFlowStep('create', args)
168
181
 
169
182
  each(point.g.params, (param: any) => {
@@ -213,8 +226,7 @@ const listStep: MakeFlowStep = (
213
226
  args: Record<string, any>
214
227
  ) => {
215
228
  if (null != opmap.list) {
216
- // Use last point as most generic
217
- const point = getelem(opmap.list.points, -1)
229
+ const point = plainPoint(opmap.list.points)
218
230
  const step = newFlowStep('list', args)
219
231
 
220
232
  each(point.g.params, (param: any) => {
@@ -240,8 +252,7 @@ const updateStep: MakeFlowStep = (
240
252
  args: Record<string, any>
241
253
  ) => {
242
254
  if (null != opmap.update) {
243
- // Use last point as most generic
244
- const point = getelem(opmap.update.points, -1)
255
+ const point = plainPoint(opmap.update.points)
245
256
  const step = newFlowStep('update', args)
246
257
 
247
258
  each(point.g.params, (param: any) => {
@@ -265,8 +276,7 @@ const loadStep: MakeFlowStep = (
265
276
  args: Record<string, any>
266
277
  ) => {
267
278
  if (null != opmap.load) {
268
- // Use last point as most generic
269
- const point = getelem(opmap.load.points, -1)
279
+ const point = plainPoint(opmap.load.points)
270
280
  const step = newFlowStep('load', args)
271
281
 
272
282
  each(point.g.params, (param: any) => {
@@ -294,8 +304,7 @@ const removeStep: MakeFlowStep = (
294
304
  // no remove step at all; a create-less remove would delete real records in
295
305
  // live mode and makes no sense as a self-contained CRUD test.
296
306
  if (null != opmap.remove && null != opmap.create) {
297
- // Use last point as most generic
298
- const point = getelem(opmap.remove.points, -1)
307
+ const point = plainPoint(opmap.remove.points)
299
308
  const step = newFlowStep('remove', args)
300
309
 
301
310
  each(point.g.params, (param: any) => {
@@ -46,7 +46,7 @@ const selectTransform: Transform = async function(
46
46
  resolveSelect(guide, ment, mop, mpoint, pdef, carrier)
47
47
  })
48
48
  if (null != mop.points && 0 < mop.points.length) {
49
- sortPoints(guide, ment, mop)
49
+ sortPoints(mop)
50
50
  warnSharedSelectors(ctx, ment, mop)
51
51
  }
52
52
  })
@@ -115,11 +115,7 @@ function resolveSelect(
115
115
  }
116
116
 
117
117
 
118
- function sortPoints(
119
- _guide: Guide,
120
- _ment: ModelEntity,
121
- mop: ModelOp,
122
- ) {
118
+ function sortPoints(mop: ModelOp) {
123
119
  // Cache joined exist strings to avoid recomputing on every comparison.
124
120
  const existCache = new Map<ModelPoint, string>()
125
121
  for (const pt of mop.points) {
@@ -130,10 +126,12 @@ function sortPoints(
130
126
  // longest exist len first
131
127
  let order = b.q.exist.length - a.q.exist.length
132
128
  if (0 === order) {
133
- if (null != a.q.$action && null != b.q.$action) {
134
- order = a.q.$action < b.q.$action ? -1 :
135
- a.q.$action > b.q.$action ? 1 : 0
136
- }
129
+ // A plain point sorts before an action point, keeping the order total.
130
+ const a_action = a.q.$action
131
+ const b_action = b.q.$action
132
+ order = null == a_action ? (null == b_action ? 0 : -1) :
133
+ null == b_action ? 1 :
134
+ a_action < b_action ? -1 : a_action > b_action ? 1 : 0
137
135
 
138
136
  if (0 === order) {
139
137
  const a_exist_str = existCache.get(a)!
@@ -177,4 +175,5 @@ function warnSharedSelectors(ctx: any, ment: ModelEntity, mop: ModelOp) {
177
175
 
178
176
  export {
179
177
  selectTransform,
178
+ sortPoints,
180
179
  }