@open-commune/core 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/domains/collections/constants.d.mts +15 -0
- package/dist/domains/collections/constants.d.ts +15 -0
- package/dist/domains/collections/constants.mjs +1 -0
- package/dist/domains/collections/utils.d.mts +41 -0
- package/dist/domains/collections/utils.d.ts +41 -0
- package/dist/domains/collections/utils.mjs +1 -0
- package/dist/index.d.mts +4323 -0
- package/dist/index.d.ts +4323 -0
- package/dist/index.mjs +1 -0
- package/drizzle/0000_init.sql +109 -0
- package/drizzle/meta/0000_snapshot.json +718 -0
- package/drizzle/meta/_journal.json +13 -0
- package/package.json +69 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection constants — pure module (no server dependency), importable by
|
|
3
|
+
* the admin bundle through the `@open-commune/core/collections/constants` export.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Publication lifecycle shared by every publishable table. The editorial flow
|
|
7
|
+
* is driven from the admin; only `published` reaches the public plane.
|
|
8
|
+
*/
|
|
9
|
+
declare const PUBLICATION_STATUSES: readonly ["draft", "waiting", "ready", "scheduled", "published"];
|
|
10
|
+
type PublicationStatus = (typeof PUBLICATION_STATUSES)[number];
|
|
11
|
+
declare const FIELD_TYPES: readonly ["text", "rich-text", "number", "boolean", "date", "media", "relation", "select", "steps", "json"];
|
|
12
|
+
type FieldType = (typeof FIELD_TYPES)[number];
|
|
13
|
+
|
|
14
|
+
export { FIELD_TYPES, PUBLICATION_STATUSES };
|
|
15
|
+
export type { FieldType, PublicationStatus };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection constants — pure module (no server dependency), importable by
|
|
3
|
+
* the admin bundle through the `@open-commune/core/collections/constants` export.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Publication lifecycle shared by every publishable table. The editorial flow
|
|
7
|
+
* is driven from the admin; only `published` reaches the public plane.
|
|
8
|
+
*/
|
|
9
|
+
declare const PUBLICATION_STATUSES: readonly ["draft", "waiting", "ready", "scheduled", "published"];
|
|
10
|
+
type PublicationStatus = (typeof PUBLICATION_STATUSES)[number];
|
|
11
|
+
declare const FIELD_TYPES: readonly ["text", "rich-text", "number", "boolean", "date", "media", "relation", "select", "steps", "json"];
|
|
12
|
+
type FieldType = (typeof FIELD_TYPES)[number];
|
|
13
|
+
|
|
14
|
+
export { FIELD_TYPES, PUBLICATION_STATUSES };
|
|
15
|
+
export type { FieldType, PublicationStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=["draft","waiting","ready","scheduled","published"],t=["text","rich-text","number","boolean","date","media","relation","select","steps","json"];export{t as FIELD_TYPES,e as PUBLICATION_STATUSES};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FieldType } from './constants.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Field validation contract — pure module (zod only), importable by the admin
|
|
6
|
+
* bundle through the `@open-commune/core/collections/utils` export so forms validate
|
|
7
|
+
* with EXACTLY the rule the server applies. The Drizzle schema and the service
|
|
8
|
+
* import from here; it cannot live in schema.ts, whose table re-exports would
|
|
9
|
+
* create an import cycle with the database module.
|
|
10
|
+
*/
|
|
11
|
+
declare const fieldDefinitionSchema: z.ZodObject<{
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
label: z.ZodString;
|
|
14
|
+
type: z.ZodEnum<{
|
|
15
|
+
number: "number";
|
|
16
|
+
boolean: "boolean";
|
|
17
|
+
text: "text";
|
|
18
|
+
"rich-text": "rich-text";
|
|
19
|
+
date: "date";
|
|
20
|
+
media: "media";
|
|
21
|
+
relation: "relation";
|
|
22
|
+
select: "select";
|
|
23
|
+
steps: "steps";
|
|
24
|
+
json: "json";
|
|
25
|
+
}>;
|
|
26
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
28
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
|
+
target: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
type FieldDefinition = z.infer<typeof fieldDefinitionSchema>;
|
|
32
|
+
declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
|
|
33
|
+
/**
|
|
34
|
+
* Build the Zod schema validating an entry's `data` from a collection
|
|
35
|
+
* definition. Standalone on purpose: the migration CLI and the admin forms
|
|
36
|
+
* use it too.
|
|
37
|
+
*/
|
|
38
|
+
declare function buildDataSchema(fields: FieldDefinition[]): z.ZodType<Record<string, unknown>>;
|
|
39
|
+
|
|
40
|
+
export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema };
|
|
41
|
+
export type { FieldDefinition };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FieldType } from './constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Field validation contract — pure module (zod only), importable by the admin
|
|
6
|
+
* bundle through the `@open-commune/core/collections/utils` export so forms validate
|
|
7
|
+
* with EXACTLY the rule the server applies. The Drizzle schema and the service
|
|
8
|
+
* import from here; it cannot live in schema.ts, whose table re-exports would
|
|
9
|
+
* create an import cycle with the database module.
|
|
10
|
+
*/
|
|
11
|
+
declare const fieldDefinitionSchema: z.ZodObject<{
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
label: z.ZodString;
|
|
14
|
+
type: z.ZodEnum<{
|
|
15
|
+
number: "number";
|
|
16
|
+
boolean: "boolean";
|
|
17
|
+
text: "text";
|
|
18
|
+
"rich-text": "rich-text";
|
|
19
|
+
date: "date";
|
|
20
|
+
media: "media";
|
|
21
|
+
relation: "relation";
|
|
22
|
+
select: "select";
|
|
23
|
+
steps: "steps";
|
|
24
|
+
json: "json";
|
|
25
|
+
}>;
|
|
26
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
28
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
|
+
target: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
type FieldDefinition = z.infer<typeof fieldDefinitionSchema>;
|
|
32
|
+
declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
|
|
33
|
+
/**
|
|
34
|
+
* Build the Zod schema validating an entry's `data` from a collection
|
|
35
|
+
* definition. Standalone on purpose: the migration CLI and the admin forms
|
|
36
|
+
* use it too.
|
|
37
|
+
*/
|
|
38
|
+
declare function buildDataSchema(fields: FieldDefinition[]): z.ZodType<Record<string, unknown>>;
|
|
39
|
+
|
|
40
|
+
export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema };
|
|
41
|
+
export type { FieldDefinition };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"zod";import{FIELD_TYPES as i}from"./constants.mjs";const a=e.object({name:e.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/,"nom de champ invalide"),label:e.string().min(1),type:e.enum(i),required:e.boolean().default(!1),hidden:e.boolean().default(!1),options:e.array(e.string().min(1)).optional(),target:e.string().optional()}).check(t=>{t.value.type==="select"&&!t.value.options?.length&&t.issues.push({code:"custom",message:"options requises pour un champ select",input:t.value}),t.value.type==="relation"&&!t.value.target&&t.issues.push({code:"custom",message:"target requis pour un champ relation",input:t.value})}),u=e.record(e.string(),e.unknown()),s={text:e.string(),"rich-text":e.record(e.string(),e.unknown()),number:e.number().or(e.string()),boolean:e.boolean(),date:e.iso.datetime({offset:!0}).or(e.iso.date()),media:e.string().or(e.array(e.string())),relation:e.string().or(e.array(e.string())),select:e.string(),steps:e.array(u),json:e.union([e.record(e.string(),e.unknown()),e.array(e.unknown()),e.string(),e.number(),e.boolean()])};function l(t){const r={};for(const n of t){let o=s[n.type];n.type==="select"&&n.options?.length&&(o=e.enum(n.options)),r[n.name]=n.required?o:o.nullable().optional()}return e.strictObject(r)}export{s as FIELD_VALUE_SCHEMAS,l as buildDataSchema,a as fieldDefinitionSchema};
|