From 7a28a94639e4ce9777c3e4a11c032f665ab2ccb0 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Mon, 3 Aug 2026 15:33:01 -0700 Subject: [PATCH] =?UTF-8?q?feat(namespace):=20find's=20own=20filter=20buil?= =?UTF-8?q?ders=20speak=20the=20frozen=20keys=20=E2=80=94=20params.type/su?= =?UTF-8?q?btype/service=20become=20system.*=20index=20keys=20at=20every?= =?UTF-8?q?=20construction=20site=20(three=20pipelines=20+=20the=20canonic?= =?UTF-8?q?al=20buildMetadataFilter);=20the=20where.type=E2=86=92noun=20al?= =?UTF-8?q?ias=20is=20dead=20(bare=20'type'=20belongs=20to=20the=20user=20?= =?UTF-8?q?now)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/brainy.ts | 64 ++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/src/brainy.ts b/src/brainy.ts index d8eca08b..a8df56bd 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -6148,20 +6148,18 @@ export class Brainy implements BrainyInterface { // Build filter for metadata index let filter: any = {} if (params.where) { + // Where keys pass through UNTOUCHED — the addressing law parses + // them at the index boundary. The old where.type→noun alias is + // dead: bare 'type' is the user's own field now. Object.assign(filter, params.where) - // Alias: where.type → where.noun (storage field name for entity type) - if ('type' in filter && !('noun' in filter)) { - filter.noun = filter.type - delete filter.type - } } - if (params.service) filter.service = params.service + if (params.service) filter['system.service'] = params.service // Subtype (top-level standard field — fast path, not metadata fallback). // Must be assigned BEFORE the type-array expansion below so the spread // into each anyOf branch carries it through. if (params.subtype !== undefined) { - filter.subtype = Array.isArray(params.subtype) + filter['system.subtype'] = Array.isArray(params.subtype) ? { oneOf: params.subtype } : params.subtype } @@ -6169,11 +6167,11 @@ export class Brainy implements BrainyInterface { if (params.type) { const types = Array.isArray(params.type) ? params.type : [params.type] if (types.length === 1) { - filter.noun = types[0] + filter['system.type'] = types[0] } else { filter = { anyOf: types.map(type => ({ - noun: type, + 'system.type': type, ...filter })) } @@ -11388,27 +11386,26 @@ export class Brainy implements BrainyInterface { if (params.where || params.subtype || params.service) { let filter: any = {} if (params.where) { + // Where keys pass through UNTOUCHED — the one addressing law + // parses them at the index boundary (bare = user metadata, + // system.* = engine scalars). The old where.type→noun alias is + // dead: a bare 'type' is the user's own field now. Object.assign(filter, params.where) - // Alias: where.type → where.noun (storage field name for entity type) - if ('type' in filter && !('noun' in filter)) { - filter.noun = filter.type - delete filter.type - } } - if (params.service) filter.service = params.service + if (params.service) filter['system.service'] = params.service if (params.subtype !== undefined) { - filter.subtype = Array.isArray(params.subtype) + filter['system.subtype'] = Array.isArray(params.subtype) ? { oneOf: params.subtype } : params.subtype } if (params.type) { const types = Array.isArray(params.type) ? params.type : [params.type] if (types.length === 1) { - filter.noun = types[0] + filter['system.type'] = types[0] } else { const baseFilter = { ...filter } filter = { - anyOf: types.map(type => ({ noun: type, ...baseFilter })) + anyOf: types.map(type => ({ 'system.type': type, ...baseFilter })) } } } @@ -11458,27 +11455,24 @@ export class Brainy implements BrainyInterface { // Use MetadataIndexManager for efficient filtered streaming let filterObj: any = {} if (filter.where) { + // Where keys pass through — the addressing law parses them at + // the index boundary; the type→noun alias is dead. Object.assign(filterObj, filter.where) - // Alias: where.type → where.noun (storage field name for entity type) - if ('type' in filterObj && !('noun' in filterObj)) { - filterObj.noun = filterObj.type - delete filterObj.type - } } - if (filter.service) filterObj.service = filter.service + if (filter.service) filterObj['system.service'] = filter.service if (filter.subtype !== undefined) { - filterObj.subtype = Array.isArray(filter.subtype) + filterObj['system.subtype'] = Array.isArray(filter.subtype) ? { oneOf: filter.subtype } : filter.subtype } if (filter.type) { const types = Array.isArray(filter.type) ? filter.type : [filter.type] if (types.length === 1) { - filterObj.noun = types[0] + filterObj['system.type'] = types[0] } else { const baseFilterObj = { ...filterObj } filterObj = { - anyOf: types.map(type => ({ noun: type, ...baseFilterObj })) + anyOf: types.map(type => ({ 'system.type': type, ...baseFilterObj })) } } } @@ -13605,14 +13599,12 @@ export class Brainy implements BrainyInterface { } let filter: any = {} if (params.where) { + // Where keys pass through UNTOUCHED — the one addressing law parses + // them at the index boundary (bare = user metadata, system.* = engine + // scalars, typed refusal otherwise). The old type→noun alias is dead. Object.assign(filter, params.where) - // Alias: where.type → where.noun (storage field name for entity type) - if ('type' in filter && !('noun' in filter)) { - filter.noun = filter.type - delete filter.type - } } - if (params.service) filter.service = params.service + if (params.service) filter['system.service'] = params.service if (params.excludeVFS === true) { filter.vfsType = { exists: false } filter.isVFSEntity = { ne: true } @@ -13620,14 +13612,14 @@ export class Brainy implements BrainyInterface { // Subtype (top-level standard field — fast path). Assigned BEFORE the type-array // expansion below so the spread into each anyOf branch carries it through. if (params.subtype !== undefined) { - filter.subtype = Array.isArray(params.subtype) ? { oneOf: params.subtype } : params.subtype + filter['system.subtype'] = Array.isArray(params.subtype) ? { oneOf: params.subtype } : params.subtype } if (params.type) { const types = Array.isArray(params.type) ? params.type : [params.type] if (types.length === 1) { - filter.noun = types[0] + filter['system.type'] = types[0] } else { - filter = { anyOf: types.map((type) => ({ noun: type, ...filter })) } + filter = { anyOf: types.map((type) => ({ 'system.type': type, ...filter })) } } } return filter