Skip to content

Commit

Permalink
[Templates] Use ES6 imports instead of require (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuF authored Sep 11, 2024
1 parent 158404f commit 800b131
Show file tree
Hide file tree
Showing 91 changed files with 684 additions and 595 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { Request, Response, Upload } from "sdk/http";

var upload = require('http/upload');
var request = require('http/request');
var response = require('http/response');

if (request.getMethod() === "POST") {
if (upload.isMultipartContent()) {
var fileItems = upload.parseRequest();
for (i=0; i<fileItems.size(); i++) {
var fileItem = fileItems.get(i);
if (!fileItem.isFormField()) {
response.println("File Name: " + fileItem.getName());
response.println("File Bytes (as text): " + String.fromCharCode.apply(null, fileItem.getBytes()));
} else {
response.println("Field Name: " + fileItem.getFieldName());
response.println("Field Text: " + fileItem.getText());
}
}
} else {
response.println("The request's content must be 'multipart'");
}
} else if (request.getMethod() === "GET") {
response.println("Use POST request.");
if (Request.getMethod() === "POST") {
if (Upload.isMultipartContent()) {
const fileItems = Upload.parseRequest();
for (let i = 0; i < fileItems.size(); i++) {
var fileItem = fileItems.get(i);
if (!fileItem.isEmpty()) {
Response.println("File Name: " + fileItem.getName());
Response.println("File Bytes (as text): " + String.fromCharCode.apply(null, fileItem.getBytes()));
} else {
Response.println("Field Name: " + fileItem.getName());
Response.println("Field Text: " + fileItem.getText());
}
}
} else {
Response.println("The request's content must be 'multipart'");
}
} else if (Request.getMethod() === "GET") {
Response.println("Use POST Request.");
}

response.flush();
response.close();
Response.flush();
Response.close();
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
const handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onError(__context.get("error"));
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
const handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onMessage(__context.get("message"));
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onClose();
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onError(__context.get("error"));
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onMessage(__context.get("message"), __context.get("from"));
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

handler.onOpen();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
var handler = require(__context.get("handler"));
let handler;

try {
// Fallback to require()
handler = dirigibleRequire(__context.get("handler"));
} catch (e) {
handler = await import(__context.get("handler"));
}

if (__context.get("method") === 'create') {
if (__context.get("type") === 'before') {
handler.onBeforeCreate(__context);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/
// Deprecated

let rs = require('http/rs');
let configurations = require('core/configurations');
import { rs } from 'sdk/http';
import { Configurations } from 'sdk/core';

let DIRIGIBLE_BRANDING_NAME = 'DIRIGIBLE_BRANDING_NAME';
let DIRIGIBLE_BRANDING_BRAND = 'DIRIGIBLE_BRANDING_BRAND';
Expand All @@ -32,12 +32,12 @@ rs.service()
.resource('')
.get(function (ctx, request, response) {
let branding = {
'name': configurations.get(DIRIGIBLE_BRANDING_NAME, DIRIGIBLE_BRANDING_NAME_DEFAULT),
'brand': configurations.get(DIRIGIBLE_BRANDING_BRAND, DIRIGIBLE_BRANDING_BRAND_DEFAULT),
'brandUrl': configurations.get(DIRIGIBLE_BRANDING_BRAND_URL, DIRIGIBLE_BRANDING_BRAND_URL_DEFAULT),
'icon': configurations.get(DIRIGIBLE_BRANDING_ICON, DIRIGIBLE_BRANDING_ICON_DEFAULT),
'logo': configurations.get(DIRIGIBLE_BRANDING_LOGO, DIRIGIBLE_BRANDING_LOGO_DEFAULT),
'welcomePage': configurations.get(DIRIGIBLE_BRANDING_WELCOME_PAGE, DIRIGIBLE_BRANDING_WELCOME_PAGE_DEFAULT)
'name': Configurations.get(DIRIGIBLE_BRANDING_NAME, DIRIGIBLE_BRANDING_NAME_DEFAULT),
'brand': Configurations.get(DIRIGIBLE_BRANDING_BRAND, DIRIGIBLE_BRANDING_BRAND_DEFAULT),
'brandUrl': Configurations.get(DIRIGIBLE_BRANDING_BRAND_URL, DIRIGIBLE_BRANDING_BRAND_URL_DEFAULT),
'icon': Configurations.get(DIRIGIBLE_BRANDING_ICON, DIRIGIBLE_BRANDING_ICON_DEFAULT),
'logo': Configurations.get(DIRIGIBLE_BRANDING_LOGO, DIRIGIBLE_BRANDING_LOGO_DEFAULT),
'welcomePage': Configurations.get(DIRIGIBLE_BRANDING_WELCOME_PAGE, DIRIGIBLE_BRANDING_WELCOME_PAGE_DEFAULT)
};
response.println(JSON.stringify(branding));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.getTemplate = function () {
export function getTemplate() {
return {
"name": "csvim",
"label": "CSVIM file",
"extension": "csvim",
"data": '[]'
name: "csvim",
label: "CSVIM file",
extension: "csvim",
data: "[]"
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.getTemplate = function () {
let template = {
"name": "database-table",
"label": "Database Table",
"extension": "table",
"data": '{"name":"MYTABLE","type":"TABLE","columns":[{"name":"ID","type":"INTEGER","length":"0","nullable":"false","primaryKey":"true","defaultValue":""}]}'
export function getTemplate() {
return {
name: "database-table",
label: "Database Table",
extension: "table",
data: JSON.stringify({
name: "MYTABLE",
type: "TABLE",
columns: [
{
name: "ID",
type: "INTEGER",
length: "0",
nullable: "false",
primaryKey: "true",
defaultValue: ""
}
]
}, null, 4)
};
return template;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.getTemplate = function () {
let template = {
"name": "database-view",
"label": "Database View",
"extension": "view",
"data": '{"name":"MYVIEW","type":"VIEW","query":"SELECT * FROM MYTABLE","dependencies":[{"name":"MYTABLE","type":"TABLE"}]}'
export function getTemplate() {
return {
name: "database-view",
label: "Database View",
extension: "view",
data: JSON.stringify({
name: "MYVIEW",
type: "VIEW",
query: "SELECT * FROM MYTABLE",
dependencies: [
{
name: "MYTABLE",
type: "TABLE"
}
]
}, null, 4)
};
return template;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.getView = function () {
export function getView() {
return {
id: "documents-constraints",
name: "Constraints",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.getTemplate = function () {
let template = {
"name": "edm",
"label": "Entity Data Model",
"extension": "edm",
"data": '<model><entities></entities><mxGraphModel><root></root></mxGraphModel></model>',
"order": 10
export function getTemplate() {
return {
name: "edm",
label: "Entity Data Model",
extension: "edm",
data: '<model><entities></entities><mxGraphModel><root></root></mxGraphModel></model>',
order: 10
};
return template;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
const transformer = require("ide-entity/template/transform-edm");
import * as transformer from "ide-entity/template/transform-edm";

exports.generate = function (model, parameters) {
export function generate(model, parameters) {
let workspaceName = parameters.workspaceName;
let projectName = parameters.projectName;
let filePath = parameters.filePath;
Expand All @@ -22,13 +22,12 @@ exports.generate = function (model, parameters) {
}]
};

exports.getTemplate = function () {
let template = {
"name": "Entity Data to JSON Model Transformer",
"description": "Model transformer template",
"extension": "edm",
"sources": [],
"parameters": []
};
return template;
export function getTemplate() {
return {
name: "Entity Data to JSON Model Transformer",
description: "Model transformer template",
extension: "edm",
sources: [],
parameters: []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
* SPDX-FileCopyrightText: Eclipse Dirigible contributors
* SPDX-License-Identifier: EPL-2.0
*/
exports.transform = function (workspaceName, projectName, filePath) {

import { Workspace as workspaceManager } from "sdk/platform";
import { Bytes } from "sdk/io";
import { XML } from "sdk/utils";

export function transform(workspaceName, projectName, filePath) {

if (!filePath.endsWith('.edm')) {
return null;
}

let workspaceManager = require("platform/workspace");
let contents = workspaceManager.getWorkspace(workspaceName)
.getProject(projectName).getFile(filePath).getContent();

let bytes = require("io/bytes");
contents = bytes.byteArrayToText(contents);
contents = Bytes.byteArrayToText(contents);

let xml = require("utils/xml");
let raw = JSON.parse(xml.toJson(contents));
let raw = JSON.parse(XML.toJson(contents));

let root = {};
root.model = {};
Expand Down
Loading

0 comments on commit 800b131

Please sign in to comment.