@ghentcdh/crouton-api 0.0.1-alpha.38 → 0.0.1-alpha.39
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.cjs +208 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +208 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -688,6 +688,14 @@ var FieldInputSchema = import_zod9.z.object({
|
|
|
688
688
|
relation: import_zod9.z.string().optional(),
|
|
689
689
|
/** Override the display order in form views. Lower values come first. */
|
|
690
690
|
position: import_zod9.z.number().optional(),
|
|
691
|
+
/**
|
|
692
|
+
* Value to pre-fill this field with on the create form. Injected into the
|
|
693
|
+
* generated form view's JSON Schema as `properties[id].default`, which
|
|
694
|
+
* `parseValue({})` (see `@ghentcdh/crouton-vue`'s `form-def.ts`) applies when
|
|
695
|
+
* opening a blank record. Not applicable to `format: "relation"` fields —
|
|
696
|
+
* relation columns are excluded from the picked data schema entirely.
|
|
697
|
+
*/
|
|
698
|
+
defaultValue: import_zod9.z.unknown().optional(),
|
|
691
699
|
options: import_zod9.z.union([
|
|
692
700
|
RelationFieldInputOptionsSchema,
|
|
693
701
|
import_zod9.z.unknown()
|
|
@@ -1550,6 +1558,15 @@ var patchFilterProperties = /* @__PURE__ */ __name((jsonSchema, columns) => {
|
|
|
1550
1558
|
}
|
|
1551
1559
|
}
|
|
1552
1560
|
}, "patchFilterProperties");
|
|
1561
|
+
var injectFieldDefaults = /* @__PURE__ */ __name((jsonSchema, columns) => {
|
|
1562
|
+
const properties = jsonSchema.properties;
|
|
1563
|
+
if (!properties) return;
|
|
1564
|
+
for (const col of columns) {
|
|
1565
|
+
if (col.fieldInput?.defaultValue === void 0) continue;
|
|
1566
|
+
const prop = properties[col.id];
|
|
1567
|
+
if (prop) prop.default = col.fieldInput.defaultValue;
|
|
1568
|
+
}
|
|
1569
|
+
}, "injectFieldDefaults");
|
|
1553
1570
|
var buildView = /* @__PURE__ */ __name((schema, columns, visible, buildUiSchema, sort = false, schemaVisible) => {
|
|
1554
1571
|
if (!schema || !columns?.length) return void 0;
|
|
1555
1572
|
const visibleCols = sort ? sortByPosition(columns.filter(visible)) : columns.filter(visible);
|
|
@@ -1568,6 +1585,7 @@ var buildView = /* @__PURE__ */ __name((schema, columns, visible, buildUiSchema,
|
|
|
1568
1585
|
...jsonSchemaOpts
|
|
1569
1586
|
});
|
|
1570
1587
|
applySchemaTransforms(jsonSchema);
|
|
1588
|
+
injectFieldDefaults(jsonSchema, visibleCols);
|
|
1571
1589
|
if (schemaVisible) {
|
|
1572
1590
|
const nonEditableIds = new Set(schemaCols.filter((c) => c.idField || c.createable === false && c.updateable === false).map((c) => c.id));
|
|
1573
1591
|
const required = jsonSchema["required"];
|
|
@@ -1645,7 +1663,10 @@ var buildViewsFromColumns = /* @__PURE__ */ __name((columns) => {
|
|
|
1645
1663
|
...isObject ? {} : {
|
|
1646
1664
|
type: c.columnType ?? "string"
|
|
1647
1665
|
},
|
|
1648
|
-
title: c.label ?? c.id
|
|
1666
|
+
title: c.label ?? c.id,
|
|
1667
|
+
...c.fieldInput?.defaultValue !== void 0 ? {
|
|
1668
|
+
default: c.fieldInput.defaultValue
|
|
1669
|
+
} : {}
|
|
1649
1670
|
};
|
|
1650
1671
|
}
|
|
1651
1672
|
}
|
|
@@ -4420,6 +4441,20 @@ var resolveRelationType = /* @__PURE__ */ __name((field, index) => {
|
|
|
4420
4441
|
if (field.isList) return otherIsList ? "manyToMany" : "oneToMany";
|
|
4421
4442
|
return otherIsList ? "manyToOne" : "oneToOne";
|
|
4422
4443
|
}, "resolveRelationType");
|
|
4444
|
+
var literalDefault = /* @__PURE__ */ __name((value) => {
|
|
4445
|
+
if (value === void 0 || value === null) return void 0;
|
|
4446
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
4447
|
+
return value;
|
|
4448
|
+
}
|
|
4449
|
+
if (Array.isArray(value) && value.every((v) => [
|
|
4450
|
+
"string",
|
|
4451
|
+
"number",
|
|
4452
|
+
"boolean"
|
|
4453
|
+
].includes(typeof v))) {
|
|
4454
|
+
return value;
|
|
4455
|
+
}
|
|
4456
|
+
return void 0;
|
|
4457
|
+
}, "literalDefault");
|
|
4423
4458
|
var dmmfToDbModels = /* @__PURE__ */ __name((dmmf) => {
|
|
4424
4459
|
const { models, enums } = dmmf.datamodel;
|
|
4425
4460
|
const enumNames = new Set(enums.map((e) => e.name));
|
|
@@ -4453,6 +4488,9 @@ var dmmfToDbModels = /* @__PURE__ */ __name((dmmf) => {
|
|
|
4453
4488
|
isUnique: f.isUnique,
|
|
4454
4489
|
isUpdatedAt: f.isUpdatedAt,
|
|
4455
4490
|
hasDefault: f.hasDefaultValue,
|
|
4491
|
+
...f.hasDefaultValue && literalDefault(f.default) !== void 0 ? {
|
|
4492
|
+
defaultValue: literalDefault(f.default)
|
|
4493
|
+
} : {},
|
|
4456
4494
|
isTimestamp: kind === "scalar" && isTimestampField({
|
|
4457
4495
|
name: f.name,
|
|
4458
4496
|
type: f.type,
|
|
@@ -4534,7 +4572,10 @@ var classify = /* @__PURE__ */ __name((model, ctx = {}) => {
|
|
|
4534
4572
|
} : {
|
|
4535
4573
|
fieldInput: {
|
|
4536
4574
|
type: "date",
|
|
4537
|
-
position: position
|
|
4575
|
+
position: position++,
|
|
4576
|
+
...field.defaultValue !== void 0 ? {
|
|
4577
|
+
defaultValue: field.defaultValue
|
|
4578
|
+
} : {}
|
|
4538
4579
|
}
|
|
4539
4580
|
};
|
|
4540
4581
|
} else if (field.kind === "foreignKey") {
|
|
@@ -4546,7 +4587,10 @@ var classify = /* @__PURE__ */ __name((model, ctx = {}) => {
|
|
|
4546
4587
|
} : {
|
|
4547
4588
|
fieldInput: {
|
|
4548
4589
|
type: "text",
|
|
4549
|
-
position: position
|
|
4590
|
+
position: position++,
|
|
4591
|
+
...field.defaultValue !== void 0 ? {
|
|
4592
|
+
defaultValue: field.defaultValue
|
|
4593
|
+
} : {}
|
|
4550
4594
|
}
|
|
4551
4595
|
};
|
|
4552
4596
|
} else if (field.kind === "relation") {
|
|
@@ -4555,7 +4599,6 @@ var classify = /* @__PURE__ */ __name((model, ctx = {}) => {
|
|
|
4555
4599
|
col = {
|
|
4556
4600
|
hiddenInTable: ruleset.hideRelationsInTable,
|
|
4557
4601
|
fieldInput: {
|
|
4558
|
-
type: "relation",
|
|
4559
4602
|
format: "relation",
|
|
4560
4603
|
resource: target,
|
|
4561
4604
|
relationType: field.relationType
|
|
@@ -4591,14 +4634,20 @@ var classify = /* @__PURE__ */ __name((model, ctx = {}) => {
|
|
|
4591
4634
|
fieldInput: {
|
|
4592
4635
|
type: "select",
|
|
4593
4636
|
position: position++,
|
|
4594
|
-
options
|
|
4637
|
+
options,
|
|
4638
|
+
...field.defaultValue !== void 0 ? {
|
|
4639
|
+
defaultValue: field.defaultValue
|
|
4640
|
+
} : {}
|
|
4595
4641
|
}
|
|
4596
4642
|
};
|
|
4597
4643
|
} else {
|
|
4598
4644
|
col = {
|
|
4599
4645
|
fieldInput: {
|
|
4600
4646
|
type: scalarFieldInputType(field.name, field.type),
|
|
4601
|
-
position: position
|
|
4647
|
+
position: position++,
|
|
4648
|
+
...field.defaultValue !== void 0 ? {
|
|
4649
|
+
defaultValue: field.defaultValue
|
|
4650
|
+
} : {}
|
|
4602
4651
|
}
|
|
4603
4652
|
};
|
|
4604
4653
|
}
|
|
@@ -5854,42 +5903,6 @@ DevResourcesController = _ts_decorate5([
|
|
|
5854
5903
|
])
|
|
5855
5904
|
], DevResourcesController);
|
|
5856
5905
|
|
|
5857
|
-
// src/lib/crud/builder/schema.helpers.ts
|
|
5858
|
-
var pickByColumns = /* @__PURE__ */ __name((schema, columns, filter) => {
|
|
5859
|
-
if (!schema) return void 0;
|
|
5860
|
-
if (!columns?.length) return schema;
|
|
5861
|
-
const baseFilter = /* @__PURE__ */ __name((c) => !isRelation(c) && (filter ? filter(c) : true), "baseFilter");
|
|
5862
|
-
const schemaKeys = new Set(Object.keys(schema.shape));
|
|
5863
|
-
const filtered = columns.filter((c) => baseFilter(c) && schemaKeys.has(c.id));
|
|
5864
|
-
if (!filtered.length) return void 0;
|
|
5865
|
-
const mask = Object.fromEntries(filtered.map((c) => [
|
|
5866
|
-
c.id,
|
|
5867
|
-
true
|
|
5868
|
-
]));
|
|
5869
|
-
return schema.pick(mask);
|
|
5870
|
-
}, "pickByColumns");
|
|
5871
|
-
var opWithSchema = /* @__PURE__ */ __name((enabled, schema) => {
|
|
5872
|
-
if (enabled === false) return void 0;
|
|
5873
|
-
return schema ? {
|
|
5874
|
-
schema
|
|
5875
|
-
} : true;
|
|
5876
|
-
}, "opWithSchema");
|
|
5877
|
-
var upsertOp = /* @__PURE__ */ __name((entry, schema) => {
|
|
5878
|
-
if (!entry) return void 0;
|
|
5879
|
-
if (entry === true) {
|
|
5880
|
-
throw new Error("`operations.upsert` must be an object with `upsertOn`, not `true`.");
|
|
5881
|
-
}
|
|
5882
|
-
if (typeof entry === "object") {
|
|
5883
|
-
return {
|
|
5884
|
-
upsertOn: entry.upsertOn,
|
|
5885
|
-
...schema && {
|
|
5886
|
-
schema
|
|
5887
|
-
}
|
|
5888
|
-
};
|
|
5889
|
-
}
|
|
5890
|
-
return void 0;
|
|
5891
|
-
}, "upsertOp");
|
|
5892
|
-
|
|
5893
5906
|
// src/lib/crud/enum-registry/enum-registry.types.ts
|
|
5894
5907
|
var import_zod25 = require("zod");
|
|
5895
5908
|
var EnumEntrySchema = import_zod25.z.object({
|
|
@@ -5941,6 +5954,42 @@ var injectEnumValues = /* @__PURE__ */ __name((columns, enums) => {
|
|
|
5941
5954
|
}
|
|
5942
5955
|
}, "injectEnumValues");
|
|
5943
5956
|
|
|
5957
|
+
// src/lib/crud/builder/schema.helpers.ts
|
|
5958
|
+
var pickByColumns = /* @__PURE__ */ __name((schema, columns, filter) => {
|
|
5959
|
+
if (!schema) return void 0;
|
|
5960
|
+
if (!columns?.length) return schema;
|
|
5961
|
+
const baseFilter = /* @__PURE__ */ __name((c) => !isRelation(c) && (filter ? filter(c) : true), "baseFilter");
|
|
5962
|
+
const schemaKeys = new Set(Object.keys(schema.shape));
|
|
5963
|
+
const filtered = columns.filter((c) => baseFilter(c) && schemaKeys.has(c.id));
|
|
5964
|
+
if (!filtered.length) return void 0;
|
|
5965
|
+
const mask = Object.fromEntries(filtered.map((c) => [
|
|
5966
|
+
c.id,
|
|
5967
|
+
true
|
|
5968
|
+
]));
|
|
5969
|
+
return schema.pick(mask);
|
|
5970
|
+
}, "pickByColumns");
|
|
5971
|
+
var opWithSchema = /* @__PURE__ */ __name((enabled, schema) => {
|
|
5972
|
+
if (enabled === false) return void 0;
|
|
5973
|
+
return schema ? {
|
|
5974
|
+
schema
|
|
5975
|
+
} : true;
|
|
5976
|
+
}, "opWithSchema");
|
|
5977
|
+
var upsertOp = /* @__PURE__ */ __name((entry, schema) => {
|
|
5978
|
+
if (!entry) return void 0;
|
|
5979
|
+
if (entry === true) {
|
|
5980
|
+
throw new Error("`operations.upsert` must be an object with `upsertOn`, not `true`.");
|
|
5981
|
+
}
|
|
5982
|
+
if (typeof entry === "object") {
|
|
5983
|
+
return {
|
|
5984
|
+
upsertOn: entry.upsertOn,
|
|
5985
|
+
...schema && {
|
|
5986
|
+
schema
|
|
5987
|
+
}
|
|
5988
|
+
};
|
|
5989
|
+
}
|
|
5990
|
+
return void 0;
|
|
5991
|
+
}, "upsertOp");
|
|
5992
|
+
|
|
5944
5993
|
// src/lib/crud/adapter/relation-type.ts
|
|
5945
5994
|
var import_zod26 = require("zod");
|
|
5946
5995
|
var unwrapZodType = /* @__PURE__ */ __name((type) => {
|
|
@@ -6721,7 +6770,114 @@ var buildSummary = /* @__PURE__ */ __name((databases, resources) => {
|
|
|
6721
6770
|
resourceErrors
|
|
6722
6771
|
};
|
|
6723
6772
|
}, "buildSummary");
|
|
6724
|
-
var
|
|
6773
|
+
var getSystemEnums = /* @__PURE__ */ __name(() => {
|
|
6774
|
+
return [
|
|
6775
|
+
{
|
|
6776
|
+
name: "RelationType",
|
|
6777
|
+
category: "Relationships",
|
|
6778
|
+
values: [
|
|
6779
|
+
{
|
|
6780
|
+
value: "oneToOne",
|
|
6781
|
+
label: "One to One"
|
|
6782
|
+
},
|
|
6783
|
+
{
|
|
6784
|
+
value: "manyToOne",
|
|
6785
|
+
label: "Many to One"
|
|
6786
|
+
},
|
|
6787
|
+
{
|
|
6788
|
+
value: "oneToMany",
|
|
6789
|
+
label: "One to Many"
|
|
6790
|
+
},
|
|
6791
|
+
{
|
|
6792
|
+
value: "manyToMany",
|
|
6793
|
+
label: "Many to Many"
|
|
6794
|
+
}
|
|
6795
|
+
]
|
|
6796
|
+
},
|
|
6797
|
+
{
|
|
6798
|
+
name: "DetailLayout",
|
|
6799
|
+
category: "Layout",
|
|
6800
|
+
values: [
|
|
6801
|
+
{
|
|
6802
|
+
value: "collapse",
|
|
6803
|
+
label: "Collapse"
|
|
6804
|
+
},
|
|
6805
|
+
{
|
|
6806
|
+
value: "row",
|
|
6807
|
+
label: "Row"
|
|
6808
|
+
}
|
|
6809
|
+
]
|
|
6810
|
+
},
|
|
6811
|
+
{
|
|
6812
|
+
name: "SortDirection",
|
|
6813
|
+
category: "Sorting",
|
|
6814
|
+
values: [
|
|
6815
|
+
{
|
|
6816
|
+
value: "asc",
|
|
6817
|
+
label: "Ascending"
|
|
6818
|
+
},
|
|
6819
|
+
{
|
|
6820
|
+
value: "desc",
|
|
6821
|
+
label: "Descending"
|
|
6822
|
+
}
|
|
6823
|
+
]
|
|
6824
|
+
},
|
|
6825
|
+
{
|
|
6826
|
+
name: "DisplayMode",
|
|
6827
|
+
category: "Display",
|
|
6828
|
+
values: [
|
|
6829
|
+
{
|
|
6830
|
+
value: "page",
|
|
6831
|
+
label: "Page"
|
|
6832
|
+
},
|
|
6833
|
+
{
|
|
6834
|
+
value: "modal",
|
|
6835
|
+
label: "Modal"
|
|
6836
|
+
}
|
|
6837
|
+
]
|
|
6838
|
+
},
|
|
6839
|
+
{
|
|
6840
|
+
name: "ModalSize",
|
|
6841
|
+
category: "Display",
|
|
6842
|
+
values: [
|
|
6843
|
+
{
|
|
6844
|
+
value: "xs",
|
|
6845
|
+
label: "Extra Small"
|
|
6846
|
+
},
|
|
6847
|
+
{
|
|
6848
|
+
value: "sm",
|
|
6849
|
+
label: "Small"
|
|
6850
|
+
},
|
|
6851
|
+
{
|
|
6852
|
+
value: "lg",
|
|
6853
|
+
label: "Large"
|
|
6854
|
+
},
|
|
6855
|
+
{
|
|
6856
|
+
value: "xl",
|
|
6857
|
+
label: "Extra Large"
|
|
6858
|
+
}
|
|
6859
|
+
]
|
|
6860
|
+
}
|
|
6861
|
+
];
|
|
6862
|
+
}, "getSystemEnums");
|
|
6863
|
+
var getProjectEnums = /* @__PURE__ */ __name((enumRegistry) => {
|
|
6864
|
+
if (!enumRegistry) return [];
|
|
6865
|
+
return Object.entries(enumRegistry).map(([name, entries]) => ({
|
|
6866
|
+
name,
|
|
6867
|
+
category: "Project",
|
|
6868
|
+
values: entries.map((entry) => ({
|
|
6869
|
+
value: entry.value,
|
|
6870
|
+
label: entry.label
|
|
6871
|
+
}))
|
|
6872
|
+
}));
|
|
6873
|
+
}, "getProjectEnums");
|
|
6874
|
+
var getEnums = /* @__PURE__ */ __name((enumRegistry) => {
|
|
6875
|
+
return {
|
|
6876
|
+
system: getSystemEnums(),
|
|
6877
|
+
project: getProjectEnums(enumRegistry)
|
|
6878
|
+
};
|
|
6879
|
+
}, "getEnums");
|
|
6880
|
+
var buildStatus = /* @__PURE__ */ __name(async (registry, loadedConfigs, enumRegistry) => {
|
|
6725
6881
|
const databases = await checkDatabases(registry);
|
|
6726
6882
|
const resources = getResourceStatus(loadedConfigs);
|
|
6727
6883
|
const summary = buildSummary(databases, resources);
|
|
@@ -6731,7 +6887,8 @@ var buildStatus = /* @__PURE__ */ __name(async (registry, loadedConfigs) => {
|
|
|
6731
6887
|
environment: getEnvironment(),
|
|
6732
6888
|
summary,
|
|
6733
6889
|
databases,
|
|
6734
|
-
resources
|
|
6890
|
+
resources,
|
|
6891
|
+
enums: getEnums(enumRegistry)
|
|
6735
6892
|
};
|
|
6736
6893
|
}, "buildStatus");
|
|
6737
6894
|
|
|
@@ -6749,7 +6906,7 @@ function _ts_metadata5(k, v) {
|
|
|
6749
6906
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6750
6907
|
}
|
|
6751
6908
|
__name(_ts_metadata5, "_ts_metadata");
|
|
6752
|
-
var createStatusController = /* @__PURE__ */ __name(() => {
|
|
6909
|
+
var createStatusController = /* @__PURE__ */ __name((enumRegistry) => {
|
|
6753
6910
|
let StatusController = class StatusController {
|
|
6754
6911
|
static {
|
|
6755
6912
|
__name(this, "StatusController");
|
|
@@ -6762,7 +6919,7 @@ var createStatusController = /* @__PURE__ */ __name(() => {
|
|
|
6762
6919
|
}
|
|
6763
6920
|
async getStatus() {
|
|
6764
6921
|
const configs = await this.configRegistry.getAll();
|
|
6765
|
-
return buildStatus(this.dataSourceRegistry, configs);
|
|
6922
|
+
return buildStatus(this.dataSourceRegistry, configs, enumRegistry);
|
|
6766
6923
|
}
|
|
6767
6924
|
};
|
|
6768
6925
|
_ts_decorate6([
|
|
@@ -6795,6 +6952,8 @@ var createStatusController = /* @__PURE__ */ __name(() => {
|
|
|
6795
6952
|
}, "createStatusController");
|
|
6796
6953
|
|
|
6797
6954
|
// src/lib/crouton-api.module.ts
|
|
6955
|
+
var import_node_path19 = require("path");
|
|
6956
|
+
var import_node_url2 = require("url");
|
|
6798
6957
|
function _ts_decorate7(decorators, target, key, desc2) {
|
|
6799
6958
|
var c = arguments.length, r = c < 3 ? target : desc2 === null ? desc2 = Object.getOwnPropertyDescriptor(target, key) : desc2, d;
|
|
6800
6959
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc2);
|
|
@@ -6815,6 +6974,8 @@ var CroutonApiModule = class _CroutonApiModule {
|
|
|
6815
6974
|
}
|
|
6816
6975
|
static forResources(configs, dataSources, loader, { baseUrl }, config) {
|
|
6817
6976
|
const dataSourceRegistry = new DataSourceRegistry(dataSources);
|
|
6977
|
+
const startDir = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path19.dirname)((0, import_node_url2.fileURLToPath)(importMetaUrl));
|
|
6978
|
+
const enumRegistry = loadEnumRegistry(startDir, config.enumsFile);
|
|
6818
6979
|
const validConfigs = [];
|
|
6819
6980
|
for (const c of configs) {
|
|
6820
6981
|
try {
|
|
@@ -6846,7 +7007,7 @@ var CroutonApiModule = class _CroutonApiModule {
|
|
|
6846
7007
|
...IS_DEV ? [
|
|
6847
7008
|
DevResourcesController
|
|
6848
7009
|
] : [],
|
|
6849
|
-
createStatusController()
|
|
7010
|
+
createStatusController(enumRegistry)
|
|
6850
7011
|
];
|
|
6851
7012
|
return {
|
|
6852
7013
|
module: _CroutonApiModule,
|