@yrest/cli 0.9.0 → 0.11.0

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.mts CHANGED
@@ -4,6 +4,48 @@ import * as http from 'http';
4
4
 
5
5
  /** A single REST resource item. Field names and value types are user-defined in the YAML file. */
6
6
  type Resource = Record<string, unknown>;
7
+ /**
8
+ * Descriptor for a single field declared in the `_schema` block.
9
+ *
10
+ * All properties are optional — omit what you don't need. Fields not mentioned
11
+ * in `_schema` are inferred from the collection data and treated as optional.
12
+ *
13
+ * Shorthand: `fieldName: required` normalises to `{ required: true }`.
14
+ */
15
+ type FieldDef = {
16
+ /** If `true`, the field is listed in the OpenAPI `required` array and (Phase B) validated on POST/PUT. */
17
+ required?: boolean;
18
+ /** Explicit type override. If absent, inferred from the data. */
19
+ type?: "string" | "integer" | "number" | "boolean" | "object" | "array";
20
+ /** OpenAPI `format` hint (e.g. `email`, `date`, `uuid`, `uri`, `date-time`). */
21
+ format?: string;
22
+ /** Restricts the field to a fixed set of values. */
23
+ enum?: unknown[];
24
+ /** Human-readable description included in the OpenAPI spec. */
25
+ description?: string;
26
+ /** Default value included in the OpenAPI spec. */
27
+ default?: unknown;
28
+ };
29
+ /**
30
+ * Field-level schema declarations for one or more collections, parsed from `_schema` in the YAML.
31
+ *
32
+ * - Outer key: collection name.
33
+ * - Inner key: field name within that collection.
34
+ * - Value: {@link FieldDef} descriptor (or the string shorthand `"required"` / `"optional"`).
35
+ *
36
+ * @example
37
+ * ```yaml
38
+ * _schema:
39
+ * users:
40
+ * name: required # shorthand
41
+ * email:
42
+ * required: true
43
+ * format: email
44
+ * age:
45
+ * type: integer
46
+ * ```
47
+ */
48
+ type SchemaBlock = Record<string, Record<string, FieldDef>>;
7
49
  /**
8
50
  * The full in-memory database.
9
51
  * Keys are collection names (e.g. `"users"`); values are arrays of {@link Resource} items.
@@ -38,11 +80,17 @@ type Data = Record<string, Resource[]>;
38
80
  type RelationDef = {
39
81
  type: "many2one";
40
82
  target: string;
83
+ foreignKey?: string;
41
84
  nested?: boolean;
85
+ carDirect?: string;
86
+ carInverse?: string;
42
87
  } | {
43
88
  type: "one2one";
44
89
  target: string;
90
+ foreignKey?: string;
45
91
  nested?: boolean;
92
+ carDirect?: string;
93
+ carInverse?: string;
46
94
  } | {
47
95
  type: "many2many";
48
96
  target: string;
@@ -50,6 +98,8 @@ type RelationDef = {
50
98
  foreignKey: string;
51
99
  otherKey: string;
52
100
  nested?: boolean;
101
+ carDirect?: string;
102
+ carInverse?: string;
53
103
  };
54
104
  /**
55
105
  * Relational mappings declared under `_rel` in the YAML file, normalised to {@link RelationDef}.
@@ -180,6 +230,8 @@ interface YrestStorage {
180
230
  getData(): Data;
181
231
  /** Returns the relational mappings declared under `_rel`. */
182
232
  getRelations(): Relations;
233
+ /** Returns the field-level schema declarations from `_schema`, or `{}` if absent. */
234
+ getSchema(): SchemaBlock;
183
235
  /**
184
236
  * Returns the items in a named collection, or `undefined` if it does not exist.
185
237
  *
@@ -481,16 +533,6 @@ type YrestServerOptions = YrestServerBaseOptions & ({
481
533
  */
482
534
  declare function createYrestServer(options: YrestServerOptions): YrestServer;
483
535
 
484
- /**
485
- * Creates a {@link YrestStorage} instance backed by the given YAML file.
486
- *
487
- * The file is read and parsed eagerly on construction. The `_rel` key is
488
- * extracted as relational metadata; `_routes` as custom route declarations;
489
- * all other top-level keys become collections.
490
- *
491
- * @param filePath - Relative or absolute path to the YAML database file.
492
- * @throws {Error} If the file cannot be read or its YAML is invalid.
493
- */
494
536
  declare function createYrestStorage(filePath: string): YrestStorage;
495
537
 
496
538
  export { type CustomRoute, type Data, type Handler, type HandlerMap, type HandlerRequest, type HandlerResponse, type Relations, type Resource, type YrestOptions, type YrestServer, type YrestServerBaseOptions, type YrestServerOptions, type YrestStorage, createServer, createYrestServer, createYrestServerFromStorage, createYrestStorage, yrest, yrestOptionsSchema };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,48 @@ import * as http from 'http';
4
4
 
5
5
  /** A single REST resource item. Field names and value types are user-defined in the YAML file. */
6
6
  type Resource = Record<string, unknown>;
7
+ /**
8
+ * Descriptor for a single field declared in the `_schema` block.
9
+ *
10
+ * All properties are optional — omit what you don't need. Fields not mentioned
11
+ * in `_schema` are inferred from the collection data and treated as optional.
12
+ *
13
+ * Shorthand: `fieldName: required` normalises to `{ required: true }`.
14
+ */
15
+ type FieldDef = {
16
+ /** If `true`, the field is listed in the OpenAPI `required` array and (Phase B) validated on POST/PUT. */
17
+ required?: boolean;
18
+ /** Explicit type override. If absent, inferred from the data. */
19
+ type?: "string" | "integer" | "number" | "boolean" | "object" | "array";
20
+ /** OpenAPI `format` hint (e.g. `email`, `date`, `uuid`, `uri`, `date-time`). */
21
+ format?: string;
22
+ /** Restricts the field to a fixed set of values. */
23
+ enum?: unknown[];
24
+ /** Human-readable description included in the OpenAPI spec. */
25
+ description?: string;
26
+ /** Default value included in the OpenAPI spec. */
27
+ default?: unknown;
28
+ };
29
+ /**
30
+ * Field-level schema declarations for one or more collections, parsed from `_schema` in the YAML.
31
+ *
32
+ * - Outer key: collection name.
33
+ * - Inner key: field name within that collection.
34
+ * - Value: {@link FieldDef} descriptor (or the string shorthand `"required"` / `"optional"`).
35
+ *
36
+ * @example
37
+ * ```yaml
38
+ * _schema:
39
+ * users:
40
+ * name: required # shorthand
41
+ * email:
42
+ * required: true
43
+ * format: email
44
+ * age:
45
+ * type: integer
46
+ * ```
47
+ */
48
+ type SchemaBlock = Record<string, Record<string, FieldDef>>;
7
49
  /**
8
50
  * The full in-memory database.
9
51
  * Keys are collection names (e.g. `"users"`); values are arrays of {@link Resource} items.
@@ -38,11 +80,17 @@ type Data = Record<string, Resource[]>;
38
80
  type RelationDef = {
39
81
  type: "many2one";
40
82
  target: string;
83
+ foreignKey?: string;
41
84
  nested?: boolean;
85
+ carDirect?: string;
86
+ carInverse?: string;
42
87
  } | {
43
88
  type: "one2one";
44
89
  target: string;
90
+ foreignKey?: string;
45
91
  nested?: boolean;
92
+ carDirect?: string;
93
+ carInverse?: string;
46
94
  } | {
47
95
  type: "many2many";
48
96
  target: string;
@@ -50,6 +98,8 @@ type RelationDef = {
50
98
  foreignKey: string;
51
99
  otherKey: string;
52
100
  nested?: boolean;
101
+ carDirect?: string;
102
+ carInverse?: string;
53
103
  };
54
104
  /**
55
105
  * Relational mappings declared under `_rel` in the YAML file, normalised to {@link RelationDef}.
@@ -180,6 +230,8 @@ interface YrestStorage {
180
230
  getData(): Data;
181
231
  /** Returns the relational mappings declared under `_rel`. */
182
232
  getRelations(): Relations;
233
+ /** Returns the field-level schema declarations from `_schema`, or `{}` if absent. */
234
+ getSchema(): SchemaBlock;
183
235
  /**
184
236
  * Returns the items in a named collection, or `undefined` if it does not exist.
185
237
  *
@@ -481,16 +533,6 @@ type YrestServerOptions = YrestServerBaseOptions & ({
481
533
  */
482
534
  declare function createYrestServer(options: YrestServerOptions): YrestServer;
483
535
 
484
- /**
485
- * Creates a {@link YrestStorage} instance backed by the given YAML file.
486
- *
487
- * The file is read and parsed eagerly on construction. The `_rel` key is
488
- * extracted as relational metadata; `_routes` as custom route declarations;
489
- * all other top-level keys become collections.
490
- *
491
- * @param filePath - Relative or absolute path to the YAML database file.
492
- * @throws {Error} If the file cannot be read or its YAML is invalid.
493
- */
494
536
  declare function createYrestStorage(filePath: string): YrestStorage;
495
537
 
496
538
  export { type CustomRoute, type Data, type Handler, type HandlerMap, type HandlerRequest, type HandlerResponse, type Relations, type Resource, type YrestOptions, type YrestServer, type YrestServerBaseOptions, type YrestServerOptions, type YrestStorage, createServer, createYrestServer, createYrestServerFromStorage, createYrestStorage, yrest, yrestOptionsSchema };