// hello.ts
// My first Typescript Hello on MLE.
export async function hello( req:any, resp:any ) {
resp.content_type('text/plain');
resp.status(200);
resp.send('Hello World - TypeScript !');
}
% curl http://localhost:8181/ords/apexdev/tshello/tshello
Hello World - TypeScript !
%
grant execute on javascript to [APEXワークスペース名];
grant execute dynamic mle to [APEXワークスペース名];
grant create mle to [APEXワークスペース名];
cd ts-hello
npm init -y
% npm -v
10.9.2
% mkdir ts-hello
% cd ts-hello
ts-hello % npm init -y
Wrote to /Users/username/Documents/ts-hello/package.json:
{
"name": "ts-hello",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
ts-hello %
npm install --save-dev typescript rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs @rollup/plugin-typescript tslib
ts-hello % npm install --save-dev typescript rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs @rollup/plugin-typescript tslib
added 2 packages, and audited 27 packages in 2s
5 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
ts-hello %
ts-hello % npx tsc --init
Created a new tsconfig.json with:
TS
target: es2016
module: commonjs
strict: true
esModuleInterop: true
skipLibCheck: true
forceConsistentCasingInFileNames: true
You can learn more at https://aka.ms/tsconfig
ts-hello %
ここからはフォルダts-helloをVS Codeで開いて作業を進めます。
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"outDir": "dist",
"esModuleInterop": true,
"strict": true
},
"include": ["src"]
}
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
export default {
input: "src/hello.ts",
output: {
format: "esm",
},
plugins: [resolve(), commonjs(), typescript()],
};
// hello.ts
// My first Typescript Hello on MLE.
export async function hello( req:any, resp:any ) {
resp.content_type('text/plain');
resp.status(200);
resp.send('Hello World - TypeScript !');
}
declare | |
l_exists integer; | |
l_module_id user_ords_modules.id%type; | |
l_template_id user_ords_templates.id%type; | |
begin | |
/* prepare ords module for tshello */ | |
begin | |
select id into l_module_id from user_ords_modules where name = 'tshello'; | |
dbms_output.put_line('Module tshello exists'); | |
exception | |
when no_data_found then | |
/* create tshello module */ | |
ords.define_module( | |
p_module_name => 'tshello' | |
,p_base_path => '/tshello/' | |
,p_items_per_page => 25 | |
,p_status => 'PUBLISHED' | |
,p_comments => null | |
); | |
select id into l_module_id from user_ords_modules where name = 'tshello'; | |
dbms_output.put_line('Module tshello created'); | |
end; | |
/* prepare ords template for tshello */ | |
begin | |
/* l_template_id is never be used for handler definition */ | |
select id into l_template_id from user_ords_templates where uri_template = 'tshello' and module_id = l_module_id; | |
dbms_output.put_line('Template tshello exists'); | |
exception | |
when no_data_found then | |
/* create tshello template */ | |
ords.define_template( | |
p_module_name => 'tshello' | |
,p_pattern => 'tshello' | |
,p_priority => 0 | |
,p_comments => null | |
); | |
select id into l_template_id from user_ords_templates where uri_template = 'tshello' and module_id = l_module_id; | |
dbms_output.put_line('Template tshello created'); | |
end; | |
/* define handler */ | |
ords.define_handler( | |
p_module_name => 'tshello' | |
,p_pattern => 'tshello' | |
,p_method => 'GET' | |
,p_source_type => 'mle/javascript' | |
,p_mle_env_name => 'TS_HELLO_ENV' | |
,p_source => | |
q'~ | |
( req, resp ) => { | |
const { hello } = await import('tshello'); | |
await hello( req, resp ); | |
}~' | |
,p_comments => null | |
); | |
dbms_output.put_line('GET Handler for template tshello created or updated'); | |
end; | |
/ | |
commit; |
( req, resp ) => {
const { hello } = await import('tshello');
await hello( req, resp );
}
mle create-module -bundler rollup -bundler-config rollup.config.mjs -filename src/hello.ts -module-name TS_HELLO -replace
Module tshello created
Template tshello created
GET Handler for template tshello created or updated
PL/SQLプロシージャが正常に完了しました。
コミットが完了しました。
curl http[s]://ホスト名:ポート番号/ords/ワークスペース別名/tshello/tshello
% curl http://localhost:8181/ords/apexdev/tshello/tshello
Hello World - TypeScript !%
// hello.ts
// My first Typescript Hello on MLE.
export async function hello( req:any, resp:any ) {
resp.content_type('text/plain');
resp.status(200);
resp.send('Hello World Again - TypeScript !');
}
% curl http://localhost:8181/ords/apexdev/tshello/tshello
Hello World Again - TypeScript !%