simple-strapi 1.0.0-alpha.16 → 1.0.0-alpha.18

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/client.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { InferBoolean, BooleanField, BooleanOptions } from "./fields/boolean";
1
2
  import { InferNumber, NumberField, NumberOptions } from "./fields/number";
2
3
  import { InferText, TextField, TextOptions } from "./fields/text";
3
4
  import { InferRelationHasMany, InferRelationHasOne, RelationHasManyField, RelationHasManyOptions, RelationHasOneField, RelationHasOneOptions } from "./fields/relation";
@@ -8,16 +9,17 @@ import { ComponentRepeatableField, ComponentRepeatableOptions, ComponentSingleFi
8
9
  import { InferMediaSingle, MediaSingleField, MediaSingleOptions } from "./fields/media";
9
10
  import { EnumerationField, EnumerationOptions, InferEnumeration } from "./fields/enumeration";
10
11
  import { InferRichTextBlocks, RichTextBlocksField, RichTextBlocksOptions } from "./fields/richText";
12
+ import { InferJSON, JSONField, JSONOptions } from "./fields/json";
11
13
  type RequestParams = Record<string, any>;
12
14
  type EntityRequest<P = {}> = {
13
15
  where?: Record<string, string>;
14
16
  params?: RequestParams;
15
17
  headers?: Record<string, string>;
16
18
  } & P;
17
- export type SchemaField = TextField | NumberField | RelationHasManyField | RelationHasOneField | DynamicField | ComponentSingleField | ComponentRepeatableField | MediaSingleField | EnumerationField | RichTextBlocksField;
19
+ export type SchemaField = TextField | NumberField | BooleanField | RelationHasManyField | RelationHasOneField | DynamicField | ComponentSingleField | ComponentRepeatableField | MediaSingleField | EnumerationField | RichTextBlocksField | JSONField;
18
20
  export type Schema = Record<string, SchemaField>;
19
21
  export type InferSchema<S extends Schema> = {
20
- [K in keyof S]: S[K] extends ["text", infer O extends TextOptions] ? InferText<O> : S[K] extends ["number", infer O extends NumberOptions] ? InferNumber<O> : S[K] extends [
22
+ [K in keyof S]: S[K] extends ["text", infer O extends TextOptions] ? InferText<O> : S[K] extends ["number", infer O extends NumberOptions] ? InferNumber<O> : S[K] extends ["boolean", infer O extends BooleanOptions] ? InferBoolean<O> : S[K] extends ["json", infer O extends JSONOptions] ? InferJSON<O> : S[K] extends [
21
23
  "relation.hasMany",
22
24
  infer R extends Schema,
23
25
  infer O extends RelationHasManyOptions
@@ -0,0 +1,8 @@
1
+ import { ZodType } from "zod";
2
+ export type BooleanOptions = {
3
+ required?: boolean;
4
+ };
5
+ export type InferBoolean<O extends BooleanOptions> = O["required"] extends true ? boolean : boolean | null | undefined;
6
+ export declare const boolean: <O extends BooleanOptions = {}>(options?: O) => ["boolean", O];
7
+ export declare const booleanSchema: (opts: BooleanOptions) => ZodType;
8
+ export type BooleanField = ReturnType<typeof boolean>;
@@ -0,0 +1,10 @@
1
+ import z from "zod";
2
+ export const boolean = (options = {}) => {
3
+ return ["boolean", options];
4
+ };
5
+ export const booleanSchema = (opts) => {
6
+ let schema = z.boolean();
7
+ if (!opts.required)
8
+ schema = schema.nullable().optional();
9
+ return schema;
10
+ };
@@ -0,0 +1,8 @@
1
+ import { ZodType } from "zod";
2
+ export type JSONOptions = {
3
+ required?: boolean;
4
+ };
5
+ export type InferJSON<O extends JSONOptions> = O["required"] extends true ? any : any | null | undefined;
6
+ export declare const json: <O extends JSONOptions = {}>(options?: O) => ["json", O];
7
+ export declare const jsonSchema: (opts: JSONOptions) => ZodType;
8
+ export type JSONField = ReturnType<typeof json>;
@@ -0,0 +1,10 @@
1
+ import z from "zod";
2
+ export const json = (options = {}) => {
3
+ return ["json", options];
4
+ };
5
+ export const jsonSchema = (opts) => {
6
+ let schema = z.any();
7
+ if (!opts.required)
8
+ schema = schema.nullable().optional();
9
+ return schema;
10
+ };
@@ -4,8 +4,6 @@ export const number = (options = {}) => {
4
4
  };
5
5
  export const numberSchema = (opts) => {
6
6
  let schema = z.number();
7
- // if (opts.nullable) schema = schema.nullable();
8
- // if (opts.optional) schema = schema.optional();
9
7
  if (!opts.required)
10
8
  schema = schema.nullable().optional();
11
9
  return schema;
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export * from "./fields/component";
7
7
  export * from "./fields/media";
8
8
  export * from "./fields/enumeration";
9
9
  export * from "./fields/richText";
10
+ export * from "./fields/boolean";
package/dist/index.js CHANGED
@@ -7,3 +7,4 @@ export * from "./fields/component";
7
7
  export * from "./fields/media";
8
8
  export * from "./fields/enumeration";
9
9
  export * from "./fields/richText";
10
+ export * from "./fields/boolean";
@@ -1,11 +1,13 @@
1
+ import { booleanSchema } from "../fields/boolean";
1
2
  import { dynamicSchema } from "../fields/dynamic";
3
+ import { enumerationSchema } from "../fields/enumeration";
2
4
  import { mediaSingleSchema } from "../fields/media";
3
5
  import { numberSchema } from "../fields/number";
4
6
  import { repeatableSchema, singleSchema } from "../fields/component";
7
+ import { richTextBlocksSchema } from "../fields/richText";
5
8
  import { textSchema } from "../fields/text";
6
9
  import z from "zod";
7
- import { enumerationSchema } from "../fields/enumeration";
8
- import { richTextBlocksSchema } from "../fields/richText";
10
+ import { jsonSchema } from "../fields/json";
9
11
  export const defaultStrapiFields = {
10
12
  id: z.number(),
11
13
  documentId: z.string().optional(),
@@ -28,6 +30,16 @@ export const schemaToParser = (schema) => {
28
30
  shape[key] = numberSchema(args);
29
31
  break;
30
32
  }
33
+ case "json": {
34
+ const [, args] = field;
35
+ shape[key] = jsonSchema(args);
36
+ break;
37
+ }
38
+ case "boolean": {
39
+ const [, args] = field;
40
+ shape[key] = booleanSchema(args);
41
+ break;
42
+ }
31
43
  case "dynamic": {
32
44
  const [, ...args] = field;
33
45
  shape[key] = dynamicSchema(...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-strapi",
3
- "version": "1.0.0-alpha.16",
3
+ "version": "1.0.0-alpha.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",