Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions apps/azure/src/components/editor/FrameView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ import React from 'react';
import { LayeredProcessView } from '@variscout/ui';
import { useProjectStore } from '@variscout/stores';
import type { ProcessContext } from '@variscout/core';
import { detectGaps, type ProcessMap } from '@variscout/core/frame';

const createEmptyMap = (): ProcessMap => {
const now = new Date().toISOString();
return {
version: 1,
nodes: [],
tributaries: [],
createdAt: now,
updatedAt: now,
};
};
import { createEmptyMap, detectGaps, type ProcessMap } from '@variscout/core/frame';

const FrameView: React.FC = () => {
const rawData = useProjectStore(s => s.rawData);
Expand Down
13 changes: 1 addition & 12 deletions apps/pwa/src/components/views/FrameView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,7 @@ import React from 'react';
import { LayeredProcessView } from '@variscout/ui';
import { useProjectStore } from '@variscout/stores';
import type { ProcessContext } from '@variscout/core';
import { detectGaps, type ProcessMap } from '@variscout/core/frame';

const createEmptyMap = (): ProcessMap => {
const now = new Date().toISOString();
return {
version: 1,
nodes: [],
tributaries: [],
createdAt: now,
updatedAt: now,
};
};
import { createEmptyMap, detectGaps, type ProcessMap } from '@variscout/core/frame';

const FrameView: React.FC = () => {
const rawData = useProjectStore(s => s.rawData);
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/frame/__tests__/factories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest';
import { createEmptyMap } from '../factories';

describe('createEmptyMap', () => {
it('returns a v1 ProcessMap with no nodes or tributaries', () => {
const map = createEmptyMap();
expect(map.version).toBe(1);
expect(map.nodes).toEqual([]);
expect(map.tributaries).toEqual([]);
});

it('stamps createdAt and updatedAt with the same ISO timestamp', () => {
const map = createEmptyMap();
expect(map.createdAt).toBe(map.updatedAt);
expect(() => new Date(map.createdAt).toISOString()).not.toThrow();
});

it('produces independent instances on each call', () => {
const a = createEmptyMap();
const b = createEmptyMap();
expect(a).not.toBe(b);
expect(a.nodes).not.toBe(b.nodes);
expect(a.tributaries).not.toBe(b.tributaries);
});
});
16 changes: 16 additions & 0 deletions packages/core/src/frame/factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ProcessMap } from './types';

/**
* Build an empty `ProcessMap` with current timestamps. Used by FRAME views in
* both apps as the initial state when no `processContext.processMap` exists.
*/
export function createEmptyMap(): ProcessMap {
const now = new Date().toISOString();
return {
version: 1,
nodes: [],
tributaries: [],
createdAt: now,
updatedAt: now,
};
}
1 change: 1 addition & 0 deletions packages/core/src/frame/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export type {
export { inferMode } from './modeInference';
export { detectGaps } from './gapDetector';
export { subgroupAxisColumns } from './subgroupAxes';
export { createEmptyMap } from './factories';