@stonecrop/schema 0.31.0 → 0.33.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/README.md +10 -10
- package/dist/cli.js +194 -121
- package/dist/cli.js.map +1 -1
- package/dist/converter-CLwduvT_.js +2102 -0
- package/dist/converter-CLwduvT_.js.map +1 -0
- package/dist/flatten-Bx2cfvw3.js +37 -0
- package/dist/flatten-Bx2cfvw3.js.map +1 -0
- package/dist/index.js +123 -117
- package/dist/index.js.map +1 -1
- package/dist/record-BQOOi83C.js +134 -0
- package/dist/record-BQOOi83C.js.map +1 -0
- package/dist/record.js +2 -6
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +34 -18
- package/dist/flatten-C1MjkzFh.js +0 -10
- package/dist/flatten-C1MjkzFh.js.map +0 -1
- package/dist/record-Bc0lI9Rq.js +0 -61
- package/dist/record-Bc0lI9Rq.js.map +0 -1
- package/dist/record.js.map +0 -1
- package/dist/schema.tsbuildinfo +0 -1
- package/dist/src/badge.d.ts +0 -74
- package/dist/src/badge.d.ts.map +0 -1
- package/dist/src/badge.js +0 -158
- package/dist/src/cli.d.ts +0 -3
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -292
- package/dist/src/column-schema.d.ts +0 -163
- package/dist/src/column-schema.d.ts.map +0 -1
- package/dist/src/column-schema.js +0 -0
- package/dist/src/component-meta.d.ts +0 -96
- package/dist/src/component-meta.d.ts.map +0 -1
- package/dist/src/component-meta.js +0 -88
- package/dist/src/converter/aggregate.d.ts +0 -127
- package/dist/src/converter/aggregate.d.ts.map +0 -1
- package/dist/src/converter/aggregate.js +0 -235
- package/dist/src/converter/authored.d.ts +0 -43
- package/dist/src/converter/authored.d.ts.map +0 -1
- package/dist/src/converter/authored.js +0 -52
- package/dist/src/converter/heuristics.d.ts +0 -60
- package/dist/src/converter/heuristics.d.ts.map +0 -1
- package/dist/src/converter/heuristics.js +0 -304
- package/dist/src/converter/index.d.ts +0 -51
- package/dist/src/converter/index.d.ts.map +0 -1
- package/dist/src/converter/index.js +0 -195
- package/dist/src/converter/merge.d.ts +0 -102
- package/dist/src/converter/merge.d.ts.map +0 -1
- package/dist/src/converter/merge.js +0 -136
- package/dist/src/converter/scalars.d.ts +0 -46
- package/dist/src/converter/scalars.d.ts.map +0 -1
- package/dist/src/converter/scalars.js +0 -83
- package/dist/src/converter/types.d.ts +0 -157
- package/dist/src/converter/types.d.ts.map +0 -1
- package/dist/src/converter/types.js +0 -5
- package/dist/src/doctype.d.ts +0 -516
- package/dist/src/doctype.d.ts.map +0 -1
- package/dist/src/doctype.js +0 -343
- package/dist/src/field.d.ts +0 -423
- package/dist/src/field.d.ts.map +0 -1
- package/dist/src/field.js +0 -378
- package/dist/src/flatten.d.ts +0 -29
- package/dist/src/flatten.d.ts.map +0 -1
- package/dist/src/flatten.js +0 -38
- package/dist/src/index.d.ts +0 -16
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -20
- package/dist/src/mode.d.ts +0 -15
- package/dist/src/mode.d.ts.map +0 -1
- package/dist/src/mode.js +0 -0
- package/dist/src/naming.d.ts +0 -80
- package/dist/src/naming.d.ts.map +0 -1
- package/dist/src/naming.js +0 -106
- package/dist/src/record.d.ts +0 -29
- package/dist/src/record.d.ts.map +0 -1
- package/dist/src/record.js +0 -55
- package/dist/src/table.d.ts +0 -33
- package/dist/src/table.d.ts.map +0 -1
- package/dist/src/table.js +0 -25
- package/dist/src/validation.d.ts +0 -54
- package/dist/src/validation.d.ts.map +0 -1
- package/dist/src/validation.js +0 -60
- package/dist/validation-C9P__pRF.js +0 -994
- package/dist/validation-C9P__pRF.js.map +0 -1
package/dist/record-Bc0lI9Rq.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { f as d } from "./flatten-C1MjkzFh.js";
|
|
2
|
-
const r = {
|
|
3
|
-
ATextInput: "text",
|
|
4
|
-
ATextboxInput: "text",
|
|
5
|
-
ANumericInput: "number",
|
|
6
|
-
ACheckbox: "boolean",
|
|
7
|
-
ADate: "date",
|
|
8
|
-
ADatePicker: "date",
|
|
9
|
-
ADateSelection: "date",
|
|
10
|
-
ADateTime: "datetime",
|
|
11
|
-
ADuration: "text",
|
|
12
|
-
ADateRange: "date",
|
|
13
|
-
ADropdown: "select",
|
|
14
|
-
ASegmentedControl: "select",
|
|
15
|
-
ACodeEditor: "code",
|
|
16
|
-
AFormLink: "link",
|
|
17
|
-
AFileAttach: "attach",
|
|
18
|
-
AQuantityInput: "quantity",
|
|
19
|
-
ACurrencyInput: "currency"
|
|
20
|
-
};
|
|
21
|
-
function A(e) {
|
|
22
|
-
return e ? r[e] : void 0;
|
|
23
|
-
}
|
|
24
|
-
const c = {
|
|
25
|
-
AFormLink: "inline",
|
|
26
|
-
AForm: "expand",
|
|
27
|
-
ATable: "expand"
|
|
28
|
-
};
|
|
29
|
-
function s(e) {
|
|
30
|
-
return e ? c[e] : void 0;
|
|
31
|
-
}
|
|
32
|
-
function f(e, n) {
|
|
33
|
-
return s(e.component ?? n) === "inline" ? "inline" : e.cardinality === "noneOrMany" || e.cardinality === "atLeastOne" ? "table" : "record";
|
|
34
|
-
}
|
|
35
|
-
const p = [
|
|
36
|
-
.../* @__PURE__ */ new Set([...Object.keys(r), ...Object.keys(c)])
|
|
37
|
-
].toSorted();
|
|
38
|
-
function m(e, n) {
|
|
39
|
-
const o = new Set(
|
|
40
|
-
d(e).filter((t) => t.kind === "field" && !!t.doctype).filter((t) => s(t.component) === "inline").map((t) => t.fieldname)
|
|
41
|
-
);
|
|
42
|
-
if (o.size === 0) return n;
|
|
43
|
-
const i = new Set(e.filter((t) => t.kind === "fieldset").map((t) => t.fieldname));
|
|
44
|
-
return u(o, i, n);
|
|
45
|
-
}
|
|
46
|
-
function u(e, n, o) {
|
|
47
|
-
const i = { ...o };
|
|
48
|
-
for (const [t, a] of Object.entries(i))
|
|
49
|
-
a === null || typeof a != "object" || Array.isArray(a) || (e.has(t) ? "id" in a && (i[t] = a.id) : n.has(t) && (i[t] = u(e, n, a)));
|
|
50
|
-
return i;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
p as C,
|
|
54
|
-
r as a,
|
|
55
|
-
c as b,
|
|
56
|
-
A as c,
|
|
57
|
-
s as d,
|
|
58
|
-
f as r,
|
|
59
|
-
m as u
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=record-Bc0lI9Rq.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"record-Bc0lI9Rq.js","sources":["../src/component-meta.ts","../src/record.ts"],"sourcesContent":["/**\n * Semantic category for a rendering component.\n *\n * `component` is the primary field axis, so the runtime consumers that need to know what a field\n * *means* (atable cell formatting / filter widgets, record-default init) derive it from here. This\n * is the single source of \"what kind of value does this component render\", keyed by the canonical\n * registered component names — each consumer maps the category to its own concern (filter widget,\n * default value, …).\n *\n * @public\n */\nexport type ComponentCategory =\n\t'text' | 'number' | 'boolean' | 'date' | 'datetime' | 'select' | 'code' | 'link' | 'attach' | 'quantity' | 'currency'\n\n/**\n * Canonical component → semantic category. Only the components Stonecrop ships with appear here;\n * custom/unknown component names have no category and consumers fall back to their default.\n * @public\n */\nexport const COMPONENT_CATEGORY: Record<string, ComponentCategory> = {\n\tATextInput: 'text',\n\tATextboxInput: 'text',\n\tANumericInput: 'number',\n\tACheckbox: 'boolean',\n\tADate: 'date',\n\tADatePicker: 'date',\n\tADateSelection: 'date',\n\tADateTime: 'datetime',\n\tADuration: 'text',\n\tADateRange: 'date',\n\tADropdown: 'select',\n\tASegmentedControl: 'select',\n\tACodeEditor: 'code',\n\tAFormLink: 'link',\n\tAFileAttach: 'attach',\n\tAQuantityInput: 'quantity',\n\tACurrencyInput: 'currency',\n}\n\n/**\n * Resolve a component's semantic category, or `undefined` for an unknown (custom) component —\n * callers treat that as \"no opinion\" and use their own default.\n * @public\n */\nexport function componentCategory(component?: string): ComponentCategory | undefined {\n\treturn component ? COMPONENT_CATEGORY[component] : undefined\n}\n\n/**\n * Whether a link component expands its target doctype, or renders the link inline.\n *\n * This is the *only* axis the component decides. It deliberately does not choose between an\n * embedded record and an embedded table: `cardinality` states whether the value is a scalar or\n * an array, which is a fact about the data rather than a rendering preference, so a component\n * must not be able to override it (an `AForm` over a `noneOrMany` link would be handed an array\n * it cannot render). Component names encode both axes — `AFormLink`/`ATableLink` are the inline\n * pair, `AForm`/`ATable` the expanding pair — but only the inline/expand half is authoritative.\n *\n * @public\n */\nexport type LinkExpansion = 'inline' | 'expand'\n\n/**\n * Canonical link component → expansion. Only components Stonecrop ships with appear here; an\n * unmapped (custom) component has none, and callers treat that as `expand` — the behaviour that\n * predates this map, so a custom component can never silently collapse a link to a picker.\n * @public\n */\nexport const COMPONENT_LINK_EXPANSION: Record<string, LinkExpansion> = {\n\tAFormLink: 'inline',\n\tAForm: 'expand',\n\tATable: 'expand',\n}\n\n/**\n * Resolve a component's link expansion, or `undefined` for an absent/unmapped component.\n * @public\n */\nexport function componentLinkExpansion(component?: string): LinkExpansion | undefined {\n\treturn component ? COMPONENT_LINK_EXPANSION[component] : undefined\n}\n\n/**\n * How a link field renders.\n *\n * - `inline` — a scalar id-picker; the target is *not* expanded (the field keeps its own value\n * and carries a `doctype` prop for async display-text resolution and navigation).\n * - `record` — the target doctype is resolved and embedded as a nested form.\n * - `table` — the target doctype is resolved and embedded as a child table.\n *\n * @public\n */\nexport type LinkRenderMode = 'inline' | 'record' | 'table'\n\n/**\n * Decide how a *declared* link (one with a `LinkDeclaration`) renders.\n *\n * Two independent axes: the **component** picks inline vs expand, and when expanding the\n * **cardinality** picks record vs table (many → table). The declaration's component wins over the\n * field's, matching the precedence the resolver already uses for the rendered component.\n *\n * This is the single definition of \"does this link expand\" — it is consumed by both the client\n * resolver (which builds the nested schema) and the server column builder (which must still\n * SELECT an `inline` link's FK column). Call it; never re-derive the rule at the call site, or\n * the two will drift and the client will render a table for a column the server never selected.\n *\n * @param link - the link declaration (only `component` and `cardinality` are consulted)\n * @param fieldComponent - the linked field's own `component`, used when the declaration names none\n * @public\n */\nexport function resolveLinkRenderMode(\n\tlink: { component?: string; cardinality?: string },\n\tfieldComponent?: string\n): LinkRenderMode {\n\tif (componentLinkExpansion(link.component ?? fieldComponent) === 'inline') return 'inline'\n\treturn link.cardinality === 'noneOrMany' || link.cardinality === 'atLeastOne' ? 'table' : 'record'\n}\n\n/**\n * Every component Stonecrop ships with that can render a value field, sorted by name.\n *\n * The union of the two maps above is the definition, not a copy of it: a shipped component either\n * categorises a value ({@link COMPONENT_CATEGORY}) or is one of the link containers that has no\n * value of its own ({@link COMPONENT_LINK_EXPANSION}'s `AForm`/`ATable`). `AFieldset` is absent by\n * the same rule — it is a `kind: 'fieldset'` container, so it is never a value field's component.\n *\n * `component` is an **open** axis: any string is valid, and naming a custom component is how an app\n * renders a field Stonecrop ships no widget for. This list is therefore the set to *suggest* to an\n * author, and to check first-party data against — never a set to validate arbitrary input against.\n *\n * @public\n */\nexport const CANONICAL_COMPONENTS: readonly string[] = [\n\t...new Set([...Object.keys(COMPONENT_CATEGORY), ...Object.keys(COMPONENT_LINK_EXPANSION)]),\n].toSorted()\n","import { componentLinkExpansion } from './component-meta'\nimport type { DoctypeField } from './field'\nimport { flattenFields } from './flatten'\n\n/**\n * Reduce a record's *inline* link values to the ids that get persisted.\n *\n * The adapter returns an inline link as `{ id, displayText }`, so that is what a record holds\n * everywhere it is read — the store, a list row, a form field. A column takes the id alone, so\n * this is the single definition of the shape a record leaves in, and it belongs at the boundary\n * a record crosses on its way to the server, never on the way into the store.\n *\n * Doing it on the way in destroys the text the adapter looked up: nothing else holds it, so the\n * field that resolved a moment ago renders its raw id, and the same record then renders\n * differently depending on whether anything had edited the form yet. That is the bug this exists\n * to prevent, and its damage is a wrong render, not a throw.\n *\n * Only *inline* links may be reduced. An inline link's value is indistinguishable by inspection\n * from an expanded one (`{ id, ...the whole target record }`), so `component` — which states\n * which of the two a field is — is what tells them apart, via {@link componentLinkExpansion}.\n * Reducing an expanded link would send the id in place of the record.\n *\n * Fieldsets are descended into in both shapes a record appears in: flat, as the store and the\n * server hold it, and nested under the fieldset's own key, as a form emits it.\n *\n * @param fields - the doctype's top-level fields\n * @param record - the record to reduce; not mutated\n * @returns a shallow copy with every inline link reduced to its id\n * @public\n */\nexport function unwrapInlineLinks(fields: readonly DoctypeField[], record: Record<string, any>): Record<string, any> {\n\tconst inline = new Set(\n\t\tflattenFields(fields)\n\t\t\t.filter(field => field.kind === 'field' && Boolean(field.doctype))\n\t\t\t.filter(field => componentLinkExpansion(field.component) === 'inline')\n\t\t\t.map(field => field.fieldname)\n\t)\n\tif (inline.size === 0) return record\n\n\tconst fieldsets = new Set(fields.filter(field => field.kind === 'fieldset').map(field => field.fieldname))\n\treturn unwrapWith(inline, fieldsets, record)\n}\n\nfunction unwrapWith(\n\tinline: ReadonlySet<string>,\n\tfieldsets: ReadonlySet<string>,\n\trecord: Record<string, any>\n): Record<string, any> {\n\tconst result: Record<string, any> = { ...record }\n\tfor (const [key, value] of Object.entries(result)) {\n\t\tif (value === null || typeof value !== 'object' || Array.isArray(value)) continue\n\t\tif (inline.has(key)) {\n\t\t\t// `'id' in value` rather than a truthiness test: an inline link that was never resolved\n\t\t\t// is still a bare scalar, and reducing it a second time would be a no-op at best.\n\t\t\tif ('id' in value) result[key] = value.id\n\t\t} else if (fieldsets.has(key)) {\n\t\t\tresult[key] = unwrapWith(inline, fieldsets, value)\n\t\t}\n\t}\n\treturn result\n}\n"],"names":["COMPONENT_CATEGORY","componentCategory","component","COMPONENT_LINK_EXPANSION","componentLinkExpansion","resolveLinkRenderMode","link","fieldComponent","CANONICAL_COMPONENTS","unwrapInlineLinks","fields","record","inline","flattenFields","field","fieldsets","unwrapWith","result","key","value"],"mappings":";AAmBO,MAAMA,IAAwD;AAAA,EACpE,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,eAAe;AAAA,EACf,WAAW;AAAA,EACX,OAAO;AAAA,EACP,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,gBAAgB;AACjB;AAOO,SAASC,EAAkBC,GAAmD;AACpF,SAAOA,IAAYF,EAAmBE,CAAS,IAAI;AACpD;AAsBO,MAAMC,IAA0D;AAAA,EACtE,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AACT;AAMO,SAASC,EAAuBF,GAA+C;AACrF,SAAOA,IAAYC,EAAyBD,CAAS,IAAI;AAC1D;AA8BO,SAASG,EACfC,GACAC,GACiB;AACjB,SAAIH,EAAuBE,EAAK,aAAaC,CAAc,MAAM,WAAiB,WAC3ED,EAAK,gBAAgB,gBAAgBA,EAAK,gBAAgB,eAAe,UAAU;AAC3F;AAgBO,MAAME,IAA0C;AAAA,EACtD,GAAG,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAKR,CAAkB,GAAG,GAAG,OAAO,KAAKG,CAAwB,CAAC,CAAC;AAC1F,EAAE,SAAA;ACxGK,SAASM,EAAkBC,GAAiCC,GAAkD;AACpH,QAAMC,IAAS,IAAI;AAAA,IAClBC,EAAcH,CAAM,EAClB,OAAO,CAAAI,MAASA,EAAM,SAAS,WAAW,EAAQA,EAAM,OAAQ,EAChE,OAAO,CAAAA,MAASV,EAAuBU,EAAM,SAAS,MAAM,QAAQ,EACpE,IAAI,CAAAA,MAASA,EAAM,SAAS;AAAA,EAAA;AAE/B,MAAIF,EAAO,SAAS,EAAG,QAAOD;AAE9B,QAAMI,IAAY,IAAI,IAAIL,EAAO,OAAO,CAAAI,MAASA,EAAM,SAAS,UAAU,EAAE,IAAI,CAAAA,MAASA,EAAM,SAAS,CAAC;AACzG,SAAOE,EAAWJ,GAAQG,GAAWJ,CAAM;AAC5C;AAEA,SAASK,EACRJ,GACAG,GACAJ,GACsB;AACtB,QAAMM,IAA8B,EAAE,GAAGN,EAAA;AACzC,aAAW,CAACO,GAAKC,CAAK,KAAK,OAAO,QAAQF,CAAM;AAC/C,IAAIE,MAAU,QAAQ,OAAOA,KAAU,YAAY,MAAM,QAAQA,CAAK,MAClEP,EAAO,IAAIM,CAAG,IAGb,QAAQC,MAAOF,EAAOC,CAAG,IAAIC,EAAM,MAC7BJ,EAAU,IAAIG,CAAG,MAC3BD,EAAOC,CAAG,IAAIF,EAAWJ,GAAQG,GAAWI,CAAK;AAGnD,SAAOF;AACR;"}
|
package/dist/record.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/schema.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"6.0.3"}
|
package/dist/src/badge.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { FieldOptions } from './field';
|
|
2
|
-
/**
|
|
3
|
-
* Semantic badge variant. Maps to theme tokens `--sc-badge-{variant}-*`.
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export type BadgeVariant = 'neutral' | 'success' | 'warning' | 'danger' | 'brand';
|
|
7
|
-
/**
|
|
8
|
-
* Where ABadge paints the same descriptor.
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export type BadgePresentation = 'cell-fill' | 'input-accent';
|
|
12
|
-
/**
|
|
13
|
-
* Per-choice badge configuration in a Select options map.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export interface BadgeSpecObject {
|
|
17
|
-
variant?: BadgeVariant;
|
|
18
|
-
color?: string;
|
|
19
|
-
label?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Value in a choice→badge map: shorthand variant or object form.
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
export type BadgeSpec = BadgeVariant | BadgeSpecObject;
|
|
26
|
-
/**
|
|
27
|
-
* Select field options when choices carry badge colors.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export interface SelectOptions extends Record<string, unknown> {
|
|
31
|
-
choices: string[];
|
|
32
|
-
badges?: Record<string, BadgeSpec>;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Resolved badge for rendering. Returned by `format` or built from an options map.
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export interface BadgeDescriptor {
|
|
39
|
-
label: string;
|
|
40
|
-
variant?: BadgeVariant;
|
|
41
|
-
color?: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* True when `value` is a resolved badge descriptor for ACell / ADropdown.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export declare function isBadgeDescriptor(value: unknown): value is BadgeDescriptor;
|
|
48
|
-
/**
|
|
49
|
-
* True when `options` is a Select choice map (`{ Open: "warning", ... }` or
|
|
50
|
-
* `{ choices: [...], badges: {...} }`), not a quantity/currency/code config bag.
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
export declare function isSelectChoiceMap(options: FieldOptions | undefined): options is Record<string, BadgeSpec>;
|
|
54
|
-
/**
|
|
55
|
-
* True when `options` uses the structured SelectOptions shape.
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export declare function isSelectOptions(options: FieldOptions | undefined): options is SelectOptions;
|
|
59
|
-
/**
|
|
60
|
-
* Dropdown / filter choice strings.
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
export declare function selectChoices(options: FieldOptions | undefined): string[];
|
|
64
|
-
/**
|
|
65
|
-
* Resolve a stored choice value to a badge descriptor using field options.
|
|
66
|
-
* @public
|
|
67
|
-
*/
|
|
68
|
-
export declare function lookupBadge(options: FieldOptions | undefined, key: string | undefined): BadgeDescriptor | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Whether field options carry any badge mapping.
|
|
71
|
-
* @public
|
|
72
|
-
*/
|
|
73
|
-
export declare function hasBadgeOptions(options: FieldOptions | undefined): boolean;
|
|
74
|
-
//# sourceMappingURL=badge.d.ts.map
|
package/dist/src/badge.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../../src/badge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEjF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,cAAc,CAAA;AAE5D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,eAAe,CAAA;AAEtD;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAsCD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAS1E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAUzG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,IAAI,aAAa,CAG3F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,EAAE,CAOzE;AAgCD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,CAOnH;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,OAAO,CAK1E"}
|
package/dist/src/badge.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
const BADGE_VARIANTS = new Set(['neutral', 'success', 'warning', 'danger', 'brand']);
|
|
2
|
-
const BADGE_SPEC_OBJECT_KEYS = new Set(['variant', 'color', 'label']);
|
|
3
|
-
function isOptionsRecord(options) {
|
|
4
|
-
return !Array.isArray(options);
|
|
5
|
-
}
|
|
6
|
-
function isBadgeVariant(value) {
|
|
7
|
-
return typeof value === 'string' && BADGE_VARIANTS.has(value);
|
|
8
|
-
}
|
|
9
|
-
function isBadgeSpecObject(value) {
|
|
10
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
11
|
-
return false;
|
|
12
|
-
for (const key of Object.keys(value)) {
|
|
13
|
-
if (!BADGE_SPEC_OBJECT_KEYS.has(key))
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const obj = value;
|
|
17
|
-
if (obj.variant !== undefined && !isBadgeVariant(obj.variant))
|
|
18
|
-
return false;
|
|
19
|
-
if (obj.color !== undefined && typeof obj.color !== 'string')
|
|
20
|
-
return false;
|
|
21
|
-
if (obj.label !== undefined && typeof obj.label !== 'string')
|
|
22
|
-
return false;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
function isBadgeSpec(value) {
|
|
26
|
-
return isBadgeVariant(value) || isBadgeSpecObject(value);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Narrows an options record to the structured `{ choices, badges }` form. A type predicate rather
|
|
30
|
-
* than a cast: `SelectOptions` requires `choices`, so asserting into it trips `no-unsafe-type-assertion`.
|
|
31
|
-
*/
|
|
32
|
-
function isStructuredSelectOptions(options) {
|
|
33
|
-
return Array.isArray(options.choices);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* True when `value` is a resolved badge descriptor for ACell / ADropdown.
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export function isBadgeDescriptor(value) {
|
|
40
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
41
|
-
return false;
|
|
42
|
-
// Partial<> keeps this a widening assertion; asserting into BadgeDescriptor itself (required
|
|
43
|
-
// `label`) narrows, which `no-unsafe-type-assertion` rejects.
|
|
44
|
-
const obj = value;
|
|
45
|
-
if (typeof obj.label !== 'string')
|
|
46
|
-
return false;
|
|
47
|
-
if (obj.variant !== undefined && !isBadgeVariant(obj.variant))
|
|
48
|
-
return false;
|
|
49
|
-
if (obj.color !== undefined && typeof obj.color !== 'string')
|
|
50
|
-
return false;
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* True when `options` is a Select choice map (`{ Open: "warning", ... }` or
|
|
55
|
-
* `{ choices: [...], badges: {...} }`), not a quantity/currency/code config bag.
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export function isSelectChoiceMap(options) {
|
|
59
|
-
if (options === undefined || Array.isArray(options) || !isOptionsRecord(options))
|
|
60
|
-
return false;
|
|
61
|
-
if (isStructuredSelectOptions(options)) {
|
|
62
|
-
const badges = options.badges;
|
|
63
|
-
if (badges === undefined)
|
|
64
|
-
return false;
|
|
65
|
-
return Object.values(badges).every(isBadgeSpec);
|
|
66
|
-
}
|
|
67
|
-
const entries = Object.entries(options);
|
|
68
|
-
if (entries.length === 0)
|
|
69
|
-
return false;
|
|
70
|
-
return entries.every(([, value]) => isBadgeSpec(value));
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* True when `options` uses the structured SelectOptions shape.
|
|
74
|
-
* @public
|
|
75
|
-
*/
|
|
76
|
-
export function isSelectOptions(options) {
|
|
77
|
-
if (options === undefined || Array.isArray(options) || !isOptionsRecord(options))
|
|
78
|
-
return false;
|
|
79
|
-
return isStructuredSelectOptions(options);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Dropdown / filter choice strings.
|
|
83
|
-
* @public
|
|
84
|
-
*/
|
|
85
|
-
export function selectChoices(options) {
|
|
86
|
-
if (options === undefined)
|
|
87
|
-
return [];
|
|
88
|
-
if (Array.isArray(options))
|
|
89
|
-
return options;
|
|
90
|
-
if (!isOptionsRecord(options))
|
|
91
|
-
return [];
|
|
92
|
-
if (isStructuredSelectOptions(options))
|
|
93
|
-
return options.choices;
|
|
94
|
-
if (isSelectChoiceMap(options))
|
|
95
|
-
return Object.keys(options);
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
function normalizeBadgeSpec(spec, key) {
|
|
99
|
-
if (isBadgeVariant(spec)) {
|
|
100
|
-
return { label: key, variant: spec };
|
|
101
|
-
}
|
|
102
|
-
// A malformed spec still names a real choice, so keep the label and drop only the styling.
|
|
103
|
-
// Reading `.variant`/`.color` off an unvalidated value is what let a misspelt variant reach the
|
|
104
|
-
// DOM as an unmatched class, and threw outright on null.
|
|
105
|
-
if (!isBadgeSpecObject(spec)) {
|
|
106
|
-
return { label: key };
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
label: spec.label ?? key,
|
|
110
|
-
variant: spec.variant,
|
|
111
|
-
color: spec.color,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function lookupFromBareMap(map, key) {
|
|
115
|
-
if (key === undefined || key === '')
|
|
116
|
-
return undefined;
|
|
117
|
-
if (!(key in map))
|
|
118
|
-
return undefined;
|
|
119
|
-
return normalizeBadgeSpec(map[key], key);
|
|
120
|
-
}
|
|
121
|
-
function lookupFromStructured(options, key) {
|
|
122
|
-
if (key === undefined || key === '')
|
|
123
|
-
return undefined;
|
|
124
|
-
const badges = options.badges;
|
|
125
|
-
if (!badges || !(key in badges))
|
|
126
|
-
return undefined;
|
|
127
|
-
return normalizeBadgeSpec(badges[key], key);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Resolve a stored choice value to a badge descriptor using field options.
|
|
131
|
-
* @public
|
|
132
|
-
*/
|
|
133
|
-
export function lookupBadge(options, key) {
|
|
134
|
-
if (options === undefined || key === undefined || key === '')
|
|
135
|
-
return undefined;
|
|
136
|
-
if (Array.isArray(options))
|
|
137
|
-
return undefined;
|
|
138
|
-
if (!isOptionsRecord(options))
|
|
139
|
-
return undefined;
|
|
140
|
-
if (isStructuredSelectOptions(options))
|
|
141
|
-
return lookupFromStructured(options, key);
|
|
142
|
-
if (isSelectChoiceMap(options))
|
|
143
|
-
return lookupFromBareMap(options, key);
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Whether field options carry any badge mapping.
|
|
148
|
-
* @public
|
|
149
|
-
*/
|
|
150
|
-
export function hasBadgeOptions(options) {
|
|
151
|
-
if (options === undefined || Array.isArray(options))
|
|
152
|
-
return false;
|
|
153
|
-
if (!isOptionsRecord(options))
|
|
154
|
-
return false;
|
|
155
|
-
if (isStructuredSelectOptions(options))
|
|
156
|
-
return options.badges !== undefined && Object.keys(options.badges).length > 0;
|
|
157
|
-
return isSelectChoiceMap(options);
|
|
158
|
-
}
|
package/dist/src/cli.d.ts
DELETED
package/dist/src/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/src/cli.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* oxlint-disable no-console */
|
|
3
|
-
/**
|
|
4
|
-
* Stonecrop Schema CLI
|
|
5
|
-
*
|
|
6
|
-
* Converts GraphQL introspection results to Stonecrop doctype JSON schemas.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* stonecrop-schema generate --endpoint <url> --output <dir>
|
|
10
|
-
* stonecrop-schema generate --introspection <file.json> --output <dir>
|
|
11
|
-
* stonecrop-schema generate --sdl <file.graphql> --output <dir>
|
|
12
|
-
*
|
|
13
|
-
* @packageDocumentation
|
|
14
|
-
*/
|
|
15
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
16
|
-
import { resolve, join } from 'node:path';
|
|
17
|
-
import { parseArgs } from 'node:util';
|
|
18
|
-
import { getIntrospectionQuery } from 'graphql';
|
|
19
|
-
import { authoredPrimaryKey } from './converter/authored';
|
|
20
|
-
import { convertGraphQLSchema, formatDoctypeDrift, mergeIntrospectedDoctype, planGeneration } from './converter/index';
|
|
21
|
-
import { stripFieldKind } from './field';
|
|
22
|
-
import { validateDoctype } from './validation';
|
|
23
|
-
/**
|
|
24
|
-
* Fetch an introspection result from a live GraphQL endpoint.
|
|
25
|
-
*
|
|
26
|
-
* @param endpoint - The GraphQL endpoint URL
|
|
27
|
-
* @param headers - Optional HTTP headers
|
|
28
|
-
* @returns The introspection query result
|
|
29
|
-
*/
|
|
30
|
-
async function fetchIntrospection(endpoint, headers) {
|
|
31
|
-
const response = await fetch(endpoint, {
|
|
32
|
-
method: 'POST',
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': 'application/json',
|
|
35
|
-
...headers,
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify({
|
|
38
|
-
query: getIntrospectionQuery(),
|
|
39
|
-
}),
|
|
40
|
-
});
|
|
41
|
-
if (!response.ok) {
|
|
42
|
-
throw new Error(`Failed to fetch introspection: ${response.status} ${response.statusText}`);
|
|
43
|
-
}
|
|
44
|
-
const json = await response.json();
|
|
45
|
-
if (json.errors?.length) {
|
|
46
|
-
throw new Error(`GraphQL errors: ${json.errors.map(e => e.message).join(', ')}`);
|
|
47
|
-
}
|
|
48
|
-
if (!json.data) {
|
|
49
|
-
throw new Error('No data in introspection response');
|
|
50
|
-
}
|
|
51
|
-
return json.data;
|
|
52
|
-
}
|
|
53
|
-
async function main() {
|
|
54
|
-
const { values, positionals } = parseArgs({
|
|
55
|
-
allowPositionals: true,
|
|
56
|
-
options: {
|
|
57
|
-
endpoint: { type: 'string', short: 'e' },
|
|
58
|
-
introspection: { type: 'string', short: 'i' },
|
|
59
|
-
sdl: { type: 'string', short: 's' },
|
|
60
|
-
output: { type: 'string', short: 'o' },
|
|
61
|
-
include: { type: 'string' },
|
|
62
|
-
exclude: { type: 'string' },
|
|
63
|
-
names: { type: 'string' },
|
|
64
|
-
'custom-scalars': { type: 'string' },
|
|
65
|
-
'include-unmapped': { type: 'boolean', default: false },
|
|
66
|
-
'no-aggregates': { type: 'boolean', default: false },
|
|
67
|
-
check: { type: 'boolean', default: false },
|
|
68
|
-
help: { type: 'boolean', short: 'h' },
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const command = positionals[0];
|
|
72
|
-
if (values.help || !command) {
|
|
73
|
-
printHelp();
|
|
74
|
-
process.exit(command ? 0 : 1);
|
|
75
|
-
}
|
|
76
|
-
if (command !== 'generate') {
|
|
77
|
-
console.error(`Unknown command: ${command}`);
|
|
78
|
-
console.error('Available commands: generate');
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
// Determine source
|
|
82
|
-
const sourceCount = [values.endpoint, values.introspection, values.sdl].filter(Boolean).length;
|
|
83
|
-
if (sourceCount !== 1) {
|
|
84
|
-
console.error('Exactly one of --endpoint, --introspection, or --sdl must be provided');
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
if (!values.output) {
|
|
88
|
-
console.error('--output <dir> is required');
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
const outputDir = resolve(values.output);
|
|
92
|
-
// Build conversion options
|
|
93
|
-
const options = {
|
|
94
|
-
includeUnmappedMeta: values['include-unmapped'],
|
|
95
|
-
};
|
|
96
|
-
if (values.include) {
|
|
97
|
-
options.include = values.include.split(',').map(s => s.trim());
|
|
98
|
-
}
|
|
99
|
-
if (values.exclude) {
|
|
100
|
-
options.exclude = values.exclude.split(',').map(s => s.trim());
|
|
101
|
-
}
|
|
102
|
-
if (values.names) {
|
|
103
|
-
const namesPath = resolve(values.names);
|
|
104
|
-
options.doctypeNames = JSON.parse(readFileSync(namesPath, 'utf-8'));
|
|
105
|
-
}
|
|
106
|
-
options.onWarning = message => console.warn(` WARN: ${message}`);
|
|
107
|
-
if (values['custom-scalars']) {
|
|
108
|
-
const scalarsPath = resolve(values['custom-scalars']);
|
|
109
|
-
const scalarsContent = readFileSync(scalarsPath, 'utf-8');
|
|
110
|
-
options.customScalars = JSON.parse(scalarsContent);
|
|
111
|
-
}
|
|
112
|
-
// Resolve source
|
|
113
|
-
let source;
|
|
114
|
-
if (values.endpoint) {
|
|
115
|
-
console.log(`Fetching introspection from ${values.endpoint}...`);
|
|
116
|
-
source = await fetchIntrospection(values.endpoint);
|
|
117
|
-
}
|
|
118
|
-
else if (values.introspection) {
|
|
119
|
-
const filePath = resolve(values.introspection);
|
|
120
|
-
const content = readFileSync(filePath, 'utf-8');
|
|
121
|
-
const parsed = JSON.parse(content);
|
|
122
|
-
// Handle both { data: { __schema: ... } } and { __schema: ... } formats
|
|
123
|
-
source = parsed.data ?? parsed;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
const filePath = resolve(values.sdl);
|
|
127
|
-
source = readFileSync(filePath, 'utf-8');
|
|
128
|
-
}
|
|
129
|
-
// Convert
|
|
130
|
-
const entities = convertGraphQLSchema(source, options);
|
|
131
|
-
if (entities.length === 0) {
|
|
132
|
-
console.warn('No entity types found in the schema. Check your include/exclude filters.');
|
|
133
|
-
process.exit(0);
|
|
134
|
-
}
|
|
135
|
-
// Read the identity each authored doctype declares, before planning rather than during the write
|
|
136
|
-
// loop below. SDL cannot express which UNIQUE column is a table's key, so for a natural-key
|
|
137
|
-
// doctype the declaration in the file is the only answer that exists — and planning is what
|
|
138
|
-
// decides whether the aggregate can be built at all. Reading it 20 lines later, as the loop
|
|
139
|
-
// does, made the "declare a primaryKey and re-run" warning a dead end: re-running after
|
|
140
|
-
// declaring one changed nothing.
|
|
141
|
-
const identity = {};
|
|
142
|
-
for (const entity of entities) {
|
|
143
|
-
const entityPath = join(outputDir, `${entity.slug}.json`);
|
|
144
|
-
if (!existsSync(entityPath))
|
|
145
|
-
continue;
|
|
146
|
-
const declared = authoredPrimaryKey(JSON.parse(readFileSync(entityPath, 'utf-8')));
|
|
147
|
-
if (declared !== undefined)
|
|
148
|
-
identity[entity.name] = declared;
|
|
149
|
-
}
|
|
150
|
-
// Each table yields two doctypes — the entity and its aggregate — written as peers, one file
|
|
151
|
-
// each, along with what each is verified against. See `planGeneration`.
|
|
152
|
-
const doctypes = planGeneration(entities, {
|
|
153
|
-
noAggregates: values['no-aggregates'],
|
|
154
|
-
identity,
|
|
155
|
-
onWarning: message => console.warn(` WARN: ${message}`),
|
|
156
|
-
});
|
|
157
|
-
// Write output
|
|
158
|
-
if (!existsSync(outputDir)) {
|
|
159
|
-
mkdirSync(outputDir, { recursive: true });
|
|
160
|
-
}
|
|
161
|
-
let warnings = 0;
|
|
162
|
-
let errors = 0;
|
|
163
|
-
let changed = 0;
|
|
164
|
-
const driftLines = [];
|
|
165
|
-
for (const { generated, basis, subset } of doctypes) {
|
|
166
|
-
const fileName = `${generated.slug}.json`;
|
|
167
|
-
const filePath = join(outputDir, fileName);
|
|
168
|
-
// When a doctype already exists it is the source of truth: generation confirms it and adds
|
|
169
|
-
// provenance markers, and reports anything it disagrees with rather than applying it. A
|
|
170
|
-
// doctype legitimately declares identity the schema cannot express — most often a natural
|
|
171
|
-
// key that is a UNIQUE constraint, not the table's PRIMARY KEY — and overwriting that would
|
|
172
|
-
// silently re-key the doctype on every run. A first generation has nothing to merge into,
|
|
173
|
-
// so converter output is written verbatim.
|
|
174
|
-
let output = generated;
|
|
175
|
-
if (existsSync(filePath)) {
|
|
176
|
-
const { doctype: merged, drift } = mergeIntrospectedDoctype(JSON.parse(readFileSync(filePath, 'utf-8')), basis, {
|
|
177
|
-
subset,
|
|
178
|
-
});
|
|
179
|
-
output = merged;
|
|
180
|
-
driftLines.push(...formatDoctypeDrift(drift));
|
|
181
|
-
}
|
|
182
|
-
// Serialize the merged object directly. Never round-trip it through the Zod parser first:
|
|
183
|
-
// that runs in strip mode and would silently drop every key this package does not model,
|
|
184
|
-
// `handler` on an action being the one consumers actually rely on.
|
|
185
|
-
//
|
|
186
|
-
// `kind` is dropped on the way out because it is the discriminated-union tag the parser
|
|
187
|
-
// synthesizes, not authored data — `injectKind` puts it back on every read. Writing it made
|
|
188
|
-
// the generator and the docbuilder disagree with hand-authored files about what a doctype
|
|
189
|
-
// looks like, and re-added the key on every regeneration.
|
|
190
|
-
const serializable = { ...output };
|
|
191
|
-
if (Array.isArray(serializable.fields)) {
|
|
192
|
-
serializable.fields = serializable.fields.map(stripFieldKind);
|
|
193
|
-
}
|
|
194
|
-
const json = JSON.stringify(serializable, null, '\t') + '\n';
|
|
195
|
-
const unchanged = existsSync(filePath) && readFileSync(filePath, 'utf-8') === json;
|
|
196
|
-
if (!unchanged)
|
|
197
|
-
changed++;
|
|
198
|
-
if (!values.check && !unchanged) {
|
|
199
|
-
writeFileSync(filePath, json, 'utf-8');
|
|
200
|
-
}
|
|
201
|
-
// Validate the output
|
|
202
|
-
const validation = validateDoctype(output);
|
|
203
|
-
if (!validation.success) {
|
|
204
|
-
errors++;
|
|
205
|
-
console.error(` ERROR: ${fileName} failed validation:`);
|
|
206
|
-
for (const err of validation.errors) {
|
|
207
|
-
console.error(` ${err.path.join('.')}: ${err.message}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
// Check for unmapped fields
|
|
212
|
-
const unmappedFields = generated.fields.filter((f) => f._unmapped);
|
|
213
|
-
if (unmappedFields.length > 0) {
|
|
214
|
-
warnings++;
|
|
215
|
-
console.warn(` WARN: ${fileName} has ${unmappedFields.length} unmapped field(s): ${unmappedFields
|
|
216
|
-
.map((f) => f.fieldname)
|
|
217
|
-
.join(', ')}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (driftLines.length > 0) {
|
|
222
|
-
console.log('\nDrift between the authored doctypes and the schema (reported, not applied):');
|
|
223
|
-
for (const line of driftLines)
|
|
224
|
-
console.log(line);
|
|
225
|
-
}
|
|
226
|
-
console.log(`\n${values.check ? 'Checked' : 'Generated'} ${doctypes.length} doctype(s) in ${outputDir}` +
|
|
227
|
-
(changed ? ` (${changed} ${values.check ? 'would change' : 'written'})` : ' (all up to date)') +
|
|
228
|
-
(warnings ? ` (${warnings} with warnings)` : '') +
|
|
229
|
-
(errors ? ` (${errors} with errors)` : ''));
|
|
230
|
-
if (errors > 0 || (values.check && changed > 0)) {
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function printHelp() {
|
|
235
|
-
console.log(`
|
|
236
|
-
stonecrop-schema - Convert GraphQL schemas to Stonecrop doctypes
|
|
237
|
-
|
|
238
|
-
USAGE:
|
|
239
|
-
stonecrop-schema generate [options]
|
|
240
|
-
|
|
241
|
-
SOURCE (exactly one required):
|
|
242
|
-
--endpoint, -e <url> Fetch introspection from a live GraphQL endpoint
|
|
243
|
-
--introspection, -i <file> Read from a saved introspection JSON file
|
|
244
|
-
--sdl, -s <file> Read from a GraphQL SDL (.graphql) file
|
|
245
|
-
|
|
246
|
-
OUTPUT:
|
|
247
|
-
--output, -o <dir> Directory to write doctype JSON files (required)
|
|
248
|
-
|
|
249
|
-
OPTIONS:
|
|
250
|
-
--include <types> Comma-separated list of type names to include
|
|
251
|
-
--exclude <types> Comma-separated list of type names to exclude
|
|
252
|
-
--names <file> JSON file mapping GraphQL type name to doctype name
|
|
253
|
-
--custom-scalars <file> JSON file mapping custom scalar names to field templates
|
|
254
|
-
--include-unmapped Include _graphqlType metadata on unmapped fields
|
|
255
|
-
--no-aggregates Emit only the entity doctype, not its aggregate
|
|
256
|
-
--check Report drift and exit non-zero if anything would change; write nothing
|
|
257
|
-
--help, -h Show this help message
|
|
258
|
-
|
|
259
|
-
Each table generates TWO doctypes: the entity (every column, backs the record form) and its
|
|
260
|
-
aggregate (the collection view, identity column only by default), named as simple plurals —
|
|
261
|
-
'task.json' and 'tasks.json'. Widen an aggregate by adding fields to it — curation survives
|
|
262
|
-
regeneration. A doctype whose name is already plural gets no aggregate, because it would claim
|
|
263
|
-
its own name and its own file; the run says so and still writes the entity.
|
|
264
|
-
|
|
265
|
-
An aggregate needs an identity column. A table keyed on 'id' gives one up; for a natural key,
|
|
266
|
-
declare 'primaryKey' on the field in the entity's own file and re-run — the aggregate is keyed
|
|
267
|
-
on whatever that file declares.
|
|
268
|
-
|
|
269
|
-
NOTE: an existing doctype file is the source of truth. Regeneration verifies it against the
|
|
270
|
-
schema and adds 'source: introspected' markers; it reports disagreements rather than
|
|
271
|
-
overwriting them, so hand-curation survives. Use --check in CI.
|
|
272
|
-
|
|
273
|
-
EXAMPLES:
|
|
274
|
-
# From a live PostGraphile server
|
|
275
|
-
stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas
|
|
276
|
-
|
|
277
|
-
# From a saved introspection result
|
|
278
|
-
stonecrop-schema generate -i introspection.json -o ./schemas
|
|
279
|
-
|
|
280
|
-
# From an SDL file with custom scalars
|
|
281
|
-
stonecrop-schema generate -s schema.graphql -o ./schemas \\
|
|
282
|
-
--custom-scalars custom-scalars.json
|
|
283
|
-
|
|
284
|
-
# Only convert specific types
|
|
285
|
-
stonecrop-schema generate -e http://localhost:5000/graphql -o ./schemas \\
|
|
286
|
-
--include "User,Post,Comment"
|
|
287
|
-
`);
|
|
288
|
-
}
|
|
289
|
-
main().catch(err => {
|
|
290
|
-
console.error('Error:', err.message);
|
|
291
|
-
process.exit(1);
|
|
292
|
-
});
|