meta-to-blocks 0.1.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/LICENSE +21 -0
- package/README.md +89 -0
- package/convert.d.ts +19 -0
- package/convert.js +196 -0
- package/esm/convert.js +190 -0
- package/esm/index.js +4 -0
- package/esm/naming.js +19 -0
- package/esm/schema.js +239 -0
- package/esm/types.js +10 -0
- package/index.d.ts +4 -0
- package/index.js +20 -0
- package/naming.d.ts +8 -0
- package/naming.js +22 -0
- package/package.json +52 -0
- package/schema.d.ts +32 -0
- package/schema.js +247 -0
- package/types.d.ts +157 -0
- package/types.js +11 -0
package/types.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural types for the slice of Constructive's `_meta` contract this
|
|
3
|
+
* package reads.
|
|
4
|
+
*
|
|
5
|
+
* These mirror `@constructive-io/data`'s `Metaschema*` types but are declared
|
|
6
|
+
* locally and permissively (nullable, optional) so a `_meta` payload from that
|
|
7
|
+
* package — or from a raw GraphQL response — is assignable without this package
|
|
8
|
+
* depending on a GraphQL client.
|
|
9
|
+
*/
|
|
10
|
+
import type { UINodeType } from 'blocks-schema';
|
|
11
|
+
import type { JSONSchema, WidgetRule } from 'json-schema-to-blocks';
|
|
12
|
+
export interface MetaEnum {
|
|
13
|
+
name?: string | null;
|
|
14
|
+
values?: readonly (string | null)[] | null;
|
|
15
|
+
}
|
|
16
|
+
export interface MetaEncoding {
|
|
17
|
+
kind?: string | null;
|
|
18
|
+
elementType?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface MetaType {
|
|
21
|
+
gqlType?: string | null;
|
|
22
|
+
pgType?: string | null;
|
|
23
|
+
isArray?: boolean | null;
|
|
24
|
+
subtype?: string | null;
|
|
25
|
+
encoding?: MetaEncoding | null;
|
|
26
|
+
}
|
|
27
|
+
export interface MetaField {
|
|
28
|
+
name: string;
|
|
29
|
+
type?: MetaType | null;
|
|
30
|
+
isNotNull?: boolean | null;
|
|
31
|
+
hasDefault?: boolean | null;
|
|
32
|
+
isPrimaryKey?: boolean | null;
|
|
33
|
+
isForeignKey?: boolean | null;
|
|
34
|
+
description?: string | null;
|
|
35
|
+
enumValues?: MetaEnum | null;
|
|
36
|
+
}
|
|
37
|
+
export interface MetaTableRef {
|
|
38
|
+
name?: string | null;
|
|
39
|
+
}
|
|
40
|
+
export interface MetaForeignKey {
|
|
41
|
+
name?: string | null;
|
|
42
|
+
fields?: readonly (MetaField | null)[] | null;
|
|
43
|
+
referencedTable?: string | null;
|
|
44
|
+
referencedFields?: readonly (string | null)[] | null;
|
|
45
|
+
refTable?: MetaTableRef | null;
|
|
46
|
+
refFields?: readonly (MetaField | null)[] | null;
|
|
47
|
+
}
|
|
48
|
+
export interface MetaHasRelation {
|
|
49
|
+
fieldName?: string | null;
|
|
50
|
+
isUnique?: boolean | null;
|
|
51
|
+
referencedBy?: MetaTableRef | null;
|
|
52
|
+
keys?: readonly (MetaField | null)[] | null;
|
|
53
|
+
}
|
|
54
|
+
export interface MetaManyToManyRelation {
|
|
55
|
+
fieldName?: string | null;
|
|
56
|
+
rightTable?: MetaTableRef | null;
|
|
57
|
+
junctionTable?: MetaTableRef | null;
|
|
58
|
+
}
|
|
59
|
+
export interface MetaRelations {
|
|
60
|
+
belongsTo?: readonly unknown[] | null;
|
|
61
|
+
hasOne?: readonly (MetaHasRelation | null)[] | null;
|
|
62
|
+
hasMany?: readonly (MetaHasRelation | null)[] | null;
|
|
63
|
+
manyToMany?: readonly (MetaManyToManyRelation | null)[] | null;
|
|
64
|
+
}
|
|
65
|
+
export interface MetaTableQuery {
|
|
66
|
+
all?: string | null;
|
|
67
|
+
one?: string | null;
|
|
68
|
+
create?: string | null;
|
|
69
|
+
update?: string | null;
|
|
70
|
+
delete?: string | null;
|
|
71
|
+
}
|
|
72
|
+
export interface MetaConstraints {
|
|
73
|
+
primaryKey?: {
|
|
74
|
+
fields?: readonly (MetaField | null)[] | null;
|
|
75
|
+
} | null;
|
|
76
|
+
foreignKey?: readonly (MetaForeignKey | null)[] | null;
|
|
77
|
+
}
|
|
78
|
+
/** The `_meta` table shape this package lowers. */
|
|
79
|
+
export interface MetaTable {
|
|
80
|
+
name: string;
|
|
81
|
+
schemaName?: string | null;
|
|
82
|
+
description?: string | null;
|
|
83
|
+
fields?: readonly (MetaField | null)[] | null;
|
|
84
|
+
query?: MetaTableQuery | null;
|
|
85
|
+
relations?: MetaRelations | null;
|
|
86
|
+
constraints?: MetaConstraints | readonly unknown[] | null;
|
|
87
|
+
foreignKeyConstraints?: readonly (MetaForeignKey | null)[] | null;
|
|
88
|
+
primaryKeyConstraints?: readonly ({
|
|
89
|
+
fields?: readonly (MetaField | null)[] | null;
|
|
90
|
+
} | null)[] | null;
|
|
91
|
+
storage?: {
|
|
92
|
+
isFilesTable?: boolean | null;
|
|
93
|
+
isBucketsTable?: boolean | null;
|
|
94
|
+
} | null;
|
|
95
|
+
i18n?: {
|
|
96
|
+
translatableFields?: readonly ({
|
|
97
|
+
name: string;
|
|
98
|
+
} | null)[] | null;
|
|
99
|
+
} | null;
|
|
100
|
+
}
|
|
101
|
+
/** How a field is presented, overriding what the column type implies. */
|
|
102
|
+
export interface FieldOverride {
|
|
103
|
+
widget?: UINodeType;
|
|
104
|
+
label?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
placeholder?: string;
|
|
107
|
+
hidden?: boolean;
|
|
108
|
+
disabled?: boolean;
|
|
109
|
+
order?: number;
|
|
110
|
+
props?: Record<string, unknown>;
|
|
111
|
+
/** Drop the field from the generated document entirely. */
|
|
112
|
+
omit?: boolean;
|
|
113
|
+
}
|
|
114
|
+
export interface MetaOptions {
|
|
115
|
+
/** Document id; defaults to `<table>-<kind>`. */
|
|
116
|
+
id?: string;
|
|
117
|
+
/** Screen title; defaults to the titleized table name. */
|
|
118
|
+
title?: string;
|
|
119
|
+
/** Widget rules tried before `json-schema-to-blocks`' defaults. */
|
|
120
|
+
rules?: WidgetRule[];
|
|
121
|
+
replaceDefaultRules?: boolean;
|
|
122
|
+
/** Per-column presentation overrides, keyed by column name. */
|
|
123
|
+
fields?: Record<string, FieldOverride>;
|
|
124
|
+
/** Columns to leave out. */
|
|
125
|
+
omitFields?: readonly string[];
|
|
126
|
+
/**
|
|
127
|
+
* Emit primary keys, defaulted columns and audit columns too. Off for forms
|
|
128
|
+
* (the database fills them), on for list and detail screens.
|
|
129
|
+
*/
|
|
130
|
+
includeSystemFields?: boolean;
|
|
131
|
+
/** Explicit column order; unlisted columns keep their `_meta` order after these. */
|
|
132
|
+
fieldOrder?: readonly string[];
|
|
133
|
+
}
|
|
134
|
+
export interface FormOptions extends MetaOptions {
|
|
135
|
+
/** Wrap the fields in a `Form` node. Default `true`. */
|
|
136
|
+
form?: boolean;
|
|
137
|
+
submitLabel?: string;
|
|
138
|
+
rootKey?: string;
|
|
139
|
+
/** `create` omits system fields, `update` disables the primary key. Default `create`. */
|
|
140
|
+
mode?: 'create' | 'update';
|
|
141
|
+
}
|
|
142
|
+
export interface ListOptions extends MetaOptions {
|
|
143
|
+
/** Columns to show; defaults to the lowerable columns, capped by `maxColumns`. */
|
|
144
|
+
columns?: readonly string[];
|
|
145
|
+
maxColumns?: number;
|
|
146
|
+
rootKey?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface DetailOptions extends MetaOptions {
|
|
149
|
+
/** Emit a `RelationList` per `hasMany`/`manyToMany` relation. Default `true`. */
|
|
150
|
+
relations?: boolean;
|
|
151
|
+
rootKey?: string;
|
|
152
|
+
}
|
|
153
|
+
/** A column lowered to a JSON Schema fragment, keyed by its column name. */
|
|
154
|
+
export interface LoweredField {
|
|
155
|
+
name: string;
|
|
156
|
+
schema: JSONSchema;
|
|
157
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Structural types for the slice of Constructive's `_meta` contract this
|
|
4
|
+
* package reads.
|
|
5
|
+
*
|
|
6
|
+
* These mirror `@constructive-io/data`'s `Metaschema*` types but are declared
|
|
7
|
+
* locally and permissively (nullable, optional) so a `_meta` payload from that
|
|
8
|
+
* package — or from a raw GraphQL response — is assignable without this package
|
|
9
|
+
* depending on a GraphQL client.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|