@overspace-app/client 0.1.1 → 0.1.2

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './client/index.js';
2
2
  export * from './css.js';
3
3
  export { defineSite, field } from './schema/index.js';
4
- export type { SiteDefinition, SectionContent, PageContent, SectionKey, PageKey, ImageValue, LinkValue, RichTextDoc } from './schema/index.js';
4
+ export type { SiteDefinition, SectionContent, PageContent, SectionKey, PageKey, ImageValue, LinkValue, RichTextDoc, ReferencedArticle } from './schema/index.js';
5
5
  export { parseVideoUrl, canonicalVideoUrl, isValidVideo } from './video.js';
6
6
  export { isSafeHref } from './schema/index.js';
package/dist/preview.js CHANGED
@@ -10,7 +10,7 @@ export const PREVIEW_MAX_BYTES = 2_000_000;
10
10
  export function previewUrl(siteBase, pagePath) {
11
11
  const base = siteBase.replace(/\/+$/, '');
12
12
  const path = pagePath.startsWith('/') ? pagePath : '/' + pagePath;
13
- return base + PREVIEW_PATH + (path === '/' ? '/' : path);
13
+ return base + PREVIEW_PATH + (path === '/' ? '' : path);
14
14
  }
15
15
  export function readPreviewMessage(data) {
16
16
  if (!data || typeof data !== 'object')
@@ -86,3 +86,4 @@ export declare function compileSite(def: SiteDefinition): CompiledSchema;
86
86
  * Suppose une forme déjà correcte (types de base vérifiés par Zod côté serveur, par TypeScript côté CLI).
87
87
  */
88
88
  export declare function checkCompiledSchema(s: CompiledSchema): string[];
89
+ export declare const FIELD_KEYS: Record<string, readonly string[]>;
@@ -136,6 +136,23 @@ export function checkCompiledSchema(s) {
136
136
  }
137
137
  return problems;
138
138
  }
139
+ const COMMON_KEYS = ['key', 'label', 'hint', 'required', 'translatable', 'renamedFrom', 'default', 'type'];
140
+ export const FIELD_KEYS = {
141
+ text: [...COMMON_KEYS, 'maxLength', 'placeholder'],
142
+ textarea: [...COMMON_KEYS, 'maxLength', 'rows'],
143
+ richText: [...COMMON_KEYS, 'marks'],
144
+ image: [...COMMON_KEYS, 'ratio', 'altRequired'],
145
+ gallery: [...COMMON_KEYS, 'min', 'max', 'ratio'],
146
+ video: COMMON_KEYS,
147
+ url: COMMON_KEYS,
148
+ link: [...COMMON_KEYS, 'internalOnly'],
149
+ number: [...COMMON_KEYS, 'min', 'max', 'step', 'unit'],
150
+ date: [...COMMON_KEYS, 'min', 'max'],
151
+ boolean: COMMON_KEYS,
152
+ select: [...COMMON_KEYS, 'options', 'multiple'],
153
+ reference: [...COMMON_KEYS, 'category'],
154
+ list: ['key', 'label', 'hint', 'type', 'item', 'itemLabel', 'min', 'max', 'addable', 'renamedFrom', 'default'],
155
+ };
139
156
  function checkFields(fields, where, p, inList = false) {
140
157
  const keys = new Set();
141
158
  const sources = new Set();
@@ -149,6 +166,11 @@ function checkFields(fields, where, p, inList = false) {
149
166
  p(`${at} : type « ${String(f.type)} » inconnu`);
150
167
  continue;
151
168
  }
169
+ const allowed = FIELD_KEYS[f.type];
170
+ for (const k of Object.keys(f)) {
171
+ if (allowed && !allowed.includes(k))
172
+ p(`${at} : option « ${printable(k)} » inconnue pour un champ ${f.type}`);
173
+ }
152
174
  checkLabel(f.label, at, p);
153
175
  if (f.hint !== undefined && f.hint.length > LIMITS.hint)
154
176
  p(`${at} : aide trop longue (> ${LIMITS.hint})`);
@@ -129,6 +129,24 @@ export type FieldValue<F> = F extends ListField<infer I> ? Array<{
129
129
  }> : F extends SelectField<infer O> ? F extends {
130
130
  multiple: true;
131
131
  } ? O[] : O : F extends RichTextField ? RichTextDoc : F extends ImageField ? ImageValue : F extends GalleryField ? ImageValue[] : F extends LinkField ? LinkValue : F extends NumberField ? number : F extends BooleanField ? boolean : string;
132
+ /** Article cité par un champ `reference`, tel que la LECTURE le renvoie (résumé d'un article publié). */
133
+ export type ReferencedArticle = {
134
+ id: string;
135
+ title: string;
136
+ slug: string;
137
+ excerpt: string | null;
138
+ cover_url: string | null;
139
+ category: string | null;
140
+ locale: string | null;
141
+ published_at: string | null;
142
+ };
143
+ /**
144
+ * Valeur LUE (API v1, SDK, aperçu) : comme `FieldValue` (qui décrit aussi les valeurs par défaut écrites dans la
145
+ * config), sauf qu'une référence arrive RÉSOLUE en article publié, ou `null` (article absent ou non publié, R-31).
146
+ */
147
+ export type ReadValue<F> = F extends ListField<infer I> ? Array<{
148
+ -readonly [K in keyof I]: ReadValue<I[K]>;
149
+ }> : F extends ReferenceField ? ReferencedArticle | null : FieldValue<F>;
132
150
  type Opts<F> = Omit<F, 'type'>;
133
151
  export declare const field: {
134
152
  text: (o: Opts<TextField>) => TextField;
@@ -1,4 +1,4 @@
1
- import type { AnyField, FieldValue } from './fields.js';
1
+ import type { AnyField, ReadValue } from './fields.js';
2
2
  /**
3
3
  * Définition d'un site (`overspace.config.ts`) — docs/integration/design.md §2.
4
4
  * Objets indexés par clé : l'ordre d'écriture est l'ordre d'affichage, et TypeScript déduit les
@@ -33,7 +33,7 @@ export type SiteDefinition = {
33
33
  export declare function defineSite<const D extends SiteDefinition>(definition: D): D;
34
34
  /** Contenu d'une section tel que l'API le renvoie (langue déjà résolue). */
35
35
  export type SectionValues<S extends SectionDefinition> = {
36
- -readonly [K in keyof S['fields']]: FieldValue<S['fields'][K]>;
36
+ -readonly [K in keyof S['fields']]: ReadValue<S['fields'][K]>;
37
37
  };
38
38
  /** Clés de section d'un site. */
39
39
  export type SectionKey<D extends SiteDefinition> = Extract<keyof D['sections'], string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overspace-app/client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Overspace — schéma de site et client de lecture typé (sans dépendance).",
5
5
  "license": "MIT",
6
6
  "type": "module",