@mrtdown/core 2.0.0-alpha.4 → 2.0.0-alpha.5
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/dist/cli/commands/create.js +3 -3
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/list.js +2 -2
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/show.js +3 -3
- package/dist/cli/commands/show.js.map +1 -1
- package/dist/cli/commands/validate.js +1 -1
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/helpers/keyForAffectedEntity.d.ts +1 -1
- package/dist/helpers/keyForAffectedEntity.js.map +1 -1
- package/dist/helpers/normalizeRecurringPeriod.d.ts +1 -1
- package/dist/helpers/normalizeRecurringPeriod.js +1 -1
- package/dist/helpers/normalizeRecurringPeriod.js.map +1 -1
- package/dist/helpers/normalizeRecurringPeriod.test.js.map +1 -1
- package/dist/helpers/resolvePeriods.d.ts +1 -1
- package/dist/helpers/resolvePeriods.js +1 -1
- package/dist/helpers/resolvePeriods.js.map +1 -1
- package/dist/helpers/resolvePeriods.test.js.map +1 -1
- package/dist/index.d.ts +25 -25
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/llm/common/MemoryStore.d.ts +2 -2
- package/dist/llm/common/MemoryStore.js.map +1 -1
- package/dist/llm/common/formatCurrentState.d.ts +2 -2
- package/dist/llm/common/formatCurrentState.js.map +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js +3 -3
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js.map +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.d.ts +2 -2
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js +4 -4
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js.map +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.d.ts +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.js.map +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.d.ts +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js.map +1 -1
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.d.ts +2 -2
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js +2 -2
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js.map +1 -1
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js +2 -2
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js.map +1 -1
- package/dist/llm/functions/translate/index.js +4 -4
- package/dist/llm/functions/translate/index.js.map +1 -1
- package/dist/llm/functions/triageNewEvidence/eval.test.js +2 -2
- package/dist/llm/functions/triageNewEvidence/eval.test.js.map +1 -1
- package/dist/llm/functions/triageNewEvidence/index.d.ts +1 -1
- package/dist/llm/functions/triageNewEvidence/index.js +4 -4
- package/dist/llm/functions/triageNewEvidence/index.js.map +1 -1
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.d.ts +2 -2
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js +1 -1
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js.map +1 -1
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.d.ts +1 -1
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js +1 -1
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js.map +1 -1
- package/dist/repo/issue/IssueRepository.d.ts +1 -1
- package/dist/repo/issue/IssueRepository.js +3 -3
- package/dist/repo/issue/IssueRepository.js.map +1 -1
- package/dist/repo/issue/helpers/deriveCurrentState.d.ts +6 -6
- package/dist/repo/issue/helpers/deriveCurrentState.js +1 -1
- package/dist/repo/issue/helpers/deriveCurrentState.js.map +1 -1
- package/dist/repo/issue/helpers/deriveCurrentState.test.js.map +1 -1
- package/dist/schema/issue/evidence.js +1 -1
- package/dist/schema/issue/evidence.js.map +1 -1
- package/dist/schema/issue/issue.js +1 -1
- package/dist/schema/issue/issue.js.map +1 -1
- package/dist/util/ingestContent/helpers/getSlugDateTimeFromClaims.d.ts +1 -1
- package/dist/util/ingestContent/helpers/getSlugDateTimeFromClaims.js +1 -1
- package/dist/util/ingestContent/helpers/getSlugDateTimeFromClaims.js.map +1 -1
- package/dist/util/ingestContent/index.js +9 -9
- package/dist/util/ingestContent/index.js.map +1 -1
- package/dist/validators/buildContext.js +6 -6
- package/dist/validators/buildContext.js.map +1 -1
- package/dist/validators/issue.d.ts +1 -1
- package/dist/validators/issue.js +3 -3
- package/dist/validators/issue.js.map +1 -1
- package/dist/validators/line.d.ts +1 -1
- package/dist/validators/line.js +1 -1
- package/dist/validators/line.js.map +1 -1
- package/dist/validators/operator.js +1 -1
- package/dist/validators/operator.js.map +1 -1
- package/dist/validators/town.d.ts +1 -1
- package/dist/validators/town.js +1 -1
- package/dist/validators/town.js.map +1 -1
- package/dist/write/issue/IssueWriter.d.ts +3 -3
- package/dist/write/issue/IssueWriter.js.map +1 -1
- package/package.json +1 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriveCurrentState.test.js","sourceRoot":"/","sources":["repo/issue/helpers/deriveCurrentState.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAKhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,aAAa,GAAG,EAAE,IAAI,EAAE,SAAkB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACrE,MAAM,MAAM,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAEnD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IACl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EAAE;gBAC3C,KAAK,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;aACpC;YACD;gBACE,EAAE,EAAE,aAAa;gBACjB,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,sBAAsB;gBAC1B,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,OAAO;wBACb,OAAO,EAAE,2BAA2B;wBACpC,KAAK,EAAE,2BAA2B;qBACnC;iBACF;gBACD,KAAK,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;aACpC;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAE1C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC;YACnD,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE;YAC3C,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,2BAA2B;oBACpC,KAAK,EAAE,2BAA2B;iBACnC;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;YACvD,MAAM,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;YACpC,OAAO,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;SACtC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test } from 'vitest';\nimport type { IssueBundle } from '#schema/issue/bundle.js';\nimport type { Period } from '#schema/issue/period.js';\nimport type { ServiceEffect } from '#schema/issue/serviceEffect.js';\nimport type { ServiceScope } from '#schema/issue/serviceScope.js';\nimport { keyForAffectedEntity } from '../../../helpers/keyForAffectedEntity.js';\nimport { deriveCurrentState } from './deriveCurrentState.js';\n\nconst defaultTarget = { type: 'service' as const, serviceId: 'NSL' };\nconst nslKey = keyForAffectedEntity(defaultTarget);\n\ndescribe('deriveCurrentState', () => {\n const createMockIssue = () => ({\n id: '2025-01-01-test-issue',\n type: 'disruption' as const,\n title: {\n 'en-SG': 'Test Issue',\n 'zh-Hans': null,\n ms: null,\n ta: null,\n },\n titleMeta: {\n source: 'test',\n },\n });\n\n const createMockBundle = (\n impact: IssueBundle['impactEvents'],\n ): IssueBundle => ({\n issue: createMockIssue(),\n evidence: [],\n impactEvents: impact,\n path: 'test/path',\n });\n\n test('returns empty state for bundle with no impacts', () => {\n const bundle = createMockBundle([]);\n const result = deriveCurrentState(bundle);\n\n expect(result).toEqual({\n services: {},\n servicesProvenance: {},\n facilities: {},\n facilitiesProvenance: {},\n impactEventIds: [],\n });\n });\n\n test('handles service_effects.set impact', () => {\n const effect: ServiceEffect = { kind: 'delay', duration: null };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect,\n scopes: [],\n periods: [],\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n effect: { evidenceId: 'evidence-1' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles periods_set impact', () => {\n const periods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n {\n kind: 'fixed',\n startAt: '2025-01-01T14:00:00+08:00',\n endAt: null,\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n periods,\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: [],\n periods,\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n periods: { evidenceId: 'evidence-3' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles causes.set impact', () => {\n const causes = ['signal.fault', 'track.fault'] as const;\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_cause_001',\n type: 'causes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n causes: [...causes],\n basis: { evidenceId: 'evidence-cause' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: [],\n periods: [],\n causes,\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n causes: { evidenceId: 'evidence-cause' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_cause_001']);\n });\n\n test('handles service_scopes_set impact', () => {\n const serviceScopes: ServiceScope[] = [\n {\n type: 'service.whole',\n },\n {\n type: 'service.segment',\n fromStationId: 'station-1',\n toStationId: 'station-2',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n serviceScopes,\n basis: {\n evidenceId: 'evidence-5',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: serviceScopes,\n periods: [],\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n scopes: { evidenceId: 'evidence-5' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles multiple impacts - later impacts overwrite earlier ones', () => {\n const firstEffect: ServiceEffect = { kind: 'delay', duration: null };\n const secondEffect: ServiceEffect = { kind: 'no-service' };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: firstEffect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n effect: secondEffect,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(secondEffect);\n expect(result.servicesProvenance[nslKey].effect?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('handles mixed impact types', () => {\n const effect: ServiceEffect = { kind: 'delay', duration: null };\n const periods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ];\n const serviceScopes: ServiceScope[] = [\n {\n type: 'service.point',\n stationId: 'station-1',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n {\n id: 'ie_test_003',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T12:00:00Z',\n serviceScopes,\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(effect);\n expect(result.services[nslKey].periods).toEqual(periods);\n expect(result.services[nslKey].scopes).toEqual(serviceScopes);\n expect(result.servicesProvenance[nslKey].effect?.evidenceId).toBe(\n 'evidence-1',\n );\n expect(result.servicesProvenance[nslKey].periods?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.servicesProvenance[nslKey].scopes?.evidenceId).toBe(\n 'evidence-3',\n );\n expect(result.impactEventIds).toEqual([\n 'ie_test_001',\n 'ie_test_003',\n 'ie_test_002',\n ]);\n });\n\n test('handles all service effect kinds', () => {\n const effectKinds: ServiceEffect['kind'][] = [\n 'delay',\n 'no-service',\n 'reduced-service',\n 'service-hours-adjustment',\n ];\n\n for (const kind of effectKinds) {\n const effect: ServiceEffect =\n kind === 'delay' ? { kind: 'delay', duration: null } : { kind };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(effect);\n }\n });\n\n test('handles all scope types', () => {\n const allScopes: ServiceScope[] = [\n {\n type: 'service.whole',\n },\n {\n type: 'service.segment',\n fromStationId: 'station-1',\n toStationId: 'station-2',\n },\n {\n type: 'service.point',\n stationId: 'station-3',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n serviceScopes: allScopes,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].scopes).toEqual(allScopes);\n expect(result.services[nslKey].scopes).toHaveLength(3);\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles empty arrays in impacts', () => {\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'no-service' },\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods: [],\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n {\n id: 'ie_test_003',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T12:00:00Z',\n serviceScopes: [],\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual({ kind: 'no-service' });\n expect(result.services[nslKey].periods).toEqual([]);\n expect(result.services[nslKey].scopes).toEqual([]);\n expect(result.impactEventIds).toEqual([\n 'ie_test_001',\n 'ie_test_003',\n 'ie_test_002',\n ]);\n });\n\n test('preserves order of impacts when processing', () => {\n const firstPeriods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ];\n const secondPeriods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T14:00:00+08:00',\n endAt: null,\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n periods: firstPeriods,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods: secondPeriods,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].periods).toEqual(secondPeriods);\n expect(result.servicesProvenance[nslKey].periods?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('groups impacts by target - different targets produce separate entries', () => {\n const nslTarget = { type: 'service' as const, serviceId: 'NSL' };\n const ewlTarget = { type: 'service' as const, serviceId: 'EWL' };\n const nslKeyLocal = keyForAffectedEntity(nslTarget);\n const ewlKey = keyForAffectedEntity(ewlTarget);\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: nslTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'delay', duration: null },\n basis: { evidenceId: 'evidence-1' },\n },\n {\n id: 'ie_test_002',\n type: 'service_effects.set',\n entity: ewlTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'no-service' },\n basis: { evidenceId: 'evidence-2' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(Object.keys(result.services)).toHaveLength(2);\n expect(result.services[nslKeyLocal].effect).toEqual({\n kind: 'delay',\n duration: null,\n });\n expect(result.services[nslKeyLocal]).toMatchObject({ id: 'NSL' });\n expect(result.services[ewlKey].effect).toEqual({ kind: 'no-service' });\n expect(result.services[ewlKey]).toMatchObject({ id: 'EWL' });\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('handles facility impacts', () => {\n const facilityEntity = {\n type: 'facility' as const,\n stationId: 'JUR',\n kind: 'lift' as const,\n };\n const facilityKey = keyForAffectedEntity(facilityEntity);\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'facility_effects.set',\n entity: facilityEntity,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'facility-out-of-service' },\n basis: { evidenceId: 'evidence-1' },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: facilityEntity,\n ts: '2025-01-01T10:00:00Z',\n periods: [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ],\n basis: { evidenceId: 'evidence-2' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.facilities[facilityKey]).toMatchObject({\n stationId: 'JUR',\n kind: 'lift',\n effect: { kind: 'facility-out-of-service' },\n periods: [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ],\n });\n expect(result.facilitiesProvenance[facilityKey]).toEqual({\n effect: { evidenceId: 'evidence-1' },\n periods: { evidenceId: 'evidence-2' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_002', 'ie_test_001']);\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"deriveCurrentState.test.js","sourceRoot":"/","sources":["repo/issue/helpers/deriveCurrentState.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAKhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,aAAa,GAAG,EAAE,IAAI,EAAE,SAAkB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACrE,MAAM,MAAM,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAEnD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;QAC7B,EAAE,EAAE,uBAAuB;QAC3B,IAAI,EAAE,YAAqB;QAC3B,KAAK,EAAE;YACL,OAAO,EAAE,YAAY;YACrB,SAAS,EAAE,IAAI;YACf,EAAE,EAAE,IAAI;YACR,EAAE,EAAE,IAAI;SACT;QACD,SAAS,EAAE;YACT,MAAM,EAAE,MAAM;SACf;KACF,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,CACvB,MAAmC,EACtB,EAAE,CAAC,CAAC;QACjB,KAAK,EAAE,eAAe,EAAE;QACxB,QAAQ,EAAE,EAAE;QACZ,YAAY,EAAE,MAAM;QACpB,IAAI,EAAE,WAAW;KAClB,CAAC,CAAC;IAEH,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;QAC1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAE1C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,QAAQ,EAAE,EAAE;YACZ,kBAAkB,EAAE,EAAE;YACt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QACH,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;YACvD,MAAM,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;YACpC,OAAO,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE;SACtC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expect, test } from 'vitest';\nimport type { IssueBundle } from '../../../schema/issue/bundle.js';\nimport type { Period } from '../../../schema/issue/period.js';\nimport type { ServiceEffect } from '../../../schema/issue/serviceEffect.js';\nimport type { ServiceScope } from '../../../schema/issue/serviceScope.js';\nimport { keyForAffectedEntity } from '../../../helpers/keyForAffectedEntity.js';\nimport { deriveCurrentState } from './deriveCurrentState.js';\n\nconst defaultTarget = { type: 'service' as const, serviceId: 'NSL' };\nconst nslKey = keyForAffectedEntity(defaultTarget);\n\ndescribe('deriveCurrentState', () => {\n const createMockIssue = () => ({\n id: '2025-01-01-test-issue',\n type: 'disruption' as const,\n title: {\n 'en-SG': 'Test Issue',\n 'zh-Hans': null,\n ms: null,\n ta: null,\n },\n titleMeta: {\n source: 'test',\n },\n });\n\n const createMockBundle = (\n impact: IssueBundle['impactEvents'],\n ): IssueBundle => ({\n issue: createMockIssue(),\n evidence: [],\n impactEvents: impact,\n path: 'test/path',\n });\n\n test('returns empty state for bundle with no impacts', () => {\n const bundle = createMockBundle([]);\n const result = deriveCurrentState(bundle);\n\n expect(result).toEqual({\n services: {},\n servicesProvenance: {},\n facilities: {},\n facilitiesProvenance: {},\n impactEventIds: [],\n });\n });\n\n test('handles service_effects.set impact', () => {\n const effect: ServiceEffect = { kind: 'delay', duration: null };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect,\n scopes: [],\n periods: [],\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n effect: { evidenceId: 'evidence-1' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles periods_set impact', () => {\n const periods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n {\n kind: 'fixed',\n startAt: '2025-01-01T14:00:00+08:00',\n endAt: null,\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n periods,\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: [],\n periods,\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n periods: { evidenceId: 'evidence-3' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles causes.set impact', () => {\n const causes = ['signal.fault', 'track.fault'] as const;\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_cause_001',\n type: 'causes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n causes: [...causes],\n basis: { evidenceId: 'evidence-cause' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: [],\n periods: [],\n causes,\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n causes: { evidenceId: 'evidence-cause' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_cause_001']);\n });\n\n test('handles service_scopes_set impact', () => {\n const serviceScopes: ServiceScope[] = [\n {\n type: 'service.whole',\n },\n {\n type: 'service.segment',\n fromStationId: 'station-1',\n toStationId: 'station-2',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n serviceScopes,\n basis: {\n evidenceId: 'evidence-5',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey]).toMatchObject({\n id: 'NSL',\n effect: null,\n scopes: serviceScopes,\n periods: [],\n });\n expect(result.servicesProvenance[nslKey]).toEqual({\n scopes: { evidenceId: 'evidence-5' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles multiple impacts - later impacts overwrite earlier ones', () => {\n const firstEffect: ServiceEffect = { kind: 'delay', duration: null };\n const secondEffect: ServiceEffect = { kind: 'no-service' };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: firstEffect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n effect: secondEffect,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(secondEffect);\n expect(result.servicesProvenance[nslKey].effect?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('handles mixed impact types', () => {\n const effect: ServiceEffect = { kind: 'delay', duration: null };\n const periods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ];\n const serviceScopes: ServiceScope[] = [\n {\n type: 'service.point',\n stationId: 'station-1',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n {\n id: 'ie_test_003',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T12:00:00Z',\n serviceScopes,\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(effect);\n expect(result.services[nslKey].periods).toEqual(periods);\n expect(result.services[nslKey].scopes).toEqual(serviceScopes);\n expect(result.servicesProvenance[nslKey].effect?.evidenceId).toBe(\n 'evidence-1',\n );\n expect(result.servicesProvenance[nslKey].periods?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.servicesProvenance[nslKey].scopes?.evidenceId).toBe(\n 'evidence-3',\n );\n expect(result.impactEventIds).toEqual([\n 'ie_test_001',\n 'ie_test_003',\n 'ie_test_002',\n ]);\n });\n\n test('handles all service effect kinds', () => {\n const effectKinds: ServiceEffect['kind'][] = [\n 'delay',\n 'no-service',\n 'reduced-service',\n 'service-hours-adjustment',\n ];\n\n for (const kind of effectKinds) {\n const effect: ServiceEffect =\n kind === 'delay' ? { kind: 'delay', duration: null } : { kind };\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual(effect);\n }\n });\n\n test('handles all scope types', () => {\n const allScopes: ServiceScope[] = [\n {\n type: 'service.whole',\n },\n {\n type: 'service.segment',\n fromStationId: 'station-1',\n toStationId: 'station-2',\n },\n {\n type: 'service.point',\n stationId: 'station-3',\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n serviceScopes: allScopes,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].scopes).toEqual(allScopes);\n expect(result.services[nslKey].scopes).toHaveLength(3);\n expect(result.impactEventIds).toEqual(['ie_test_001']);\n });\n\n test('handles empty arrays in impacts', () => {\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'no-service' },\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods: [],\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n {\n id: 'ie_test_003',\n type: 'service_scopes.set',\n entity: defaultTarget,\n ts: '2025-01-01T12:00:00Z',\n serviceScopes: [],\n basis: {\n evidenceId: 'evidence-3',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].effect).toEqual({ kind: 'no-service' });\n expect(result.services[nslKey].periods).toEqual([]);\n expect(result.services[nslKey].scopes).toEqual([]);\n expect(result.impactEventIds).toEqual([\n 'ie_test_001',\n 'ie_test_003',\n 'ie_test_002',\n ]);\n });\n\n test('preserves order of impacts when processing', () => {\n const firstPeriods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ];\n const secondPeriods: Period[] = [\n {\n kind: 'fixed',\n startAt: '2025-01-01T14:00:00+08:00',\n endAt: null,\n },\n ];\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T10:00:00Z',\n periods: firstPeriods,\n basis: {\n evidenceId: 'evidence-1',\n },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: defaultTarget,\n ts: '2025-01-01T11:00:00Z',\n periods: secondPeriods,\n basis: {\n evidenceId: 'evidence-2',\n },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.services[nslKey].periods).toEqual(secondPeriods);\n expect(result.servicesProvenance[nslKey].periods?.evidenceId).toBe(\n 'evidence-2',\n );\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('groups impacts by target - different targets produce separate entries', () => {\n const nslTarget = { type: 'service' as const, serviceId: 'NSL' };\n const ewlTarget = { type: 'service' as const, serviceId: 'EWL' };\n const nslKeyLocal = keyForAffectedEntity(nslTarget);\n const ewlKey = keyForAffectedEntity(ewlTarget);\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'service_effects.set',\n entity: nslTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'delay', duration: null },\n basis: { evidenceId: 'evidence-1' },\n },\n {\n id: 'ie_test_002',\n type: 'service_effects.set',\n entity: ewlTarget,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'no-service' },\n basis: { evidenceId: 'evidence-2' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(Object.keys(result.services)).toHaveLength(2);\n expect(result.services[nslKeyLocal].effect).toEqual({\n kind: 'delay',\n duration: null,\n });\n expect(result.services[nslKeyLocal]).toMatchObject({ id: 'NSL' });\n expect(result.services[ewlKey].effect).toEqual({ kind: 'no-service' });\n expect(result.services[ewlKey]).toMatchObject({ id: 'EWL' });\n expect(result.impactEventIds).toEqual(['ie_test_002']);\n });\n\n test('handles facility impacts', () => {\n const facilityEntity = {\n type: 'facility' as const,\n stationId: 'JUR',\n kind: 'lift' as const,\n };\n const facilityKey = keyForAffectedEntity(facilityEntity);\n\n const bundle = createMockBundle([\n {\n id: 'ie_test_001',\n type: 'facility_effects.set',\n entity: facilityEntity,\n ts: '2025-01-01T10:00:00Z',\n effect: { kind: 'facility-out-of-service' },\n basis: { evidenceId: 'evidence-1' },\n },\n {\n id: 'ie_test_002',\n type: 'periods.set',\n entity: facilityEntity,\n ts: '2025-01-01T10:00:00Z',\n periods: [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ],\n basis: { evidenceId: 'evidence-2' },\n },\n ]);\n\n const result = deriveCurrentState(bundle);\n\n expect(result.facilities[facilityKey]).toMatchObject({\n stationId: 'JUR',\n kind: 'lift',\n effect: { kind: 'facility-out-of-service' },\n periods: [\n {\n kind: 'fixed',\n startAt: '2025-01-01T10:00:00+08:00',\n endAt: '2025-01-01T12:00:00+08:00',\n },\n ],\n });\n expect(result.facilitiesProvenance[facilityKey]).toEqual({\n effect: { evidenceId: 'evidence-1' },\n periods: { evidenceId: 'evidence-2' },\n });\n expect(result.impactEventIds).toEqual(['ie_test_002', 'ie_test_001']);\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evidence.js","sourceRoot":"/","sources":["schema/issue/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"evidence.js","sourceRoot":"/","sources":["schema/issue/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,oBAAoB,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,+BAA+B,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACvE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;IACrC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAKH,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,MAAM,CAAC;IAClE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACjE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACzD,+BAA+B;IAC/B,0BAA0B;IAC1B,yBAAyB;CAC1B,CAAC,CAAC","sourcesContent":["import z from 'zod';\nimport { TranslationsSchema } from '../common.js';\n\nexport const EvidenceRenderSchema = z.object({\n text: TranslationsSchema,\n source: z.string(),\n});\nexport type EvidenceRender = z.infer<typeof EvidenceRenderSchema>;\n\nexport const EvidenceBaseSchema = z.object({\n id: z.string(),\n ts: z.string(),\n text: z.string(),\n render: EvidenceRenderSchema.nullable(),\n});\nexport type EvidenceBase = z.infer<typeof EvidenceBaseSchema>;\n\nexport const EvidenceOfficialStatementSchema = EvidenceBaseSchema.extend({\n type: z.literal('official-statement'),\n sourceUrl: z.string(),\n});\nexport type EvidenceOfficialStatement = z.infer<\n typeof EvidenceOfficialStatementSchema\n>;\n\nexport const EvidencePublicReportSchema = EvidenceBaseSchema.extend({\n type: z.literal('public.report'),\n sourceUrl: z.string(),\n});\nexport type EvidencePublicReport = z.infer<typeof EvidencePublicReportSchema>;\n\nexport const EvidenceMediaReportSchema = EvidenceBaseSchema.extend({\n type: z.literal('media.report'),\n sourceUrl: z.string(),\n});\nexport type EvidenceMediaReport = z.infer<typeof EvidenceMediaReportSchema>;\n\nexport const EvidenceSchema = z.discriminatedUnion('type', [\n EvidenceOfficialStatementSchema,\n EvidencePublicReportSchema,\n EvidenceMediaReportSchema,\n]);\nexport type Evidence = z.infer<typeof EvidenceSchema>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue.js","sourceRoot":"/","sources":["schema/issue/issue.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"/","sources":["schema/issue/issue.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,aAAa;IACjB,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,kBAAkB;IACzB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;QAClB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import z from 'zod';\nimport { TranslationsSchema } from '../common.js';\nimport { IssueIdSchema } from './id.js';\nimport { IssueTypeSchema } from './issueType.js';\n\nexport const IssueSchema = z.object({\n id: IssueIdSchema,\n type: IssueTypeSchema,\n title: TranslationsSchema,\n titleMeta: z.object({\n source: z.string(),\n }),\n});\nexport type Issue = z.infer<typeof IssueSchema>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSlugDateTimeFromClaims.js","sourceRoot":"/","sources":["util/ingestContent/helpers/getSlugDateTimeFromClaims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAe;IACvD,MAAM,SAAS,GAAG,MAAM;SACrB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;SAC1C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,qBAAqB,CAAC,CAAC;QACpD,QAAQ,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1B,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { Claim } from '
|
|
1
|
+
{"version":3,"file":"getSlugDateTimeFromClaims.js","sourceRoot":"/","sources":["util/ingestContent/helpers/getSlugDateTimeFromClaims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAe;IACvD,MAAM,SAAS,GAAG,MAAM;SACrB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;SAC1C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,qBAAqB,CAAC,CAAC;QACpD,QAAQ,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1B,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { Claim } from '../../../schema/issue/claim.js';\nimport { assert } from '../../assert.js';\n\n/**\n * Get the slug date time from the claims.\n * @param claims - The claims.\n * @returns The slug date time or null if no time hints are found.\n */\nexport function getSlugDateTimeFromClaims(claims: Claim[]): string | null {\n const timeHints = claims\n .filter((claim) => claim.timeHints != null)\n .map((claim) => claim.timeHints);\n\n if (timeHints.length > 0) {\n assert(timeHints[0] != null, 'Expected time hints');\n switch (timeHints[0].kind) {\n case 'fixed': {\n return timeHints[0].startAt;\n }\n case 'recurring': {\n return timeHints[0].startAt;\n }\n }\n }\n\n return null;\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
3
|
import { ulid } from 'ulid';
|
|
4
|
-
import { computeImpactFromEvidenceClaims } from '
|
|
5
|
-
import { extractClaimsFromNewEvidence } from '
|
|
6
|
-
import { generateIssueTitleAndSlug } from '
|
|
7
|
-
import { translate } from '
|
|
8
|
-
import { triageNewEvidence } from '
|
|
9
|
-
import { FileStore } from '
|
|
10
|
-
import { MRTDownRepository } from '
|
|
11
|
-
import { FileWriteStore } from '
|
|
12
|
-
import { MRTDownWriter } from '
|
|
4
|
+
import { computeImpactFromEvidenceClaims } from '../../helpers/computeImpactFromEvidenceClaims.js';
|
|
5
|
+
import { extractClaimsFromNewEvidence } from '../../llm/functions/extractClaimsFromNewEvidence/index.js';
|
|
6
|
+
import { generateIssueTitleAndSlug } from '../../llm/functions/generateIssueTitleAndSlug/index.js';
|
|
7
|
+
import { translate } from '../../llm/functions/translate/index.js';
|
|
8
|
+
import { triageNewEvidence } from '../../llm/functions/triageNewEvidence/index.js';
|
|
9
|
+
import { FileStore } from '../../repo/common/FileStore.js';
|
|
10
|
+
import { MRTDownRepository } from '../../repo/MRTDownRepository.js';
|
|
11
|
+
import { FileWriteStore } from '../../write/common/FileWriteStore.js';
|
|
12
|
+
import { MRTDownWriter } from '../../write/MRTDownWriter.js';
|
|
13
13
|
import { assert } from '../assert.js';
|
|
14
14
|
import { getSlugDateTimeFromClaims } from './helpers/getSlugDateTimeFromClaims.js';
|
|
15
15
|
const DATA_DIR = resolve(import.meta.dirname, '../../../data');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["util/ingestContent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,4BAA4B,EAAE,MAAM,sDAAsD,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,SA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YACpB,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,KAAK,SAAS,CAAC;QACf,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,OAAO,eAAe,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { resolve } from 'node:path';\nimport { DateTime } from 'luxon';\nimport { ulid } from 'ulid';\nimport { computeImpactFromEvidenceClaims } from '#helpers/computeImpactFromEvidenceClaims.js';\nimport { extractClaimsFromNewEvidence } from '#llm/functions/extractClaimsFromNewEvidence/index.js';\nimport { generateIssueTitleAndSlug } from '#llm/functions/generateIssueTitleAndSlug/index.js';\nimport { translate } from '#llm/functions/translate/index.js';\nimport { triageNewEvidence } from '#llm/functions/triageNewEvidence/index.js';\nimport { FileStore } from '#repo/common/FileStore.js';\nimport { MRTDownRepository } from '#repo/MRTDownRepository.js';\nimport type { IssueBundle } from '#schema/issue/bundle.js';\nimport type { Evidence } from '#schema/issue/evidence.js';\nimport type { Issue } from '#schema/issue/issue.js';\nimport { FileWriteStore } from '#write/common/FileWriteStore.js';\nimport { MRTDownWriter } from '#write/MRTDownWriter.js';\nimport { assert } from '../assert.js';\nimport { getSlugDateTimeFromClaims } from './helpers/getSlugDateTimeFromClaims.js';\nimport type { IngestContent } from './types.js';\n\nconst DATA_DIR = resolve(import.meta.dirname, '../../../data');\n\nconst store = new FileStore(DATA_DIR);\nconst writeStore = new FileWriteStore(DATA_DIR);\nconst repo = new MRTDownRepository({ store });\nconst writer = new MRTDownWriter({ store: writeStore });\n\n/**\n * Ingests content from social media, news, or other sources into the MRTDown issue system.\n *\n * Triages the content to determine if it belongs to an existing issue or a new one, extracts\n * claims, computes impact (affected lines, stations, periods), and persists evidence and impact\n * events. Irrelevant content is ignored.\n *\n * @param content - The content to ingest (Reddit post, news article, or Twitter/Mastodon post).\n * @returns `null` when content is irrelevant or after successful ingestion.\n */\nexport async function ingestContent(content: IngestContent) {\n // --- Normalise input ---\n // HACK: Force `createdAt` to be Asia/Singapore timezone\n const createdAt = DateTime.fromISO(content.createdAt)\n .setZone('Asia/Singapore')\n .toISO();\n assert(createdAt != null, 'Expected valid createdAt');\n\n content.createdAt = createdAt;\n console.log('[ingestContent]', content);\n\n // --- Triage: existing issue, new issue, or irrelevant ---\n const triageResult = await triageNewEvidence({\n newEvidence: {\n ts: content.createdAt,\n text: getText(content),\n },\n repo,\n });\n console.log('[ingestContent.triageNewEvidence]', triageResult);\n\n if (triageResult.result.kind === 'irrelevant-content') {\n console.log('[ingestContent] Nothing to do.');\n return null;\n }\n\n // --- Extract structured claims (lines, stations, periods, effects) ---\n const { claims } = await extractClaimsFromNewEvidence({\n newEvidence: {\n ts: content.createdAt,\n text: getText(content),\n },\n repo,\n });\n console.log('[ingestContent.extractClaimsFromNewEvidence]', claims);\n\n // --- Resolve issue bundle: fetch existing or create new ---\n let issueBundle: IssueBundle;\n\n switch (triageResult.result.kind) {\n case 'part-of-existing-issue': {\n // Load full bundle (issue + evidence + impact) for impact computation\n const { issueId } = triageResult.result;\n const existingBundle = repo.issues.get(issueId);\n assert(existingBundle != null, `Expected issue for id=${issueId}`);\n issueBundle = existingBundle;\n break;\n }\n case 'part-of-new-issue': {\n // Create issue: derive date from claims, generate title/slug, translate, persist\n const slugDateTime = DateTime.fromISO(\n getSlugDateTimeFromClaims(claims) ?? content.createdAt,\n );\n assert(slugDateTime.isValid, `Invalid date: ${content.createdAt}`);\n\n const { title, slug } = await generateIssueTitleAndSlug({\n text: getText(content),\n });\n console.log('[ingestContent.generateSlug]', slug);\n\n const translatedTitles = await translate(title);\n\n const issueId = `${slugDateTime.toFormat('yyyy-MM-dd')}-${slug}`;\n\n const issue: Issue = {\n id: issueId,\n type: triageResult.result.issueType,\n title: translatedTitles,\n titleMeta: {\n source: '@openai/gpt-5-nano',\n },\n };\n writer.issues.create(issue);\n\n issueBundle = {\n issue,\n evidence: [],\n impactEvents: [],\n path: DATA_DIR,\n };\n break;\n }\n }\n\n // --- Build evidence record ---\n const contentDateTime = DateTime.fromISO(content.createdAt);\n assert(contentDateTime.isValid, `Invalid date: ${content.createdAt}`);\n\n const evidence: Evidence = {\n id: `ev_${ulid(contentDateTime.toMillis())}`,\n ts: contentDateTime.toISO({ includeOffset: true }),\n type: getEvidenceType(content),\n text: getText(content),\n sourceUrl: content.url,\n render: {\n text: await translate(getText(content)),\n source: '@openai/gpt-5-nano',\n },\n };\n\n // --- Compute impact events from claims (effects, scopes, periods) ---\n const { newImpactEvents } = computeImpactFromEvidenceClaims({\n issueBundle: {\n ...issueBundle,\n evidence: [...issueBundle.evidence, evidence],\n },\n evidenceId: evidence.id,\n evidenceTs: evidence.ts,\n claims,\n });\n\n // --- Persist to disk ---\n writer.issues.appendEvidence(issueBundle.issue.id, evidence);\n for (const impact of newImpactEvents) {\n writer.issues.appendImpact(issueBundle.issue.id, impact);\n }\n\n return null;\n}\n\n/**\n * Extracts the primary text content from an IngestContent item based on its source type.\n *\n * @param content - The content to extract text from.\n * @returns The text body (selftext for Reddit, summary for news, text for social).\n */\nfunction getText(content: IngestContent) {\n switch (content.source) {\n case 'reddit': {\n return content.selftext;\n }\n case 'news-website': {\n return content.summary;\n }\n case 'twitter':\n case 'mastodon': {\n return content.text;\n }\n }\n}\n\n/**\n * Maps IngestContent source type to the corresponding Evidence type for provenance tracking.\n *\n * @param content - The content to classify.\n * @returns The evidence type: official-statement (Reddit), media.report (news), or public.report (social).\n */\nfunction getEvidenceType(content: IngestContent) {\n switch (content.source) {\n case 'reddit': {\n return 'official-statement';\n }\n case 'news-website': {\n return 'media.report';\n }\n case 'twitter':\n case 'mastodon': {\n return 'public.report';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["util/ingestContent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,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C,CAAC;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,OAAsB;IAC7C,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,oBAAoB,CAAC;QAC9B,CAAC;QACD,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,KAAK,SAAS,CAAC;QACf,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,OAAO,eAAe,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { resolve } from 'node:path';\nimport { DateTime } from 'luxon';\nimport { ulid } from 'ulid';\nimport { computeImpactFromEvidenceClaims } from '../../helpers/computeImpactFromEvidenceClaims.js';\nimport { extractClaimsFromNewEvidence } from '../../llm/functions/extractClaimsFromNewEvidence/index.js';\nimport { generateIssueTitleAndSlug } from '../../llm/functions/generateIssueTitleAndSlug/index.js';\nimport { translate } from '../../llm/functions/translate/index.js';\nimport { triageNewEvidence } from '../../llm/functions/triageNewEvidence/index.js';\nimport { FileStore } from '../../repo/common/FileStore.js';\nimport { MRTDownRepository } from '../../repo/MRTDownRepository.js';\nimport type { IssueBundle } from '../../schema/issue/bundle.js';\nimport type { Evidence } from '../../schema/issue/evidence.js';\nimport type { Issue } from '../../schema/issue/issue.js';\nimport { FileWriteStore } from '../../write/common/FileWriteStore.js';\nimport { MRTDownWriter } from '../../write/MRTDownWriter.js';\nimport { assert } from '../assert.js';\nimport { getSlugDateTimeFromClaims } from './helpers/getSlugDateTimeFromClaims.js';\nimport type { IngestContent } from './types.js';\n\nconst DATA_DIR = resolve(import.meta.dirname, '../../../data');\n\nconst store = new FileStore(DATA_DIR);\nconst writeStore = new FileWriteStore(DATA_DIR);\nconst repo = new MRTDownRepository({ store });\nconst writer = new MRTDownWriter({ store: writeStore });\n\n/**\n * Ingests content from social media, news, or other sources into the MRTDown issue system.\n *\n * Triages the content to determine if it belongs to an existing issue or a new one, extracts\n * claims, computes impact (affected lines, stations, periods), and persists evidence and impact\n * events. Irrelevant content is ignored.\n *\n * @param content - The content to ingest (Reddit post, news article, or Twitter/Mastodon post).\n * @returns `null` when content is irrelevant or after successful ingestion.\n */\nexport async function ingestContent(content: IngestContent) {\n // --- Normalise input ---\n // HACK: Force `createdAt` to be Asia/Singapore timezone\n const createdAt = DateTime.fromISO(content.createdAt)\n .setZone('Asia/Singapore')\n .toISO();\n assert(createdAt != null, 'Expected valid createdAt');\n\n content.createdAt = createdAt;\n console.log('[ingestContent]', content);\n\n // --- Triage: existing issue, new issue, or irrelevant ---\n const triageResult = await triageNewEvidence({\n newEvidence: {\n ts: content.createdAt,\n text: getText(content),\n },\n repo,\n });\n console.log('[ingestContent.triageNewEvidence]', triageResult);\n\n if (triageResult.result.kind === 'irrelevant-content') {\n console.log('[ingestContent] Nothing to do.');\n return null;\n }\n\n // --- Extract structured claims (lines, stations, periods, effects) ---\n const { claims } = await extractClaimsFromNewEvidence({\n newEvidence: {\n ts: content.createdAt,\n text: getText(content),\n },\n repo,\n });\n console.log('[ingestContent.extractClaimsFromNewEvidence]', claims);\n\n // --- Resolve issue bundle: fetch existing or create new ---\n let issueBundle: IssueBundle;\n\n switch (triageResult.result.kind) {\n case 'part-of-existing-issue': {\n // Load full bundle (issue + evidence + impact) for impact computation\n const { issueId } = triageResult.result;\n const existingBundle = repo.issues.get(issueId);\n assert(existingBundle != null, `Expected issue for id=${issueId}`);\n issueBundle = existingBundle;\n break;\n }\n case 'part-of-new-issue': {\n // Create issue: derive date from claims, generate title/slug, translate, persist\n const slugDateTime = DateTime.fromISO(\n getSlugDateTimeFromClaims(claims) ?? content.createdAt,\n );\n assert(slugDateTime.isValid, `Invalid date: ${content.createdAt}`);\n\n const { title, slug } = await generateIssueTitleAndSlug({\n text: getText(content),\n });\n console.log('[ingestContent.generateSlug]', slug);\n\n const translatedTitles = await translate(title);\n\n const issueId = `${slugDateTime.toFormat('yyyy-MM-dd')}-${slug}`;\n\n const issue: Issue = {\n id: issueId,\n type: triageResult.result.issueType,\n title: translatedTitles,\n titleMeta: {\n source: '@openai/gpt-5-nano',\n },\n };\n writer.issues.create(issue);\n\n issueBundle = {\n issue,\n evidence: [],\n impactEvents: [],\n path: DATA_DIR,\n };\n break;\n }\n }\n\n // --- Build evidence record ---\n const contentDateTime = DateTime.fromISO(content.createdAt);\n assert(contentDateTime.isValid, `Invalid date: ${content.createdAt}`);\n\n const evidence: Evidence = {\n id: `ev_${ulid(contentDateTime.toMillis())}`,\n ts: contentDateTime.toISO({ includeOffset: true }),\n type: getEvidenceType(content),\n text: getText(content),\n sourceUrl: content.url,\n render: {\n text: await translate(getText(content)),\n source: '@openai/gpt-5-nano',\n },\n };\n\n // --- Compute impact events from claims (effects, scopes, periods) ---\n const { newImpactEvents } = computeImpactFromEvidenceClaims({\n issueBundle: {\n ...issueBundle,\n evidence: [...issueBundle.evidence, evidence],\n },\n evidenceId: evidence.id,\n evidenceTs: evidence.ts,\n claims,\n });\n\n // --- Persist to disk ---\n writer.issues.appendEvidence(issueBundle.issue.id, evidence);\n for (const impact of newImpactEvents) {\n writer.issues.appendImpact(issueBundle.issue.id, impact);\n }\n\n return null;\n}\n\n/**\n * Extracts the primary text content from an IngestContent item based on its source type.\n *\n * @param content - The content to extract text from.\n * @returns The text body (selftext for Reddit, summary for news, text for social).\n */\nfunction getText(content: IngestContent) {\n switch (content.source) {\n case 'reddit': {\n return content.selftext;\n }\n case 'news-website': {\n return content.summary;\n }\n case 'twitter':\n case 'mastodon': {\n return content.text;\n }\n }\n}\n\n/**\n * Maps IngestContent source type to the corresponding Evidence type for provenance tracking.\n *\n * @param content - The content to classify.\n * @returns The evidence type: official-statement (Reddit), media.report (news), or public.report (social).\n */\nfunction getEvidenceType(content: IngestContent) {\n switch (content.source) {\n case 'reddit': {\n return 'official-statement';\n }\n case 'news-website': {\n return 'media.report';\n }\n case 'twitter':\n case 'mastodon': {\n return 'public.report';\n }\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { NdJson } from 'json-nd';
|
|
3
3
|
import z from 'zod';
|
|
4
|
-
import { LandmarkSchema } from '
|
|
5
|
-
import { LineSchema } from '
|
|
6
|
-
import { OperatorSchema } from '
|
|
7
|
-
import { ServiceSchema } from '
|
|
8
|
-
import { StationSchema } from '
|
|
9
|
-
import { TownSchema } from '
|
|
4
|
+
import { LandmarkSchema } from '../schema/Landmark.js';
|
|
5
|
+
import { LineSchema } from '../schema/Line.js';
|
|
6
|
+
import { OperatorSchema } from '../schema/Operator.js';
|
|
7
|
+
import { ServiceSchema } from '../schema/Service.js';
|
|
8
|
+
import { StationSchema } from '../schema/Station.js';
|
|
9
|
+
import { TownSchema } from '../schema/Town.js';
|
|
10
10
|
import { DIR_ISSUE, DIR_LANDMARK, DIR_LINE, DIR_OPERATOR, DIR_SERVICE, DIR_STATION, DIR_TOWN, } from '../constants.js';
|
|
11
11
|
import { loadJson } from './utils.js';
|
|
12
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildContext.js","sourceRoot":"/","sources":["validators/buildContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAA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join } from 'node:path';\nimport { NdJson } from 'json-nd';\nimport z from 'zod';\nimport { LandmarkSchema } from '#schema/Landmark.js';\nimport { LineSchema } from '#schema/Line.js';\nimport { OperatorSchema } from '#schema/Operator.js';\nimport { ServiceSchema } from '#schema/Service.js';\nimport { StationSchema } from '#schema/Station.js';\nimport { TownSchema } from '#schema/Town.js';\nimport {\n DIR_ISSUE,\n DIR_LANDMARK,\n DIR_LINE,\n DIR_OPERATOR,\n DIR_SERVICE,\n DIR_STATION,\n DIR_TOWN,\n} from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationContext } from './types.js';\nimport { loadJson } from './utils.js';\n\n/**\n * Loads all entity IDs from the store into a ValidationContext.\n * Use this to build context once, then pass it to validators for relationship checks.\n */\nexport function buildContext(store: IStore): ValidationContext {\n const ctx: ValidationContext = {\n townIds: new Set(),\n landmarkIds: new Set(),\n operatorIds: new Set(),\n lineIds: new Set(),\n serviceIds: new Set(),\n stationIds: new Set(),\n evidenceIdsByIssue: new Map(),\n };\n\n try {\n for (const file of store.listDir(DIR_TOWN)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_TOWN, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = TownSchema.safeParse(raw);\n if (parsed.success) ctx.townIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid town: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load towns:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_LANDMARK)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_LANDMARK, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = LandmarkSchema.safeParse(raw);\n if (parsed.success) ctx.landmarkIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid landmark: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load landmarks:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_OPERATOR)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_OPERATOR, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = OperatorSchema.safeParse(raw);\n if (parsed.success) ctx.operatorIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid operator: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load operators:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_LINE)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_LINE, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = LineSchema.safeParse(raw);\n if (parsed.success) ctx.lineIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid line: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load lines:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_STATION)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_STATION, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = StationSchema.safeParse(raw);\n if (parsed.success) ctx.stationIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid station: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load stations:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_SERVICE)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_SERVICE, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = ServiceSchema.safeParse(raw);\n if (parsed.success) ctx.serviceIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid service: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load services:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n const years = store.listDir(DIR_ISSUE);\n for (const year of years) {\n if (!/^\\d{4}$/.test(year)) continue;\n const monthsPath = join(DIR_ISSUE, year);\n const months = store.listDir(monthsPath);\n for (const month of months) {\n if (!/^\\d{2}$/.test(month)) continue;\n const issuesPath = join(monthsPath, month);\n const issues = store.listDir(issuesPath);\n for (const issueId of issues) {\n const relBase = join(DIR_ISSUE, year, month, issueId);\n const evidencePath = join(relBase, 'evidence.ndjson');\n const evidenceIds = new Set<string>();\n try {\n const content = store.readText(evidencePath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (const row of parsed) {\n const idParsed = z.object({ id: z.string() }).safeParse(row);\n if (idParsed.success) evidenceIds.add(idParsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid evidence row in ${evidencePath}:`,\n idParsed.error?.message ?? idParsed.error,\n );\n }\n }\n } catch (err) {\n console.warn(\n `[buildContext] Failed to read evidence: ${evidencePath}`,\n err instanceof Error ? err.message : err,\n );\n }\n ctx.evidenceIdsByIssue.set(relBase, evidenceIds);\n }\n }\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load issues/evidence:',\n err instanceof Error ? err.message : err,\n );\n }\n\n return ctx;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"buildContext.js","sourceRoot":"/","sources":["validators/buildContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAA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ED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { NdJson } from 'json-nd';\nimport z from 'zod';\nimport { LandmarkSchema } from '../schema/Landmark.js';\nimport { LineSchema } from '../schema/Line.js';\nimport { OperatorSchema } from '../schema/Operator.js';\nimport { ServiceSchema } from '../schema/Service.js';\nimport { StationSchema } from '../schema/Station.js';\nimport { TownSchema } from '../schema/Town.js';\nimport {\n DIR_ISSUE,\n DIR_LANDMARK,\n DIR_LINE,\n DIR_OPERATOR,\n DIR_SERVICE,\n DIR_STATION,\n DIR_TOWN,\n} from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationContext } from './types.js';\nimport { loadJson } from './utils.js';\n\n/**\n * Loads all entity IDs from the store into a ValidationContext.\n * Use this to build context once, then pass it to validators for relationship checks.\n */\nexport function buildContext(store: IStore): ValidationContext {\n const ctx: ValidationContext = {\n townIds: new Set(),\n landmarkIds: new Set(),\n operatorIds: new Set(),\n lineIds: new Set(),\n serviceIds: new Set(),\n stationIds: new Set(),\n evidenceIdsByIssue: new Map(),\n };\n\n try {\n for (const file of store.listDir(DIR_TOWN)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_TOWN, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = TownSchema.safeParse(raw);\n if (parsed.success) ctx.townIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid town: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load towns:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_LANDMARK)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_LANDMARK, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = LandmarkSchema.safeParse(raw);\n if (parsed.success) ctx.landmarkIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid landmark: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load landmarks:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_OPERATOR)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_OPERATOR, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = OperatorSchema.safeParse(raw);\n if (parsed.success) ctx.operatorIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid operator: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load operators:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_LINE)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_LINE, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = LineSchema.safeParse(raw);\n if (parsed.success) ctx.lineIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid line: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load lines:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_STATION)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_STATION, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = StationSchema.safeParse(raw);\n if (parsed.success) ctx.stationIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid station: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load stations:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n for (const file of store.listDir(DIR_SERVICE)) {\n if (!file.endsWith('.json')) continue;\n const path = join(DIR_SERVICE, file);\n const raw = loadJson<unknown>(store, path);\n const parsed = ServiceSchema.safeParse(raw);\n if (parsed.success) ctx.serviceIds.add(parsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid service: ${path}`,\n parsed.error?.message ?? parsed.error,\n );\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load services:',\n err instanceof Error ? err.message : err,\n );\n }\n\n try {\n const years = store.listDir(DIR_ISSUE);\n for (const year of years) {\n if (!/^\\d{4}$/.test(year)) continue;\n const monthsPath = join(DIR_ISSUE, year);\n const months = store.listDir(monthsPath);\n for (const month of months) {\n if (!/^\\d{2}$/.test(month)) continue;\n const issuesPath = join(monthsPath, month);\n const issues = store.listDir(issuesPath);\n for (const issueId of issues) {\n const relBase = join(DIR_ISSUE, year, month, issueId);\n const evidencePath = join(relBase, 'evidence.ndjson');\n const evidenceIds = new Set<string>();\n try {\n const content = store.readText(evidencePath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (const row of parsed) {\n const idParsed = z.object({ id: z.string() }).safeParse(row);\n if (idParsed.success) evidenceIds.add(idParsed.data.id);\n else\n console.warn(\n `[buildContext] Skipping invalid evidence row in ${evidencePath}:`,\n idParsed.error?.message ?? idParsed.error,\n );\n }\n }\n } catch (err) {\n console.warn(\n `[buildContext] Failed to read evidence: ${evidencePath}`,\n err instanceof Error ? err.message : err,\n );\n }\n ctx.evidenceIdsByIssue.set(relBase, evidenceIds);\n }\n }\n }\n } catch (err) {\n console.warn(\n '[buildContext] Failed to load issues/evidence:',\n err instanceof Error ? err.message : err,\n );\n }\n\n return ctx;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImpactEvent } from '
|
|
1
|
+
import type { ImpactEvent } from '../schema/issue/impactEvent.js';
|
|
2
2
|
import type { IStore } from '../repo/common/store.js';
|
|
3
3
|
import type { ValidationContext, ValidationError } from './types.js';
|
|
4
4
|
export declare function validateIssueSchema(data: unknown): ValidationError[];
|
package/dist/validators/issue.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { NdJson } from 'json-nd';
|
|
3
3
|
import z from 'zod';
|
|
4
|
-
import { EvidenceSchema } from '
|
|
5
|
-
import { ImpactEventSchema } from '
|
|
6
|
-
import { IssueSchema } from '
|
|
4
|
+
import { EvidenceSchema } from '../schema/issue/evidence.js';
|
|
5
|
+
import { ImpactEventSchema } from '../schema/issue/impactEvent.js';
|
|
6
|
+
import { IssueSchema } from '../schema/issue/issue.js';
|
|
7
7
|
import { DIR_ISSUE } from '../constants.js';
|
|
8
8
|
import { loadJson } from './utils.js';
|
|
9
9
|
export function validateIssueSchema(data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue.js","sourceRoot":"/","sources":["validators/issue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,UAAU,mBAAmB,CAAC,IAAa;IAC/C,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrC,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,EAAE;KAC1E,CAAC,CAAC,CA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AAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;oBACtD,MAAM,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { NdJson } from 'json-nd';\nimport z from 'zod';\nimport { EvidenceSchema } from '#schema/issue/evidence.js';\nimport type { ImpactEvent } from '#schema/issue/impactEvent.js';\nimport { ImpactEventSchema } from '#schema/issue/impactEvent.js';\nimport { IssueSchema } from '#schema/issue/issue.js';\nimport { DIR_ISSUE } from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationContext, ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateIssueSchema(data: unknown): ValidationError[] {\n const result = IssueSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateEvidenceSchema(data: unknown): ValidationError[] {\n const result = EvidenceSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateImpactEventSchema(data: unknown): ValidationError[] {\n const result = ImpactEventSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateImpactEventRelationships(\n event: ImpactEvent,\n evidenceIds: Set<string>,\n file: string,\n lineNum: number,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n\n if (!evidenceIds.has(event.basis.evidenceId)) {\n errors.push({\n file,\n line: lineNum,\n message: `basis.evidenceId \"${event.basis.evidenceId}\" does not exist in evidence`,\n });\n }\n\n if (!ctx) return errors;\n\n if (event.entity.type === 'service') {\n if (!ctx.serviceIds.has(event.entity.serviceId)) {\n errors.push({\n file,\n line: lineNum,\n message: `entity.serviceId \"${event.entity.serviceId}\" does not exist`,\n });\n }\n } else {\n if (!ctx.stationIds.has(event.entity.stationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `entity.stationId \"${event.entity.stationId}\" does not exist`,\n });\n }\n }\n\n if ('serviceScopes' in event && event.serviceScopes) {\n for (const scope of event.serviceScopes) {\n if (scope.type === 'service.segment') {\n if (!ctx.stationIds.has(scope.fromStationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].fromStationId \"${scope.fromStationId}\" does not exist`,\n });\n }\n if (!ctx.stationIds.has(scope.toStationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].toStationId \"${scope.toStationId}\" does not exist`,\n });\n }\n } else if (scope.type === 'service.point') {\n if (!ctx.stationIds.has(scope.stationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].stationId \"${scope.stationId}\" does not exist`,\n });\n }\n }\n }\n }\n\n return errors;\n}\n\nfunction validateIssueAtPath(\n store: IStore,\n relBase: string,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n const issueJsonPath = join(relBase, 'issue.json');\n\n if (!store.exists(issueJsonPath)) {\n errors.push({\n file: issueJsonPath,\n message: 'Issue not found',\n });\n return errors;\n }\n\n const issueRaw = loadJson<unknown>(store, issueJsonPath);\n if (issueRaw) {\n const schemaErrs = validateIssueSchema(issueRaw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || issueJsonPath });\n }\n } else {\n errors.push({\n file: issueJsonPath,\n message: 'Failed to parse JSON',\n });\n }\n\n const evidenceIdsFromCtx = ctx?.evidenceIdsByIssue.get(relBase);\n const evidenceIds =\n evidenceIdsFromCtx !== undefined ? evidenceIdsFromCtx : new Set<string>();\n const needToBuildEvidenceIds = evidenceIdsFromCtx === undefined;\n\n const evidencePath = join(relBase, 'evidence.ndjson');\n try {\n const content = store.readText(evidencePath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (let i = 0; i < parsed.length; i++) {\n const row = parsed[i];\n const schemaErrs = validateEvidenceSchema(row);\n for (const e of schemaErrs) {\n errors.push({\n ...e,\n file: evidencePath,\n line: i + 1,\n });\n }\n if (needToBuildEvidenceIds) {\n const idParsed = z.object({ id: z.string() }).safeParse(row);\n if (idParsed.success) evidenceIds.add(idParsed.data.id);\n }\n }\n }\n } catch {\n // ignore missing\n }\n\n const impactPath = join(relBase, 'impact.ndjson');\n try {\n const content = store.readText(impactPath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (let i = 0; i < parsed.length; i++) {\n const row = parsed[i];\n const schemaErrs = validateImpactEventSchema(row);\n for (const e of schemaErrs) {\n errors.push({\n ...e,\n file: impactPath,\n line: i + 1,\n });\n }\n const eventResult = z\n .object({\n entity: z.any(),\n basis: z.any(),\n serviceScopes: z.any().optional(),\n })\n .safeParse(row);\n if (eventResult.success) {\n const relErrs = validateImpactEventRelationships(\n row as ImpactEvent,\n evidenceIds,\n impactPath,\n i + 1,\n ctx,\n );\n errors.push(...relErrs);\n }\n }\n }\n } catch {\n // ignore missing\n }\n\n return errors;\n}\n\n/**\n * Validates a single issue at the given path (e.g. \"issue/2025/03/2025-03-11-x\").\n * Pass ctx for relationship validation (serviceIds, stationIds, evidenceIds).\n */\nexport function validateIssue(\n store: IStore,\n relBase: string,\n ctx?: ValidationContext,\n): ValidationError[] {\n return validateIssueAtPath(store, relBase, ctx);\n}\n\nexport function validateIssues(\n store: IStore,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const years = store.listDir(DIR_ISSUE);\n for (const year of years) {\n if (!/^\\d{4}$/.test(year)) continue;\n const monthsPath = join(DIR_ISSUE, year);\n const months = store.listDir(monthsPath);\n for (const month of months) {\n if (!/^\\d{2}$/.test(month)) continue;\n const issuesPath = join(monthsPath, month);\n const issues = store.listDir(issuesPath);\n for (const issueId of issues) {\n const relBase = join(DIR_ISSUE, year, month, issueId);\n errors.push(...validateIssueAtPath(store, relBase, ctx));\n }\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_ISSUE,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"/","sources":["validators/issue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,UAAU,mBAAmB,CAAC,IAAa;IAC/C,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,K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,IAAI,MAAM,EAAE,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;oBAAE,SAAS;gBACrC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBAC3C,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACzC,KAAK,MAAM,OAAO,IAAI,MAAM,EAAE,CAAC;oBAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;oBACtD,MAAM,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { NdJson } from 'json-nd';\nimport z from 'zod';\nimport { EvidenceSchema } from '../schema/issue/evidence.js';\nimport type { ImpactEvent } from '../schema/issue/impactEvent.js';\nimport { ImpactEventSchema } from '../schema/issue/impactEvent.js';\nimport { IssueSchema } from '../schema/issue/issue.js';\nimport { DIR_ISSUE } from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationContext, ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateIssueSchema(data: unknown): ValidationError[] {\n const result = IssueSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateEvidenceSchema(data: unknown): ValidationError[] {\n const result = EvidenceSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateImpactEventSchema(data: unknown): ValidationError[] {\n const result = ImpactEventSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateImpactEventRelationships(\n event: ImpactEvent,\n evidenceIds: Set<string>,\n file: string,\n lineNum: number,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n\n if (!evidenceIds.has(event.basis.evidenceId)) {\n errors.push({\n file,\n line: lineNum,\n message: `basis.evidenceId \"${event.basis.evidenceId}\" does not exist in evidence`,\n });\n }\n\n if (!ctx) return errors;\n\n if (event.entity.type === 'service') {\n if (!ctx.serviceIds.has(event.entity.serviceId)) {\n errors.push({\n file,\n line: lineNum,\n message: `entity.serviceId \"${event.entity.serviceId}\" does not exist`,\n });\n }\n } else {\n if (!ctx.stationIds.has(event.entity.stationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `entity.stationId \"${event.entity.stationId}\" does not exist`,\n });\n }\n }\n\n if ('serviceScopes' in event && event.serviceScopes) {\n for (const scope of event.serviceScopes) {\n if (scope.type === 'service.segment') {\n if (!ctx.stationIds.has(scope.fromStationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].fromStationId \"${scope.fromStationId}\" does not exist`,\n });\n }\n if (!ctx.stationIds.has(scope.toStationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].toStationId \"${scope.toStationId}\" does not exist`,\n });\n }\n } else if (scope.type === 'service.point') {\n if (!ctx.stationIds.has(scope.stationId)) {\n errors.push({\n file,\n line: lineNum,\n message: `serviceScopes[].stationId \"${scope.stationId}\" does not exist`,\n });\n }\n }\n }\n }\n\n return errors;\n}\n\nfunction validateIssueAtPath(\n store: IStore,\n relBase: string,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n const issueJsonPath = join(relBase, 'issue.json');\n\n if (!store.exists(issueJsonPath)) {\n errors.push({\n file: issueJsonPath,\n message: 'Issue not found',\n });\n return errors;\n }\n\n const issueRaw = loadJson<unknown>(store, issueJsonPath);\n if (issueRaw) {\n const schemaErrs = validateIssueSchema(issueRaw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || issueJsonPath });\n }\n } else {\n errors.push({\n file: issueJsonPath,\n message: 'Failed to parse JSON',\n });\n }\n\n const evidenceIdsFromCtx = ctx?.evidenceIdsByIssue.get(relBase);\n const evidenceIds =\n evidenceIdsFromCtx !== undefined ? evidenceIdsFromCtx : new Set<string>();\n const needToBuildEvidenceIds = evidenceIdsFromCtx === undefined;\n\n const evidencePath = join(relBase, 'evidence.ndjson');\n try {\n const content = store.readText(evidencePath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (let i = 0; i < parsed.length; i++) {\n const row = parsed[i];\n const schemaErrs = validateEvidenceSchema(row);\n for (const e of schemaErrs) {\n errors.push({\n ...e,\n file: evidencePath,\n line: i + 1,\n });\n }\n if (needToBuildEvidenceIds) {\n const idParsed = z.object({ id: z.string() }).safeParse(row);\n if (idParsed.success) evidenceIds.add(idParsed.data.id);\n }\n }\n }\n } catch {\n // ignore missing\n }\n\n const impactPath = join(relBase, 'impact.ndjson');\n try {\n const content = store.readText(impactPath).trim();\n if (content) {\n const parsed = NdJson.parse(content);\n for (let i = 0; i < parsed.length; i++) {\n const row = parsed[i];\n const schemaErrs = validateImpactEventSchema(row);\n for (const e of schemaErrs) {\n errors.push({\n ...e,\n file: impactPath,\n line: i + 1,\n });\n }\n const eventResult = z\n .object({\n entity: z.any(),\n basis: z.any(),\n serviceScopes: z.any().optional(),\n })\n .safeParse(row);\n if (eventResult.success) {\n const relErrs = validateImpactEventRelationships(\n row as ImpactEvent,\n evidenceIds,\n impactPath,\n i + 1,\n ctx,\n );\n errors.push(...relErrs);\n }\n }\n }\n } catch {\n // ignore missing\n }\n\n return errors;\n}\n\n/**\n * Validates a single issue at the given path (e.g. \"issue/2025/03/2025-03-11-x\").\n * Pass ctx for relationship validation (serviceIds, stationIds, evidenceIds).\n */\nexport function validateIssue(\n store: IStore,\n relBase: string,\n ctx?: ValidationContext,\n): ValidationError[] {\n return validateIssueAtPath(store, relBase, ctx);\n}\n\nexport function validateIssues(\n store: IStore,\n ctx?: ValidationContext,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const years = store.listDir(DIR_ISSUE);\n for (const year of years) {\n if (!/^\\d{4}$/.test(year)) continue;\n const monthsPath = join(DIR_ISSUE, year);\n const months = store.listDir(monthsPath);\n for (const month of months) {\n if (!/^\\d{2}$/.test(month)) continue;\n const issuesPath = join(monthsPath, month);\n const issues = store.listDir(issuesPath);\n for (const issueId of issues) {\n const relBase = join(DIR_ISSUE, year, month, issueId);\n errors.push(...validateIssueAtPath(store, relBase, ctx));\n }\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_ISSUE,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type z from 'zod';
|
|
2
|
-
import { LineSchema } from '
|
|
2
|
+
import { LineSchema } from '../schema/Line.js';
|
|
3
3
|
import type { IStore } from '../repo/common/store.js';
|
|
4
4
|
import type { ValidationContext, ValidationError } from './types.js';
|
|
5
5
|
export declare function validateLineSchema(data: unknown): ValidationError[];
|
package/dist/validators/line.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line.js","sourceRoot":"/","sources":["validators/line.ts"],"names":[],"mappings":"AAA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rD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAa,EACb,GAAuB;IAEvB,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,SAAS;YACtC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrC,MAAM,GAAG,GAAG,QAAQ,CAAU,KAAK,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAI,GAAG,KAAK,IAAI;gBAAE,SAAS;YAC3B,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACzC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,MAAM,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport type z from 'zod';\nimport { LineSchema } from '../schema/Line.js';\nimport { DIR_LINE } from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationContext, ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateLineSchema(data: unknown): ValidationError[] {\n const result = LineSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateLineRelationships(\n data: z.infer<typeof LineSchema>,\n ctx: ValidationContext,\n file: string,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n\n for (const op of data.operators) {\n if (!ctx.operatorIds.has(op.operatorId)) {\n errors.push({\n file,\n message: `operators[].operatorId \"${op.operatorId}\" does not exist`,\n });\n }\n }\n\n for (const serviceId of data.serviceIds) {\n if (!ctx.serviceIds.has(serviceId)) {\n errors.push({\n file,\n message: `serviceIds: \"${serviceId}\" does not exist`,\n });\n }\n }\n\n return errors;\n}\n\nexport function validateLines(store: IStore): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_LINE);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_LINE, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) {\n errors.push({ file: relPath, message: 'Failed to parse JSON' });\n continue;\n }\n const schemaErrs = validateLineSchema(raw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || relPath });\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_LINE,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n\nexport function validateLinesRelationships(\n store: IStore,\n ctx?: ValidationContext,\n): ValidationError[] {\n if (!ctx) return [];\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_LINE);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_LINE, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) continue;\n const parsed = LineSchema.safeParse(raw);\n if (parsed.success) {\n errors.push(...validateLineRelationships(parsed.data, ctx, relPath));\n }\n }\n } catch {\n // ignore\n }\n return errors;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import { OperatorSchema } from '
|
|
2
|
+
import { OperatorSchema } from '../schema/Operator.js';
|
|
3
3
|
import { DIR_OPERATOR } from '../constants.js';
|
|
4
4
|
import { loadJson } from './utils.js';
|
|
5
5
|
export function validateOperatorSchema(data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operator.js","sourceRoot":"/","sources":["validators/operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"operator.js","sourceRoot":"/","sources":["validators/operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,UAAU,sBAAsB,CACpC,IAAa;IAEb,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrC,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,EAAE;KAC1E,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,SAAS;YACtC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YACzC,MAAM,GAAG,GAAG,QAAQ,CAAU,KAAK,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC;gBAChE,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;YAC/C,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { OperatorSchema } from '../schema/Operator.js';\nimport { DIR_OPERATOR } from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport type { ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateOperatorSchema(\n data: unknown,\n): { file: string; message: string }[] {\n const result = OperatorSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateOperators(store: IStore): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_OPERATOR);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_OPERATOR, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) {\n errors.push({ file: relPath, message: 'Failed to parse JSON' });\n continue;\n }\n const schemaErrs = validateOperatorSchema(raw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || relPath });\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_OPERATOR,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n"]}
|
package/dist/validators/town.js
CHANGED