Skip to content

Commit 3b4fff7

Browse files
committed
fix: gate findings (ADR-0122 aliases, slot typing, test double conformance, counts)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012eJQ8dtut5bZsnhFE3XGHF
1 parent a7fc798 commit 3b4fff7

7 files changed

Lines changed: 55 additions & 14 deletions

File tree

‎content/docs/getting-started/quick-reference.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Categories that have no section here at all are named under
2222
[Categories Without a Section](#categories-without-a-section) — that curation is stated,
2323
not left implicit.
2424

25-
## Data Protocol (15 of 30 schemas)
25+
## Data Protocol (15 of 31 schemas)
2626

2727
Core business logic and data modeling schemas.
2828

‎packages/metadata-protocol/src/seed-loader-seed-files.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
StoreFieldFileInput,
1313
} from '@objectstack/spec/contracts';
1414
import { RAW_FILE_VALUES_CONTEXT_KEY, seedFile } from '@objectstack/spec/data';
15+
import { assertEngineDeleteDispatch, assertEngineUpdateDispatch, assertEngineFindOnePredicate } from '@objectstack/metadata-core';
1516

1617
/**
1718
* [#25779] A seed record writes `seedFile(path)` into a file field; `os build`
@@ -33,17 +34,22 @@ function createEngine(): { engine: IDataEngine; store: Record<string, any[]>; fi
3334
const store: Record<string, any[]> = {};
3435
const findContexts: unknown[] = [];
3536
let next = 0;
37+
/** Equality on plain keys; a combinator or operator this fake does not implement is refused, never misread. */
38+
const matches = (row: Record<string, any>, where: Record<string, unknown>) =>
39+
Object.entries(where).every(([k, v]) => {
40+
if (k.startsWith('$')) throw new Error(`fake driver: unsupported operator ${k}`);
41+
return row[k] === v;
42+
});
3643
const engine = {
3744
find: vi.fn(async (object: string, query?: any) => {
3845
findContexts.push(query?.context);
3946
let rows = store[object] ?? [];
40-
if (query?.where) rows = rows.filter((r) => Object.entries(query.where).every(([k, v]) => r[k] === v));
47+
if (query?.where) rows = rows.filter((r) => matches(r, query.where));
4148
return rows.map((r) => ({ ...r }));
4249
}),
4350
findOne: vi.fn(async (object: string, query?: any) => {
44-
const rows = (store[object] ?? []).filter((r) =>
45-
Object.entries(query?.where ?? {}).every(([k, v]) => r[k] === v),
46-
);
51+
assertEngineFindOnePredicate(object, query);
52+
const rows = (store[object] ?? []).filter((r) => matches(r, query?.where ?? {}));
4753
return rows[0] ? { ...rows[0] } : null;
4854
}),
4955
insert: vi.fn(async (object: string, data: any) => {
@@ -56,12 +62,16 @@ function createEngine(): { engine: IDataEngine; store: Record<string, any[]>; fi
5662
return Array.isArray(data) ? data.map(one) : one(data);
5763
}),
5864
update: vi.fn(async (object: string, data: any) => {
65+
assertEngineUpdateDispatch(data, undefined);
5966
const rows = store[object] ?? [];
6067
const i = rows.findIndex((r) => r.id === data.id);
6168
if (i >= 0) rows[i] = { ...rows[i], ...data };
6269
return data;
6370
}),
64-
delete: vi.fn(async () => ({ deleted: 1 })),
71+
delete: vi.fn(async (_object: string, options?: any) => {
72+
assertEngineDeleteDispatch(options);
73+
return { deleted: 1 };
74+
}),
6575
count: vi.fn(async (object: string) => (store[object] ?? []).length),
6676
aggregate: vi.fn(async () => []),
6777
} as unknown as IDataEngine;

‎packages/services/service-storage/src/storage-service-plugin.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import type { TenancyPosture } from '@objectstack/spec/security';
6262
import { registerStorageFamily } from './storage-routes.js';
6363
import type { FileReadVerdict, StorageGatedSessionReader, StorageUploadSession } from './storage-routes.js';
6464
import { installAttachmentLifecycleHooks, createSysFileReapGuard, createUploadSessionReapGuard, findFileHolder, findHeldFiles } from './attachment-lifecycle.js';
65-
import { installFileReferenceHooks, type FileReferenceReadAuthorizer } from './file-reference-lifecycle.js';
65+
import { installFileReferenceHooks, type FileReferenceEngine, type FileReferenceReadAuthorizer } from './file-reference-lifecycle.js';
6666
import { installAttachmentAccessHooks, installAttachmentReadVisibility } from './attachment-access-hooks.js';
6767
import { contributeAttachmentDeleteFloorAlternate } from './attachment-delete-floor-alternate.js';
6868
import { FileAttachmentService, type FileAttachmentEngine } from './file-attachment-service.js';
@@ -408,7 +408,10 @@ export class StorageServicePlugin implements Plugin {
408408
new FieldFileService({
409409
getEngine: () => {
410410
try {
411-
return ctx.getService<any>('objectql') ?? null;
411+
// The kernel's data engine is ObjectQL, which also carries the
412+
// hook and lookup surface the lifecycle's release reads.
413+
const engine: (IDataEngine & FileReferenceEngine) | undefined = ctx.getService<IDataEngine & FileReferenceEngine>('objectql');
414+
return engine ?? null;
412415
} catch {
413416
return null;
414417
}

‎packages/spec/llms.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const query = {
7777

7878
---
7979

80-
## 3. Schema Inventory by Domain (207 schemas)
80+
## 3. Schema Inventory by Domain (208 schemas)
8181

8282
Counted as `*.zod.ts` modules under `packages/spec/src/<domain>/` — the sources
8383
that ship in this tarball (`files` includes `src/**/*.zod.ts`), so every number
@@ -87,7 +87,7 @@ here is verifiable from the installed package.
8787
|--------|-------|-------------|
8888
| system | 37 | Auth, Cache, Demo Staff, Dev Login, Email / SMS Config, Encryption, Fate Supplement (organization ownership), HTTP Server, License, Logging, Metrics |
8989
| kernel | 30 | Plugin, Manifest, Events (6 sub-modules), Feature, Context, Package Registry |
90-
| data | 31 | Object, Field, Picklist, Query, Filter, Driver (SQL/NoSQL/Memory/Mongo/Postgres), Cube |
90+
| data | 32 | Object, Field, Picklist, Query, Filter, Driver (SQL/NoSQL/Memory/Mongo/Postgres), Cube, Seed |
9191
| api | 31 | Endpoint, REST Server, Discovery, OData, Batch, WebSocket, Response Envelope, Package Lifecycle, Package API (assembled stage) |
9292
| ui | 18 | View, App, Action, Dashboard, Page, Chart, Component, Animation |
9393
| automation | 14 | Flow, Approval, BPMN Interop, Control Flow, Webhook, Schedule Organization |

‎packages/spec/src/data/seed-file.zod.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function isSeedFilePath(path: unknown): path is string {
6262
export const SeedFilePathSchema = lazySchema(() => z.string()
6363
.regex(SEED_FILE_PATH_PATTERN, SEED_FILE_PATH_RULE)
6464
.describe('Path of a file the package ships, relative to the package root (e.g. `fixtures/nda-v1.pdf`)'));
65-
export type SeedFilePath = z.infer<typeof SeedFilePathSchema>;
65+
export type SeedFilePath = z.input<typeof SeedFilePathSchema>;
6666

6767
/** A MIME type: `type/subtype`, the shape a `sys_file.mime_type` carries. */
6868
const MIME_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;
@@ -86,6 +86,7 @@ export const SeedFileReferenceSchema = lazySchema(() => strictObject({
8686

8787
/** Author-time shape of {@link SeedFileReferenceSchema}. */
8888
export type SeedFileReference = z.input<typeof SeedFileReferenceSchema>;
89+
export type SeedFileReferenceParsed = z.infer<typeof SeedFileReferenceSchema>;
8990

9091
/**
9192
* The bytes of one seed file, as `os build` bundles them into a dataset's
@@ -106,6 +107,7 @@ export const SeedFileContentSchema = lazySchema(() => strictObject({
106107

107108
/** Author-time shape of {@link SeedFileContentSchema}. */
108109
export type SeedFileContent = z.input<typeof SeedFileContentSchema>;
110+
export type SeedFileContentParsed = z.infer<typeof SeedFileContentSchema>;
109111

110112
/**
111113
* Write a file the package ships into a file field from a seed record.

‎packages/spec/src/type-alias-convention.pin.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,11 @@ import type * as M190 from './kernel/execution-context.zod.js';
278278
import type * as M191 from './automation/api-trigger-secret-ref.zod.js';
279279
// [#25761] The one column apply-on vocabulary both write doors read -- new module, next free index.
280280
import type * as M192 from './data/column-apply-on.zod.js';
281+
// [#25779] A seed file's package-relative path -- new module, next free index.
282+
import type * as M193 from './data/seed-file.zod.js';
281283

282284
// ---------------------------------------------------------------------------
283-
// 789 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared.
285+
// 790 isomorphic aliases: `z.input` === `z.infer`, so no `XParsed` is declared.
284286
//
285287
// That number is machine-checked, not hand-kept. The runtime companion at the
286288
// bottom of this file recomputes the pin count from the source and asserts that
@@ -907,6 +909,9 @@ export type Iso_data_query__AggregationNodeSchema = Assert<Eq< z.input< typeof M
907909
export type Iso_data_query__DateGranularity = Assert<Eq< z.input< typeof M71.DateGranularity >, z.infer< typeof M71.DateGranularity > >>;
908910
export type Iso_data_query__GroupByNodeSchema = Assert<Eq< z.input< typeof M71.GroupByNodeSchema >, z.infer< typeof M71.GroupByNodeSchema > >>;
909911

912+
// data/seed-file.zod.ts
913+
export type Iso_data_seedFile__SeedFilePathSchema = Assert<Eq< z.input< typeof M193.SeedFilePathSchema >, z.infer< typeof M193.SeedFilePathSchema > >>;
914+
910915
// data/seed-loader.zod.ts
911916
export type Iso_data_seedLoader__ReferenceResolutionErrorSchema = Assert<Eq< z.input< typeof M72.ReferenceResolutionErrorSchema >, z.infer< typeof M72.ReferenceResolutionErrorSchema > >>;
912917
export type Iso_data_seedLoader__SeedIdentitySchema = Assert<Eq< z.input< typeof M72.SeedIdentitySchema >, z.infer< typeof M72.SeedIdentitySchema > >>;
@@ -1710,7 +1715,7 @@ describe('ADR-0122 type-alias convention', () => {
17101715
// this title and the section header above the pin list — are now asserted
17111716
// against the recomputed count below, so neither can go stale without a red
17121717
// test naming it.
1713-
it('still declares all 789 isomorphic pins', () => {
1718+
it('still declares all 790 isomorphic pins', () => {
17141719
// The truth of each pin is proved by tsc, not here — an `Assert<Eq<...>>`
17151720
// that stops holding is a compile error with the alias named. What tsc
17161721
// cannot notice is a pin that was DELETED: removing the assertion removes
@@ -2600,7 +2605,13 @@ describe('ADR-0122 type-alias convention', () => {
26002605
// (Iso_ui_dataset__DatasetMeasureDurationSchema,
26012606
// Iso_ui_dataset__DatasetDurationUnit) rather than given `…Parsed`
26022607
// synonyms. +2 added.
2603-
expect(pins).toHaveLength(789);
2608+
//
2609+
// 789 -> 790 is #25779: `SeedFilePathSchema` (`data/seed-file.zod.ts`),
2610+
// the package-relative path a `seedFile(...)` reference names — a plain
2611+
// string with a pattern, so it is pinned here
2612+
// (Iso_data_seedFile__SeedFilePathSchema) rather than given a `…Parsed`
2613+
// synonym. +1 added.
2614+
expect(pins).toHaveLength(790);
26042615

26052616
// The count is stated in PROSE twice as well — this case's title and the
26062617
// section header above the pin list — and until commit c6b05c76a nothing read either

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,21 @@
20412041
"verb": "update",
20422042
"pinned": 1
20432043
},
2044+
{
2045+
"file": "packages/metadata-protocol/src/seed-loader-seed-files.test.ts",
2046+
"verb": "delete",
2047+
"pinned": 1
2048+
},
2049+
{
2050+
"file": "packages/metadata-protocol/src/seed-loader-seed-files.test.ts",
2051+
"verb": "findOne",
2052+
"pinned": 1
2053+
},
2054+
{
2055+
"file": "packages/metadata-protocol/src/seed-loader-seed-files.test.ts",
2056+
"verb": "update",
2057+
"pinned": 1
2058+
},
20442059
{
20452060
"file": "packages/metadata-protocol/src/seed-loader-sole-organization-read-failure.test.ts",
20462061
"verb": "delete",

0 commit comments

Comments
 (0)