@@ -3241,12 +3241,22 @@ export class KnowledgeService implements IKnowledgeService {
32413241 * gate that throws, or a security service that answers neither field
32423242 * question, the save is refused `503 SERVICE_UNAVAILABLE`. The system
32433243 * context is admitted, as it bypasses the gates at search.
3244+ *
3245+ * `options.door` words the sentences for the door that asks (the gates and
3246+ * the status and code are the same at both): `save`, the default, for a
3247+ * door that saves one item; `duplicate` for the package duplicate, which
3248+ * copies a package's sources. Its caller is told the source cannot be
3249+ * copied and to duplicate the package again, never to save the source, and
3250+ * no "nothing was written": that door's own prefix says once that nothing
3251+ * was copied.
32443252 */
32453253 async admitAuthoredSource (
32463254 item : unknown ,
32473255 ctx : ExecutionContext | undefined ,
3256+ options ?: { door ?: 'save' | 'duplicate' } ,
32483257 ) : Promise < { admitted : true } | { admitted : false ; status : number ; code : string ; message : string ; object : string ; field ?: string } > {
32493258 if ( ctx ?. isSystem ) return { admitted : true } ;
3259+ const wording = AUTHORED_SOURCE_DOOR_WORDING [ options ?. door === 'duplicate' ? 'duplicate' : 'save' ] ;
32503260 const body = ( item as { name ?: unknown ; source ?: unknown } | null | undefined ) ?? { } ;
32513261 const declared = body . source as
32523262 | { object ?: unknown ; content ?: unknown ; contentFields ?: unknown ; metadataFields ?: unknown ; where ?: unknown }
@@ -3267,17 +3277,17 @@ export class KnowledgeService implements IKnowledgeService {
32673277 ? { where : where as Record < string , unknown > }
32683278 : { } ) ,
32693279 } ;
3270- const named = `The knowledge source${ describeName ( body ) } was not saved ` ;
3280+ const named = `The knowledge source${ describeName ( body ) } ${ wording . notDone } ` ;
32713281 const refuse = ( status : number , code : string , message : string , field ?: string ) =>
32723282 ( { admitted : false as const , status, code, message, object, ...( field === undefined ? { } : { field } ) } ) ;
32733283 const unavailable = ( why : string ) =>
32743284 refuse (
32753285 503 ,
32763286 'SERVICE_UNAVAILABLE' ,
32773287 `${ named } : whether you may search object '${ object } ' could not be judged (${ why } ), and an author must be ` +
3278- ' allowed to search what their source indexes. Nothing was written; try again.' ,
3288+ ` allowed to search what their source indexes.${ wording . tryAgain } ` ,
32793289 ) ;
3280- if ( ! ctx ) return refuse ( 403 , 'PERMISSION_DENIED' , `${ named } : the save carries no identity, and a missing identity is not a grant of authority.` ) ;
3290+ if ( ! ctx ) return refuse ( 403 , 'PERMISSION_DENIED' , `${ named } : ${ wording . act } carries no identity, and a missing identity is not a grant of authority.` ) ;
32813291 // [ADR-0161 K4 ◆] A source that names no adapter where this deployment
32823292 // cannot place one is refused at its save as at its registration, so the
32833293 // author hears it: several adapters registered, none the deployment's.
@@ -3291,7 +3301,7 @@ export class KnowledgeService implements IKnowledgeService {
32913301 // the boot log or a search's 503. A save is served after every store's
32923302 // `start()`, so the adapters registered now are the deployment's.
32933303 if ( typeof authoredAdapter === 'string' && ! registeredAdapters . includes ( authoredAdapter ) ) {
3294- return refuse ( 400 , 'VALIDATION_ERROR' , `${ named } : ${ this . unmountedAdapterSaveText ( authoredAdapter , registeredAdapters ) } ` ) ;
3304+ return refuse ( 400 , 'VALIDATION_ERROR' , `${ named } : ${ this . unmountedAdapterSaveText ( authoredAdapter , registeredAdapters , wording . again ) } ` ) ;
32953305 }
32963306 const engine = this . options . dataEngine ;
32973307 if ( ! engine ) return unavailable ( 'the knowledge service has no data engine' ) ;
@@ -3340,7 +3350,7 @@ export class KnowledgeService implements IKnowledgeService {
33403350 'PERMISSION_DENIED' ,
33413351 `${ named } : its \`where\` reads field '${ field } ' of object '${ object } ', which you may not query (it is ` +
33423352 'hidden from you, or served to you masked), and the source would select its records by that field. ' +
3343- ' Remove the field from `where` , or have someone who may query it save the source.' ,
3353+ ` Remove the field from \ `where\` ${ wording . thenAgain } , or have someone who may query it ${ wording . byWhoMay } .` ,
33443354 field ,
33453355 ) ;
33463356 }
@@ -3351,9 +3361,9 @@ export class KnowledgeService implements IKnowledgeService {
33513361 `${ named } : you may not query field '${ field } ' of object '${ object } ' (it is hidden from you, or served ` +
33523362 'to you masked), and the index would hold its text unmasked. ' +
33533363 ( listedByAuthor
3354- ? ' Remove the field from `content` and `metadataFields` , or have someone who may query it save the source.'
3364+ ? ` Remove the field from \ `content\ ` and \ `metadataFields\` ${ wording . thenAgain } , or have someone who may query it ${ wording . byWhoMay } .`
33553365 : "The source does not list it: it is the object's display field, which every document carries as its " +
3356- ' title. Have someone who may query it save the source.' ) ,
3366+ ` title. Have someone who may query it ${ wording . byWhoMay } .` ) ,
33573367 field ,
33583368 ) ;
33593369 }
@@ -3368,13 +3378,13 @@ export class KnowledgeService implements IKnowledgeService {
33683378 * can take. Leaving `adapter` out is offered only where an omitted adapter
33693379 * would be placed ({@link adapterIdFor}).
33703380 */
3371- private unmountedAdapterSaveText ( adapter : string , mounted : readonly string [ ] ) : string {
3381+ private unmountedAdapterSaveText ( adapter : string , mounted : readonly string [ ] , again : string ) : string {
33723382 const deployment = this . options . deploymentAdapter ;
33733383 const placeable = ( deployment !== undefined && mounted . includes ( deployment ) ) || mounted . length === 1 ;
33743384 const remedies = [
33753385 ...( mounted . length === 0 ? [ ] : [ `name one of ${ mounted . map ( ( id ) => `'${ id } '` ) . join ( ', ' ) } as its \`adapter\`` ] ) ,
33763386 ...( placeable ? [ "leave `adapter` out, and the deployment's store holds it" ] : [ ] ) ,
3377- `mount the '${ adapter } ' store and save it again` ,
3387+ `mount the '${ adapter } ' store and ${ again } ` ,
33783388 ] ;
33793389 return (
33803390 `it names adapter '${ adapter } ', which this deployment does not mount ` +
@@ -3552,6 +3562,39 @@ function describeEntry(entry: KnowledgeSourceEntry): KnowledgeSourceDescription
35523562}
35533563
35543564/** ` 'NAME'` for a refusal about an input that carries a usable name (or its retired `id`), else nothing. */
3565+ /**
3566+ * The door that asks {@link KnowledgeService.admitAuthoredSource}: `save` for
3567+ * a door that saves one item, `duplicate` for the package duplicate.
3568+ */
3569+ type AuthoredSourceDoor = 'save' | 'duplicate' ;
3570+
3571+ /**
3572+ * What each door's caller is told: the source not done, the act that carries
3573+ * the identity, the retry after a verdict that could not be judged, the redo
3574+ * after a fix, and the act someone who may query the field performs. The
3575+ * `save` row is the save door's wording, unchanged.
3576+ */
3577+ const AUTHORED_SOURCE_DOOR_WORDING : Readonly <
3578+ Record < AuthoredSourceDoor , { notDone : string ; act : string ; tryAgain : string ; again : string ; thenAgain : string ; byWhoMay : string } >
3579+ > = {
3580+ save : {
3581+ notDone : 'was not saved' ,
3582+ act : 'the save' ,
3583+ tryAgain : ' Nothing was written; try again.' ,
3584+ again : 'save it again' ,
3585+ thenAgain : '' ,
3586+ byWhoMay : 'save the source' ,
3587+ } ,
3588+ duplicate : {
3589+ notDone : 'cannot be copied' ,
3590+ act : 'the duplicate' ,
3591+ tryAgain : ' Duplicate the package again.' ,
3592+ again : 'duplicate the package again' ,
3593+ thenAgain : ', then duplicate the package again' ,
3594+ byWhoMay : 'duplicate the package' ,
3595+ } ,
3596+ } ;
3597+
35553598function describeName ( input : unknown ) : string {
35563599 const { name, id } = ( input ?? { } ) as { name ?: unknown ; id ?: unknown } ;
35573600 const shown = typeof name === 'string' && name !== '' ? name : typeof id === 'string' && id !== '' ? id : undefined ;
0 commit comments