|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { z } from 'zod'; |
| 4 | +import { lazySchema } from '../shared/lazy-schema'; |
| 5 | +import { ObjectStackDefinitionSchema } from '../stack.zod'; |
| 6 | + |
| 7 | +/** |
| 8 | + * # Project Artifact Envelope (M1) |
| 9 | + * |
| 10 | + * Describes the response shape of `GET /api/v1/cloud/projects/:projectId/artifact` |
| 11 | + * — the assembled artifact ObjectOS pulls from the control plane. |
| 12 | + * |
| 13 | + * Distinct from the marketplace `PackageArtifactSchema` (a .tgz file listing). |
| 14 | + * This envelope wraps the compiled `ObjectStackDefinitionSchema` produced by |
| 15 | + * `objectstack compile` together with control-plane assigned identity |
| 16 | + * (`commitId`, `checksum`). |
| 17 | + */ |
| 18 | + |
| 19 | +// --- SHA-256 digest of a single artifact payload --- |
| 20 | +export const Sha256DigestSchema = z |
| 21 | + .string() |
| 22 | + .regex(/^[a-f0-9]{64}$/, 'Must be a 64-character lowercase hex SHA-256 digest') |
| 23 | + .describe('SHA-256 digest (64 hex chars)'); |
| 24 | + |
| 25 | +export type Sha256Digest = z.infer<typeof Sha256DigestSchema>; |
| 26 | + |
| 27 | +// --- Artifact envelope --- |
| 28 | +export const ProjectArtifactSchema = lazySchema(() => z.object({ |
| 29 | + /** Envelope format version. Increment on breaking changes. */ |
| 30 | + schemaVersion: z.literal('0.1').default('0.1'), |
| 31 | + |
| 32 | + /** Control-plane project ID this artifact belongs to. */ |
| 33 | + projectId: z.string(), |
| 34 | + |
| 35 | + /** Metadata revision assigned by the control plane on publish. */ |
| 36 | + commitId: z.string(), |
| 37 | + |
| 38 | + /** |
| 39 | + * SHA-256 digest of the canonical JSON serialization of the `metadata` |
| 40 | + * block (stable key ordering). Computed by the control plane when |
| 41 | + * assembling the GET response. |
| 42 | + */ |
| 43 | + checksum: Sha256DigestSchema, |
| 44 | + |
| 45 | + /** Build timestamp (ISO 8601). */ |
| 46 | + builtAt: z.string().datetime().optional(), |
| 47 | + |
| 48 | + /** CLI version that produced this artifact (e.g. "objectstack-cli@0.4.0"). */ |
| 49 | + builtWith: z.string().optional(), |
| 50 | + |
| 51 | + /** |
| 52 | + * Full compiled metadata definition. |
| 53 | + * Includes objects, views, flows, hooks, functions, agents, etc. |
| 54 | + * This is the direct output of `objectstack compile`. |
| 55 | + */ |
| 56 | + metadata: ObjectStackDefinitionSchema, |
| 57 | +})); |
| 58 | + |
| 59 | +export type ProjectArtifact = z.infer<typeof ProjectArtifactSchema>; |
| 60 | +export type ProjectArtifactInput = z.input<typeof ProjectArtifactSchema>; |
0 commit comments