@reventlessdev/reventless-core 3.0.0-alpha.336 → 3.0.0-alpha.338

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.
@@ -1,7 +1,9 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
3
4
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
4
5
  import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
6
+ import * as StateAnnotations$Reventless from "@reventlessdev/reventless-spec/src/components/StateAnnotations.res.mjs";
5
7
  import * as ApiNoApiHelpers$ReventlessCore from "./ApiNoApiHelpers.res.mjs";
6
8
 
7
9
  function pluralize(n) {
@@ -87,22 +89,40 @@ function canonicalPlural(n) {
87
89
  return pluralize(singularize(n));
88
90
  }
89
91
 
90
- function queryFieldNamesForReadModel(plugin, name, connectionSpecOpt) {
92
+ function declaredPlural(stateSchema) {
93
+ return Stdlib_Option.flatMap(StateAnnotations$Reventless.getSpec(stateSchema), s => s.plural);
94
+ }
95
+
96
+ function declaredSingular(stateSchema) {
97
+ return Stdlib_Option.flatMap(StateAnnotations$Reventless.getSpec(stateSchema), s => s.singular);
98
+ }
99
+
100
+ let declaredSingulars = {};
101
+
102
+ function registerSingular(plugin, name, stateSchema) {
103
+ Stdlib_Option.forEach(declaredSingular(stateSchema), singular => {
104
+ declaredSingulars[plugin + `.` + name] = singular;
105
+ });
106
+ }
107
+
108
+ function queryFieldNamesForReadModel(plugin, name, declared, declaredOne, connectionSpecOpt) {
91
109
  let connectionSpec = connectionSpecOpt !== undefined ? connectionSpecOpt : true;
92
- let singular = singularize(name);
93
- let plural = pluralize(singularize(name));
110
+ let singular = Stdlib_Option.getOr(declaredOne, singularize(name));
111
+ let plural = Stdlib_Option.getOr(declared, pluralize(singularize(name)));
94
112
  return {
95
113
  singleFieldName: plugin + `_` + singular,
96
114
  listFieldName: plugin + `_` + plural,
97
115
  returnTypeName: plugin + `_` + singular,
98
116
  pluralTypeName: plugin + `_` + plural,
99
117
  includeIdParam: true,
100
- connectionSpec: connectionSpec
118
+ connectionSpec: connectionSpec,
119
+ plural: plural,
120
+ pluralDeclared: Stdlib_Option.isSome(declared)
101
121
  };
102
122
  }
103
123
 
104
124
  function returnTypeNameFor(plugin, name) {
105
- return plugin + `_` + singularize(stripViewSuffix(name));
125
+ return plugin + `_` + Stdlib_Option.getOr(declaredSingulars[plugin + `.` + name], singularize(stripViewSuffix(name)));
106
126
  }
107
127
 
108
128
  function resolvedFieldsOfConfig(plugin, config) {
@@ -143,30 +163,35 @@ function resolvedFieldsOfConfig(plugin, config) {
143
163
  return single.concat(many);
144
164
  }
145
165
 
146
- function queryFieldNamesForStateView(plugin, viewName, connectionSpecOpt) {
166
+ function queryFieldNamesForStateView(plugin, viewName, declared, declaredOne, connectionSpecOpt) {
147
167
  let connectionSpec = connectionSpecOpt !== undefined ? connectionSpecOpt : true;
148
168
  let entity = stripViewSuffix(viewName);
149
- let singular = singularize(entity);
150
- let plural = pluralize(singularize(entity));
169
+ let singular = Stdlib_Option.getOr(declaredOne, singularize(entity));
170
+ let plural = Stdlib_Option.getOr(declared, pluralize(singularize(entity)));
151
171
  return {
152
172
  singleFieldName: plugin + `_` + singular,
153
173
  listFieldName: plugin + `_` + plural,
154
174
  returnTypeName: plugin + `_` + singular,
155
175
  pluralTypeName: plugin + `_` + plural,
156
176
  includeIdParam: true,
157
- connectionSpec: connectionSpec
177
+ connectionSpec: connectionSpec,
178
+ plural: plural,
179
+ pluralDeclared: Stdlib_Option.isSome(declared)
158
180
  };
159
181
  }
160
182
 
161
183
  function queryFieldNamesForSliceQueryDb(plugin, queryDbName, connectionSpecOpt) {
162
184
  let connectionSpec = connectionSpecOpt !== undefined ? connectionSpecOpt : true;
185
+ let plural = pluralize(singularize(queryDbName));
163
186
  return {
164
187
  singleFieldName: plugin + `_` + queryDbName,
165
- listFieldName: plugin + `_` + pluralize(singularize(queryDbName)),
188
+ listFieldName: plugin + `_` + plural,
166
189
  returnTypeName: plugin + `_` + queryDbName,
167
- pluralTypeName: plugin + `_` + pluralize(singularize(queryDbName)),
190
+ pluralTypeName: plugin + `_` + plural,
168
191
  includeIdParam: true,
169
- connectionSpec: connectionSpec
192
+ connectionSpec: connectionSpec,
193
+ plural: plural,
194
+ pluralDeclared: false
170
195
  };
171
196
  }
172
197
 
@@ -188,6 +213,10 @@ export {
188
213
  sliceMutationFields,
189
214
  sliceMutationFieldFor,
190
215
  canonicalPlural,
216
+ declaredPlural,
217
+ declaredSingular,
218
+ declaredSingulars,
219
+ registerSingular,
191
220
  queryFieldNamesForReadModel,
192
221
  returnTypeNameFor,
193
222
  resolvedFieldsOfConfig,
@@ -390,7 +390,10 @@ let classifyKeyField = (
390
390
  ->Option.getOr(Dict.make())
391
391
  ->Dict.keysToArray
392
392
  ->Array.filter(field => isKeyFieldName(field) || keyOf(field)->Option.isSome)
393
- let singular = entityName->Api_Naming.stripViewSuffix->Api_Naming.singularize
393
+ let singular =
394
+ Api_Naming.declaredSingular(schema)->Option.getOr(
395
+ entityName->Api_Naming.stripViewSuffix->Api_Naming.singularize,
396
+ )
394
397
  let conventional =
395
398
  singular->String.slice(~start=0, ~end=1)->String.toLowerCase ++
396
399
  singular->String.slice(~start=1, ~end=singular->String.length) ++ "Id"
@@ -295,7 +295,7 @@ function classifyKeyField(rowKeying, entityName, schema) {
295
295
  return Stdlib_Option.isSome(keyOf(field));
296
296
  }
297
297
  });
298
- let singular = Api_Naming$ReventlessCore.singularize(Api_Naming$ReventlessCore.stripViewSuffix(entityName));
298
+ let singular = Stdlib_Option.getOr(Api_Naming$ReventlessCore.declaredSingular(schema), Api_Naming$ReventlessCore.singularize(Api_Naming$ReventlessCore.stripViewSuffix(entityName)));
299
299
  let conventional = singular.slice(0, 1).toLowerCase() + singular.slice(1, singular.length) + "Id";
300
300
  let field = candidates.find(field => Stdlib_Option.getOr(keyOf(field), field) === conventional);
301
301
  if (field !== undefined) {
@@ -640,7 +640,12 @@ module Make = (
640
640
 
641
641
  // Populate query field names registry for all slice types BEFORE creating them
642
642
  stateViewSlices->Array.forEach((module(V: StateViewSlice.T)) => {
643
- let qn = Api_Naming.queryFieldNamesForStateView(~plugin=name, ~viewName=V.Spec.name)
643
+ let qn = Api_Naming.queryFieldNamesForStateView(
644
+ ~plugin=name,
645
+ ~viewName=V.Spec.name,
646
+ ~plural=?Api_Naming.declaredPlural(V.Spec.stateSchema->S.castToUnknown),
647
+ ~singular=?Api_Naming.declaredSingular(V.Spec.stateSchema->S.castToUnknown),
648
+ )
644
649
  let label = Plugin_Structure.labelFieldsFromStateSchema(
645
650
  ~entityName=V.Spec.name,
646
651
  V.Spec.stateSchema->S.castToUnknown,
@@ -1141,7 +1146,12 @@ module Make = (
1141
1146
  })
1142
1147
 
1143
1148
  let stateViewEntries = stateViewSlices->Array.map((module(V: StateViewSlice.T)) => {
1144
- let qn = Api_Naming.queryFieldNamesForStateView(~plugin=name, ~viewName=V.Spec.name)
1149
+ let qn = Api_Naming.queryFieldNamesForStateView(
1150
+ ~plugin=name,
1151
+ ~viewName=V.Spec.name,
1152
+ ~plural=?Api_Naming.declaredPlural(V.Spec.stateSchema->S.castToUnknown),
1153
+ ~singular=?Api_Naming.declaredSingular(V.Spec.stateSchema->S.castToUnknown),
1154
+ )
1145
1155
  let subIdField = V.Spec.subIdConfig->Option.map(c => c.subIdField)
1146
1156
  let indexes = V.Spec.config.indexes
1147
1157
  let indexQueries = if indexes->Array.length > 0 {
@@ -338,7 +338,7 @@ function Make(DcbEventLogStorage) {
338
338
  }
339
339
  }
340
340
  stateViewSlices.forEach(V => {
341
- let qn = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, V.Spec.name, undefined);
341
+ let qn = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, V.Spec.name, Api_Naming$ReventlessCore.declaredPlural(V.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(V.Spec.stateSchema), undefined);
342
342
  let label = Plugin_Structure$ReventlessCore.labelFieldsFromStateSchema(V.Spec.name, V.Spec.stateSchema);
343
343
  let newrecord = {...qn};
344
344
  newrecord.labelField = label.field;
@@ -596,7 +596,7 @@ function Make(DcbEventLogStorage) {
596
596
  };
597
597
  });
598
598
  let stateViewEntries = stateViewSlices.map(V => {
599
- let qn = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, V.Spec.name, undefined);
599
+ let qn = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, V.Spec.name, Api_Naming$ReventlessCore.declaredPlural(V.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(V.Spec.stateSchema), undefined);
600
600
  let subIdField = Stdlib_Option.map(V.Spec.subIdConfig, c => c.subIdField);
601
601
  let indexes = V.Spec.config.indexes;
602
602
  let indexQueries = indexes.length !== 0 ? indexes : undefined;
@@ -67,6 +67,24 @@ module Make = (
67
67
  let _prevPluginName = Logger.currentPluginName.contents
68
68
  Logger.currentPluginName := Some(name)
69
69
 
70
+ // Before any query entry: a `@resolves` field reaches its target's row type by spec name.
71
+ readModels->Array.forEach((
72
+ module(R: ReventlessInfra.ReadModel.T with type api = api and type role = role),
73
+ ) =>
74
+ Api_Naming.registerSingular(
75
+ ~plugin=name,
76
+ ~name=R.Spec.name,
77
+ R.Spec.stateSchema->S.castToUnknown,
78
+ )
79
+ )
80
+ stateViewSlices->Array.forEach((module(V: ReventlessInfra.StateViewSlice.T)) =>
81
+ Api_Naming.registerSingular(
82
+ ~plugin=name,
83
+ ~name=V.Spec.name,
84
+ V.Spec.stateSchema->S.castToUnknown,
85
+ )
86
+ )
87
+
70
88
  // Publish the owning plugin/platform for resource attribution, so adapters
71
89
  // creating infrastructure below this point can tag it without every adapter
72
90
  // signature having to carry the two names. Restored at the end of construct.
@@ -249,7 +267,12 @@ module Make = (
249
267
  readModels->Array.map((
250
268
  module(R: ReventlessInfra.ReadModel.T with type api = api and type role = role),
251
269
  ) => {
252
- let qn = Api_Naming.queryFieldNamesForReadModel(~plugin=name, ~name=R.Spec.name)
270
+ let qn = Api_Naming.queryFieldNamesForReadModel(
271
+ ~plugin=name,
272
+ ~name=R.Spec.name,
273
+ ~plural=?Api_Naming.declaredPlural(R.Spec.stateSchema->S.castToUnknown),
274
+ ~singular=?Api_Naming.declaredSingular(R.Spec.stateSchema->S.castToUnknown),
275
+ )
253
276
  let subIdField = R.Spec.subIdConfig->Option.map(c => c.subIdField)
254
277
  // An ordinary read model's `@index` reached the resolver layer
255
278
  // (`QueryDbResolvers_{AppSync,Lambda}` build one per `config.indexes`)
@@ -290,7 +313,12 @@ module Make = (
290
313
  readModels->Array.forEach((
291
314
  module(R: ReventlessInfra.ReadModel.T with type api = api and type role = role),
292
315
  ) => {
293
- let qn = Api_Naming.queryFieldNamesForReadModel(~plugin=name, ~name=R.Spec.name)
316
+ let qn = Api_Naming.queryFieldNamesForReadModel(
317
+ ~plugin=name,
318
+ ~name=R.Spec.name,
319
+ ~plural=?Api_Naming.declaredPlural(R.Spec.stateSchema->S.castToUnknown),
320
+ ~singular=?Api_Naming.declaredSingular(R.Spec.stateSchema->S.castToUnknown),
321
+ )
294
322
  let label = Plugin_Structure.labelFieldsFromStateSchema(
295
323
  ~entityName=R.Spec.name,
296
324
  R.Spec.stateSchema->S.castToUnknown,
@@ -451,7 +479,12 @@ module Make = (
451
479
  let readModelComponents = readModels->Array.map((
452
480
  module(R: ReventlessInfra.ReadModel.T with type api = api and type role = role),
453
481
  ) => {
454
- let qn = Api_Naming.queryFieldNamesForReadModel(~plugin=name, ~name=R.Spec.name)
482
+ let qn = Api_Naming.queryFieldNamesForReadModel(
483
+ ~plugin=name,
484
+ ~name=R.Spec.name,
485
+ ~plural=?Api_Naming.declaredPlural(R.Spec.stateSchema->S.castToUnknown),
486
+ ~singular=?Api_Naming.declaredSingular(R.Spec.stateSchema->S.castToUnknown),
487
+ )
455
488
  let schema: Plugin_Helpers.pluginDeployedSchema = {
456
489
  queryFields: [qn.singleFieldName, qn.listFieldName],
457
490
  chapter: ?chapterFor(R.Spec.name),
@@ -128,6 +128,8 @@ function Make(Spec) {
128
128
  return Component$ReventlessCore.make(ComponentType$ReventlessCore.toString(Plugin$ReventlessCore.componentType), name, (extra, extra$1) => {
129
129
  let _prevPluginName = Logger$ReventlessCore.currentPluginName.contents;
130
130
  Logger$ReventlessCore.currentPluginName.contents = extra$1;
131
+ readModels.forEach(R => Api_Naming$ReventlessCore.registerSingular(extra$1, R.Spec.name, R.Spec.stateSchema));
132
+ stateViewSlices.forEach(V => Api_Naming$ReventlessCore.registerSingular(extra$1, V.Spec.name, V.Spec.stateSchema));
131
133
  let _prevAttribution = ResourceAttribution$ReventlessCore.enter(Spec.platformName, extra$1);
132
134
  Logger$ReventlessCore.registerComponentPlugin(extra$1, extra$1);
133
135
  aggregates.forEach(M => Logger$ReventlessCore.registerComponentPlugin(M.Spec.name, extra$1));
@@ -189,7 +191,7 @@ function Make(Spec) {
189
191
  });
190
192
  let mutationEntries = mutationEntriesFromAggregates.concat(dcbResult.mutationEntries);
191
193
  let queryEntriesFromReadModels = readModels.map(R => {
192
- let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, undefined);
194
+ let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, Api_Naming$ReventlessCore.declaredPlural(R.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(R.Spec.stateSchema), undefined);
193
195
  let subIdField = Stdlib_Option.map(R.Spec.subIdConfig, c => c.subIdField);
194
196
  let indexes = R.Spec.config.indexes;
195
197
  let resolvedFields = Api_Naming$ReventlessCore.resolvedFieldsOfConfig(extra$1, R.Spec.config);
@@ -214,7 +216,7 @@ function Make(Spec) {
214
216
  }));
215
217
  let eventLogEntries = eventLogEntriesFromAggregates.concat(dcbResult.eventLogEntries);
216
218
  readModels.forEach(R => {
217
- let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, undefined);
219
+ let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, Api_Naming$ReventlessCore.declaredPlural(R.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(R.Spec.stateSchema), undefined);
218
220
  let label = Plugin_Structure$ReventlessCore.labelFieldsFromStateSchema(R.Spec.name, R.Spec.stateSchema);
219
221
  let newrecord = {...qn};
220
222
  newrecord.labelField = label.field;
@@ -331,7 +333,7 @@ function Make(Spec) {
331
333
  };
332
334
  });
333
335
  let readModelComponents = readModels.map(R => {
334
- let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, undefined);
336
+ let qn = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(extra$1, R.Spec.name, Api_Naming$ReventlessCore.declaredPlural(R.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(R.Spec.stateSchema), undefined);
335
337
  let schema_queryFields = [
336
338
  qn.singleFieldName,
337
339
  qn.listFieldName
@@ -1153,7 +1153,12 @@ let readSideDefFromSpec = (
1153
1153
  ~linkedWriteSide: array<string>=[],
1154
1154
  ~chapter: option<string>=?,
1155
1155
  ): Reventless.Plugin.readSideDef => {
1156
- let qf = Api_Naming.queryFieldNamesForReadModel(~plugin, ~name)
1156
+ let qf = Api_Naming.queryFieldNamesForReadModel(
1157
+ ~plugin,
1158
+ ~name,
1159
+ ~plural=?Api_Naming.declaredPlural(stateSchema),
1160
+ ~singular=?Api_Naming.declaredSingular(stateSchema),
1161
+ )
1157
1162
  let label = labelFieldsFromStateSchema(~entityName=name, stateSchema)
1158
1163
  // The published key is always filterable; not every filterable field is the key.
1159
1164
  let keyField = GraphQL_FragmentGenerator.resolveKeyField(
@@ -1178,6 +1183,8 @@ let readSideDefFromSpec = (
1178
1183
  visibility: ?visibilityTag(visibility),
1179
1184
  ?chapter,
1180
1185
  singleQueryField: qf.singleFieldName,
1186
+ plural: ?qf.plural,
1187
+ pluralSource: ?(qf.pluralDeclared->Option.map(d => d ? "declared" : "derived")),
1181
1188
  idField: ?(keyField->Option.map(((f, _)) => f)),
1182
1189
  idFieldSource: ?(keyField->Option.map(((_, rung)) => rung)),
1183
1190
  requiredAccess: ?accessKeysFor(authorization),
@@ -1605,7 +1612,12 @@ let make = (
1605
1612
  let readModelDefs = readModels->Array.map((
1606
1613
  module(R: ReventlessInfra.ReadModel.T with type api = api and type role = role),
1607
1614
  ) => {
1608
- let qf = Api_Naming.queryFieldNamesForReadModel(~plugin=name, ~name=R.Spec.name)
1615
+ let qf = Api_Naming.queryFieldNamesForReadModel(
1616
+ ~plugin=name,
1617
+ ~name=R.Spec.name,
1618
+ ~plural=?Api_Naming.declaredPlural(R.Spec.stateSchema->S.castToUnknown),
1619
+ ~singular=?Api_Naming.declaredSingular(R.Spec.stateSchema->S.castToUnknown),
1620
+ )
1609
1621
  let stateSchema = R.Spec.stateSchema->S.castToUnknown
1610
1622
  let label = labelFieldsFromStateSchema(~entityName=R.Spec.name, stateSchema)
1611
1623
  // The published key is always filterable; not every filterable field is the key.
@@ -1643,6 +1655,8 @@ let make = (
1643
1655
  // place that decides how `Products`/`Categories` singularise, and the
1644
1656
  // point of publishing the name is that a consumer stops guessing it.
1645
1657
  singleQueryField: qf.singleFieldName,
1658
+ plural: ?qf.plural,
1659
+ pluralSource: ?(qf.pluralDeclared->Option.map(d => d ? "declared" : "derived")),
1646
1660
  idField: ?(keyField->Option.map(((f, _)) => f)),
1647
1661
  idFieldSource: ?(keyField->Option.map(((_, rung)) => rung)),
1648
1662
  requiredAccess: ?accessKeysFor(R.Spec.authorization->Reventless.Authorization.named),
@@ -1653,7 +1667,12 @@ let make = (
1653
1667
 
1654
1668
  let stateViewDefs =
1655
1669
  stateViewSlices->Array.mapWithIndex((module(SVS: ReventlessInfra.StateViewSlice.T), i) => {
1656
- let qf = Api_Naming.queryFieldNamesForStateView(~plugin=name, ~viewName=SVS.Spec.name)
1670
+ let qf = Api_Naming.queryFieldNamesForStateView(
1671
+ ~plugin=name,
1672
+ ~viewName=SVS.Spec.name,
1673
+ ~plural=?Api_Naming.declaredPlural(SVS.Spec.stateSchema->S.castToUnknown),
1674
+ ~singular=?Api_Naming.declaredSingular(SVS.Spec.stateSchema->S.castToUnknown),
1675
+ )
1657
1676
  let (_, consumed) = svsConsumed->Array.getUnsafe(i)
1658
1677
  let stateSchema = SVS.Spec.stateSchema->S.castToUnknown
1659
1678
  let label = labelFieldsFromStateSchema(~entityName=SVS.Spec.name, stateSchema)
@@ -1684,6 +1703,8 @@ let make = (
1684
1703
  visibility: ?visibilityTag(SVS.Spec.visibility),
1685
1704
  chapter: ?chapterOf(SVS.Spec.name),
1686
1705
  singleQueryField: qf.singleFieldName,
1706
+ plural: ?qf.plural,
1707
+ pluralSource: ?(qf.pluralDeclared->Option.map(d => d ? "declared" : "derived")),
1687
1708
  idField: ?(keyField->Option.map(((f, _)) => f)),
1688
1709
  idFieldSource: ?(keyField->Option.map(((_, rung)) => rung)),
1689
1710
  requiredAccess: ?accessKeysFor(SVS.Spec.authorization->Reventless.Authorization.named),
@@ -850,7 +850,7 @@ function readSideDefFromSpec(plugin, name, stateSchema, authorization, visibilit
850
850
  let visibility = visibilityOpt !== undefined ? visibilityOpt : "Public";
851
851
  let consumedEventTypes = consumedEventTypesOpt !== undefined ? consumedEventTypesOpt : [];
852
852
  let linkedWriteSide = linkedWriteSideOpt !== undefined ? linkedWriteSideOpt : [];
853
- let qf = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(plugin, name, undefined);
853
+ let qf = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(plugin, name, Api_Naming$ReventlessCore.declaredPlural(stateSchema), Api_Naming$ReventlessCore.declaredSingular(stateSchema), undefined);
854
854
  let label = labelFieldsFromStateSchema(name, stateSchema);
855
855
  let keyField = GraphQL_FragmentGenerator$ReventlessCore.resolveKeyField("RowKeyedByEnvelope", name, stateSchema);
856
856
  return {
@@ -870,6 +870,14 @@ function readSideDefFromSpec(plugin, name, stateSchema, authorization, visibilit
870
870
  visibility: visibilityTag(visibility),
871
871
  chapter: chapter,
872
872
  singleQueryField: qf.singleFieldName,
873
+ plural: qf.plural,
874
+ pluralSource: Stdlib_Option.map(qf.pluralDeclared, d => {
875
+ if (d) {
876
+ return "declared";
877
+ } else {
878
+ return "derived";
879
+ }
880
+ }),
873
881
  idField: Stdlib_Option.map(keyField, param => param[0]),
874
882
  idFieldSource: Stdlib_Option.map(keyField, param => param[1]),
875
883
  requiredAccess: accessKeysFor(authorization),
@@ -1159,7 +1167,7 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
1159
1167
  };
1160
1168
  let recordKeyField = (rowKeying, entityName, stateSchema) => Stdlib_Option.forEach(GraphQL_FragmentGenerator$ReventlessCore.keyFieldGapMessage(GraphQL_FragmentGenerator$ReventlessCore.classifyKeyField(rowKeying, entityName, stateSchema)), why => log.warn("Plugin_Structure", undefined, name + `/` + entityName + ` ` + why));
1161
1169
  let readModelDefs = readModels.map(R => {
1162
- let qf = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(name, R.Spec.name, undefined);
1170
+ let qf = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(name, R.Spec.name, Api_Naming$ReventlessCore.declaredPlural(R.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(R.Spec.stateSchema), undefined);
1163
1171
  let stateSchema = R.Spec.stateSchema;
1164
1172
  let label = labelFieldsFromStateSchema(R.Spec.name, stateSchema);
1165
1173
  let keyField = GraphQL_FragmentGenerator$ReventlessCore.resolveKeyField("RowKeyedByEnvelope", R.Spec.name, stateSchema);
@@ -1184,6 +1192,14 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
1184
1192
  visibility: visibilityTag(R.Spec.visibility),
1185
1193
  chapter: componentChapters[R.Spec.name],
1186
1194
  singleQueryField: qf.singleFieldName,
1195
+ plural: qf.plural,
1196
+ pluralSource: Stdlib_Option.map(qf.pluralDeclared, d => {
1197
+ if (d) {
1198
+ return "declared";
1199
+ } else {
1200
+ return "derived";
1201
+ }
1202
+ }),
1187
1203
  idField: Stdlib_Option.map(keyField, param => param[0]),
1188
1204
  idFieldSource: Stdlib_Option.map(keyField, param => param[1]),
1189
1205
  requiredAccess: accessKeysFor(Authorization$Reventless.named(R.Spec.authorization)),
@@ -1191,7 +1207,7 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
1191
1207
  };
1192
1208
  });
1193
1209
  let stateViewDefs = stateViewSlices.map((SVS, i) => {
1194
- let qf = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, SVS.Spec.name, undefined);
1210
+ let qf = Api_Naming$ReventlessCore.queryFieldNamesForStateView(name, SVS.Spec.name, Api_Naming$ReventlessCore.declaredPlural(SVS.Spec.stateSchema), Api_Naming$ReventlessCore.declaredSingular(SVS.Spec.stateSchema), undefined);
1195
1211
  let match = svsConsumed[i];
1196
1212
  let consumed = match[1];
1197
1213
  let stateSchema = SVS.Spec.stateSchema;
@@ -1217,6 +1233,14 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
1217
1233
  visibility: visibilityTag(SVS.Spec.visibility),
1218
1234
  chapter: componentChapters[SVS.Spec.name],
1219
1235
  singleQueryField: qf.singleFieldName,
1236
+ plural: qf.plural,
1237
+ pluralSource: Stdlib_Option.map(qf.pluralDeclared, d => {
1238
+ if (d) {
1239
+ return "declared";
1240
+ } else {
1241
+ return "derived";
1242
+ }
1243
+ }),
1220
1244
  idField: Stdlib_Option.map(keyField, param => param[0]),
1221
1245
  idFieldSource: Stdlib_Option.map(keyField, param => param[1]),
1222
1246
  requiredAccess: accessKeysFor(Authorization$Reventless.named(SVS.Spec.authorization)),
@@ -103,6 +103,24 @@ module PsCategoriesViewSlice: ReventlessInfra.StateViewSlice.T = {
103
103
  type component = svsComponent
104
104
  let make = (~dcbEventLog as _, ~runtime as _=?, ~opts as _=?): component => Obj.magic(0)
105
105
  }
106
+ module PsPeopleViewSlice: ReventlessInfra.StateViewSlice.T = {
107
+ module Spec = PsPeopleView
108
+ module Projection = {
109
+ let project = PsPeopleView.project
110
+ let moduleUrl = PsPeopleView.moduleUrl
111
+ }
112
+ type component = svsComponent
113
+ let make = (~dcbEventLog as _, ~runtime as _=?, ~opts as _=?): component => Obj.magic(0)
114
+ }
115
+ module PsStatusViewSlice: ReventlessInfra.StateViewSlice.T = {
116
+ module Spec = PsStatusView
117
+ module Projection = {
118
+ let project = PsStatusView.project
119
+ let moduleUrl = PsStatusView.moduleUrl
120
+ }
121
+ type component = svsComponent
122
+ let make = (~dcbEventLog as _, ~runtime as _=?, ~opts as _=?): component => Obj.magic(0)
123
+ }
106
124
 
107
125
  module PsAttachInvoiceSlice: ReventlessInfra.StateChangeSlice.T = {
108
126
  module Spec = PsAttachInvoice
@@ -1300,6 +1318,72 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
1300
1318
  )
1301
1319
  })
1302
1320
 
1321
+ describe("plural / pluralSource — the plural the list field is built from", () => {
1322
+ let views = Plugin_Structure.make(
1323
+ ~name="TestPlugin",
1324
+ ~stateChangeSlices=[],
1325
+ ~stateViewSlices=[module(PsCategoriesViewSlice), module(PsPeopleViewSlice)],
1326
+ ).stateViewSlices
1327
+ let summary = (q: Reventless.Plugin.readSideDef) => (
1328
+ q.queryField,
1329
+ q.singleQueryField,
1330
+ q.plural,
1331
+ q.pluralSource,
1332
+ )
1333
+
1334
+ testSync(
1335
+ "@singular names the single field and the row type; the key follows it",
1336
+ () => {
1337
+ let status =
1338
+ Plugin_Structure.make(
1339
+ ~name="TestPlugin",
1340
+ ~stateChangeSlices=[],
1341
+ ~stateViewSlices=[module(PsStatusViewSlice)],
1342
+ ).stateViewSlices->Array.getUnsafe(0)
1343
+ expect((
1344
+ status.queryField,
1345
+ status.singleQueryField,
1346
+ status.idField,
1347
+ status.idFieldSource,
1348
+ ))->toEqual((
1349
+ "TestPlugin_Statuses",
1350
+ Some("TestPlugin_Status"),
1351
+ Some("statusId"),
1352
+ Some("convention"),
1353
+ ))
1354
+ },
1355
+ )
1356
+
1357
+ testSync(
1358
+ "a @resolves target's row type is the singular its view declares",
1359
+ () => {
1360
+ Api_Naming.registerSingular(
1361
+ ~plugin="TestPlugin",
1362
+ ~name="Status",
1363
+ PsStatusView.stateSchema->S.castToUnknown,
1364
+ )
1365
+ expect((
1366
+ Api_Naming.returnTypeNameFor(~plugin="TestPlugin", ~name="Status"),
1367
+ Api_Naming.returnTypeNameFor(~plugin="TestPlugin", ~name="Categories"),
1368
+ ))->toEqual(("TestPlugin_Status", "TestPlugin_Category"))
1369
+ },
1370
+ )
1371
+
1372
+ testSync(
1373
+ "@plural names the list field and the singular stays the name",
1374
+ () =>
1375
+ expect(views->Array.map(summary))->toEqual([
1376
+ (
1377
+ "TestPlugin_Categories",
1378
+ Some("TestPlugin_Category"),
1379
+ Some("Categories"),
1380
+ Some("derived"),
1381
+ ),
1382
+ ("TestPlugin_People", Some("TestPlugin_Person"), Some("People"), Some("declared")),
1383
+ ]),
1384
+ )
1385
+ })
1386
+
1303
1387
  // Which field identifies a row, and whether the author said so or this side
1304
1388
  // worked it out — the same declaration-vs-guess distinction `labelFieldSource`
1305
1389
  // publishes, for the field the generated filter and order-by are built from.