@tricoteuses/tisseuse 0.14.12 → 0.14.13

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/README.md CHANGED
@@ -153,11 +153,12 @@ Les documents sans URL, externes au Sénat, sans Akoma Ntoso ou en échec de par
153
153
 
154
154
  ## Legal reference resolver
155
155
 
156
- Tisseuse resolves legal references through the Canutes-backed `LegiResolver`.
157
- `LegiResolver` is exported as an abstract class from both
158
- `@tricoteuses/tisseuse` and `@tricoteuses/tisseuse/server`, so applications can
159
- provide another storage-backed implementation. At process startup, the Canutes
160
- resolver reads the title metadata it needs directly from
156
+ Tisseuse resolves legal references through a `LegiResolver`. `LegiResolver` is
157
+ exported as an abstract class from both `@tricoteuses/tisseuse` and
158
+ `@tricoteuses/tisseuse/server`, so applications can provide another
159
+ storage-backed implementation.
160
+
161
+ The default Canutes resolver reads the title metadata it needs directly from
161
162
  `legifrance.texte_version` and builds the parser indexes in memory. Concurrent
162
163
  callers share the same preload operation, and the resulting indexes remain fixed
163
164
  for the lifetime of the process.
@@ -216,6 +217,34 @@ The caller owns the PostgreSQL client and its lifecycle. Importing the adapter
216
217
  does not open a connection, read environment variables, or preload title data.
217
218
  The generic Tisseuse entry points do not load this adapter.
218
219
 
220
+ `FlegiResolver` expects the flat database schema generated by `legi-flat-db`,
221
+ including `text_titles_infos` and `text_titles_infos_parser_cache`. The first
222
+ table is the source relation generated from Canutes. The second is a JSONB cache
223
+ of the parser-aware `TextTitlesInfos` structure used by Tisseuse. It is filled
224
+ lazily by `FlegiResolver`, not by `legi-flat-db` SQL, so the TypeScript parser
225
+ logic remains in this package.
226
+
227
+ On `preloadTextTitlesInfos`, `FlegiResolver` first tries to load the `current`
228
+ cache row matching the package cache format version. On a miss or format
229
+ mismatch, it takes a PostgreSQL advisory transaction lock, re-checks the cache,
230
+ locks `text_titles_infos` through the `SECURITY DEFINER` helper
231
+ `lock_text_titles_infos_for_parser_cache()`, rebuilds the parser indexes from
232
+ `text_titles_infos`, writes the JSONB cache, then installs it in memory. A trigger
233
+ on `text_titles_infos` invalidates the cache by deleting the `current` row when
234
+ the source title relation changes.
235
+
236
+ Operational notes for `f_legi` deployments:
237
+
238
+ - Regenerate or migrate the flat database before using this adapter version; the
239
+ schema check requires `text_titles_infos_parser_cache`.
240
+ - The runtime role needs `SELECT` on the source tables, `INSERT`/`UPDATE` on the
241
+ cache table, and `EXECUTE` on `lock_text_titles_infos_for_parser_cache()`.
242
+ - The owner of the `SECURITY DEFINER` helper must be able to lock
243
+ `text_titles_infos`; `legi-flat-db` sets the helper owner to the importing
244
+ role.
245
+ - Increment `textTitlesInfosParserCacheFormatVersion` when the serialized
246
+ `TextTitlesInfos` shape changes.
247
+
219
248
  External adapters can extend the public `LegiResolver` class. The public package
220
249
  also exports the resolver option types and `buildAndInstallTextTitlesInfos`, so
221
250
  an adapter does not need deep imports into Tisseuse.