@opendatacapture/instrument-guidelines 2.0.0 → 2.1.1

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 (2) hide show
  1. package/AGENTS.md +42 -2
  2. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -179,9 +179,26 @@ The `content` may be either a bare ordered array of identities, or an object tha
179
179
  with optional series-level `params`:
180
180
 
181
181
  ```ts
182
- type SeriesContent =
182
+ // TData defaults to `any`; annotate the `data` parameter (or pass TData) to type it.
183
+ // A localized message keyed by language, e.g. `{ en: '…', fr: '…' }`.
184
+ type CompletionMessage = { [L in Language]?: string };
185
+
186
+ type SeriesParams<TItemName extends string = string, TData = any> = {
187
+ // Returns a custom localized message for the completion screen, or `null`/`undefined` for the
188
+ // default. `terminated` is `true` when the series ended early via `terminate`, so the message
189
+ // can differ per outcome.
190
+ completionMessage?: (this: void, context: { itemName?: TItemName; terminated: boolean }) => CompletionMessage | null;
191
+ skipProgress?: boolean;
192
+ // Called after each item is submitted with that item's data and its
193
+ // `{ itemIndex, itemName }`. Return `true` to end the series early: the
194
+ // remaining items are not administered and the series is marked complete.
195
+ // The terminating item's own record is still saved.
196
+ terminate?: (this: void, data: TData, context: { itemIndex: number; itemName: TItemName }) => boolean;
197
+ };
198
+
199
+ type SeriesContent<TItemName extends string = string, TData = any> =
183
200
  | ScalarInstrumentInternal[]
184
- | { items: ScalarInstrumentInternal[]; params?: { skipProgress?: boolean } };
201
+ | { items: ScalarInstrumentInternal[]; params?: SeriesParams<TItemName, TData> };
185
202
 
186
203
  interface SeriesInstrument<TLanguage extends InstrumentLanguage> extends BaseInstrument<TLanguage> {
187
204
  content: SeriesContent;
@@ -190,6 +207,29 @@ interface SeriesInstrument<TLanguage extends InstrumentLanguage> extends BaseIns
190
207
  }
191
208
  ```
192
209
 
210
+ Use `terminate` for conditional early exit — e.g. a consent form as the first item that,
211
+ when declined, prevents the remaining items from being shown. When the series is authored with
212
+ `defineSeriesInstrument`, `itemName` is narrowed to the literal union of the series' item names.
213
+ `data` defaults to `any`, so annotate it inline with the terminating item's data shape:
214
+
215
+ ```ts
216
+ params: {
217
+ // itemName: 'CONSENT_FORM' | 'QUESTIONNAIRE'
218
+ terminate: (data: { consent?: boolean }, { itemName }) => itemName === 'CONSENT_FORM' && data.consent === false;
219
+ }
220
+ ```
221
+
222
+ Use `completionMessage` to customize the localized text on the final "Thank You" screen — for
223
+ example, to explain that the series ended because consent was declined. Return a `{ en, fr }`
224
+ object (a bare string is treated as a translation key, not literal text), or `null` for the default:
225
+
226
+ ```ts
227
+ params: {
228
+ completionMessage: ({ terminated }) =>
229
+ terminated ? { en: 'Because you did not consent, the questionnaire was not administered.', fr: '…' } : null;
230
+ }
231
+ ```
232
+
193
233
  ### 1.2 Scalar Instrument Kinds
194
234
 
195
235
  #### 1.3.1 Form Instruments
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@opendatacapture/instrument-guidelines",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.1.1",
5
5
  "description": "Guidelines for authoring Open Data Capture instruments, intended to be read by an AI agent (e.g. Claude Code).",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {