@gzl10/nexus-sdk 0.12.7 → 0.13.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.js CHANGED
@@ -1,80 +1,36 @@
1
- // src/generators.ts
2
- function isPersistentEntity(entity) {
3
- const withoutOwnTable = ["action", "external", "virtual", "computed", "single"];
4
- return !withoutOwnTable.includes(entity.type ?? "collection");
5
- }
6
- function isSingletonEntity(entity) {
7
- return entity.type === "single";
8
- }
9
- function hasTable(entity) {
10
- return "table" in entity && typeof entity.table === "string";
11
- }
12
- function getEntityName(entity) {
13
- if ("table" in entity) {
14
- const withoutPrefix = entity.table.replace(/^[a-z]{2,4}_/, "");
15
- return toPascalCase(toSingular(withoutPrefix));
16
- } else if ("key" in entity) {
17
- return toPascalCase(entity.key);
18
- } else {
19
- const label = resolveLocalized(entity.label, "en");
20
- return toSingular(label).replace(/\s+/g, "");
21
- }
22
- }
23
- function getEntitySubject(entity) {
24
- return entity.casl?.subject ?? tableToSubject(entity.table);
25
- }
26
- function toPascalCase(str) {
27
- return str.split("_").map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
28
- }
29
- function toSingular(str) {
30
- if (str.endsWith("ies")) return str.slice(0, -3) + "y";
31
- if (str.endsWith("s")) return str.slice(0, -1);
32
- return str;
33
- }
34
- function tableToSubject(table) {
35
- const match = table.match(/^([a-z]{2,4})_(.+)$/);
36
- if (!match) {
37
- const withoutPrefix = table.replace(/^[a-z]{2,4}_/, "");
38
- return toPascalCase(toSingular(withoutPrefix));
39
- }
40
- const [, prefix, rest] = match;
41
- const prefixPascal = prefix.charAt(0).toUpperCase() + prefix.slice(1);
42
- return prefixPascal + toPascalCase(toSingular(rest));
43
- }
44
-
45
- // src/index.ts
46
- function resolveLocalized(value, locale) {
47
- if (!value) return "";
48
- if (typeof value === "string") return value;
49
- return value[locale] || value["en"] || Object.values(value)[0] || "";
50
- }
51
- function getCountLabel(label, labelPlural, count, locale) {
52
- const resolved = count === 1 ? label : labelPlural || label;
53
- return resolveLocalized(resolved, locale);
54
- }
55
- var CATEGORIES = {
56
- data: { label: { en: "Data", es: "Datos" }, icon: "mdi:database", order: 1 },
57
- content: { label: { en: "Content", es: "Contenido" }, icon: "mdi:file-document-outline", order: 2 },
58
- assets: { label: { en: "Assets", es: "Recursos" }, icon: "mdi:folder-outline", order: 3 },
59
- messaging: { label: { en: "Messaging", es: "Mensajer\xEDa" }, icon: "mdi:message-outline", order: 4 },
60
- jobs: { label: { en: "Jobs", es: "Tareas" }, icon: "mdi:clock-outline", order: 5 },
61
- ai: { label: { en: "AI", es: "IA" }, icon: "mdi:robot-outline", order: 6 },
62
- analytics: { label: { en: "Analytics", es: "Anal\xEDticas" }, icon: "mdi:chart-line", order: 7 },
63
- integrations: { label: { en: "Integrations", es: "Integraciones" }, icon: "mdi:puzzle-outline", order: 8 },
64
- commerce: { label: { en: "Commerce", es: "Comercio" }, icon: "mdi:shopping-outline", order: 9 },
65
- security: { label: { en: "Security", es: "Seguridad" }, icon: "mdi:shield-lock-outline", order: 10 },
66
- legal: { label: { en: "Legal", es: "Legal" }, icon: "mdi:scale-balance", order: 11 },
67
- settings: { label: { en: "Settings", es: "Configuraci\xF3n" }, icon: "mdi:cog-outline", order: 12 }
68
- };
69
- var CATEGORY_ORDER = Object.keys(CATEGORIES).sort((a, b) => CATEGORIES[a].order - CATEGORIES[b].order);
1
+ import {
2
+ CATEGORIES,
3
+ CATEGORY_ORDER,
4
+ assertAllowedDomain,
5
+ checkAllowedDomain,
6
+ createOidcClient,
7
+ createStateManager,
8
+ getCountLabel,
9
+ getEntityName,
10
+ getEntitySubject,
11
+ getOidcClient,
12
+ hasTable,
13
+ isPersistentEntity,
14
+ isSingletonEntity,
15
+ refMaster,
16
+ refOptions,
17
+ resolveLocalized
18
+ } from "./chunk-JIEVWBDA.js";
70
19
  export {
71
20
  CATEGORIES,
72
21
  CATEGORY_ORDER,
22
+ assertAllowedDomain,
23
+ checkAllowedDomain,
24
+ createOidcClient,
25
+ createStateManager,
73
26
  getCountLabel,
74
27
  getEntityName,
75
28
  getEntitySubject,
29
+ getOidcClient,
76
30
  hasTable,
77
31
  isPersistentEntity,
78
32
  isSingletonEntity,
33
+ refMaster,
34
+ refOptions,
79
35
  resolveLocalized
80
36
  };
@@ -0,0 +1,120 @@
1
+ import { L as LocalizedString, i as FieldDefinition } from '../field-CngHXora.js';
2
+ import { u as RolePermission, R as ReferenceEntityDefinition, e as TreeEntityDefinition } from '../entity-kPgsCMdR.js';
3
+ import 'knex';
4
+ import 'express';
5
+ import 'pino';
6
+
7
+ /**
8
+ * Master Entity Types
9
+ *
10
+ * Configuration and types for master/reference entities.
11
+ */
12
+
13
+ /**
14
+ * Configuration options for master entity factories.
15
+ */
16
+ interface MasterEntityConfig {
17
+ /** Prefix for table name: 'custom_' → custom_countries */
18
+ tablePrefix?: string;
19
+ /** Complete override of table name */
20
+ table?: string;
21
+ /** Override singular label */
22
+ label?: LocalizedString;
23
+ /** Override plural label */
24
+ labelPlural?: LocalizedString;
25
+ /** Override CASL subject name */
26
+ caslSubject?: string;
27
+ }
28
+ /**
29
+ * Master entity factory function type.
30
+ */
31
+ type MasterEntityFactory<T> = (config?: MasterEntityConfig) => T;
32
+
33
+ /**
34
+ * Master Entity Helpers
35
+ *
36
+ * Shared field definitions and factory utilities for master entities.
37
+ */
38
+
39
+ /** Entity types that can be used as master entities */
40
+ type MasterEntityDefinition = ReferenceEntityDefinition | TreeEntityDefinition;
41
+ /**
42
+ * Standard ID field for masters.
43
+ * Note: Masters typically use custom IDs (like 'EUR', '+34') instead of generated ULIDs.
44
+ */
45
+ declare const masterIdField: FieldDefinition;
46
+ /**
47
+ * Standard is_active field for masters.
48
+ * @alias isActiveField from fields/common
49
+ */
50
+ declare const masterIsActiveField: FieldDefinition;
51
+ /**
52
+ * Standard order field for masters.
53
+ * @alias orderField from fields/common
54
+ */
55
+ declare const masterOrderField: FieldDefinition;
56
+ /**
57
+ * Standard master entity CASL permissions.
58
+ * Public read access, admin-only write access.
59
+ */
60
+ declare const masterCaslPermissions: Record<string, RolePermission>;
61
+ /**
62
+ * Apply configuration to a master entity definition.
63
+ */
64
+ declare function applyMasterConfig<T extends MasterEntityDefinition>(base: T, config?: MasterEntityConfig, defaultTable?: string, _defaultSubject?: string): T;
65
+ /**
66
+ * Create a factory function for a master entity.
67
+ */
68
+ declare function createMasterFactory<T extends MasterEntityDefinition>(base: T, defaultTable: string, defaultSubject: string): MasterEntityFactory<T>;
69
+
70
+ declare const currencyMaster: ReferenceEntityDefinition;
71
+ declare const createCurrencyMaster: MasterEntityFactory<ReferenceEntityDefinition>;
72
+
73
+ declare const languageMaster: ReferenceEntityDefinition;
74
+ declare const createLanguageMaster: MasterEntityFactory<ReferenceEntityDefinition>;
75
+
76
+ declare const timezoneMaster: ReferenceEntityDefinition;
77
+ declare const createTimezoneMaster: MasterEntityFactory<ReferenceEntityDefinition>;
78
+
79
+ declare const socialNetworkMaster: ReferenceEntityDefinition;
80
+ declare const createSocialNetworkMaster: MasterEntityFactory<ReferenceEntityDefinition>;
81
+
82
+ declare const genderMaster: ReferenceEntityDefinition;
83
+ declare const createGenderMaster: MasterEntityFactory<ReferenceEntityDefinition>;
84
+
85
+ declare const maritalStatusMaster: ReferenceEntityDefinition;
86
+ declare const createMaritalStatusMaster: MasterEntityFactory<ReferenceEntityDefinition>;
87
+
88
+ declare const educationLevelMaster: ReferenceEntityDefinition;
89
+ declare const createEducationLevelMaster: MasterEntityFactory<ReferenceEntityDefinition>;
90
+
91
+ declare const industryMaster: ReferenceEntityDefinition;
92
+ declare const createIndustryMaster: MasterEntityFactory<ReferenceEntityDefinition>;
93
+
94
+ declare const companyTypeMaster: ReferenceEntityDefinition;
95
+ declare const createCompanyTypeMaster: MasterEntityFactory<ReferenceEntityDefinition>;
96
+
97
+ declare const unitMaster: ReferenceEntityDefinition;
98
+ declare const createUnitMaster: MasterEntityFactory<ReferenceEntityDefinition>;
99
+
100
+ declare const productCategoryMaster: ReferenceEntityDefinition;
101
+ declare const createProductCategoryMaster: MasterEntityFactory<ReferenceEntityDefinition>;
102
+
103
+ declare const locationMaster: TreeEntityDefinition;
104
+ declare const createLocationMaster: MasterEntityFactory<TreeEntityDefinition>;
105
+
106
+ /**
107
+ * Extended config for phone prefix
108
+ */
109
+ type PhonePrefixMasterConfig = MasterEntityConfig;
110
+ declare const phonePrefixMaster: ReferenceEntityDefinition;
111
+ declare const createPhonePrefixMaster: MasterEntityFactory<ReferenceEntityDefinition>;
112
+
113
+ /**
114
+ * Extended config for document type
115
+ */
116
+ type DocumentTypeMasterConfig = MasterEntityConfig;
117
+ declare const documentTypeMaster: ReferenceEntityDefinition;
118
+ declare const createDocumentTypeMaster: MasterEntityFactory<ReferenceEntityDefinition>;
119
+
120
+ export { type DocumentTypeMasterConfig, type MasterEntityConfig, type MasterEntityFactory, type PhonePrefixMasterConfig, applyMasterConfig, companyTypeMaster, createCompanyTypeMaster, createCurrencyMaster, createDocumentTypeMaster, createEducationLevelMaster, createGenderMaster, createIndustryMaster, createLanguageMaster, createLocationMaster, createMaritalStatusMaster, createMasterFactory, createPhonePrefixMaster, createProductCategoryMaster, createSocialNetworkMaster, createTimezoneMaster, createUnitMaster, currencyMaster, documentTypeMaster, educationLevelMaster, genderMaster, industryMaster, languageMaster, locationMaster, maritalStatusMaster, masterCaslPermissions, masterIdField, masterIsActiveField, masterOrderField, phonePrefixMaster, productCategoryMaster, socialNetworkMaster, timezoneMaster, unitMaster };