@itrocks/framework 0.3.11 → 0.3.12

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.
@@ -0,0 +1 @@
1
+ export declare function bind(): void;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bind = bind;
4
+ const lazy_loading_1 = require("@itrocks/lazy-loading");
5
+ (0, lazy_loading_1.initLazyLoading)();
6
+ const action_1 = require("@itrocks/action");
7
+ const app_dir_1 = require("@itrocks/app-dir");
8
+ const class_file_1 = require("@itrocks/class-file");
9
+ const class_type_1 = require("@itrocks/class-type");
10
+ const class_type_2 = require("@itrocks/class-type");
11
+ const class_view_1 = require("@itrocks/class-view");
12
+ const class_view_2 = require("@itrocks/class-view");
13
+ const collection_1 = require("@itrocks/collection");
14
+ const composition_1 = require("@itrocks/composition");
15
+ const config_1 = require("@itrocks/config");
16
+ const core_transformers_1 = require("@itrocks/core-transformers");
17
+ const core_transformers_2 = require("@itrocks/core-transformers");
18
+ const property_1 = require("@itrocks/decorator/property");
19
+ const file_1 = require("@itrocks/file");
20
+ const lazy_loading_2 = require("@itrocks/lazy-loading");
21
+ const list_properties_1 = require("@itrocks/list-properties");
22
+ const mysql_1 = require("@itrocks/mysql");
23
+ const password_1 = require("@itrocks/password");
24
+ const transformers_1 = require("@itrocks/password/transformers");
25
+ const property_translate_1 = require("@itrocks/property-translate");
26
+ const transformers_2 = require("@itrocks/property-translate/transformers");
27
+ const property_view_1 = require("@itrocks/property-view");
28
+ const property_view_2 = require("@itrocks/property-view");
29
+ const rename_1 = require("@itrocks/rename");
30
+ const rename_2 = require("@itrocks/rename");
31
+ const required_1 = require("@itrocks/required");
32
+ const route_1 = require("@itrocks/route");
33
+ const route_2 = require("@itrocks/route");
34
+ const sql_functions_1 = require("@itrocks/sql-functions");
35
+ const storage_1 = require("@itrocks/storage");
36
+ const store_1 = require("@itrocks/store");
37
+ const store_2 = require("@itrocks/store");
38
+ const string_formats_1 = require("@itrocks/string-formats");
39
+ const transformers_3 = require("@itrocks/string-formats/transformers");
40
+ const template_1 = require("@itrocks/template");
41
+ const template_insight_1 = require("@itrocks/template-insight");
42
+ const transformer_1 = require("@itrocks/transformer");
43
+ const transformer_2 = require("@itrocks/transformer");
44
+ const transformer_3 = require("@itrocks/transformer");
45
+ const translate_1 = require("@itrocks/translate");
46
+ const date_fns_1 = require("date-fns");
47
+ const node_path_1 = require("node:path");
48
+ const node_path_2 = require("node:path");
49
+ async function propertyOutput(object, property) {
50
+ return (0, transformer_1.applyTransformer)(await object[property], object, property, transformer_2.HTML, transformer_3.OUTPUT);
51
+ }
52
+ function bind() {
53
+ (0, class_view_1.classViewDependsOn)({ propertyOutput, requiredOf: required_1.requiredOf, tr: translate_1.tr });
54
+ if (config_1.config.dataSource) {
55
+ (0, storage_1.createDataSource)(config_1.config.dataSource);
56
+ }
57
+ (0, collection_1.initCollection)();
58
+ (0, core_transformers_1.initCoreTransformers)({
59
+ displayOf: property_view_1.displayOf,
60
+ fieldIdOf: rename_2.toCssId,
61
+ fieldNameOf: rename_2.toField,
62
+ formatDate: date => (0, date_fns_1.format)(date, (0, translate_1.tr)('dd/MM/yyyy', { ucFirst: false })),
63
+ ignoreTransformedValue: transformer_2.IGNORE,
64
+ parseDate: date => (0, date_fns_1.parse)(date, (0, translate_1.tr)('dd/MM/yyyy', { ucFirst: false }), new Date),
65
+ propertyOutput,
66
+ representativeValueOf: class_view_2.representativeValueOf,
67
+ routeOf: route_2.routeOf,
68
+ tr: translate_1.tr
69
+ });
70
+ (0, file_1.initFileTransformers)();
71
+ (0, list_properties_1.initListProperties)();
72
+ (0, property_view_2.initOrderedProperties)();
73
+ (0, string_formats_1.multilineDependsOn)({
74
+ setTransformers: transformers_3.setMultilineTransformers
75
+ });
76
+ (0, mysql_1.mysqlDependsOn)({
77
+ applyReadTransformer: async function (data, property, object) {
78
+ const value = await (0, transformer_1.applyTransformer)(data[property.toString()], object, property, transformer_3.SQL, transformer_3.READ, data);
79
+ if ((value !== transformer_2.IGNORE) && Reflect.getOwnMetadata(lazy_loading_2.PROTECT_GET, object, (0, property_1.metadataNameOf)(property))) {
80
+ Reflect.deleteMetadata(lazy_loading_2.PROTECT_GET, object, (0, property_1.metadataNameOf)(property));
81
+ }
82
+ return value;
83
+ },
84
+ applySaveTransformer: async function (object, property, data) {
85
+ const value = Reflect.getMetadata(lazy_loading_2.PROTECT_GET, object, (0, property_1.metadataNameOf)(property))
86
+ ? (Object.hasOwn(object, property) ? object[property] : undefined)
87
+ : await object[property];
88
+ return (0, transformer_1.applyTransformer)(value, object, property, transformer_3.SQL, transformer_3.SAVE, data);
89
+ },
90
+ columnOf: rename_1.toColumn,
91
+ componentOf: composition_1.componentOf,
92
+ ignoreTransformedValue: transformer_2.IGNORE,
93
+ QueryFunction: sql_functions_1.SqlFunction,
94
+ queryFunctionCall: value => [value.value, value.sql],
95
+ storeOf: store_2.storeOf
96
+ });
97
+ (0, password_1.passwordDependsOn)({
98
+ setTransformers: transformers_1.setPasswordTransformers
99
+ });
100
+ (0, route_1.routeDependsOn)({
101
+ calculate: (target) => route_2.routes.summarize((0, class_file_1.fileOf)(target).slice(app_dir_1.appDir.length, -3))
102
+ });
103
+ (0, property_translate_1.propertyTranslateDependsOn)({
104
+ setTransformers: transformers_2.setPropertyTranslateTransformers
105
+ });
106
+ (0, store_1.storeDependsOn)({
107
+ setTransformers: core_transformers_2.initStoreTransformers,
108
+ toStoreName: rename_1.toColumn
109
+ });
110
+ (0, template_1.templateDependsOn)({
111
+ toString: async (data) => (((typeof data)[0] === 'o') && (data.toString === Object.prototype.toString))
112
+ ? (await require('@itrocks/class-view').representativeValueOf(data))
113
+ : '' + data
114
+ });
115
+ (0, translate_1.trInit)('fr-FR');
116
+ (0, translate_1.trLoad)((0, node_path_1.join)(__dirname, '..', 'fr-FR.csv')).catch();
117
+ (0, translate_1.trLoad)((0, node_path_1.join)(app_dir_1.appDir, 'app', 'fr-FR.csv')).catch();
118
+ (0, translate_1.trLoad)((0, node_path_1.join)(app_dir_1.appDir, 'fr-FR.csv')).catch();
119
+ action_1.Action.prototype.htmlTemplateResponse = async function (data, request, templateFile, statusCode = 200, headers = {}) {
120
+ const containerData = Object.assign(defaultContainerData(request), this);
121
+ const contained = !request.request.headers['xhr-info'] && config_1.config.container?.file;
122
+ const template = new template_insight_1.Template(data, containerData);
123
+ return this.htmlResponse(await template.parseFile(templateFile, contained && (0, node_path_1.join)(app_dir_1.appDir, config_1.config.container.file)), statusCode, headers);
124
+ };
125
+ }
126
+ function configContainerData() {
127
+ const configContainerData = config_1.config.container?.data ?? {};
128
+ for (const [name, value] of Object.entries(configContainerData)) {
129
+ if ((typeof value === 'string') && '@.'.includes(value[0])) {
130
+ const exported = value.includes(':')
131
+ ? require(value.split(':')[0])[value.split(':')[1]]
132
+ : (require(value).default ?? Object.values(require(value))[0]);
133
+ configContainerData[name] =
134
+ (0, class_type_1.isAnyFunction)(exported) ? exported(config_1.config[name]) :
135
+ (0, class_type_2.isAnyType)(exported) ? new exported(config_1.config[name]) :
136
+ exported;
137
+ }
138
+ }
139
+ return configContainerData;
140
+ }
141
+ function defaultContainerData(request) {
142
+ return Object.assign({
143
+ action: request.action,
144
+ favicon: config_1.config.container?.favicon ?? (0, node_path_2.normalize)((0, node_path_1.join)(__dirname, '../favicon.ico')),
145
+ manifest: config_1.config.container?.manifest ? [config_1.config.container.manifest] : [],
146
+ request,
147
+ scripts: config_1.config.container?.scripts,
148
+ session: request.request.session,
149
+ styleSheets: config_1.config.container?.styleSheets,
150
+ }, configContainerData());
151
+ }
152
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1,4 @@
1
+ import '@itrocks/class-file/automation';
2
+ export { servers } from './main';
3
+ export { ReflectClass } from './reflect-class';
4
+ export { ReflectProperty } from './reflect-property';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReflectProperty = exports.ReflectClass = exports.servers = void 0;
4
+ require("@itrocks/class-file/automation");
5
+ const compose_1 = require("@itrocks/compose");
6
+ const config_1 = require("@itrocks/config");
7
+ const config_2 = require("@itrocks/config");
8
+ var main_1 = require("./main");
9
+ Object.defineProperty(exports, "servers", { enumerable: true, get: function () { return main_1.servers; } });
10
+ var reflect_class_1 = require("./reflect-class");
11
+ Object.defineProperty(exports, "ReflectClass", { enumerable: true, get: function () { return reflect_class_1.ReflectClass; } });
12
+ var reflect_property_1 = require("./reflect-property");
13
+ Object.defineProperty(exports, "ReflectProperty", { enumerable: true, get: function () { return reflect_property_1.ReflectProperty; } });
14
+ (0, config_2.scanConfigFiles)().then(() => {
15
+ const frameworkCompose = {
16
+ '@itrocks/store:Store': '/store-representative:Store'
17
+ };
18
+ (0, compose_1.compose)(__dirname, Object.assign(frameworkCompose, config_1.config.compose));
19
+ require('@itrocks/default-action-workflow').build();
20
+ require('./dependencies').bind();
21
+ require('./main').run();
22
+ });
23
+ //# sourceMappingURL=framework.js.map
package/cjs/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function run(): Promise<void>;
2
+ export declare const servers: {
3
+ stop: () => void;
4
+ }[];
package/cjs/main.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.servers = void 0;
4
+ exports.run = run;
5
+ const action_1 = require("@itrocks/action");
6
+ const action_2 = require("@itrocks/action");
7
+ const action_request_1 = require("@itrocks/action-request");
8
+ const action_request_2 = require("@itrocks/action-request");
9
+ const app_dir_1 = require("@itrocks/app-dir");
10
+ const class_type_1 = require("@itrocks/class-type");
11
+ const config_1 = require("@itrocks/config");
12
+ const fastify_1 = require("@itrocks/fastify");
13
+ const fastify_file_session_store_1 = require("@itrocks/fastify-file-session-store");
14
+ const request_response_1 = require("@itrocks/request-response");
15
+ const route_1 = require("@itrocks/route");
16
+ const store_1 = require("@itrocks/store");
17
+ const template_1 = require("@itrocks/template");
18
+ const node_path_1 = require("node:path");
19
+ const node_path_2 = require("node:path");
20
+ template_1.frontScripts.push('/lib/air-datepicker/locale/en.js', '/lib/air-datepicker/locale/fr.js');
21
+ async function execute(request) {
22
+ // Access control
23
+ if ((config_1.config.access?.free !== '*')
24
+ && !request.request.session.user
25
+ && !config_1.config.access?.free?.includes(request.route + '/' + request.action)) {
26
+ request.action = 'login';
27
+ request.route = '/user';
28
+ }
29
+ // Resolve action class or function module
30
+ const module = route_1.routes.resolve(request.route + '/' + request.action);
31
+ // undefined module
32
+ if (!module) {
33
+ console.error('Action ' + request.route + '/' + request.action + ' not found');
34
+ throw 'Action ' + request.route + '/' + request.action + ' not found';
35
+ }
36
+ // ActionClass module
37
+ if ((0, class_type_1.isAnyType)(module)) {
38
+ const action = (new module);
39
+ if (request.format in action) {
40
+ const need = (0, action_2.needOf)(action);
41
+ if (need.alternative
42
+ && (need.alternative !== request.action)
43
+ && (((need.need === 'object') && !request.ids.length)
44
+ || ((need.need === 'Store') && !(0, store_1.storeOf)(request.type)))) {
45
+ request.action = need.alternative;
46
+ return execute(request);
47
+ }
48
+ if ((need.need === 'object') && !request.ids.length && !request.request.data.confirm) {
49
+ console.error('Action ' + request.route + '/' + request.action + ' needs at least one object');
50
+ throw 'Action ' + request.route + '/' + request.action + ' needs at least one ';
51
+ }
52
+ return toResponse(await action[request.format](request));
53
+ }
54
+ }
55
+ // ActionFunction module
56
+ return toResponse(await module(request));
57
+ }
58
+ async function run() {
59
+ await (0, route_1.loadRoutes)(route_1.routes, config_1.config.routes ?? {});
60
+ (0, action_request_1.actionRequestDependsOn)({
61
+ getModule: route_1.routes.resolve.bind(route_1.routes),
62
+ isDomainObject: object => (0, class_type_1.isAnyType)(object) && !(object.prototype instanceof action_1.Action)
63
+ });
64
+ const server = new fastify_1.FastifyServer({
65
+ assetPath: app_dir_1.appDir,
66
+ execute: request => execute(new action_request_2.Request(request)),
67
+ favicon: config_1.config.container?.favicon ?? (0, node_path_2.normalize)((0, node_path_1.join)(__dirname, '../favicon.png')),
68
+ frontScripts: template_1.frontScripts,
69
+ host: config_1.config.server.host,
70
+ manifest: config_1.config.container?.manifest,
71
+ port: config_1.config.server.port,
72
+ scriptCalls: ['loadCss', 'loadScript'],
73
+ secret: config_1.config.session.secret ?? config_1.config.secret ?? 'defaultSecretHaving32CharactersOrGreater',
74
+ secure: config_1.config.server.secure ?? 'auto',
75
+ store: new fastify_file_session_store_1.FileStore((0, node_path_2.normalize)((0, node_path_1.join)(app_dir_1.appDir, config_1.config.session.path)))
76
+ });
77
+ server.run();
78
+ exports.servers.push(server);
79
+ }
80
+ exports.servers = new Array();
81
+ function toResponse(mixedResponse) {
82
+ return (typeof mixedResponse === 'string')
83
+ ? new request_response_1.Response(mixedResponse)
84
+ : mixedResponse;
85
+ }
86
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,10 @@
1
+ import { PropertyTypes } from '@itrocks/property-type';
2
+ import { ReflectClass as RC } from '@itrocks/reflect';
3
+ import { ReflectProperty } from './reflect-property';
4
+ export declare class ReflectClass<T extends object = object> extends RC<T> {
5
+ inheritPropertyTypes(propertyTypes: PropertyTypes<T>): void;
6
+ get parent(): ReflectClass | null;
7
+ get properties(): ReflectProperty<T, keyof T>[];
8
+ get property(): { [K in keyof T]: ReflectProperty<T, K>; };
9
+ get uses(): import("@itrocks/class-type").Type[];
10
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReflectClass = void 0;
4
+ const reflect_1 = require("@itrocks/reflect");
5
+ const uses_1 = require("@itrocks/uses");
6
+ const reflect_property_1 = require("./reflect-property");
7
+ class ReflectClass extends reflect_1.ReflectClass {
8
+ inheritPropertyTypes(propertyTypes) {
9
+ super.inheritPropertyTypes(propertyTypes);
10
+ for (const uses of this.uses) {
11
+ Object.assign(propertyTypes, new ReflectClass(uses).propertyTypes);
12
+ }
13
+ }
14
+ get parent() {
15
+ const parentType = Object.getPrototypeOf(this.type);
16
+ const parent = (parentType === Function.prototype) ? null : new ReflectClass(parentType);
17
+ Object.defineProperty(this, 'parent', { configurable: true, enumerable: false, value: parent, writable: true });
18
+ return parent;
19
+ }
20
+ get properties() {
21
+ const properties = new Array;
22
+ for (const name of this.propertyNames) {
23
+ properties.push(new reflect_property_1.ReflectProperty(this, name));
24
+ }
25
+ Object.defineProperty(this, 'properties', { configurable: true, enumerable: false, value: properties, writable: true });
26
+ return properties;
27
+ }
28
+ get property() {
29
+ const properties = {};
30
+ for (const property of this.properties) {
31
+ properties[property.name] = property;
32
+ }
33
+ Object.defineProperty(this, 'property', { configurable: true, enumerable: false, value: properties, writable: true });
34
+ return properties;
35
+ }
36
+ get uses() {
37
+ const value = (0, uses_1.usesOf)(this.type);
38
+ Object.defineProperty(this, 'uses', { configurable: true, enumerable: false, value, writable: true });
39
+ return value;
40
+ }
41
+ }
42
+ exports.ReflectClass = ReflectClass;
43
+ //# sourceMappingURL=reflect-class.js.map
@@ -0,0 +1,10 @@
1
+ import { HtmlContainer } from '@itrocks/core-transformers';
2
+ import { ReflectProperty as RP } from '@itrocks/reflect';
3
+ import { ReflectClass } from './reflect-class';
4
+ export declare class ReflectProperty<T extends object, K extends keyof T = keyof T> extends RP<T, K> {
5
+ get class(): ReflectClass<T>;
6
+ edit(format?: string): Promise<any>;
7
+ output(format?: string, askFor?: HtmlContainer): Promise<any>;
8
+ outputMandatoryContainer(format?: string): Promise<any>;
9
+ outputOptionalContainer(format?: string): Promise<any>;
10
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReflectProperty = void 0;
4
+ const core_transformers_1 = require("@itrocks/core-transformers");
5
+ const reflect_1 = require("@itrocks/reflect");
6
+ const transformer_1 = require("@itrocks/transformer");
7
+ const transformer_2 = require("@itrocks/transformer");
8
+ const reflect_class_1 = require("./reflect-class");
9
+ class ReflectProperty extends reflect_1.ReflectProperty {
10
+ get class() {
11
+ const value = super.class;
12
+ Object.defineProperty(this, 'class', { configurable: true, enumerable: false, value, writable: true });
13
+ return value ? new reflect_class_1.ReflectClass(value.object ?? value.type) : value;
14
+ }
15
+ async edit(format = transformer_2.HTML) {
16
+ const object = this.object ?? this.class.type;
17
+ const value = this.object ? this.object[this.name] : undefined;
18
+ return (0, transformer_1.applyTransformer)(await value, object, this.name, format, transformer_2.EDIT);
19
+ }
20
+ async output(format = transformer_2.HTML, askFor) {
21
+ const object = this.object ?? this.class.type;
22
+ const value = this.object ? await this.object[this.name] : undefined;
23
+ return (0, transformer_1.applyTransformer)(value, object, this.name, format, transformer_2.OUTPUT, askFor);
24
+ }
25
+ async outputMandatoryContainer(format = transformer_2.HTML) {
26
+ return this.output(format, new core_transformers_1.HtmlContainer(true));
27
+ }
28
+ async outputOptionalContainer(format = transformer_2.HTML) {
29
+ return this.output(format, new core_transformers_1.HtmlContainer(false));
30
+ }
31
+ }
32
+ exports.ReflectProperty = ReflectProperty;
33
+ //# sourceMappingURL=reflect-property.js.map
@@ -0,0 +1,2 @@
1
+ import { Type } from '@itrocks/class-type';
2
+ export declare function Store(name?: string | false): (target: Type) => void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Store = Store;
4
+ const class_view_1 = require("@itrocks/class-view");
5
+ const store_1 = require("@itrocks/store");
6
+ function Store(name = '') {
7
+ const callBack = (0, store_1.Store)(name);
8
+ return function (target) {
9
+ (0, class_view_1.representativeOf)(target);
10
+ callBack(target);
11
+ };
12
+ }
13
+ //# sourceMappingURL=store-representative.js.map
package/package.json CHANGED
@@ -69,6 +69,8 @@
69
69
  "favicon.png",
70
70
  "LICENSE",
71
71
  "README.md",
72
+ "cjs",
73
+ "!*.map",
72
74
  "*.csv",
73
75
  "*.d.ts",
74
76
  "*.js"
@@ -97,5 +99,5 @@
97
99
  "build:back": "tsc",
98
100
  "build:front": "tsc -p src/front/tsconfig.json && sed -i 's#../../##g' *.js *.d.ts"
99
101
  },
100
- "version": "0.3.11"
102
+ "version": "0.3.12"
101
103
  }