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
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@
import { describe, it, expect, vi } from 'vitest';
import { BatchOperationResultSchema, BatchUpdateResponseSchema } from '@objectstack/spec/api';
import { ObjectStackProtocolImplementation } from './protocol.js';
import { assertEngineUpdateDispatch, assertEngineDeleteDispatch } from '@objectstack/metadata-core';

const SCHEMA = { name: 'invoice', fields: { title: { name: 'title', type: 'text' } } };

Expand DownExpand Up@@ -56,6 +57,7 @@ function makeStoreEngine() {
return rec;
}),
update: vi.fn(async (_object: string, data: any, options?: any) => {
assertEngineUpdateDispatch(data, options);
const id = options?.where?.id;
const current = rows.get(id);
if (!current) throw new Error(`no such record: ${id}`);
Expand All@@ -66,6 +68,7 @@ function makeStoreEngine() {
}),
// Contract per #4435: `false` is the positive not-found value.
delete: vi.fn(async (_object: string, options?: any) => {
assertEngineDeleteDispatch(options);
const id = options?.where?.id;
if (!rows.has(id)) return false;
rows.delete(id);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,7 +66,7 @@
*/

import { describe, it, expect, vi } from 'vitest';
import { assertEngineDeleteDispatch } from '@objectstack/metadata-core';
import { assertEngineDeleteDispatch, assertEngineUpdateDispatch } from '@objectstack/metadata-core';
import { resolveThrownHttpError, validationFailureDetails } from '@objectstack/types';
import { ObjectStackProtocolImplementation } from './protocol.js';

Expand DownExpand Up@@ -170,6 +170,7 @@ function makeEngine(throwOn: (verb: string, id: unknown) => unknown | undefined)
return rec;
}),
update: vi.fn(async (_o: string, data: any, opts?: any) => {
assertEngineUpdateDispatch(data, opts);
const id = opts?.where?.id;
const boom = throwOn('update', id);
if (boom) throw boom;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,7 +57,7 @@
*/

import { describe, it, expect, vi } from 'vitest';
import { assertEngineDeleteDispatch } from '@objectstack/metadata-core';
import { assertEngineDeleteDispatch, assertEngineUpdateDispatch } from '@objectstack/metadata-core';
import { resolveThrownHttpError } from '@objectstack/types';
import { ObjectStackProtocolImplementation } from './protocol.js';

Expand DownExpand Up@@ -172,6 +172,7 @@ function makeEngine(throwOn: (verb: string, id: unknown) => unknown | undefined)
return rec;
}),
update: vi.fn(async (_o: string, data: any, opts?: any) => {
assertEngineUpdateDispatch(data, opts);
const id = opts?.where?.id;
const boom = throwOn('update', id);
if (boom) throw boom;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@

import { describe, it, expect, vi } from 'vitest';
import { ObjectStackProtocolImplementation } from './protocol.js';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

const SCHEMA = {
name: 'approval_case',
Expand All@@ -29,6 +30,7 @@ describe('updateData — forwards engine write strips as droppedFields (#3431)',
registry: { getObject: () => SCHEMA },
// Stand in for the engine stripping `approval_status` and reporting it.
update: vi.fn(async (object: string, data: any, options?: any) => {
assertEngineUpdateDispatch(data, options);
options?.onFieldsDropped?.({ object, fields: ['approval_status'], reason: 'readonly' });
return { id: 'rec-1', title: data.title };
}),
Expand All@@ -55,7 +57,8 @@ describe('updateData — forwards engine write strips as droppedFields (#3431)',
it('forwards multiple strip passes in order (readonly_when then readonly)', async () => {
const engine = {
registry: { getObject: () => SCHEMA },
update: vi.fn(async (object: string, _data: any, options?: any) => {
update: vi.fn(async (object: string, data: any, options?: any) => {
assertEngineUpdateDispatch(data, options);
options?.onFieldsDropped?.({ object, fields: ['locked'], reason: 'readonly_when' });
options?.onFieldsDropped?.({ object, fields: ['approval_status'], reason: 'readonly' });
return { id: 'rec-1' };
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* Composite externalId (framework#3434).
Expand DownExpand Up@@ -57,6 +58,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* #5127 — pass 2 RESOLVES the target and then has no record to write it onto.
Expand DownExpand Up@@ -66,6 +67,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) { records[idx] = { ...records[idx], ...data }; return records[idx]; }
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* framework#2805: a pass-2 (deferred) reference back-fill that FAILS must be
Expand DownExpand Up@@ -51,6 +52,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) { records[idx] = { ...records[idx], ...data }; return records[idx]; }
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* Reference-graph fallback to the ENGINE schema registry.
Expand DownExpand Up@@ -63,6 +64,7 @@ function createFaithfulEngine(schemas: Record<string, any>) {
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* Multi-value reference resolution (`Field.lookup(..., { multiple: true })`).
Expand DownExpand Up@@ -58,6 +59,7 @@ function createEngine(schemas: Record<string, any>) {
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) {
Expand Down
2 changes: 2 additions & 0 deletions packages/metadata-protocol/src/seed-loader-replay.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* Replay regression: seeds with lookup natural keys must survive a dev-server
Expand DownExpand Up@@ -54,6 +55,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) {
Expand Down
2 changes: 2 additions & 0 deletions packages/metadata-protocol/src/seed-loader-retry.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* framework#3150: the self-referencing seed path (`hasSelfRef`) writes records
Expand DownExpand Up@@ -47,6 +48,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) { records[idx] = { ...records[idx], ...data }; return records[idx]; }
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* #3433 — a curated seed is a snapshot of ESTABLISHED facts (a project already
Expand DownExpand Up@@ -99,6 +100,7 @@ function createEnforcingEngine(): { engine: IDataEngine; store: Record<string, a
return Array.isArray(data) ? written : written[0];
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const rows = store[objectName] || [];
const idx = rows.findIndex((r) => r.id === data.id);
if (idx >= 0) {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import { describe, it, expect, vi } from 'vitest';
import { SeedLoadResultSchema, SeedLoaderResultSchema } from '@objectstack/spec/data';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* framework#4998: a roll-up summary recompute that exhausts its retries must be
Expand DownExpand Up@@ -59,6 +60,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) { records[idx] = { ...records[idx], ...data }; return records[idx]; }
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import { describe, it, expect, vi } from 'vitest';
// tests; this one is the one tsc can actually read.
import { SeedLoaderService } from './seed-loader.js';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

/**
* framework#4997: a record DROPPED because its reference cannot be resolved —
Expand DownExpand Up@@ -70,6 +71,7 @@ function createFaithfulEngine(): { engine: IDataEngine; store: Record<string, an
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex((r) => r.id === data.id);
if (idx >= 0) { records[idx] = { ...records[idx], ...data }; return records[idx]; }
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
import { SchemaRegistry } from './registry.js';
import { assertEngineDeleteDispatch } from '@objectstack/metadata-core';

/** One env-wide, active overlay row for `rc1_probe`, stored under the canonical type. */
const OVERLAY_ROW = {
Expand DownExpand Up@@ -66,6 +67,7 @@ describe('#4432 — canonical `/meta` type segment', () => {
insert: vi.fn(async () => ({ id: 'new' })),
update: vi.fn(async () => ({ id: 'row_1' })),
delete: vi.fn(async (_t: string, opts: any) => {
assertEngineDeleteDispatch(opts);
const id = opts?.where?.id;
rows = rows.filter((r) => r.id !== id);
return { deleted: 1 };
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@

import { describe, it, expect, vi } from 'vitest';
import { claimSeedOwnership } from './claim-seed-ownership.js';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

const SYSTEM = 'usr_system';
const ADMIN = 'usr_admin_human';
Expand All@@ -19,6 +20,7 @@ function makeQL(schemas: any[], rowsByObject: Record<string, any[]>) {
return all;
}),
update: vi.fn(async (object: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
updates.push({ object, data });
const row = (rowsByObject[object] ?? []).find((r) => r.id === data.id);
if (row) row.owner_id = data.owner_id;
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime/src/meta-overlay-read-your-writes.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { ObjectStackProtocolImplementation, resetEnvWritableMetadataTypes } from '@objectstack/metadata-protocol';
import { SchemaRegistry } from '@objectstack/objectql';
import { SchemaRegistry, assertEngineUpdateDispatch, assertEngineDeleteDispatch } from '@objectstack/objectql';
import { resolveRouteActionDeclaration, type ActionExecutionDeps } from './action-execution.js';

/**
Expand All@@ -72,11 +72,13 @@ function makeEngine(registry: SchemaRegistry) {
return row;
}),
update: vi.fn(async (_table: string, data: any, opts: any) => {
assertEngineUpdateDispatch(data, opts);
const target = rows.find((r) => matches(r, opts?.where ?? {}));
if (target) Object.assign(target, data);
return target ?? null;
}),
delete: vi.fn(async (_table: string, opts: any) => {
assertEngineDeleteDispatch(opts);
const before = rows.length;
rows = rows.filter((r) => !matches(r, opts?.where ?? {}));
return { deleted: before - rows.length };
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/seed-loader.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { SeedLoaderService } from './seed-loader';
import type { IDataEngine, IMetadataService } from '@objectstack/spec/contracts';
import type { SeedLoaderRequest, SeedLoaderConfig } from '@objectstack/spec/data';
import { assertEngineUpdateDispatch } from '@objectstack/metadata-core';

// ==========================================================================
// Mock Helpers
Expand DownExpand Up@@ -56,6 +57,7 @@ function createMockEngine(data: Record<string, any[]> = {}): IDataEngine {
return record;
}),
update: vi.fn(async (objectName: string, data: any) => {
assertEngineUpdateDispatch(data, undefined);
const records = store[objectName] || [];
const idx = records.findIndex(r => r.id === data.id);
if (idx >= 0) {
Expand Down
Loading
Loading